/* ==========================================================================
   Reset + app shell layout
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  font: var(--t-body);
  color: var(--label);
  background: var(--bg-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior-y: none;
  text-rendering: optimizeLegibility;
}

html.is-modal-open, body.is-modal-open { overflow: hidden; }

h1, h2, h3, h4, p, figure, blockquote { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
  margin: 0;
}

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); text-decoration: none; }

img, svg { display: block; max-width: 100%; }

:focus-visible {
  outline: 2.5px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

::selection { background: var(--accent-soft); }

/* Scrollbars — invisible until hover, like macOS overlay scrollers. */
* { scrollbar-width: thin; scrollbar-color: transparent transparent; }
*:hover { scrollbar-color: var(--label-quaternary) transparent; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: transparent; border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }
*:hover::-webkit-scrollbar-thumb { background: var(--label-quaternary); background-clip: padding-box; }

/* ==========================================================================
   Shell
   ========================================================================== */

#app { min-height: 100dvh; }

.shell {
  display: grid;
  min-height: 100dvh;
  grid-template-columns: 1fr;
}

.shell__main {
  position: relative;
  min-width: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* --- Scroll container ---------------------------------------------------- */
.scroller {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  padding-left: max(var(--sp-4), var(--safe-left));
  padding-right: max(var(--sp-4), var(--safe-right));
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + var(--sp-8));
}

@media (prefers-reduced-motion: reduce) {
  .scroller { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

.page {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding-bottom: var(--sp-6);
}

.page--narrow { max-width: 720px; }

/* ==========================================================================
   Navigation bar (iOS) / toolbar (macOS)
   ========================================================================== */

.navbar {
  position: sticky;
  top: 0;
  z-index: 40;
  padding-top: var(--safe-top);
  background: var(--glass-bar);
  -webkit-backdrop-filter: var(--glass-blur-strong);
  backdrop-filter: var(--glass-blur-strong);
  transition: box-shadow var(--dur-base) var(--ease-ios), background var(--dur-base) var(--ease-ios);
}

.navbar::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 1px;
  background: var(--separator);
  opacity: 0;
  transition: opacity var(--dur-base) var(--ease-ios);
}

.navbar.is-scrolled::after { opacity: 1; }

.navbar__row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: var(--nav-h);
  padding: 0 max(var(--sp-4), var(--safe-left)) 0 max(var(--sp-4), var(--safe-right));
  max-width: var(--content-max);
  margin: 0 auto;
  width: 100%;
}

.navbar__lead, .navbar__trail {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  flex: 0 0 auto;
}

.navbar__title {
  flex: 1;
  min-width: 0;
  text-align: center;
  font: var(--t-headline);
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity var(--dur-base) var(--ease-ios), transform var(--dur-base) var(--ease-ios);
}

.navbar.is-scrolled .navbar__title,
.navbar.is-compact .navbar__title { opacity: 1; transform: none; }

.navbar__button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 34px;
  min-width: 34px;
  padding: 0 var(--sp-2);
  border-radius: var(--r-full);
  color: var(--accent);
  font: var(--t-body);
  transition: background var(--dur-fast) var(--ease-ios), transform var(--dur-fast) var(--ease-ios);
}

@media (hover: hover) { .navbar__button:hover { background: var(--bg-hover); } }
.navbar__button:active { transform: scale(0.93); background: var(--bg-active); }
.navbar__button--plain { color: var(--label); }
.navbar__button[disabled] { color: var(--label-tertiary); pointer-events: none; }

.navbar__glass-button {
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: var(--r-full);
  background: var(--glass-control);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  box-shadow: inset 0 0 0 0.5px var(--border-glass);
}

/* Large title that lives in the scroll content */
.large-title {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: var(--sp-2) 0 var(--sp-3);
  max-width: var(--content-max);
  margin: 0 auto;
}

.large-title h1 {
  font: var(--t-large-title);
  letter-spacing: -0.022em;
}

.large-title__sub {
  font: var(--t-subhead);
  color: var(--label-secondary);
  margin-top: 2px;
}

/* ==========================================================================
   Tab bar (mobile) — floating liquid-glass capsule
   ========================================================================== */

.tabbar {
  position: fixed;
  z-index: 60;
  left: max(var(--sp-3), var(--safe-left));
  right: max(var(--sp-3), var(--safe-right));
  bottom: calc(var(--safe-bottom) + var(--sp-2));
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  align-items: center;
  height: var(--tabbar-h);
  padding: 0 var(--sp-1);
  border-radius: var(--r-2xl);
  background: var(--glass-bar);
  -webkit-backdrop-filter: var(--glass-blur-strong);
  backdrop-filter: var(--glass-blur-strong);
  box-shadow: var(--shadow-tabbar), inset 0 0 0 0.5px var(--border-glass);
  transition: transform var(--dur-base) var(--ease-ios), opacity var(--dur-base) var(--ease-ios);
}

