/* =========================================================================
   03-layout.css — application structure & modern layout
   Top bar, primary navigation, page container, and the two-panel board with
   its collapse to a tab switcher.
   Originate Command · application
   ========================================================================= */

/* ---- top bar ------------------------------------------------------------ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: var(--s3);
  height: var(--topbar-h);
  padding: 0 var(--s5);
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--rule);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
}
/* a single hairline of brand colour, not a rainbow rule */
.topbar::after {
  content: "";
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, var(--blueprint) 0%, var(--brand-orange) 55%, transparent 100%);
  opacity: 0.5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}
.brand .mark {
  width: 34px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #1E293B 0%, #0F172A 100%);
  border: 1px solid rgba(249, 115, 22, 0.65);
  color: #FFFFFF;
  border-radius: 9px;
  font-family: var(--font-display, 'Plus Jakarta Sans', sans-serif);
  font-weight: 800;
  font-size: 14.5px;
  letter-spacing: -0.02em;
  box-shadow: var(--sh1);
  transition: border-color var(--t), box-shadow var(--t);
}
.brand:hover .mark {
  border-color: var(--brand-orange);
  box-shadow: var(--sh2);
}
.brand .lockup {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  /* `.brand span` below styles the SRS line; the lockup is a span too, so it
     has to opt out or the wordmark inherits the caps and tracking. */
  text-transform: none;
  letter-spacing: normal;
}
.brand b {
  font-family: var(--font-display, 'Plus Jakarta Sans', sans-serif);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-transform: none;
}
.brand .lockup span {
  font-family: var(--font-sans, 'Plus Jakarta Sans', sans-serif);
  font-size: 10px;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--text-secondary);
  font-weight: 700;
}

.topbar .who {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: 5px 12px 5px 6px;
  border: 1px solid var(--rule);
  border-radius: var(--r-pill);
  background: var(--card-bg-alt);
  max-width: 340px;
  min-width: 0;
}
.topbar .who > div {
  min-width: 0;
}
.topbar .who strong,
.topbar .who .mono {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
}
.topbar .who select {
  width: auto;
  min-width: 220px;
  height: var(--ctl-sm);
  font-size: 13px;
  font-weight: 500;
}

/* .iconbtn and .toggle-theme are the top-bar utility controls: same height,
   same radius and the same quiet neutral as .btn, so the bar reads as one row
   of controls rather than three unrelated shapes. */
.iconbtn,
.toggle-theme {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 13px;
  background: var(--btn-bg);
  color: var(--btn-text);
  border: 1px solid var(--btn-border);
  border-radius: var(--r1);
  font-family: var(--font-sans, 'Plus Jakarta Sans', sans-serif);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--sh1);
  transition: color var(--t-fast), border-color var(--t-fast), background var(--t-fast);
}
.iconbtn:hover,
.toggle-theme:hover {
  color: var(--btn-hover-text);
  border-color: var(--btn-hover-border);
  background: var(--btn-hover-bg);
}
.iconbtn:active,
.toggle-theme:active {
  transform: translateY(1px);
}
.iconbtn:focus-visible,
.toggle-theme:focus-visible {
  outline: 2px solid var(--blueprint);
  outline-offset: 2px;
}
.toggle-theme .icon {
  width: 14px;
  height: 14px;
}
.iconbtn .icon {
  width: 13px;
  height: 13px;
}
.iconbtn .count {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: var(--signal);
  color: #FFFFFF !important;
  border-radius: var(--r-pill);
  font-size: 10.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

/* ---- navigation --------------------------------------------------------- */
.nav {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  padding: 0 var(--s5);
  background: var(--card-bg);
  border-bottom: 1px solid var(--rule);
  position: sticky;
  top: var(--topbar-h);
  z-index: 25;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
/* Underline tabs: the current section is marked by a 2px rule sitting on the
   nav's own bottom border, so the row keeps a single clean baseline. */
.nav button {
  position: relative;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 16px;
  height: var(--nav-h, 46px);
  font-family: var(--font-sans, 'Plus Jakarta Sans', sans-serif);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  user-select: none;
  transition: color var(--t-fast), background var(--t-fast);
}
.nav button::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: transparent;
  transition: background var(--t-fast);
}
.nav button:hover {
  color: var(--ink);
}
.nav button:hover::after {
  background: var(--rule-strong);
}
.nav button:focus-visible {
  outline: 2px solid var(--blueprint);
  outline-offset: -3px;
  border-radius: 4px;
}
.nav button[aria-current="page"] {
  color: var(--blueprint);
  font-weight: 700;
}
.nav button[aria-current="page"]::after {
  background: var(--blueprint);
}

/* ---- page --------------------------------------------------------------- */
.page {
  max-width: var(--page-max, 1440px);
  margin: 0 auto;
  padding: var(--s6) var(--s5) 96px;
  animation: pageFadeIn 140ms cubic-bezier(0.16, 1, 0.3, 1);
  will-change: opacity, transform;
}
@keyframes pageFadeIn {
  from {
    opacity: 0.88;
    transform: translateY(2px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
/* Page heading. The title was a clipped gradient, which faded the last word of
   every heading; solid ink reads better and stays legible in both themes. */
.page-head {
  margin-bottom: var(--s5);
  padding-bottom: var(--s4);
  border-bottom: 1px solid var(--rule);
}
.page-head h1 {
  font-size: 26px;
  line-height: 1.2;
  margin-bottom: 7px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--ink);
}
.page-head p {
  color: var(--text-secondary);
  font-size: 14px;
  max-width: 72ch;
  line-height: 1.6;
}

/* ---- the two-panel board ------------------------------------------------ */
.board {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--s4);
  align-items: start;
}
.panel-tabs {
  display: none;
  gap: 0;
  margin-bottom: var(--s3);
  border: 1px solid var(--rule-strong);
  border-radius: var(--r1);
  overflow: hidden;
}

@media (max-width: 1100px) {
  .board {
    grid-template-columns: 1fr;
  }
  .panel-tabs {
    display: flex;
  }
  .board[data-panel="todos"] .panel--instructions {
    display: none;
  }
  .board[data-panel="instructions"] .panel--todos {
    display: none;
  }
}

.panel-tabs button {
  flex: 1;
  background: var(--card-bg);
  border: none;
  cursor: pointer;
  padding: 10px 12px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-secondary);
  user-select: none;
  transition: background var(--t-fast), color var(--t-fast), transform var(--t-instant);
}
.panel-tabs button + button {
  border-left: 1px solid var(--rule);
}
.panel-tabs button:hover {
  background: var(--tint);
  color: var(--ink);
}
.panel-tabs button:active {
  transform: scale(0.96);
  transition: transform var(--t-instant);
}
.panel-tabs button[aria-pressed="true"] {
  background: var(--blueprint);
  color: #FFFFFF;
  font-weight: 700;
}

/* Panels sit still. Hover used to swap the border to blue and jump two
   elevation steps, which made a static page feel jittery under the cursor. */
.panel {
  border: 1px solid var(--rule);
  border-radius: var(--r2);
  background: var(--card-bg);
  box-shadow: var(--sh1);
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  gap: var(--s3);
  flex-wrap: wrap;
  min-height: 60px;
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--rule);
  background: var(--card-bg-alt);
}
/* a segmented control in a panel head sits on the same 60px rhythm as the
   buttons beside it, so two panels side by side keep one baseline */
