/* Global base styles — P3.1-001.
 *
 * Consumes the custom properties from tokens.css (loaded first via a
 * separate <link>; cross-file CSS includes are forbidden — INV-4
 * second-fetch ban). Covers
 * the page shell (body/header/nav/main), tables, cards, forms, buttons and
 * links. Page-specific polish (graph panel, login card, charts, gantt)
 * lives in its own per-task stylesheet so P3.1-002/003/004 never edit this
 * file concurrently.
 */

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--font-size);
  line-height: var(--line-height);
  -webkit-font-smoothing: antialiased;
}

/* --- Page shell (P3.3-008 MiroFish app-bar) -------------------------- */
/* A bordered header with two rows: row 1 (.app-bar) = brand logo-left +
   slim global nav; row 2 (.app-header-bar) = the prominent page title + the
   segmented case tabs (page_heading / page_tabs blocks) + an optional
   right-aligned layout switcher (app_switcher, graph page only). The page
   title carries the top context, not the brand. */

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

/* Optional topmost "back to the host platform" strip (base.html renders it
   only when VCA_WEB_HOME_URL is set). A slim muted band above the brand bar
   so it reads as "leave VCA", distinct from the in-app global nav. */
.app-top-strip {
  display: flex;
  align-items: center;
  padding: var(--space-1) var(--space-5);
  border-bottom: 1px solid var(--border);
}

.app-home-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--muted);
  font-size: 0.8rem;
  text-decoration: none;
}

.app-home-link:hover,
.app-home-link:focus {
  color: var(--text);
}

.app-home-arrow {
  font-size: 0.9rem;
  line-height: 1;
}

.app-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-2) var(--space-5);
  border-bottom: 1px solid var(--border);
}

.app-brand {
  display: inline-flex;
  align-items: baseline;
  gap: var(--space-2);
  white-space: nowrap;
  text-decoration: none;
  line-height: 1.2;
}

.app-brand-short {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  color: var(--accent-strong);
}

.app-brand-full {
  font-size: 0.8rem;
  color: var(--muted);
}

.app-brand:hover .app-brand-full,
.app-brand:focus .app-brand-full {
  color: var(--text);
}

.global-nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
}

.global-nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
  padding: var(--space-1) 0;
  border-bottom: 2px solid transparent;
}

.global-nav a:hover,
.global-nav a:focus {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.app-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-5);
}

.app-header-lead {
  min-width: 0; /* let a long title / tab row shrink + wrap */
  flex: 1 1 auto;
  /* P3.3-011 #1-follow-up: put the page title and the centred case-tab row on
     the SAME line (the centred nav must sit at the title's vertical position,
     not on a row below it — superseding the P3.3-011 #7 column stack). A
     1fr/auto/1fr grid keeps the title at the left and centres .case-nav in the
     lead; align-items centres both on one baseline. Pages without case tabs
     (cases list / search / settings) carry only the title — it lands in
     column 1, left-aligned, and is unaffected. */
  display: grid;
  /* minmax(0,1fr) side tracks so a long title WRAPS within its track instead
     of forcing the row wider than the viewport when the centred tab row is wide
     (codex P2): the auto middle track is content-sized, the shrinkable sides
     absorb the squeeze. Below the mobile breakpoint the lead reverts to a
     stacked column (media query) so the tabs get a full-width row to wrap. */
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: var(--space-2) var(--space-4);
}

/* Centre the case-tab row on the title's row (P3.3-011 #1-follow-up): the
   middle auto column is balanced by the two 1fr columns, and justify-self keeps
   the nav centred in its cell. The base .case-nav top margin is dropped so it
   lines up vertically with the title. */
.app-header-lead .case-nav {
  grid-column: 2;
  justify-self: center;
  /* Cap at the cell width so a row wider than the viewport wraps (the nav's own
     flex-wrap) instead of overflowing horizontally (codex P2). */
  max-width: 100%;
  margin: 0;
}

.page-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--heading);
  letter-spacing: 0.01em;
}

main {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-5);
}

/* Full-bleed opt-in: pages that need the whole viewport (the flow
   graph) set {% block main_class %}layout-fluid{% endblock %}. */
main.layout-fluid {
  max-width: none;
}

h2,
h3,
h4 {
  color: var(--heading);
  font-weight: 600;
  line-height: 1.25;
}

/* --- Links ----------------------------------------------------------- */

a {
  color: var(--accent);
}

a:hover,
a:focus {
  color: var(--accent-strong);
}

/* --- Tables ---------------------------------------------------------- */

