/* ==========================================================================
   Saras · Layout shell
   Breakpoints: mobile <= 640 · tablet 641-1024 · laptop >= 1025
   ========================================================================== */

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "rail topbar"
    "rail main";
}

/* ---------- Side rail ---------- */
.rail {
  grid-area: rail;
  background: var(--ink-900);
  color: var(--text-invert);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 60;
}

.rail-brand {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-4);
  min-height: var(--topbar-h);
  border-bottom: 1px solid rgba(243, 247, 245, 0.1);
}

/* Three bands at the foot of the mark nod to the three chariots of the Puri
   Rath Yatra — Nandighosa (yellow), Taladhwaja (green) and Darpadalana (red/black) —
   the way the design tokens above already split lien-active, verified and rejected. */
.rail-mark {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: var(--r-md);
  background:
    linear-gradient(180deg, var(--ink-900) 0 60%,
      var(--plate-400) 60% 73%, var(--seal-500) 73% 86%, var(--brick-600) 86% 100%);
  color: var(--text-invert);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: var(--fs-17);
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
  box-shadow: inset 0 0 0 1px rgba(243, 247, 245, 0.18);
}

.rail-name {
  display: block;
  font-size: var(--fs-15);
  font-weight: 600;
  line-height: 1.2;
}
.rail-sub {
  display: block;
  font-size: var(--fs-11);
  color: var(--ink-300);
  line-height: 1.3;
  margin-top: 1px;
}

.rail-nav {
  padding: var(--s-4) var(--s-3);
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.rail-group {
  font-size: var(--fs-11);
  color: var(--ink-400);
  padding: var(--s-4) var(--s-2) var(--s-2);
  font-weight: 500;
}
.rail-group:first-child { padding-top: 0; }

/* A labelled run of rail links. .rail-group is the label itself, so the links
   under it need something to sit in — without this they inherited the label's
   11px type and the whole administration menu came out smaller than the rest
   of the rail. */
.rail-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* An unread mark on a rail item: a bill due or overdue. Sized and positioned
   like .rail-count, which it sits in place of — a count would be wrong here
   because the number of overdue invoices is not what the administrator needs
   to know from the rail; that something needs paying is. */
.rail-dot {
  margin-left: auto;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--plate-400, #e8b300);
  flex: none;
}

.rail-link {
  display: flex;
  background: transparent;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-md);
  color: #d5ded9;
  font-size: var(--fs-14);
  border: 0;
  border-left: 2px solid transparent;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.rail-link:hover {
  background: rgba(243, 247, 245, 0.07);
  color: #fff;
  border-bottom-color: transparent;
}
.rail-link svg { flex: none; width: 18px; height: 18px; opacity: 0.85; }

.rail-link[aria-current="page"] {
  background: rgba(232, 179, 0, 0.13);
  color: #fff;
  border-left-color: var(--plate-400);
  font-weight: 500;
}
.rail-link[aria-current="page"] svg { opacity: 1; color: var(--plate-400); }

.rail-count {
  margin-left: auto;
  font-size: var(--fs-11);
  font-variant-numeric: tabular-nums;
  background: rgba(243, 247, 245, 0.12);
  padding: 1px var(--s-2);
  border-radius: var(--r-pill);
}

.rail-foot {
  border-top: 1px solid rgba(243, 247, 245, 0.1);
  padding: var(--s-3);
}

.rail-user {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-2);
}
.rail-user-avatar {
  flex: none;
  width: 32px; height: 32px;
  border-radius: var(--r-pill);
  background: var(--seal-500);
  color: #fff;
  display: grid; place-items: center;
  font-size: var(--fs-12);
  font-weight: 600;
}
.rail-user-name { font-size: var(--fs-13); font-weight: 500; }
.rail-user-role { font-size: var(--fs-11); color: var(--ink-300); }

/* ---------- Topbar ---------- */
.topbar {
  grid-area: topbar;
  position: sticky;
  top: 0;
  z-index: 50;
  min-height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: var(--s-4);
  padding: var(--s-2) var(--s-5);
}

