/* Shell: sidebar (rail on desktop, drawer on phones), glass top bar, tab bar, dialogs, task panel, composer, toast. */
.app {
  position: fixed; inset: 0; z-index: 1;
  display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr);
  transition: grid-template-columns .45s var(--spring-soft);
}
.app[data-sidebar="collapsed"] { grid-template-columns: var(--side-rail) minmax(0, 1fr); }

/* ---- sidebar */
.sidebar {
  grid-column: 1; height: 100dvh; display: flex; flex-direction: column; gap: 2px; padding: 14px 12px;
  padding-top: max(14px, env(safe-area-inset-top));
  border-right: 1px solid var(--line); overflow-y: auto; overflow-x: hidden;
  background: color-mix(in oklch, var(--surface) 72%, transparent); backdrop-filter: blur(18px) saturate(1.4);
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 14px; min-height: 52px; }
.brand-mark {
  flex: none; width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center;
  background: linear-gradient(140deg, var(--accent), oklch(0.66 0.19 35)); color: var(--on-accent);
  font: 700 13px/1 var(--f-display); letter-spacing: -.02em; box-shadow: 0 1px 0 oklch(1 0 0 / .5) inset, 0 8px 18px -10px var(--accent);
}
.brand-name { font: 650 1.02rem/1.1 var(--f-display); letter-spacing: -.02em; white-space: nowrap; }
.brand-name small { display: block; font: 500 .68rem/1.3 var(--f-mono); letter-spacing: .06em; color: var(--muted); text-transform: uppercase; }
.nav-group { padding: 14px 8px 6px; }
.nav-link {
  display: flex; align-items: center; gap: 12px; height: 40px; padding: 0 10px; border-radius: var(--r-sm);
  color: var(--ink-2); font-weight: 560; font-size: .93rem; white-space: nowrap; position: relative;
  transition: background .2s, color .2s, transform .45s var(--spring);
}
.nav-link svg { flex: none; width: 19px; height: 19px; }
.nav-link:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav-link:active { transform: scale(.97); }
.nav-link[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: var(--sh-1); }
.nav-link[aria-current="page"]::before { content: ""; position: absolute; left: -12px; top: 10px; bottom: 10px; width: 3px; border-radius: 3px; background: var(--accent); }
.nav-link .count { margin-left: auto; font: 600 .7rem var(--f-mono); color: var(--muted); }
.nav-link .count.crit { color: var(--crit); }
.nav-link .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); flex: none; margin: 0 5px; }
.side-foot { margin-top: auto; padding-top: 12px; display: grid; gap: 6px; border-top: 1px solid var(--line); }
.me-card { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: var(--r-sm); color: var(--ink); }
.me-card:hover { text-decoration: none; }
.me-card:hover { background: var(--surface-2); }
.me-card b { display: block; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-card small { display: block; font: 500 .7rem var(--f-mono); color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
@media (min-width: 901px) {
  .app[data-sidebar="collapsed"] .sidebar .lbl, .app[data-sidebar="collapsed"] .sidebar .count,
  .app[data-sidebar="collapsed"] .nav-group, .app[data-sidebar="collapsed"] .brand-name { display: none; }
  .app[data-sidebar="collapsed"] .nav-link { justify-content: center; padding: 0; }
  .app[data-sidebar="collapsed"] .me-card { justify-content: center; padding: 6px 0; }
  .app[data-sidebar="collapsed"] .brand { justify-content: center; padding-inline: 0; }
}
.scrim { position: fixed; inset: 0; z-index: 25; background: var(--scrim); opacity: 0; pointer-events: none; transition: opacity .3s; }

/* ---- main column */
.main { grid-column: 2; position: relative; display: flex; flex-direction: column; min-width: 0; height: 100dvh; }

/* ---- top bar: glass, sticky, degrades in tiers */
.topbar {
  position: relative; z-index: 20; height: var(--topbar-h); flex: none; display: flex; align-items: center; gap: 10px;
  padding: 0 clamp(12px, 2.2vw, 32px); margin-top: env(safe-area-inset-top);
  background: var(--glass); backdrop-filter: saturate(1.7) blur(20px); border-bottom: 1px solid var(--line);
}
.icon-btn {
  flex: none; width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; color: var(--ink-2);
  transition: background .2s, transform .45s var(--spring);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn:active { transform: scale(.92); }
.icon-btn svg { width: 20px; height: 20px; }
.menu-btn { display: none; }
.crumb { min-width: 0; display: flex; flex-direction: column; }
.crumb .eyebrow { line-height: 1.2; }
.crumb h1 { font: 650 1.12rem/1.2 var(--f-display); letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-btn {
  margin-left: auto; display: flex; align-items: center; gap: 10px; height: 38px; padding: 0 8px 0 12px; min-width: 260px;
  border-radius: 12px; border: 1px solid var(--line-2); background: color-mix(in oklch, var(--surface) 70%, transparent); color: var(--muted);
  font-size: .9rem; transition: border-color .2s, box-shadow .2s;
}
.search-btn:hover { border-color: var(--ink-2); }
.search-btn svg { width: 17px; height: 17px; }
.search-btn kbd { margin-left: auto; }
kbd { font: 600 .68rem/1 var(--f-mono); padding: 4px 6px; border-radius: 6px; border: 1px solid var(--line-2); background: var(--surface); color: var(--muted); }
.mode-badge {
  flex: none; display: inline-flex; align-items: center; gap: 8px; height: 30px; padding: 0 12px 0 10px; border-radius: 99px;
  font: 700 .64rem/1 var(--f-mono); letter-spacing: .08em; text-transform: uppercase; border: 1px solid currentColor;
}
.mode-badge i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse-dot 2.4s infinite; }
.mode-badge.warn { color: var(--warn); background: var(--warn-bg); }
.mode-badge.good { color: var(--good); background: var(--good-bg); }
.mode-badge.good i { animation: none; }
.me-btn { flex: none; border-radius: 50%; padding: 2px; transition: transform .45s var(--spring), box-shadow .2s; }
.me-btn:hover { box-shadow: 0 0 0 3px var(--accent-soft); }
.me-btn:active { transform: scale(.92); }
.me-btn .avatar { width: 34px; height: 34px; }
.avatar {
  flex: none; display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%;
  background: var(--av, var(--surface-3)); color: #fff; font: 700 .76rem/1 var(--f-display); letter-spacing: .02em;
  box-shadow: 0 0 0 2px var(--surface);
}
.avatar.xs { width: 24px; height: 24px; font-size: .62rem; }
.avatar.lg { width: 46px; height: 46px; font-size: .95rem; }
.avatar.none { background: var(--surface-3); color: var(--faint); }

/* tier 2: wide screen + open sidebar leaves a narrow top bar */
@media (max-width: 1280px) { .app:not([data-sidebar="collapsed"]) .search-btn { min-width: 0; } .app:not([data-sidebar="collapsed"]) .search-btn .lbl, .app:not([data-sidebar="collapsed"]) .search-btn kbd { display: none; } }
/* tier 3: tablet */
@media (max-width: 1100px) { .search-btn { min-width: 0; } .search-btn .lbl, .search-btn kbd { display: none; } .mode-badge .lbl { display: none; } .mode-badge { padding: 0 10px; } }

/* ---- phone: sidebar becomes a drawer, a tab bar carries the main screens */
.tabbar { display: none; }
@media (max-width: 900px) {
  .app, .app[data-sidebar="collapsed"] { grid-template-columns: 1fr; }
  .main { grid-column: 1; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(86vw, 320px); height: 100dvh; box-shadow: var(--sh-2);
    background: var(--surface); transform: translateX(-104%); visibility: hidden;
    transition: transform .55s var(--spring-soft), visibility 0s .55s;
  }
  .app[data-drawer="open"] .sidebar { transform: none; visibility: visible; transition: transform .55s var(--spring-soft); }
  .app[data-drawer="open"] .scrim { opacity: 1; pointer-events: auto; }
  .menu-btn { display: grid; }
  .collapse-btn { display: none; }
  .topbar { padding: 0 8px 0 4px; gap: 4px; }
  .search-btn { border: 0; background: none; width: 38px; height: 38px; padding: 0; justify-content: center; }
  .theme-btn { display: none; }
  .mode-badge { border: 0; background: none !important; padding: 0 6px; height: 38px; }
  .mode-badge i { width: 9px; height: 9px; }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); flex: none; position: relative; z-index: 20;
    padding: 4px 6px max(6px, env(safe-area-inset-bottom)); background: var(--glass); backdrop-filter: saturate(1.7) blur(20px);
    border-top: 1px solid var(--line);
  }
  .tabbar a {
    display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0 4px; border-radius: 12px;
    color: var(--muted); font: 600 .66rem/1.1 var(--f-text); letter-spacing: .01em; position: relative;
    transition: color .2s, transform .45s var(--spring);
  }
  .tabbar a:hover { text-decoration: none; }
  .tabbar a:active { transform: scale(.92); }
  .tabbar a svg { width: 22px; height: 22px; }
  .tabbar a[aria-current="page"] { color: var(--ink); }
  .tabbar a[aria-current="page"] svg { color: var(--accent-text); }
  .tabbar a[aria-current="page"]::before { content: ""; position: absolute; top: -5px; left: 30%; right: 30%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }
  .tabbar .badge { position: absolute; top: 2px; left: calc(50% + 6px); min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--crit); color: #fff; font: 700 .58rem/16px var(--f-mono); text-align: center; }
}
@media (max-width: 420px) { .crumb .eyebrow { display: none; } }

/* ---- views */
.views { position: relative; flex: 1; min-height: 0; }
.view { position: absolute; inset: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.view.pad { padding: clamp(14px, 2.2vw, 32px) clamp(12px, 2.2vw, 32px) 40px; }
.view.pad > .inner { max-width: var(--maxw); margin: 0 auto; }

/* ---- composer (add a task) */
.composer {
  position: relative; z-index: 10; flex: none; padding: 8px clamp(10px, 2vw, 24px) 10px;
  background: var(--glass); backdrop-filter: saturate(1.6) blur(20px); border-top: 1px solid var(--line);
}
.composer .row-in { display: flex; gap: 8px; align-items: center; max-width: 980px; margin: 0 auto; }
.composer input {
  flex: 1; min-width: 0; height: 46px; padding: 0 16px; border-radius: 99px; border: 1px solid var(--line-2);
  background: var(--surface); font-size: 1rem; box-shadow: var(--sh-1); outline: none; transition: border-color .2s, box-shadow .2s;
}
.composer input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.composer .preview { display: flex; flex-wrap: wrap; gap: 6px; max-width: 980px; margin: 0 auto 8px; }
.composer .preview:empty { display: none; }

/* ---- task panel: right side on wide screens, bottom sheet on phones */
.panel-wrap { position: fixed; inset: 0; z-index: 50; }
.panel-wrap .scrim { opacity: 1; pointer-events: auto; z-index: 0; }
.panel {
  position: absolute; z-index: 1; top: 0; right: 0; bottom: 0; width: min(520px, 100vw); overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--sh-2);
  padding: max(18px, env(safe-area-inset-top)) clamp(16px, 2vw, 26px) calc(24px + env(safe-area-inset-bottom));
  animation: panel-in .5s var(--spring-soft);
}
@keyframes panel-in { from { transform: translateX(40px); opacity: 0; } }
@media (max-width: 760px) {
  .panel {
    top: auto; left: 0; width: 100%; max-height: 92dvh; border-left: 0; border-radius: var(--r-xl) var(--r-xl) 0 0;
    animation: sheet-in .5s var(--spring-soft);
  }
  @keyframes sheet-in { from { transform: translateY(50px); opacity: 0; } }
  .panel::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 4px; background: var(--line-2); margin: -6px auto 12px; }
}