.panel-head .segmented {
  padding: 2px;
}
.panel-head .segmented button {
  height: 30px;
  padding: 0 12px;
}
.panel-head h2 {
  font-family: var(--font-display, 'Plus Jakarta Sans', sans-serif);
  font-size: 15.5px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.panel-head .sub {
  font-family: var(--font-sans, 'Plus Jakarta Sans', sans-serif);
  font-size: 12px;
  letter-spacing: normal;
  color: var(--text-secondary);
  font-weight: 500;
}
.panel-head .tools {
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin-left: auto;
  flex-wrap: wrap;
}
.panel-body {
  padding: var(--s3) var(--s4) var(--s4);
  display: flex;
  flex-direction: column;
  gap: var(--s3);
}
.panel-body.scroll {
  max-height: calc(100vh - 280px);
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: auto; /* Raw 1:1 hardware scroll tracking with no inertia lag */
  contain: layout paint;
  transform: translateZ(0);
  will-change: scroll-position;
}

.stats,
.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--s4);
  margin-bottom: var(--s5);
  align-items: stretch;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--s4);
  align-items: stretch;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: var(--s3);
  align-items: stretch;
}
/* cards in a row share the row's height so a grid never looks ragged */
.grid-2 > *,
.grid-3 > *,
.grid-4 > *,
.stats > * {
  min-width: 0;
}

/* ---- responsiveness & performance optimizations ----------------------- */
.nav::-webkit-scrollbar {
  display: none;
}

@media (max-width: 1024px) {
  .board {
    grid-template-columns: 1fr;
  }
  .stats,
  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid-3 {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  }
}

/* two metric cards to a row on a phone: one per row pushed the actual work
   four screens down */
@media (max-width: 600px) {
  .stats,
  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--s3);
  }
  .stat {
    min-height: 80px;
    padding: var(--s3) var(--s3) var(--s3) var(--s4);
  }
  .stat .v {
    font-size: 26px;
  }
}

@media (max-width: 380px) {
  .stats,
  .grid-4 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .topbar {
    height: auto;
    min-height: var(--topbar-h);
    flex-wrap: wrap;
    padding: 10px var(--s4);
    gap: 10px;
  }
  .topbar .who {
    order: 3;
    width: 100%;
    max-width: none;
    margin-left: 0;
  }
  .topbar .who select {
    flex: 1;
    min-width: 0;
  }
  .brand .lockup span {
    display: none;
  }
  .nav {
    position: sticky;
    top: auto;
    padding: 0 var(--s3);
    gap: 2px;
  }
  .nav button {
    padding: 0 14px;
    height: 42px;
    font-size: 13px;
  }
  .page {
    padding: var(--s3) var(--s3) 72px;
  }
  .page-head h1 {
    font-size: 22px;
  }
  .panel-body.scroll {
    max-height: none;
    overflow: visible;
  }
  .filters {
    grid-template-columns: 1fr 1fr;
  }
  .filterbar-head {
    flex-wrap: wrap;
    gap: 8px;
  }
  .grid-2 {
    grid-template-columns: 1fr;
  }
  .grid-3 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .topbar .theme-label,
  .topbar .topbar-signout-btn .btn-label,
  .topbar .topbar-alerts-btn .btn-label {
    display: none;
  }
  .topbar .toggle-theme,
  .topbar .topbar-signout-btn,
  .topbar .topbar-alerts-btn {
    padding: 0 9px;
    gap: 3px;
    height: 32px;
    min-width: 34px;
    justify-content: center;
  }
}

@media (max-width: 480px) {
  .topbar {
    padding: 8px var(--s3);
  }
  .brand b {
    font-size: 15px;
  }
  .brand .mark {
    width: 32px;
    height: 32px;
    font-size: 14px;
  }
  .filters {
    grid-template-columns: 1fr;
  }
  .panel-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .panel-head .tools {
    width: 100%;
    margin-left: 0;
    justify-content: flex-start;
  }
  .btn, .iconbtn {
    min-height: 38px;
  }
}
