/* Calendar (.cal-): toolbar, month grid, week/day time grid, the
   "Chưa có hạn" panel and the create / day popovers. */

.cal-page { height: 100%; min-height: 540px; display: flex; flex-direction: column; }
.cal-page > [data-content] { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.cal-mine-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; padding: 20px 20px 10px; }
.cal-shell { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.cal-toolbar { display: flex; align-items: center; gap: 8px; padding: 10px 20px; flex-wrap: wrap; }
.cal-title { margin-left: 4px; font-size: 18px; font-weight: 600; letter-spacing: -.01em; white-space: nowrap; }
.cal-side-toggle { display: none; }
.cal-body { flex: 1; min-height: 0; display: flex; border-top: 1px solid var(--line); }
.cal-main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--surface); }

/* ---------- Items ---------- */
.cal-item { --pc: var(--brand); cursor: pointer; user-select: none; -webkit-user-select: none; font-size: 12px; line-height: 1.25; min-width: 0; }
.cal-item.is-done { opacity: .55; }
.cal-item.is-done .cal-label { text-decoration: line-through; }
.cal-item:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.cal-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.cal-time { flex: none; font-weight: 500; color: var(--text-2); font-variant-numeric: tabular-nums; }
.cal-prio { width: 6px; height: 6px; flex: none; border-radius: 50%; background: var(--p-high); }
.cal-prio-urgent { background: var(--p-urgent); }
.cal-dot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--pc); }
/* Calendar items: soft project tint + hairline ring, led by the logo drop mark in the project color. */
.cal-drop { width: 12px; height: 12px; flex: none; overflow: visible; }
.cal-drop .cal-drop-shape { fill: none; stroke: var(--pc); stroke-width: 46; }
.cal-drop.is-done .cal-drop-shape { fill: var(--pc); }
.cal-drop .cal-drop-tick { fill: none; stroke: #fff; stroke-width: 70; stroke-linecap: round; stroke-linejoin: round; }
.cal-bar { position: relative; z-index: 1; display: flex; align-items: center; gap: 6px; height: 20px; margin: 1px 3px; padding: 0 7px 0 6px; border-radius: var(--r-xs); background: color-mix(in srgb, var(--pc) 13%, var(--surface)); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--pc) 24%, transparent); color: var(--text); font-weight: 500; transition: box-shadow var(--dur), background var(--dur); }
.cal-bar:hover { background: color-mix(in srgb, var(--pc) 20%, var(--surface)); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--pc) 40%, transparent), var(--shadow-1); }
/* Multi-day bars read as one continuous ribbon: slightly stronger tint. */
.cal-bar.is-span { background: color-mix(in srgb, var(--pc) 22%, var(--surface)); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--pc) 38%, transparent); }
.cal-bar.clip-l { margin-left: 0; border-top-left-radius: 0; border-bottom-left-radius: 0; }
.cal-bar.clip-r { margin-right: 0; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.cal-sub { display: inline-flex; margin-left: auto; color: var(--text-3); }
.cal-mpill { position: relative; z-index: 1; display: flex; align-items: center; gap: 6px; height: 20px; margin: 1px 3px; padding: 0 6px; border-radius: var(--r-xs); color: var(--text); }
.cal-mpill:hover { background: var(--hover); }

/* ---------- Week / day time grid ---------- */
.cal-tg { --gut: 56px; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.cal-tg-head, .cal-tg-allday, .cal-tg-grid { display: grid; grid-template-columns: var(--gut) repeat(var(--n), minmax(0, 1fr)); }
.cal-tg-head, .cal-tg-allday { flex: none; overflow-y: auto; scrollbar-gutter: stable; }
.cal-tg-head { overflow: hidden; border-bottom: 1px solid var(--line); }
.cal-gutter { display: flex; align-items: flex-end; justify-content: center; padding-bottom: 8px; font-size: 10.5px; }
.cal-dayhead { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0; color: var(--text); }
.cal-dayhead-wd { font-size: 11.5px; font-weight: 500; color: var(--text-3); }
.cal-dayhead-num { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums; transition: background var(--dur); }
.cal-dayhead:hover .cal-dayhead-num { background: var(--hover); }
.cal-dayhead.is-today .cal-dayhead-wd { color: var(--brand-text); }
.cal-dayhead.is-today .cal-dayhead-num { background: var(--brand); color: #fff; }
.cal-dayhead.is-weekend:not(.is-today) .cal-dayhead-num { color: var(--text-2); }
.cal-mode-day .cal-dayhead { flex-direction: row; justify-content: flex-start; gap: 10px; padding-left: 14px; cursor: default; }
.cal-mode-day .cal-dayhead-wd { font-size: 13px; }
.cal-tg-allday { max-height: 132px; padding: 2px 0; border-bottom: 1px solid var(--line-strong); }
.cal-allday-label { grid-column: 1; grid-row: 1 / -1; display: flex; align-items: center; justify-content: flex-end; padding-right: 8px; font-size: 10.5px; color: var(--text-3); white-space: nowrap; }
.cal-allday-cell { border-left: 1px solid var(--line); cursor: cell; transition: background var(--dur); }
.cal-allday-cell.is-today { background: color-mix(in srgb, var(--brand) 4%, transparent); }
.cal-tg-scroll { flex: 1; min-height: 0; overflow-y: auto; scrollbar-gutter: stable; position: relative; }
.cal-tg-grid { position: relative; }
.cal-tg-hours { position: relative; }
.cal-tg-hours span { position: absolute; right: 8px; transform: translateY(-50%); font-size: 10.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.cal-tg-col { position: relative; border-left: 1px solid var(--line); cursor: cell;
  background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(color-mix(in srgb, var(--line) 45%, transparent) 1px, transparent 1px);
  background-size: 100% 48px, 100% 24px; }
.cal-tg-col.is-today { background-color: color-mix(in srgb, var(--brand) 3%, transparent); }
.cal-block { position: absolute; z-index: 2; margin-left: 2px; padding: 4px 7px; display: flex; flex-direction: column; gap: 1px; overflow: hidden; border-radius: var(--r-sm); background: color-mix(in srgb, var(--pc) 15%, var(--surface)); color: var(--text); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--pc) 28%, transparent), 0 0 0 1px var(--surface); transition: box-shadow var(--dur); }
.cal-block:hover { z-index: 3; box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--pc) 45%, transparent), 0 0 0 1px var(--surface), var(--shadow-2); }
.cal-block-title { display: flex; align-items: center; gap: 6px; min-width: 0; font-weight: 600; }
.cal-block-title .cal-drop { align-self: flex-start; margin-top: 3px; }
.cal-block-time { padding-left: 18px; }
.cal-block.is-short .cal-block-title .cal-drop { align-self: center; margin-top: 0; }
.cal-block.is-short .cal-block-time { padding-left: 0; }
.cal-block-title .cal-label { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.cal-block-time { font-size: 11px; color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.cal-block.is-short { flex-direction: row; align-items: center; gap: 6px; padding-top: 0; padding-bottom: 0; }
.cal-block.is-short .cal-block-title { min-width: 0; flex: 0 1 auto; }
.cal-block.is-short .cal-label { -webkit-line-clamp: 1; }
.cal-block.is-short .cal-block-time { flex: 0 100 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.cal-block.is-resizing { z-index: 5; box-shadow: var(--shadow-2); }
.cal-resize { position: absolute; left: 0; right: 0; bottom: 0; height: 8px; cursor: ns-resize; }
.cal-resize::after { content: ""; position: absolute; left: 50%; bottom: 2px; width: 18px; height: 3px; margin-left: -9px; border-radius: 2px; background: var(--pc); opacity: 0; transition: opacity var(--dur); }
.cal-block:hover .cal-resize::after { opacity: .75; }
.cal-now { position: absolute; left: -1px; right: 0; z-index: 4; height: 2px; background: var(--danger); pointer-events: none; }
.cal-now i { position: absolute; left: -5px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--danger); }
.cal-select, .cal-drop-preview { position: absolute; left: 2px; right: 4px; z-index: 3; padding: 3px 7px; border-radius: var(--r-sm); font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; pointer-events: none; }
.cal-select { background: var(--brand-soft-2); color: var(--brand-text); border: 1px solid var(--brand); box-shadow: var(--shadow-2); }
.cal-drop-preview { z-index: 6; display: flex; flex-direction: column; gap: 1px; overflow: hidden; background: color-mix(in srgb, var(--pc) 24%, var(--surface)); color: var(--text); box-shadow: inset 0 0 0 1.5px var(--pc), var(--shadow-drag); font-weight: 500; }
.cal-drop-preview b { font-weight: 600; font-size: 12px; }
.cal-ghost-hidden .cal-drag-ghost { opacity: 0; }
.cal-allday-cell.is-drop, .cal-mcell.is-drop, .cal-allday-cell.is-creating, .cal-mcell.is-creating { background: var(--brand-soft); }
.cal-shell.is-readonly .cal-tg-col, .cal-shell.is-readonly .cal-mcell, .cal-shell.is-readonly .cal-allday-cell { cursor: default; }

/* ---------- Month ---------- */
.cal-month { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.cal-month-head { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-bottom: 1px solid var(--line); }
.cal-month-head > span { padding: 8px 10px; font-size: 12px; font-weight: 500; color: var(--text-3); }
.cal-wd-s { display: none; }
.cal-month-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.cal-week { flex: 1; min-height: 112px; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-bottom: 1px solid var(--line); overflow: hidden; }
.cal-week:last-child { border-bottom: 0; }
.cal-mcell { padding: 4px 6px; border-left: 1px solid var(--line); cursor: cell; transition: background var(--dur); }
.cal-mcell:first-child { border-left: 0; }
.cal-mcell.is-weekend { background: color-mix(in srgb, var(--surface-2) 70%, var(--surface)); }
.cal-mcell.is-out { background: var(--surface-2); }
.cal-mcell.is-out .cal-mdate { color: var(--text-3); font-weight: 500; }
.cal-mdate { height: 22px; min-width: 22px; padding: 0 6px; border-radius: var(--r-pill); font-size: 12px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.cal-mdate:hover { background: var(--hover); }
.cal-mcell.is-today .cal-mdate { background: var(--brand); color: #fff; }
.cal-more { position: relative; z-index: 1; height: 18px; margin: 0 3px; padding: 0 6px; border-radius: var(--r-xs); font-size: 11.5px; font-weight: 600; color: var(--text-2); text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-more:hover { background: var(--hover); color: var(--text); }

/* ---------- "Chưa có hạn" panel ---------- */
.cal-side { width: 268px; flex: none; display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--line); background: var(--surface-2); transition: width var(--dur) var(--ease); }
.cal-side-head { display: flex; align-items: center; gap: 4px; padding: 10px 10px 6px; }
.cal-side-collapse { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 8px; border-radius: var(--r-sm); font-size: 13.5px; color: var(--text); }
.cal-side-collapse:hover { background: var(--hover); }
.cal-side-collapse > .ico:first-child { color: var(--text-2); }
.cal-side-chev { margin-left: auto; color: var(--text-3); }
.cal-side-close { display: none; }
.cal-side-body { flex: 1; min-height: 0; overflow-y: auto; padding: 0 10px 14px; }
.cal-side-body .hint { padding: 0 8px 10px; }
.cal-side.is-collapsed { width: 52px; }
.cal-side.is-collapsed .cal-side-body, .cal-side.is-collapsed .cal-side-collapse b { display: none; }
.cal-side.is-collapsed .cal-side-head { padding: 10px 6px; }
.cal-side.is-collapsed .cal-side-collapse { flex-direction: column; height: auto; gap: 6px; padding: 8px 0; justify-content: center; }
.cal-side.is-collapsed .cal-side-chev { margin: 0; }
.cal-un-list { display: flex; flex-direction: column; gap: 6px; }
.cal-un-item { display: flex; align-items: flex-start; gap: 4px; padding: 8px 10px 8px 4px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); font-size: 13px; cursor: grab; user-select: none; -webkit-user-select: none; transition: box-shadow var(--dur), border-color var(--dur); }
.cal-un-item:hover { border-color: color-mix(in srgb, var(--pc) 45%, var(--line)); box-shadow: var(--shadow-1); }
.cal-un-item:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.cal-un-grip { padding-top: 2px; color: var(--text-3); opacity: .55; }
.cal-un-title { display: flex; align-items: center; gap: 6px; min-width: 0; font-weight: 500; }
.cal-un-meta { display: flex; align-items: center; gap: 8px; margin-top: 2px; min-width: 0; font-size: 11.5px; color: var(--text-3); }
.cal-un-proj { display: inline-flex; align-items: center; gap: 5px; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.cal-un-proj i { width: 7px; height: 7px; flex: none; border-radius: 2px; background: var(--pc); }
.cal-un-empty { display: flex; align-items: center; gap: 8px; padding: 8px; font-size: 13px; color: var(--text-3); }
.cal-un-empty .ico { color: var(--success); }

/* ---------- Popovers ---------- */
.cal-create { width: 328px; max-width: calc(100vw - 24px); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.cal-create-title { height: 40px; font-size: 15px; font-weight: 500; }
.cal-create-row { display: flex; align-items: center; gap: 8px; font-size: 13px; min-width: 0; }
.cal-create-row > .ico { color: var(--text-3); }
.cal-create-row .select { height: 32px; }
.cal-create-foot { display: flex; align-items: center; justify-content: flex-end; gap: 6px; margin-top: 2px; }
.cal-create-foot .hint { margin-right: auto; color: var(--danger); }
.cal-daypop { width: 288px; max-width: calc(100vw - 24px); padding: 6px; }
.cal-daypop-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 6px 8px 8px; font-size: 13.5px; }
.cal-daypop-list { max-height: 320px; overflow-y: auto; }
.cal-daypop-item { display: flex; align-items: center; gap: 8px; width: 100%; height: 32px; padding: 0 8px; border-radius: var(--r-sm); font-size: 13px; text-align: left; }
.cal-daypop-item:hover { background: var(--hover); }
.cal-daypop-item .cal-label { flex: 1; }
.cal-daypop-item.is-done { opacity: .55; }
.cal-daypop-item.is-done .cal-label { text-decoration: line-through; }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .cal-page { height: auto; min-height: 100%; }
  .cal-tg-scroll { flex: none; height: 62vh; }
  .cal-month-body { flex: none; }
  .cal-mine-head { padding: 14px 16px 6px; }
  .cal-mine-head .mt-switch { width: 100%; }
  .cal-toolbar { padding: 8px 12px; gap: 6px; }
  .cal-title { flex: 1; min-width: 0; font-size: 15px; overflow: hidden; text-overflow: ellipsis; }
  .cal-toolbar .ml-auto { margin-left: 0; width: 100%; justify-content: space-between; }
  .cal-side-toggle { display: inline-flex; }
  .cal-side, .cal-side.is-collapsed { position: fixed; left: 0; right: 0; bottom: 60px; z-index: 75; width: auto; height: 56vh; border-left: 0; border-top: 1px solid var(--line); border-radius: var(--r-xl) var(--r-xl) 0 0; background: var(--surface); box-shadow: var(--shadow-3); transform: translateY(110%); visibility: hidden; transition: transform 220ms var(--ease), opacity var(--dur), visibility 0s 220ms; }
  .cal-side.is-mobile-open { transform: none; visibility: visible; transition: transform 220ms var(--ease), opacity var(--dur); }
  .cal-side.is-drag-out { opacity: 0; pointer-events: none; }
  .cal-side.is-collapsed .cal-side-body { display: block; }
  .cal-side.is-collapsed .cal-side-collapse b { display: inline; }
  .cal-side.is-collapsed .cal-side-collapse { flex-direction: row; height: 32px; padding: 0 8px; justify-content: flex-start; }
  .cal-side-close { display: inline-flex; }
  .cal-side-chev { display: none; }
  .cal-tg { --gut: 44px; }
  .cal-dayhead-num { width: 28px; height: 28px; font-size: 15px; }
  .cal-week { min-height: 86px; }
  .cal-mcell { padding: 2px; }
  .cal-month-head > span { padding: 6px 2px; text-align: center; font-size: 11px; }
  .cal-wd-l { display: none; } .cal-wd-s { display: inline; }
  .cal-mdate-m { display: none; }
  .cal-allday-label { padding-right: 4px; font-size: 9.5px; }
  .cal-bar, .cal-mpill { margin: 1px; padding: 0 4px; font-size: 11px; }
  .cal-mpill .cal-time { display: none; }
}
