/* ==========================================================================
   layout.css — structural shells only. No component styling, no page styling.

   Two shells: the admin desktop one (sidebar + topbar + content) and the
   officer mobile one (.phone + navy header + sync strip).

   Ported from design/admin_prototype.html. All spacing uses logical properties
   (margin-inline-start, padding-inline-end, inset-inline-start, …) — never
   margin-left / padding-right — so the whole shell flips in Arabic without a
   single RTL override. See Section 8.2.
   ========================================================================== */

/* ---------- Admin shell ---------- */
.app {
  display: flex;
  min-height: 100vh;
}

.main {
  flex: 1;
  min-width: 0; /* lets wide tables scroll inside .content instead of stretching the shell */
  display: flex;
  flex-direction: column;
}

.content {
  padding: 26px;
  flex: 1;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 230px;
  flex-shrink: 0;
  background: var(--navy);
  color: var(--navy-text);
  display: flex;
  flex-direction: column;
  border-inline-end: 1px solid var(--navy-border);
  position: sticky;
  top: 0;
  height: 100vh;
}

.side-logo {
  padding: 20px 22px;
  border-block-end: 1px solid var(--navy-border);
}
.side-logo .logo-img {
  display: block;
  width: 100%;
  max-width: 160px;
  height: auto;
  margin-block-end: 10px;
}
.side-logo .name {
  color: var(--primary);
  font-weight: 700;
  font-size: 15px;
  margin-block-start: 2px;
}
.side-logo .sub {
  color: var(--navy-muted);
  font-size: 11px;
  margin-block-start: 2px;
}

/* ---------- Sidebar navigation ---------- */
.nav {
  padding: 12px 0;
  flex: 1;
  overflow-y: auto;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 22px;
  color: var(--navy-text);
  text-decoration: none;
  font-size: 13.5px;
  /* The active marker sits on the leading edge, so it moves to the right in Arabic. */
  border-inline-start: 3px solid transparent;
}
.nav-link:hover {
  background: rgba(255, 255, 255, .04);
  color: var(--navy-text-strong);
}
.nav-link.active {
  background: rgba(255, 255, 255, .08);
  color: var(--navy-text-strong);
  border-inline-start-color: var(--primary);
}
.nav-link .ic {
  width: 16px;
  text-align: center;
  opacity: .8;
  flex-shrink: 0;
}

/* Group headers: always visible, never collapsible (Section 8.5). */
.nav-group {
  margin-block-start: 14px;
}
.nav-group-label {
  padding: 0 22px 6px;
  color: var(--navy-muted);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .8px;
  text-transform: uppercase;
}

/* ---------- Sidebar footer ---------- */
.side-bottom {
  padding: 14px 22px;
  border-block-start: 1px solid var(--navy-border);
}

.lang-toggle {
  display: flex;
  gap: 6px;
  margin-block-end: 12px;
}
.lang-toggle button {
  flex: 1;
  background: transparent;
  color: var(--navy-text);
  border: 1px solid var(--navy-border);
  border-radius: 6px;
  padding: 5px;
  font-size: 12px;
}
.lang-toggle button.active {
  background: var(--primary);
  color: var(--navy-text-strong);
  border-color: var(--primary);
}

.userchip {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--navy-text);
}
.userchip .avatar {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--primary);
  color: var(--navy-text-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
}
.userchip .who {
  font-size: 12.5px;
  color: var(--navy-text-strong);
}
.userchip .role {
  font-size: 10.5px;
  color: var(--navy-muted);
}

.side-signout {
  margin-block-start: 10px;
  background: transparent;
  color: var(--navy-muted);
  border: none;
  font-size: 12px;
  text-align: start;
  padding: 0;
  text-decoration: underline;
}
.side-signout:hover {
  color: var(--navy-text-strong);
}

