/* Personal AI Office — component styles. Mọi giá trị lấy từ tokens (var(--…)). */
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--ground); color: var(--ink); font-family: var(--font-sans); font-size: 15px; line-height: 23px; -webkit-font-smoothing: antialiased; }
.num { font-family: var(--font-sans); font-variant-numeric: tabular-nums; }
.code { font-family: var(--font-mono); font-size: 13px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Button */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); min-height: var(--size-control); padding: 0 16px; border-radius: var(--radius-md); border: 1px solid transparent; font: 600 14px/20px var(--font-sans); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn--primary { background: var(--accent); color: var(--on-accent); }
.btn--secondary { background: var(--surface); color: var(--ink); border-color: var(--line-control); font-weight: 500; }
.btn--ghost { background: transparent; color: var(--ink-2); font-weight: 500; }
.btn--ghost:hover, .btn--secondary:hover { background: var(--surface-hover); }
.btn--danger { background: var(--surface); color: var(--danger); border-color: var(--line-control); font-weight: 500; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn--sm { min-height: 34px; padding: 0 12px; font-size: 13px; }
.btn--block { width: 100%; }
@media (max-width: 639px) { .btn--block-mobile { flex: 1; width: 100%; } }
@media (max-width: 639px) { .btn, .btn--sm { min-height: var(--size-touch); font-size: 15px; } }

/* Panel: khung trắng một lớp trên nền ground */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 6px var(--space-4) 6px; }
.panel > .field, .panel > div[style*="grid"] { padding-bottom: 10px; }
.panel > .section-head { padding-top: 8px; }
.panel .row:last-child, .panel .empty:last-child { border-bottom: 0; }
@media (max-width: 639px) { .panel { padding: 4px 14px 4px; } }

/* Field: label + input / select / textarea */
.field { display: flex; flex-direction: column; gap: 6px; }
.field__label { font: 600 13px/19px var(--font-sans); color: var(--ink-2); }
.field__hint { font: 400 13px/19px var(--font-sans); color: var(--ink-meta); }
.field__error { font: 500 13px/19px var(--font-sans); color: var(--danger); }
.input, .select, .textarea { width: 100%; min-height: var(--size-control); padding: 0 12px; border-radius: var(--radius-md); border: 1px solid var(--line-control); background: var(--surface); color: var(--ink); font: 400 15px/23px var(--font-sans); }
.textarea { padding: 8px 12px; min-height: 84px; resize: vertical; }
.select { appearance: none; padding-right: 32px; background-image: linear-gradient(45deg, transparent 50%, var(--ink-meta) 50%), linear-gradient(135deg, var(--ink-meta) 50%, transparent 50%); background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.input::placeholder, .textarea::placeholder { color: var(--ink-meta); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.input[aria-invalid="true"] { border-color: var(--danger); }
@media (max-width: 639px) { .input, .select, .textarea { min-height: var(--size-touch); font-size: 16px; } .field__hint { display: none; } }

/* Checkbox (button thật, aria-pressed) */
.check { width: 22px; height: 22px; flex-shrink: 0; padding: 0; border-radius: var(--radius-sm); border: 1.5px solid var(--line-control); background: var(--surface); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; position: relative; }
.check svg { display: none; width: 14px; height: 14px; }
.check[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); }
.check[aria-pressed="true"] svg { display: block; }
.check::after { content: ""; position: absolute; inset: -11px; } /* vùng chạm 44px */

/* StatusDot */
.dot { display: inline-flex; align-items: center; gap: 6px; font: 500 13px/19px var(--font-sans); color: var(--ink); white-space: nowrap; }
.dot::before { content: ""; width: 8px; height: 8px; border-radius: var(--radius-full); background: var(--ink-meta); flex-shrink: 0; }
.dot--success { color: var(--success); } .dot--success::before { background: var(--success); }
.dot--warning { color: var(--warning); } .dot--warning::before { background: var(--warning); }
.dot--danger { color: var(--danger); } .dot--danger::before { background: var(--danger); }
.dot--accent::before { background: var(--accent); }

/* ScopeBadge */
.scope { display: inline-flex; align-items: center; gap: 6px; font: 400 13px/19px var(--font-sans); color: var(--ink-meta); white-space: nowrap; }
.scope::before { content: ""; width: 7px; height: 7px; border-radius: var(--radius-full); background: var(--scope-public); }
.scope--work::before { background: var(--scope-work); }
.scope--personal::before { background: var(--scope-personal); }
.scope--family::before { background: var(--scope-family); }
.scope--project::before { background: var(--scope-project); }

/* SectionHeader */
.section-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding-bottom: var(--space-2); border-bottom: 1px solid var(--line); }
.section-head__title { margin: 0; display: inline-flex; align-items: center; gap: 6px; font: 600 14px/20px var(--font-sans); color: var(--ink); }
.section-head__count { font: 600 13px/19px var(--font-sans); font-variant-numeric: tabular-nums; color: var(--warning); }
.section-head a { font: 500 14px/20px var(--font-sans); color: var(--accent); text-decoration: none; min-height: 32px; display: inline-flex; align-items: center; }