.tabbar.is-hidden {
  transform: translateY(calc(100% + var(--sp-4)));
  opacity: 0;
  pointer-events: none;
}

.tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: 100%;
  border-radius: var(--r-lg);
  color: var(--label-secondary);
  font: var(--t-caption2);
  letter-spacing: -0.01em;
  transition: color var(--dur-fast) var(--ease-ios);
}

.tab svg { width: 25px; height: 25px; }
.tab.is-active { color: var(--accent); }
.tab:active { transform: scale(0.94); }

.tab__badge {
  position: absolute;
  top: 4px;
  right: 50%;
  translate: 18px 0;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: var(--r-full);
  background: var(--sys-red);
  color: #fff;
  font: 600 10px/16px var(--font-ui);
  text-align: center;
}

/* ==========================================================================
   Sidebar (tablet + desktop)
   ========================================================================== */

.sidebar {
  display: none;
  flex-direction: column;
  width: var(--sidebar-w);
  height: 100dvh;
  position: sticky;
  top: 0;
  padding: 0 var(--sp-2) var(--sp-3);
  padding-left: max(var(--sp-2), var(--safe-left));
  background: var(--bg-sidebar);
  -webkit-backdrop-filter: var(--glass-blur-strong);
  backdrop-filter: var(--glass-blur-strong);
  border-right: 0.5px solid var(--separator);
  overflow-y: auto;
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: calc(var(--safe-top) + var(--sp-5)) var(--sp-3) var(--sp-4);
  font: var(--t-title3);
  letter-spacing: -0.02em;
}

.sidebar__logo {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  flex: none;
  box-shadow: var(--shadow-sm);
}

.sidebar__section { margin-bottom: var(--sp-4); }

.sidebar__label {
  padding: 0 var(--sp-3) var(--sp-1);
  font: var(--t-caption2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--label-tertiary);
}

.sidebar__item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  padding: 7px var(--sp-3);
  margin-bottom: 1px;
  border-radius: var(--r-sm);
  color: var(--label);
  font: var(--t-callout);
  text-align: left;
  transition: background var(--dur-fast) var(--ease-ios);
}

.sidebar__item svg { width: 19px; height: 19px; flex: none; color: var(--accent); }
@media (hover: hover) { .sidebar__item:hover { background: var(--bg-hover); } }
.sidebar__item.is-active { background: var(--accent); color: var(--accent-text); font-weight: 500; }
.sidebar__item.is-active svg { color: currentColor; }
.sidebar__item span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar__count {
  font: var(--t-caption);
  color: var(--label-tertiary);
  font-variant-numeric: tabular-nums;
  min-width: 2.2em;
  text-align: right;
  flex: none;
}
.sidebar__item.is-active .sidebar__count { color: color-mix(in srgb, var(--accent-text) 78%, transparent); }

.sidebar__footer {
  margin-top: auto;
  padding: var(--sp-3) var(--sp-3) 0;
  font: var(--t-caption);
  color: var(--label-tertiary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
}

/* ==========================================================================
   Responsive layout switch
   ========================================================================== */

@media (min-width: 820px) {
  .shell { grid-template-columns: var(--sidebar-w) 1fr; }
  .sidebar { display: flex; }
  .tabbar { display: none; }
  .scroller { padding-bottom: var(--sp-8); }
  :root { --nav-h: 48px; }
  .navbar__title { opacity: 1; transform: none; }
  .navbar__row { padding-left: var(--sp-6); padding-right: var(--sp-6); }
  .scroller { padding-left: var(--sp-6); padding-right: var(--sp-6); }
}

/* Drag handle between sidebar and content (pointer devices only). */
.sidebar-resizer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: calc(var(--sidebar-w) - 3px);
  width: 7px;
  z-index: 70;
  display: none;
  cursor: col-resize;
  touch-action: none;
}

.sidebar-resizer::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 3px;
  width: 1px;
  background: var(--accent);
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease-ios);
}

.sidebar-resizer:hover::after,
.sidebar-resizer.is-dragging::after { opacity: 1; }

body.is-resizing { cursor: col-resize; user-select: none; }

@media (min-width: 820px) {
  .sidebar-resizer { display: block; }
}

/* Split view: master list + detail pane on large screens */
.split {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-5);
  align-items: start;
}

@media (min-width: 1100px) {
  .split { grid-template-columns: minmax(320px, 400px) 1fr; }
  .split__detail {
    position: sticky;
    top: calc(var(--nav-h) + var(--safe-top) + var(--sp-4));
    max-height: calc(100dvh - var(--nav-h) - var(--sp-8));
    overflow-y: auto;
  }
}

.hide-mobile { display: none; }
@media (min-width: 820px) { .hide-mobile { display: revert; } }
.hide-desktop { display: revert; }
@media (min-width: 820px) { .hide-desktop { display: none !important; } }