/* ---------- Topbar ----------
   min-height holds the ribbon at the height it takes with a button in it, so
   navigating from a page that has page actions to one that does not leaves the
   header where it was instead of shifting the whole page up a few pixels. */
.topbar {
  background: var(--card);
  border-block-end: 1px solid var(--border);
  padding: 12px 26px;
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 9;
}
.topbar .title {
  font-weight: 700;
  font-size: 18px;
}
.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* The shell's Refresh button. Its glyph is a separate span so only the icon
   spins while a redraw is in flight, and so the gap between icon and label does
   not depend on a space character surviving translation. */
.topbar-refresh {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.topbar-refresh .ic {
  font-size: 15px;
  line-height: 1;
}

/* Below the sidebar breakpoint the label is dropped and the glyph carries the
   button on its own: eleven destinations already compete for this row on a
   phone, and Refresh is the one thing here that does not need naming twice. */
@media (max-width: 640px) {
  .topbar-refresh { padding-inline: 10px; }
  .topbar-refresh .ic { font-size: 17px; }
  .topbar-refresh > :not(.ic) { display: none; }
}

/* ==========================================================================
   Mobile admin shell — bottom navigation ribbon (js/shell/mobileNav.js)

   Admins still work on desktop (Section 1); this is the same app on a phone,
   not a second one. The sidebar and the ribbon are both in the DOM on every
   draw and exactly one of them is displayed, so rotating a phone or resizing a
   window swaps navigation without a redraw.

   Below the breakpoint the sidebar goes away entirely rather than folding to
   the top of the page: a full-height column of links above the content is the
   thing that made the phone unusable — the dashboard began a screen and a half
   down. The ribbon is fixed to the bottom instead, so the page starts at the
   top of the viewport and every destination stays one tap away.
   ========================================================================== */

.mobile-nav { display: none; }

@media (max-width: 900px) {
  .sidebar { display: none; }
  .mobile-nav { display: block; }

  .content { padding: 16px; }

  /* Clear the fixed ribbon, plus the home-indicator strip on iOS, so the last
     row of a table is never trapped behind it. */
  .main { padding-block-end: calc(64px + env(safe-area-inset-bottom, 0px)); }

  /* The topbar is sticky and the ribbon is fixed; the page between them is what
     scrolls, so its own padding is all the room the title needs. */
  .topbar { padding: 12px 16px; }
}

.mobile-nav {
  position: fixed;
  inset-inline: 0;
  inset-block-end: 0;
  z-index: 20;
  background: var(--navy);
  border-block-start: 1px solid var(--navy-border);
  padding-block-end: env(safe-area-inset-bottom, 0px);
}

/* Horizontal scroll, no scrollbar: eleven destinations do not fit across a
   phone, and shrinking them until they do makes every one of them unreadable.
   The active tab is scrolled into view on navigation (mobileNav.js). */
.mnav-scroll {
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.mnav-scroll::-webkit-scrollbar { display: none; }

.mnav-link {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 74px;
  min-height: 58px;   /* a touch target, not a mouse target */
  padding: 8px 10px;
  background: transparent;
  border: none;
  /* The active marker sits on the block-start edge here, not the inline-start
     one — the strip runs across the screen, so a leading-edge bar would mark
     the tab beside the one selected. */
  border-block-start: 3px solid transparent;
  color: var(--navy-text);
  text-decoration: none;
  font-size: 10.5px;
}
.mnav-link .ic {
  font-size: 17px;
  line-height: 1;
  opacity: .85;
}
.mnav-link .lbl {
  max-width: 88px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mnav-link.active {
  background: rgba(255, 255, 255, .08);
  border-block-start-color: var(--primary);
  color: var(--navy-text-strong);
}
.mnav-link.active .ic { opacity: 1; }

/* ---------- The "More" sheet ----------
   Theme, language, who is signed in, and sign out — the sidebar footer, which
   has nowhere to live in a strip of tabs. Painted navy like the strip above it,
   which is what lets .userchip / .lang-toggle / .side-signout be reused with
   the colours they were written for. */
.mnav-sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: var(--overlay);
  display: flex;
  align-items: flex-end;
}
.mnav-sheet[hidden] { display: none; }

.mnav-sheet-panel {
  position: relative;
  width: 100%;
  background: var(--navy);
  color: var(--navy-text);
  border-start-start-radius: 16px;
  border-start-end-radius: 16px;
  padding: 20px 22px calc(20px + env(safe-area-inset-bottom, 0px));
  box-shadow: var(--shadow-md);
}
.mnav-sheet-panel .swatches { margin-block: 16px; }
.mnav-sheet-panel .lang-toggle { margin-block-end: 4px; }

.mnav-sheet-close {
  position: absolute;
  inset-block-start: 10px;
  inset-inline-end: 10px;
  min-width: 40px;
  min-height: 40px;
  background: transparent;
  border: none;
  color: var(--navy-muted);
  font-size: 15px;
}

/* ==========================================================================
   Officer mobile shell (Sections 7.1, 8.6)

   Ported from design/officer_prototype.html. Same navy header and sync strip;
   colours come from tokens.css rather than the prototype's inline hex.

   The frame is a centred column rather than a true "phone frame" chrome: the
   officer app and the admin app share one URL, so this has to be usable at
   desktop width without pretending to be a device mock-up.
   ========================================================================== */

.phone {
  max-width: 420px;
  margin-inline: auto;
  min-height: 100vh;
  background: var(--bg);
  position: relative;
  border-inline: 1px solid var(--border);
}

/* Below the frame width there is nothing to frame. */
@media (max-width: 440px) {
  .phone { border-inline: none; }
}

/* ---------- Officer header ----------
   Sticky, because the officer scrolls a long certificate list and must always
   be one tap from signing out. */
.officer-hbar {
  background: var(--navy);
  color: var(--navy-text-strong);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  position: sticky;
  inset-block-start: 0;
  z-index: 5;
}
.officer-hbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.officer-hbar .mark {
  color: var(--primary);
  font-weight: 800;
  font-size: 16px;
  letter-spacing: .5px;
}
.officer-hbar .name {
  font-weight: 700;
  font-size: 14px;
}
.officer-hbar .sub {
  color: var(--navy-text);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.officer-hbar .hbar-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.officer-hbar .hbar-btn {
  color: var(--navy-text-strong);
  font-size: 13px;
  font-weight: 600;
  min-width: 40px;
  min-height: 40px;   /* a touch target, not a mouse target */
  padding: 8px 10px;
  border: none;
  border-radius: var(--radius-control);
  background: var(--navy-soft);
}
.officer-hbar .hbar-btn:disabled { opacity: .6; }

/* ---------- Sync strip ---------- */
.sync-strip {
  background: var(--card);
  padding: 10px 16px;
  border-block-end: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
}
.sync-strip .as-of { color: var(--text2); }
.sync-strip .as-of b { color: var(--text); font-weight: 600; }
.sync-strip button {
  color: var(--primary);
  font-weight: 700;
  font-size: 13px;
  background: none;
  border: none;
  padding: 6px 4px;
  flex-shrink: 0;
}

/* Amber warning in the last stretch of the freshness window — a nudge, not the
   lockout. The lockout is a whole screen (Section 7.4). */
.stale-banner {
  background: var(--warn-bg);
  color: var(--warn-dark);
  padding: 9px 16px;
  font-size: 12.5px;
  text-align: center;
  font-weight: 600;
  border-block-end: 1px solid var(--warn);
}

/* ---------- Officer page body ---------- */
.officer-body { padding: 16px; }
.officer-body > h2 { margin: 4px 0 6px; font-size: 18px; font-weight: 800; }
.officer-intro {
  margin: 0 0 16px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text2);
}

/* Breathing room under the last panel on a scrolling verdict card. */
.officer-tail { height: 20px; }