/* ListRow */
.row { min-height: var(--size-row); padding: 10px 0; border-bottom: 1px solid var(--line-row); display: flex; align-items: center; gap: 12px; }
.row__time { font: 500 13px/19px var(--font-sans); font-variant-numeric: tabular-nums; color: var(--ink-meta); flex-shrink: 0; min-width: 44px; }
.row__time--warning { color: var(--warning); }
.row__time--danger { color: var(--danger); }
.row__main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.row__title { font: 500 15px/22px var(--font-sans); color: var(--ink); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.row__sub { font: 400 13px/19px var(--font-sans); color: var(--ink-meta); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row__meta { display: flex; align-items: center; gap: 16px; flex-shrink: 0; font: 400 13px/19px var(--font-sans); color: var(--ink-meta); }
.row--done .row__title { color: var(--ink-meta); text-decoration: line-through; }
@media (max-width: 639px) {
  .row { padding: 12px 0; align-items: flex-start; }
  .row .check { margin-top: 1px; }
  .row__time { line-height: 24px; }
  .row__title { font-size: 16px; line-height: 24px; }
  .row__meta { display: none; }
}

/* Tabs (bộ lọc, một hàng cuộn ngang) và Segmented (chọn 2–3 chế độ) */
.tabs { display: flex; gap: var(--space-1); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs__item { padding: 8px 12px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--ink-2); font: 500 14px/20px var(--font-sans); cursor: pointer; white-space: nowrap; min-height: 40px; }
.tabs__item[aria-selected="true"] { border-bottom-color: var(--accent); color: var(--ink); font-weight: 600; }
.segmented { display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px; padding: 3px; border-radius: var(--radius-lg); background: var(--surface-nav); }
.segmented__item { min-height: 34px; padding: 0 14px; border: 0; border-radius: var(--radius-md); background: transparent; color: var(--ink-2); font: 500 14px/20px var(--font-sans); cursor: pointer; white-space: nowrap; }
.segmented__item[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow-xs); }
@media (max-width: 639px) { .tabs__item, .segmented__item { min-height: var(--size-touch); font-size: 15px; } }

/* InfoTip (nút !) */
.tip { position: relative; display: inline-flex; }
.tip__btn { width: 24px; height: 24px; padding: 0; border-radius: var(--radius-full); border: 1px solid var(--line-control); background: var(--surface); color: var(--ink-2); font: 700 13px/1 var(--font-sans); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; position: relative; }
.tip__btn::after { content: ""; position: absolute; inset: -10px; }
.tip__btn[aria-expanded="true"] { background: var(--tip-bg); border-color: var(--tip-bg); color: var(--on-accent); }
.tip__pop { position: absolute; top: 30px; left: 0; z-index: 50; width: 288px; max-width: calc(100vw - 32px); padding: 12px 14px; border-radius: var(--radius-lg); background: var(--tip-bg); color: var(--tip-ink); box-shadow: var(--shadow-pop); font: 400 13.5px/20px var(--font-sans); }
.tip__pop[hidden] { display: none; }
.tip--right .tip__pop { left: auto; right: 0; }
.tip__pop strong { display: block; margin-bottom: 4px; color: var(--on-accent); font-weight: 600; }

/* Banner */
.banner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); padding: 14px 16px; border-radius: var(--radius-lg); border: 1px solid var(--warning-line); background: var(--warning-bg); }
.banner__text { display: flex; align-items: center; gap: 10px; font: 500 15px/22px var(--font-sans); color: var(--ink); }
.banner__text .num { font-weight: 600; }
@media (max-width: 639px) { .banner > div:last-child { width: 100%; } .banner > div:last-child .btn { flex: 1; } }

