/* ==========================================================================
   ArchiTask — Application shell: rail (sidebar), topbar, page frame
   ========================================================================== */

.app {
  display: block;
  min-height: 100vh;
  min-height: 100dvh;
}

/* --------------------------------------------------------------------------
   Sidebar rail
   -------------------------------------------------------------------------- */
.app-rail {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--rail-w);
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
  border-right: 1px solid var(--border);
  z-index: 60;
  transition: width var(--t-med) var(--ease), transform var(--t-med) var(--ease);
}

.rail-head {
  display: flex; align-items: center; gap: var(--s3);
  height: var(--topbar-h);
  padding: 0 var(--s4);
  flex: 0 0 auto;
  border-bottom: 1px solid var(--border);
}
.rail-logo {
  width: 32px; height: 32px; flex: 0 0 32px;
  border-radius: var(--r-md);
  /* A fixed brand green, not the themed token: the mark keeps one colour in
     both themes, and white on it clears 5.5:1. */
  background: #047857;
  display: grid; place-items: center;
}
.rail-logo svg { width: 18px; height: 18px; }
.rail-wordmark { min-width: 0; }
.rail-wordmark b {
  display: block; color: var(--sidebar-ink-hi);
  font-size: var(--fs-15); font-weight: 640; letter-spacing: -.01em; line-height: 1.15;
}
.rail-wordmark span {
  display: block; font-size: var(--fs-11); color: var(--text-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.rail-nav {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: var(--s4) var(--s3) var(--s2);
}
.nav-group + .nav-group { margin-top: var(--s5); }
.nav-group-label {
  padding: 0 var(--s3) var(--s2);
  font-size: var(--fs-11); font-weight: 620; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-3);
}

.nav-item {
  position: relative;
  display: flex; align-items: center; gap: var(--s3);
  width: 100%;
  padding: 9px var(--s3);
  margin-bottom: 2px;
  border-radius: var(--r-md);
  color: var(--sidebar-ink);
  font-size: var(--fs-14); font-weight: 500;
  text-decoration: none;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.nav-item:hover { background: var(--sidebar-hover); color: var(--sidebar-ink-hi); text-decoration: none; }
.nav-item .ico { flex: 0 0 18px; width: 18px; height: 18px; opacity: .85; }
.nav-item .nav-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Active state is the soft pill, and nothing else — no left rule, no
   recoloured label, no tinted icon. The filled shape already reads as
   "you are here"; every extra cue was the same fact said again. */
.nav-item.is-active {
  background: var(--sidebar-active);
  color: var(--sidebar-ink-hi);
  font-weight: 600;
}
.nav-item.is-active .ico { opacity: 1; }
.nav-count {
  flex: 0 0 auto;
  min-width: 20px; height: 20px; padding: 0 6px;
  display: grid; place-items: center;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  color: var(--text-2);
  font-size: var(--fs-11); font-weight: 620;
  font-variant-numeric: tabular-nums;
}
.nav-count.is-alert { background: var(--critical-soft); color: var(--critical-ink); }

.rail-foot {
  flex: 0 0 auto;
  padding: var(--s3);
  border-top: 1px solid var(--border);
}
.rail-user {
  position: relative;
  display: flex; align-items: center; gap: var(--s3);
  width: 100%; padding: var(--s2); border-radius: var(--r-md);
  transition: background var(--t-fast) var(--ease);
  text-align: left;
}
.rail-user:hover { background: var(--sidebar-hover); }
.rail-user .meta { min-width: 0; flex: 1 1 auto; }
.rail-user .meta b {
  display: block; color: var(--sidebar-ink-hi); font-size: var(--fs-13); font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rail-user .meta span {
  display: block; font-size: var(--fs-11); color: var(--text-3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rail-user-caret { flex: 0 0 auto; display: inline-flex; opacity: .6; }

/* Collapsed mode is a desktop affordance. Below 900px the rail is a full-width
   drawer, so none of this applies — without the query, collapsing on desktop
   and then narrowing left the drawer 252px wide showing icons alone. */
@media (min-width: 901px) {
  .app[data-rail="collapsed"] .app-rail { width: var(--rail-w-collapsed); }
  /* Clipped rather than removed. Every icon in the rail is aria-hidden, so
     display:none on the labels would leave each nav link and the account
     button with no accessible name at all — a screen reader would announce
     seven unnamed links. Clipping keeps the names and takes no space. */
  .app[data-rail="collapsed"] .rail-wordmark,
  .app[data-rail="collapsed"] .nav-label,
  .app[data-rail="collapsed"] .nav-count,
  .app[data-rail="collapsed"] .nav-group-label,
  .app[data-rail="collapsed"] .rail-user .meta {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
  }
  .app[data-rail="collapsed"] .nav-item,
  .app[data-rail="collapsed"] .rail-user { justify-content: center; padding-inline: 0; }
  /* The account button collapses to the same 36px tile as a nav item, rather
     than keeping a wash twice as wide as the avatar inside it. The caret is
     dropped outright: it pointed at a label that is no longer rendered. */
  .app[data-rail="collapsed"] .rail-user { padding-block: 5px; }
  .app[data-rail="collapsed"] .rail-user-caret { display: none; }
  .app[data-rail="collapsed"] .rail-head { justify-content: center; padding-inline: 0; }
  .app[data-rail="collapsed"] .app-main { margin-left: var(--rail-w-collapsed); }
  /* The collapsed hover label is positioned outside the rail, and .rail-nav
     scrolls vertically — which forces the horizontal axis to `auto` as well, so
     the label was contributing 87px of scrollable width and a scrollbar along
     the bottom of the rail.

     `overflow-x: clip` is not a way out: paired with a scrolling y axis it
     computes to `hidden`, which drops overflow-clip-margin and simply eats the
     label. So the collapsed rail stops being a scroll container. That is sound
     here because collapsed mode shows a fixed set of icon-only destinations —
     roughly 330px of nav — which fits any viewport tall enough to run the app.
     The expanded rail keeps its scrolling, where no pseudo-element escapes. */
  .app[data-rail="collapsed"] .rail-nav { overflow: visible; }

  /* Collapsed items get a hover label so the rail stays usable. */
  .app[data-rail="collapsed"] .nav-item::after,
  .app[data-rail="collapsed"] .rail-user::after {
    content: attr(data-tip);
    position: absolute; left: calc(100% + 10px); top: 50%; transform: translateY(-50%) scale(.94);
    padding: 5px 10px; border-radius: var(--r-sm);
    background: var(--text); color: var(--surface);
    font-size: var(--fs-12); font-weight: 500; white-space: nowrap;
    opacity: 0; pointer-events: none;
    transition: opacity var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
    z-index: 5;
  }
  .app[data-rail="collapsed"] .nav-item:hover::after,
  .app[data-rail="collapsed"] .rail-user:hover::after { opacity: 1; transform: translateY(-50%) scale(1); }
  /* The pointer is still over the button once the menu opens; the label would
     sit on top of it saying what the menu already says. */
  .app[data-rail="collapsed"] .rail-user[aria-expanded="true"]::after { opacity: 0; }
}

/* --------------------------------------------------------------------------
   Main column
   -------------------------------------------------------------------------- */
.app-main {
  margin-left: var(--rail-w);
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column;
  transition: margin var(--t-med) var(--ease);
}

.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--topbar-h); flex: 0 0 auto;
  display: flex; align-items: center; gap: var(--s3);
  padding: 0 var(--s6);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
@supports (backdrop-filter: blur(1px)) {
  .topbar {
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    backdrop-filter: saturate(180%) blur(12px);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
  }
}

.topbar-title { min-width: 0; }
.topbar-title:empty { display: none; }
.topbar-title + .topbar-search { margin-left: var(--s2); }
.crumbs { display: flex; align-items: center; gap: 6px; font-size: var(--fs-12); color: var(--text-3); }
.crumbs a { color: var(--text-3); }
.crumbs a:hover { color: var(--text-2); }
.crumbs .sep { opacity: .5; }

.topbar-search {
  flex: 0 1 320px;
  display: flex; align-items: center; gap: var(--s2);
  height: 34px; padding: 0 var(--s3);
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface-2); color: var(--text-3);
  font-size: var(--fs-13);
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.topbar-search:hover { border-color: var(--border-strong); background: var(--surface); }
.topbar-search .grow { text-align: left; }
.kbd {
  display: inline-flex; align-items: center; gap: 1px;
  padding: 2px 5px; border-radius: var(--r-sm);
  border: 1px solid var(--border); background: var(--surface);
  font-size: var(--fs-11); font-weight: 600; color: var(--text-3);
  font-family: var(--font);
}

.page {
  flex: 1 1 auto;
  width: 100%; max-width: var(--page-max);
  margin: 0 auto;
  padding: var(--s6);
}
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--s4); flex-wrap: wrap;
  margin-bottom: var(--s6);
}
.page-title { min-width: 0; }
.page-head .sub { color: var(--text-2); font-size: var(--fs-13); margin-top: 2px; }

.page-actions { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }

/* Grid primitives used across pages */
.grid { display: grid; gap: var(--s5); }
.grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid-2-1 { grid-template-columns: minmax(0,2fr) minmax(0,1fr); }
.grid-1-2 { grid-template-columns: minmax(0,1fr) minmax(0,2fr); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); }

/* Mobile scrim for the drawer rail */
.scrim {
  position: fixed; inset: 0; z-index: 55;
  background: rgba(8,11,18,.55);
  animation: fade-in var(--t-med) var(--ease) both;
}

/* The drawer trigger is mobile-only. It carries .btn, whose `display` is
   declared later in components.css at equal specificity — so this rule has to
   out-specify it, or the button leaks onto desktop and opens a scrim over an
   already-visible rail. */
.btn.rail-toggle { display: none; }

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 1200px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid-2-1, .grid-1-2, .grid-3 { grid-template-columns: minmax(0,1fr); }
}

@media (max-width: 900px) {
  .app-rail {
    transform: translateX(-100%);
    box-shadow: var(--sh-4);
    width: var(--rail-w);
  }
  .app[data-drawer="open"] .app-rail { transform: none; }
  .app-main, .app[data-rail="collapsed"] .app-main { margin-left: 0; }
  .btn.rail-toggle { display: inline-flex; }
  .topbar { padding: 0 var(--s4); }
  .page { padding: var(--s4); }
  .grid { gap: var(--s4); }
  .topbar-search { justify-content: center; padding: 0; width: 34px; flex: 0 0 34px; }
  .topbar-search .grow, .topbar-search .kbd { display: none; }
}

@media (max-width: 620px) {
  .grid-4, .grid-2 { grid-template-columns: minmax(0,1fr); }
  .grid-auto { grid-template-columns: minmax(0,1fr); }
  .page-head { flex-direction: column; align-items: stretch; }
  .page-actions > .btn { flex: 1 1 auto; justify-content: center; }
}