/* ---- dialogs: command palette, shortcuts, small modals */
dialog { border: 0; padding: 0; background: transparent; color: inherit; max-width: none; max-height: none; }
dialog::backdrop { background: var(--scrim); backdrop-filter: blur(2px); }
dialog[open] { animation: pop .35s var(--spring-soft); }
.palette { margin: 12dvh auto auto; width: min(640px, calc(100vw - 24px)); }
.pal-box { border-radius: 24px; overflow: hidden; background: color-mix(in oklch, var(--surface) 94%, transparent); backdrop-filter: blur(24px) saturate(1.6); box-shadow: var(--sh-2); border: 1px solid var(--line); }
.pal-input { display: flex; align-items: center; gap: 12px; padding: 0 18px; height: 60px; border-bottom: 1px solid var(--line); color: var(--muted); }
.pal-input svg { width: 20px; height: 20px; flex: none; }
.pal-input input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; font-size: 1.05rem; color: var(--ink); height: 100%; }
.pal-list { max-height: min(56dvh, 460px); overflow-y: auto; padding: 8px; }
.pal-group { padding: 10px 10px 4px; }
.pal-item { display: flex; align-items: center; gap: 12px; min-height: 46px; padding: 6px 10px; border-radius: 14px; cursor: pointer; }
.pal-item[aria-selected="true"] { background: var(--surface-3); }
.pal-ic { flex: none; width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); color: var(--ink-2); }
.pal-ic svg { width: 17px; height: 17px; }
.pal-ic.cat { background: color-mix(in oklch, var(--c) 22%, transparent); color: var(--c); }
.pal-txt { min-width: 0; flex: 1; }
.pal-txt b { display: block; font-weight: 560; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pal-txt small { display: block; color: var(--muted); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pal-go { opacity: 0; transform: translateX(-4px); transition: opacity .2s, transform .3s var(--spring); color: var(--muted); }
.pal-go svg { width: 16px; height: 16px; }
.pal-item[aria-selected="true"] .pal-go { opacity: 1; transform: none; }
.pal-foot { display: flex; gap: 14px; padding: 10px 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: .75rem; flex-wrap: wrap; }
.modal { margin: auto; width: min(460px, calc(100vw - 24px)); }
.modal-box { border-radius: var(--r-xl); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--sh-2); padding: 22px; display: grid; gap: 14px; }
.modal-box h3 { font: 650 1.2rem/1.2 var(--f-display); letter-spacing: -.02em; }
.sheet-sc { margin: auto; width: min(860px, calc(100vw - 24px)); }
.sc-body { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 8px 32px; }
.sc-body h4 { margin: 10px 0 2px; }
.sc-body dl div { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: .9rem; }
.sc-body dd { display: flex; gap: 4px; }

/* ---- toast */
.toast {
  position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 90;
  display: flex; align-items: center; gap: 10px; max-width: calc(100vw - 32px); padding: 11px 16px; border-radius: 14px;
  background: var(--ink); color: var(--bg); font-weight: 600; font-size: .9rem; box-shadow: var(--sh-2); animation: rise .4s var(--spring-soft);
}
@media (min-width: 901px) { .toast { bottom: 96px; } }