/* EmptyState */
.empty { padding: var(--space-6) 0; border-bottom: 1px solid var(--line-row); display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-2); }
.empty__title { margin: 0; font: 500 15px/22px var(--font-sans); color: var(--ink); }
.empty__text { margin: 0; font: 400 13px/19px var(--font-sans); color: var(--ink-meta); }

/* Toast */
.toast { display: inline-flex; align-items: center; gap: var(--space-3); padding: 12px var(--space-4); border-radius: var(--radius-lg); border: 1px solid var(--success-line); background: var(--success-bg); color: var(--ink); font: 500 14px/20px var(--font-sans); box-shadow: var(--shadow-pop); max-width: 440px; }
.toast--error { border-color: var(--danger-line); background: var(--danger-bg); }
.toast__action { margin-left: auto; padding: 0; min-height: 32px; border: 0; background: transparent; color: var(--accent); font: 600 14px/20px var(--font-sans); cursor: pointer; }
.toast-region { position: fixed; z-index: 60; left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100% - 32px); bottom: calc(var(--size-bottom-nav) + 12px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: var(--space-2); }
@media (min-width: 640px) { .toast-region { left: auto; right: var(--space-6); transform: none; bottom: var(--space-6); } }

/* QuickAdd */
.quick { display: flex; align-items: center; gap: var(--space-2); padding: 6px 6px 6px 14px; border-radius: var(--radius-lg); border: 1px solid var(--line-control); background: var(--surface); box-shadow: var(--shadow-xs); }
.quick .input { border: 0; padding: 0; box-shadow: none; min-height: 38px; }
.quick .input:focus { box-shadow: none; }
.quick:focus-within { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

/* Hiện/ẩn theo cỡ màn hình */
.only-mobile { display: none !important; }
@media (max-width: 639px) { .only-mobile { display: flex !important; } .hide-mobile { display: none !important; } }
@media (min-width: 1280px) { .hide-wide { display: none !important; } }

/* Tiêu đề màn hình. Mobile: thành thanh màu accent ở đầu trang. */
.page-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--space-3); }
.page-head__title { margin: 0; font: 600 22px/30px var(--font-sans); letter-spacing: -0.015em; color: var(--ink); }
.page-head__meta { display: flex; align-items: center; gap: 10px; font: 400 14px/20px var(--font-sans); color: var(--ink-meta); }
.icon-btn { width: var(--size-touch); height: var(--size-touch); display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: var(--radius-md); background: transparent; color: var(--ink-2); cursor: pointer; text-decoration: none; }
.icon-btn:hover { background: var(--surface-hover); }
@media (max-width: 639px) {
  .page-head { align-items: center; flex-wrap: nowrap; margin: calc(-1 * var(--space-4)) calc(-1 * var(--space-4)) 0; padding: 8px var(--space-4); min-height: 60px; background: var(--nav-bg); }
  .page-head__title { font-size: 20px; line-height: 28px; letter-spacing: -0.01em; color: var(--on-accent); }
  .page-head .icon-btn, .page-head .btn--ghost { color: var(--on-accent); }
  .page-head .icon-btn:hover, .page-head .btn--ghost:hover { background: var(--nav-selected); }
}

