/* ============================================================================
   KIMO v3 SHELL  (shell.css; pairs with shell.js)
   One navigation for every private app: sidebar from 768px, liquid-glass
   appbar + capsule + fab below. Tokens only (see V3-SPEC.md). Loaded AFTER
   tokens.css, components.css and app.css.
   Active state is always a FILL. Never a colored line on any edge.
   ============================================================================ */

/* ------------------------------ frame ------------------------------ */
.k-shell { display: block; min-height: 100vh; min-height: 100dvh; background: var(--bg); }
.k-main { min-width: 0; display: block; }
.k-page {
  width: 100%;
  padding: var(--page-pad, 28px 36px);
}
.k-sb, .k-capsule, .k-fab { display: none; }
.k-appbar { display: none; }

/* ------------------------------ shared atoms ------------------------------ */
.k-ico { display: inline-grid; place-content: center; flex: none; }
.k-ico svg {
  display: block; width: 18px; height: 18px; fill: none; stroke: currentColor;
  stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round;
}
.k-mark {
  display: inline-grid; place-content: center; flex: none; overflow: hidden;
  width: 24px; height: 24px; border-radius: var(--r-1);
  background: var(--accent-subtle); color: var(--accent);
  font-size: var(--fs-meta); font-weight: 700; line-height: 1;
}
.k-mark img { display: block; width: 100%; height: 100%; object-fit: cover; }
.k-nav-badge {
  display: inline-grid; place-content: center; flex: none;
  min-width: 18px; height: 18px; padding: 0 var(--sp-1); border-radius: var(--r-pill);
  background: var(--accent); color: var(--accent-ink);
  font-size: 11px; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums;
}
.k-nav-badge[hidden] { display: none; }

/* ------------------------------ switcher popover (from 768) ------------------------------ */
.k-switcher {
  position: fixed; z-index: var(--z-modal, 200); width: 232px; max-height: min(70vh, 480px); overflow-y: auto;
  padding: var(--sp-1); border: 1px solid var(--line); border-radius: var(--r-3);
  background: var(--surface); box-shadow: var(--shadow-lg);
  animation: k-sw-in var(--dur-base, 180ms) var(--ease, ease);
}
.k-switcher[hidden] { display: none; }
.k-sw-cap {
  padding: var(--sp-2) var(--sp-2) var(--sp-1); font-size: var(--fs-overline); font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase; color: var(--faint);
}
.k-sw-item {
  display: flex; align-items: center; gap: var(--sp-3); width: 100%; height: 36px; padding: 0 var(--sp-2);
  border: 0; border-radius: var(--r-2); background: transparent; color: var(--text);
  font: inherit; font-size: var(--fs-body); font-weight: 500; text-decoration: none; text-align: left; cursor: pointer;
}
.k-sw-item:hover { background: var(--hover); }
.k-sw-item.is-current { background: var(--selected); font-weight: 600; }
.k-sw-item:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; }
@keyframes k-sw-in { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }

/* ------------------------------ sidebar (from 768) ------------------------------ */
@media (min-width: 768px) {
  .k-shell { display: grid; grid-template-columns: auto minmax(0, 1fr); }

  .k-sb {
    position: sticky; top: 0; z-index: var(--z-sidebar, 20);
    height: 100vh; height: 100dvh; width: var(--sb-w, 232px);
    display: flex; flex-direction: column; gap: var(--sp-2);
    padding: var(--sp-3) var(--sp-2) var(--sp-2);
    background: var(--sidebar); border-right: 1px solid var(--line);
    transition: width var(--dur-base, 180ms) var(--ease, ease);
    view-transition-name: k-sidebar;
  }
  .k-sb.is-rail { width: var(--sb-rail, 60px); }

  .k-sb-head { display: flex; align-items: center; gap: var(--sp-1); height: 36px; padding: 0 var(--sp-1) 0 0; }
  .k-sb-brand {
    display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; height: 36px;
    padding: 0 var(--sp-2); border: 0; border-radius: var(--r-2); background: transparent;
    color: var(--text); font: inherit; text-align: left; cursor: pointer;
  }
  .k-sb-brand:hover, .k-sb-brand[aria-expanded="true"] { background: var(--hover); }
  .k-sb-brand.is-static, .k-appbar-mark.is-static { cursor: default; }
  .k-sb-brand.is-static:hover { background: transparent; }
  .k-sb-brand:focus-visible, .k-sb-row:focus-visible, .k-sb-toggle:focus-visible, .k-sb-group-head:focus-visible, .k-sb-who:focus-visible {
    outline: 2px solid var(--ring); outline-offset: -2px;
  }
  .k-sb-name { font-size: var(--fs-body); font-weight: 600; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .k-sb-chev { display: inline-grid; place-content: center; flex: none; color: var(--faint); }
  .k-sb-chev svg { width: 14px; height: 14px; display: block; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .k-sb-toggle, .k-sb-ibtn {
    display: inline-grid; place-content: center; flex: none; width: 28px; height: 28px; padding: 0;
    border: 0; border-radius: var(--r-2); background: transparent; color: var(--dim); cursor: pointer;
    transition: opacity var(--dur-fast, 140ms) var(--ease, ease), background var(--dur-fast, 140ms) var(--ease, ease);
  }
  .k-sb-toggle { opacity: .5; }
  .k-sb:hover .k-sb-toggle, .k-sb-toggle:focus-visible { opacity: 1; }
  .k-sb-toggle:hover, .k-sb-ibtn:hover { background: var(--hover); color: var(--text); }
  .k-sb-toggle svg, .k-sb-ibtn svg { width: 16px; height: 16px; display: block; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

  .k-sb-actions { display: flex; flex-direction: column; gap: 1px; padding-bottom: var(--sp-2); border-bottom: 1px solid var(--line); }
  .k-sb-actions:empty { display: none; }
  .k-sb-nav {
    flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; gap: var(--sp-3);
    margin: 0 calc(-1 * var(--sp-2)); padding: var(--sp-1) var(--sp-2); scrollbar-width: none;
  }
  .k-sb-nav::-webkit-scrollbar { display: none; }
  .k-sb-group { display: flex; flex-direction: column; gap: 1px; }

  .k-sb-row {
    display: flex; align-items: center; gap: 10px; width: 100%; height: 32px; padding: 0 var(--sp-2);
    border: 0; border-radius: var(--r-2); background: transparent;
    font: inherit; font-size: var(--fs-body); font-weight: 500; color: var(--dim);
    text-decoration: none; text-align: left; white-space: nowrap; cursor: pointer;
    transition: background var(--dur-fast, 140ms) var(--ease, ease), color var(--dur-fast, 140ms) var(--ease, ease);
  }
  .k-sb-row:hover { background: var(--hover); color: var(--text); }
  .k-sb-row[aria-current="page"] { background: var(--selected); color: var(--text); font-weight: 600; }
  .k-sb-row[aria-current="page"] .k-ico { color: var(--accent); }
  .k-sb-row .k-ico { color: var(--faint); transition: color var(--dur-fast, 140ms) var(--ease, ease); }
  .k-sb-row:hover .k-ico { color: var(--dim); }
  .k-sb-row[aria-current="page"]:hover .k-ico { color: var(--accent); }
  .k-sb-label { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; }
  .k-sb-row .k-kbd, .k-sb-kbd {
    margin-left: auto; flex: none; padding: 1px 6px; border: 1px solid var(--line); border-radius: var(--r-1);
    background: var(--surface); color: var(--faint); font-family: var(--mono, monospace); font-size: var(--fs-meta); line-height: 1.4;
  }
  .k-sb-primary { background: var(--accent-subtle); color: var(--accent); font-weight: 600; }
  .k-sb-primary:hover { background: var(--accent-weak, var(--accent-subtle)); color: var(--accent); }
  .k-sb-primary .k-ico, .k-sb-primary:hover .k-ico { color: var(--accent); }

  .k-sb-group-head {
    display: flex; align-items: center; gap: var(--sp-1); height: 26px; padding: 0 var(--sp-2);
    border: 0; border-radius: var(--r-2); background: transparent; font: inherit; text-align: left; cursor: pointer;
    font-size: var(--fs-overline); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--faint);
  }
  .k-sb-group-head:hover { color: var(--dim); }
  .k-sb-caret { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; transition: transform var(--dur-base, 180ms) var(--ease, ease); }
  .k-sb-group-head[aria-expanded="false"] .k-sb-caret { transform: rotate(-90deg); }
  .k-sb-group-body { display: flex; flex-direction: column; gap: 1px; }
  .k-sb-group-body[hidden] { display: none; }

  .k-sb-foot { display: flex; align-items: center; gap: var(--sp-1); padding: var(--sp-2) 0 0; border-top: 1px solid var(--line); }
  .k-sb-who {
    display: flex; align-items: center; gap: var(--sp-2); min-width: 0; flex: 1; height: 36px; padding: 0 var(--sp-1);
    border: 0; border-radius: var(--r-2); background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer;
  }
  .k-sb-who:hover { background: var(--hover); }
  .k-sb-who .k-avatar { width: 26px; height: 26px; font-size: var(--fs-meta); flex: none; }
  .k-sb-who .k-avatar::after { display: none; }
  .k-sb-who-name { font-size: var(--fs-meta); font-weight: 500; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .k-sb-foot-btns { display: flex; align-items: center; flex: none; }
  .k-sb-ibtn { width: 30px; height: 30px; }
  .k-sb-ibtn[hidden] { display: none; }

  /* rail: icons only */
  .k-sb.is-rail .k-sb-label, .k-sb.is-rail .k-sb-who-name, .k-sb.is-rail .k-sb-name, .k-sb.is-rail .k-sb-chev,
  .k-sb.is-rail .k-sb-kbd, .k-sb.is-rail .k-sb-row .k-nav-badge, .k-sb.is-rail .k-sb-caret { display: none; }
  .k-sb.is-rail .k-sb-head { flex-direction: column; height: auto; gap: var(--sp-2); padding: 0; }
  .k-sb.is-rail .k-sb-brand { flex: none; width: 100%; justify-content: center; padding: 0; }
  .k-sb.is-rail .k-sb-toggle { opacity: 1; }
  .k-sb.is-rail .k-sb-row { justify-content: center; padding: 0; height: 36px; position: relative; }
  .k-sb.is-rail .k-sb-row.has-badge::after {
    content: ""; position: absolute; top: 8px; right: 14px; width: 7px; height: 7px; border-radius: var(--r-pill); background: var(--accent);
  }
  .k-sb.is-rail .k-sb-group-head { justify-content: center; padding: 0; font-size: 0; }
  .k-sb.is-rail .k-sb-group-head::before { content: ""; width: 16px; height: 1px; background: var(--line-strong); }
  .k-sb.is-rail .k-sb-foot { flex-direction: column; padding-top: var(--sp-2); }
  .k-sb.is-rail .k-sb-who { flex: none; width: auto; padding: 0; justify-content: center; }
  .k-sb.is-rail .k-sb-foot-btns { flex-direction: column; }

  /* the phone shell is off from here up */
  .k-appbar, .k-capsule, .k-fab { display: none !important; }
}

/* ------------------------------ phone: appbar, capsule, fab (below 768) ------------------------------ */
@media (max-width: 767px) {
  .k-sb { display: none !important; }
  .k-switcher { display: none !important; }

  .k-appbar {
    position: sticky; top: 0; z-index: var(--z-appbar, 40);
    display: flex; align-items: center; gap: var(--sp-2);
    min-height: calc(var(--appbar-h, 52px) + var(--safe-t, env(safe-area-inset-top)));
    padding: var(--safe-t, env(safe-area-inset-top)) max(var(--sp-3), var(--safe-r, env(safe-area-inset-right))) 0 max(var(--sp-3), var(--safe-l, env(safe-area-inset-left)));
    border-bottom: 1px solid var(--glass-rim, var(--line));
    background: var(--glass-bg, var(--surface));
    -webkit-backdrop-filter: var(--glass-blur, saturate(1.8) blur(22px)); backdrop-filter: var(--glass-blur, saturate(1.8) blur(22px));
  }
  .k-appbar-mark {
    display: inline-grid; place-content: center; flex: none; width: 44px; height: 44px; padding: 0; margin-left: calc(-1 * var(--sp-2));
    border: 0; background: transparent; cursor: pointer; border-radius: var(--r-3);
  }
  .k-appbar-mark .k-mark { width: 30px; height: 30px; border-radius: var(--r-2); }
  .k-appbar-title {
    flex: 1; min-width: 0; margin: 0; font-size: var(--fs-title); font-weight: 600; letter-spacing: -.01em; line-height: var(--lh-tight, 1.15);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text);
  }
  .k-appbar-actions { display: flex; align-items: center; flex: none; gap: var(--sp-1); }
  .k-appbar-actions:empty { display: none; }
  .k-appbar-actions > * { min-width: 44px; min-height: 44px; }
  .k-appbar-avatar { display: inline-flex; flex: none; margin-right: calc(-1 * var(--sp-1)); }
  /* 44px to the finger, a 36px circle to the eye. */
  .k-appbar-avatar .k-avatar { width: 44px; height: 44px; padding: 4px; background-clip: content-box; }

  .k-page {
    padding: var(--sp-4) max(var(--sp-4), var(--safe-r, env(safe-area-inset-right)))
      calc(var(--capsule-h, 62px) + 8px + var(--safe-b, env(safe-area-inset-bottom)) + 24px) max(var(--sp-4), var(--safe-l, env(safe-area-inset-left)));
  }

  .k-capsule {
    position: fixed; z-index: var(--z-capsule, 50);
    left: max(12px, var(--safe-l, env(safe-area-inset-left)));
    right: calc(max(12px, var(--safe-r, env(safe-area-inset-right))) + var(--capsule-h, 62px) + 10px);
    bottom: max(8px, calc(var(--safe-b, env(safe-area-inset-bottom)) - 12px));
    height: var(--capsule-h, 62px); padding: var(--sp-1); gap: 0;
    display: flex; align-items: stretch;
    border: 1px solid var(--glass-rim, var(--line)); border-radius: var(--r-pill);
    background: var(--glass-bg, var(--surface));
    -webkit-backdrop-filter: var(--glass-blur, saturate(1.8) blur(22px)); backdrop-filter: var(--glass-blur, saturate(1.8) blur(22px));
    box-shadow: var(--glass-shadow, var(--shadow-md));
  }
  .k-capsule.is-wide { right: max(12px, var(--safe-r, env(safe-area-inset-right))); }
  .k-tab {
    position: relative; flex: 1 1 auto; min-width: 44px; max-width: none; margin: 0; height: 100%; padding: 0 3px; gap: 2px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    border: 0; border-radius: var(--r-pill); background: transparent; color: var(--dim);
    font: inherit; font-size: 10px; font-weight: 600; line-height: 1.1; letter-spacing: .01em; text-decoration: none; cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background var(--dur-base, 180ms) var(--ease, ease), color var(--dur-fast, 140ms) var(--ease, ease), transform var(--dur-fast, 140ms) var(--ease, ease);
  }
  .k-tab .k-ico svg { width: 24px; height: 24px; padding: 0; border-radius: 0; background: none; box-sizing: content-box; }
  .k-tab:hover { color: var(--text); }
  .k-tab[aria-current="page"]:hover, .k-tab.is-current:hover { color: var(--accent); }
  .k-tab:active { transform: var(--press, scale(.98)); }
  .k-tab[aria-current="page"], .k-tab.is-current { background: var(--accent-subtle); color: var(--accent); }
  .k-tab:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; }
  .k-tab-label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; letter-spacing: 0; }
  .k-tab .k-nav-badge { position: absolute; top: 6px; left: calc(50% + 6px); min-width: 16px; height: 16px; font-size: 10px; }

  .k-fab {
    position: fixed; z-index: var(--z-fab, 60);
    right: max(12px, var(--safe-r, env(safe-area-inset-right)));
    bottom: max(8px, calc(var(--safe-b, env(safe-area-inset-bottom)) - 12px));
    width: var(--capsule-h, 62px); height: var(--capsule-h, 62px); padding: 0;
    display: grid; place-content: center;
    border: 1px solid var(--glass-rim, var(--line)); border-radius: var(--r-pill);
    background: color-mix(in srgb, var(--accent) 86%, transparent); color: var(--accent-ink); cursor: pointer;
    -webkit-backdrop-filter: var(--glass-blur, saturate(1.8) blur(22px)); backdrop-filter: var(--glass-blur, saturate(1.8) blur(22px));
    box-shadow: var(--glass-shadow, var(--shadow-md));
    transition: transform var(--dur-fast, 140ms) var(--ease, ease);
    -webkit-tap-highlight-color: transparent;
  }
  .k-fab:hover { background: color-mix(in srgb, var(--accent) 92%, transparent); }
  .k-fab svg { width: 26px; height: 26px; display: block; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
  .k-fab:active { transform: var(--press, scale(.98)); }
  .k-fab:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

  /* toasts clear the capsule */
  .k-toast { bottom: calc(var(--capsule-h, 62px) + 20px + var(--safe-b, env(safe-area-inset-bottom))); }
}

/* glass fallbacks: solid surfaces */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .k-appbar, .k-capsule { background: var(--surface); }
  .k-fab { background: var(--accent); }
}
@media (prefers-reduced-transparency: reduce) {
  .k-appbar, .k-capsule { background: var(--surface); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .k-fab { background: var(--accent); -webkit-backdrop-filter: none; backdrop-filter: none; }
}

/* ------------------------------ More / switcher sheets (grouped list) ------------------------------ */
.k-more-cap {
  padding: var(--sp-5) var(--sp-4) var(--sp-2); font-size: var(--fs-overline); font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase; color: var(--faint);
}
.k-more-cap:first-child { padding-top: var(--sp-1); }
.k-more-group { background: var(--surface-2); border-radius: var(--r-3); overflow: hidden; }
.k-more-row {
  position: relative; display: flex; align-items: center; gap: var(--sp-3); width: 100%; min-height: 52px; padding: 0 var(--sp-3);
  border: 0; border-radius: 0; background: transparent; color: var(--text);
  font: inherit; font-size: var(--fs-body); text-align: left; text-decoration: none; cursor: pointer;
}
.k-more-row + .k-more-row::before { content: ""; position: absolute; top: 0; right: 0; left: 52px; height: 1px; background: var(--line); }
.k-more-row:active { background: var(--selected); }
.k-more-row[aria-current="page"] { background: var(--selected); color: var(--accent); font-weight: 600; }
.k-more-row:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; }
.k-more-tile {
  display: inline-grid; place-content: center; flex: none; width: 28px; height: 28px; border-radius: var(--r-2);
  background: var(--accent-subtle); color: var(--accent);
}
.k-more-tile svg { width: 18px; height: 18px; display: block; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.k-more-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.k-more-chev { display: inline-grid; flex: none; color: var(--faint); }
.k-more-chev svg { width: 18px; height: 18px; display: block; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.k-more-seg { margin-left: auto; }
.k-more-seg > button { min-height: 36px; }

.k-shell-apps { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-2); }
.k-shell-app {
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-1); min-width: 0; padding: var(--sp-2) 0;
  border-radius: var(--r-3); color: var(--text); text-decoration: none; font-size: var(--fs-meta); font-weight: 500;
}
.k-shell-app:active { background: var(--selected); }
.k-shell-app.is-current { background: var(--selected); font-weight: 600; }
.k-shell-app:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; }
.k-shell-app .k-mark { width: 48px; height: 48px; border-radius: var(--r-3); font-size: var(--fs-title); }
.k-shell-app span:last-child { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------ motion ------------------------------ */
@media (prefers-reduced-motion: reduce) {
  .k-sb, .k-sb *, .k-tab, .k-fab, .k-switcher { transition-duration: 0s !important; animation-duration: 0s !important; }
  .k-tab:active, .k-fab:active { transform: none; }
}