table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--space-4) 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

th,
td {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  background: var(--surface-raised);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

tbody tr:last-child td {
  border-bottom: none;
}

/* --- Cards ----------------------------------------------------------- */

/* The overview stat cards (#overview-cards grid + .stat-card) are styled by
   charts.css (the grid, htmx target id) and console.css (the .stat-card
   surface + dt/dd) — a single SSOT, no duplicate palette here (P3.3-008). */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: var(--space-4);
}

/* --- Forms ----------------------------------------------------------- */

label {
  display: block;
  margin-bottom: var(--space-1);
  color: var(--muted);
  font-size: 0.9rem;
}

/* Text-like controls only: a bare `input` selector would also hit the
   graph stage-filter checkboxes (built by graph_page.js) and inflate
   them to full-width text boxes (codex P2). */
input[type="text"],
input[type="password"],
input[type="search"],
input[type="email"],
input[type="number"],
select,
textarea {
  width: 100%;
  max-width: 28rem;
  padding: var(--space-2) var(--space-3);
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.95rem;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="search"]:focus,
input[type="email"]:focus,
input[type="number"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
}

input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--accent);
}

textarea {
  min-height: 5rem;
  resize: vertical;
}

/* --- Buttons (P3.3-009 #1) ------------------------------------------- */

/* All buttons read the --btn-* token palette (defined per theme in
   tokens.css) so they harmonise with the light "console" surface instead
   of reusing the dark-derived accent-strong + heading pair. One button
   language across every page — never a per-page hard-coded colour. */
button {
  display: inline-block;
  margin-top: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--btn-bg);
  color: var(--btn-text);
  border: 1px solid var(--btn-border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

button:hover {
  background: var(--btn-hover-bg);
  border-color: var(--btn-hover-border);
}

/* Visible keyboard focus ring (WCAG AA 2.4.7) — :focus-visible so a mouse
   click does not leave a lingering ring but a tab-stop is clearly shown. */
button:focus-visible {
  outline: 2px solid var(--btn-focus);
  outline-offset: 2px;
}

/* A neutral/secondary button (white-on-light / subtle-on-dark chip). */
.btn-muted {
  background: var(--btn-muted-bg);
  color: var(--btn-muted-text);
  border-color: var(--btn-muted-border);
}

.btn-muted:hover {
  background: var(--btn-muted-hover-bg);
  border-color: var(--btn-muted-border);
}

.btn-danger {
  background: var(--danger-strong);
  color: var(--btn-text);
  border-color: var(--danger-strong);
}

.btn-danger:hover {
  background: var(--danger);
  border-color: var(--danger);
}

/* --- Status text ----------------------------------------------------- */

.error,
[role="alert"] {
  color: var(--danger);
  font-weight: 600;
}

/* --- Case view tabs (P3.3-008 segmented switcher) --------------------- */
/* The 6 case tabs render as a MiroFish segmented control: a pill container
   with the active tab a raised white pill. Shared by every per-case page —
   lives here because base.css is the only sheet linked on all of them. */
.case-nav {
  display: inline-flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin: var(--space-2) 0 0;
  padding: var(--space-1);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
}

.case-nav a {
  padding: var(--space-1) var(--space-3);
  color: var(--muted);
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.case-nav a:hover {
  color: var(--text);
}

.case-nav a.active {
  color: var(--heading);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  font-weight: 600;
}

/* --- Mobile (P3.1-008) ------------------------------------------------ */
/* base.html already ships the width=device-width viewport meta; below
   the breakpoint the shell tightens and wide forensic tables scroll
   horizontally instead of blowing the layout open. */

@media (max-width: 800px) {
  .app-bar,
  .app-header-bar {
    padding: var(--space-2) var(--space-3);
  }

  /* On narrow screens the centred-on-one-row header (grid) would squeeze the
     title or overflow, so revert to the stacked column: the title sits above a
     full-width case-tab row that wraps freely (codex P2). */
  .app-header-lead {
    display: flex;
    flex-direction: column;
  }

  .app-header-lead .case-nav {
    align-self: center;
    justify-self: auto;
  }

  /* drop the long brand subtitle on narrow screens; keep "VCA" */
  .app-brand-full {
    display: none;
  }

  main {
    padding: var(--space-3);
  }

  .global-nav,
  .case-nav {
    flex-wrap: wrap;
    gap: var(--space-1);
  }

  .case-nav a {
    padding: var(--space-1) var(--space-3);
  }

  table {
    display: block;
    overflow-x: auto;
  }
}