/* Navigation: Sidebar (desktop), Rail (tablet) trên nav-bg; BottomNav (mobile) trắng */
.nav-icon { width: 22px; height: 22px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sidebar { width: var(--size-sidebar); flex-shrink: 0; min-height: 100%; padding: 20px 12px; background: var(--nav-bg); display: flex; flex-direction: column; gap: 20px; color: var(--on-nav); }
.sidebar__brand { padding: 2px 10px; display: flex; align-items: center; justify-content: space-between; font: 600 16px/22px var(--font-sans); letter-spacing: -0.01em; color: var(--on-nav); }
.sidebar__brand .dot { color: var(--on-nav-muted); }
.sidebar__nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar__link { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 10px; border-radius: var(--radius-md); color: var(--on-nav-muted); font: 500 15px/22px var(--font-sans); text-decoration: none; }
.sidebar__link:hover { background: var(--nav-selected); color: var(--on-nav); }
.sidebar__link[aria-current="page"] { background: var(--nav-selected); color: var(--on-nav); font-weight: 600; }
.sidebar__link .badge { margin-left: auto; min-width: 22px; height: 22px; padding: 0 6px; border-radius: var(--radius-full); background: var(--warning); color: var(--on-accent); font: 600 12.5px/22px var(--font-sans); text-align: center; }
.sidebar__foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--nav-selected); display: flex; flex-direction: column; gap: 8px; font: 400 13px/19px var(--font-sans); color: var(--on-nav-muted); }
.sidebar__foot div { display: flex; justify-content: space-between; align-items: center; }
.sidebar__foot .sidebar__link { margin: 0 -10px; padding: 0 10px; }
.sidebar__foot .dot { color: var(--on-nav); }
.rail { width: var(--size-rail); flex-shrink: 0; min-height: 100%; padding: 14px 6px; background: var(--nav-bg); display: flex; flex-direction: column; align-items: center; gap: 4px; }
.rail__link { width: 56px; min-height: 56px; padding: 6px 0; border-radius: var(--radius-md); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--on-nav-muted); text-decoration: none; font: 500 12px/16px var(--font-sans); }
.rail__link[aria-current="page"] { background: var(--nav-selected); color: var(--on-nav); font-weight: 600; }
.bottom-nav { position: sticky; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; height: calc(var(--size-bottom-nav) + env(safe-area-inset-bottom)); padding: 0 6px env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--line); }
.bottom-nav__link { min-height: var(--size-touch); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--ink-meta); text-decoration: none; font: 500 12px/16px var(--font-sans); }
.bottom-nav__link[aria-current="page"] { color: var(--accent); font-weight: 600; }
.bottom-nav__add { justify-self: center; width: 52px; height: 52px; border-radius: var(--radius-full); border: 0; background: var(--accent); color: var(--on-accent); display: inline-flex; align-items: center; justify-content: center; box-shadow: var(--shadow-pop); cursor: pointer; margin-top: -20px; }
.bottom-nav__add .nav-icon { width: 24px; height: 24px; stroke-width: 2.2; }

/* AppShell: chọn kiểu điều hướng theo bề rộng */
.shell { display: flex; min-height: 100vh; background: var(--ground); }
.shell__main { flex: 1; min-width: 0; padding: var(--space-6) var(--space-8); display: flex; flex-direction: column; gap: 20px; }
.shell__aside { width: var(--size-aside); flex-shrink: 0; padding: var(--space-6) var(--space-5) var(--space-6) 0; background: var(--ground); display: flex; flex-direction: column; gap: 20px; }
.shell .rail, .shell .bottom-nav { display: none; }
@media (max-width: 1279px) { .shell__aside { display: none; } }
@media (max-width: 1023px) { .shell .sidebar { display: none; } .shell .rail { display: flex; } .shell__main { padding: var(--space-6); } }
@media (max-width: 639px) {
  .shell { flex-direction: column; }
  .shell .rail { display: none; }
  .shell .bottom-nav { display: grid; }
  .shell__main { padding: var(--space-4); gap: 16px; }
}