.topbar-toggle {
  display: none;
  flex: none;
  width: 38px; height: 38px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--r-md);
  color: var(--ink-700);
  place-items: center;
  cursor: pointer;
}

.crumbs {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-size: var(--fs-13);
  color: var(--text-muted);
  min-width: 0;
  flex-wrap: wrap;
}
.crumbs a { color: var(--text-muted); }
.crumbs a:hover { color: var(--seal-600); }
.crumbs-sep { color: var(--ink-300); }
.crumbs strong { color: var(--ink-800); font-weight: 500; }

.topbar-spacer { flex: 1; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.branch-chip {
  display: flex;
  align-items: baseline;
  gap: var(--s-2);
  padding: var(--s-1) var(--s-3);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-sunken);
  font-size: var(--fs-12);
  white-space: nowrap;
}
.branch-chip span { color: var(--text-muted); }

/* ---------- Main ---------- */
.main {
  grid-area: main;
  min-width: 0;
  padding: var(--s-6) var(--s-5) var(--s-9);
}
.wrap {
  max-width: var(--content-max);
  margin: 0 auto;
}

.page-head {
  display: flex;
  align-items: flex-end;
  gap: var(--s-4);
  flex-wrap: wrap;
  margin-bottom: var(--s-6);
}
.page-head-text { min-width: 0; flex: 1 1 320px; }
.page-head h1 { font-size: var(--fs-30); letter-spacing: -0.02em; }
.page-head p {
  margin: var(--s-2) 0 0;
  color: var(--text-muted);
  font-size: var(--fs-14);
}
.page-head-actions {
  display: flex;
  gap: var(--s-2);
  flex-wrap: wrap;
}

/* ---------- Column utilities ---------- */
.cols {
  display: grid;
  gap: var(--s-5);
}
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cols-main-side { grid-template-columns: minmax(0, 2.1fr) minmax(0, 1fr); }

.stack { display: flex; flex-direction: column; gap: var(--s-5); }
.row { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; }
.row-end { justify-content: flex-end; }
.push { margin-left: auto; }

/* ---------- Drawer scrim (mobile / tablet rail) ---------- */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(20, 28, 26, 0.45);
  z-index: 55;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur) var(--ease);
}
body.rail-open .scrim { opacity: 1; pointer-events: auto; }

/* ==========================================================================
   Tablet and below: rail becomes an off-canvas drawer
   ========================================================================== */
@media (max-width: 1024px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "main";
  }

  .rail {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: min(84vw, var(--rail-w));
    transform: translateX(-102%);
    transition: transform 180ms var(--ease);
    box-shadow: var(--shadow-float);
  }
  body.rail-open .rail { transform: translateX(0); }

  .topbar-toggle { display: grid; }
  .main { padding: var(--s-5) var(--s-4) var(--s-8); }
  .cols-3, .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols-main-side { grid-template-columns: minmax(0, 1fr); }
}

/* ==========================================================================
   Mobile
   ========================================================================== */
@media (max-width: 640px) {
  .topbar { padding: var(--s-2) var(--s-3); gap: var(--s-3); }
  .branch-chip { display: none; }
  .crumbs { font-size: var(--fs-12); flex-wrap: nowrap; }
  /* Only the current location survives; the trail is redundant on a phone. */
  .crumbs a,
  .crumbs .crumbs-sep { display: none; }
  .main { padding: var(--s-4) var(--s-3) var(--s-8); }
  .page-head h1 { font-size: var(--fs-24); }
  .page-head-actions { width: 100%; }
  .page-head-actions .btn { flex: 1 1 auto; justify-content: center; }
  .cols { gap: var(--s-4); }
  .cols-2, .cols-3, .cols-4 { grid-template-columns: minmax(0, 1fr); }
}

/* TWO CARDS SIDE BY SIDE, stacking on a narrow screen. Added for the vehicle
   catalogue, where makes and the models of the chosen make are read together —
   two stacked tables would put the models below the fold on every click. */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-5);
  align-items: start;
}
@media (max-width: 1100px) {
  .grid-2 { grid-template-columns: 1fr; }
}
