/*
 * app.css — shell + base-component styles. Every rule refers only to tokens
 * from `tokens.css`. Loaded on every authenticated page (via _shell_top.php);
 * `/login` is standalone and loads it too so form controls stay consistent.
 *
 * Layout: CSS grid with a fixed-width sidebar column and a fluid main column.
 * Mobile (≤900px) collapses the sidebar off-canvas; a checkbox-hack input
 * toggled by the hamburger label opens it as an overlay — no JS needed for
 * this piece (theme.js only handles the dark-mode toggle).
 */

/* ─────────────────────── Reset-ish ─────────────────────── */

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

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--line-height-body);
  color: var(--text-primary);
  background: var(--surface-page);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

h1, h2, h3, h4, h5, h6 {
  color: var(--text-primary);
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-tight);
  margin: 0;
}

p {
  margin: 0 0 var(--space-3);
}

code {
  background: var(--surface-inset);
  border-radius: var(--radius-sm);
  padding: 0 var(--space-1);
  font-size: 0.9em;
}

/*
 * Universal focus ring — every keyboard-focusable element in the app picks
 * this up. Uses `outline` (not box-shadow) so `outline-offset` gives the
 * 2px gap the ticket-05 spec calls out, and so the ring won't clip inside
 * containers with `overflow: hidden` (kanban card, modal, etc.). The ring
 * only paints its own outline — it deliberately does NOT set border-radius
 * so each focused element keeps its native corner shape.
 */
:focus-visible {
  outline: 2px solid var(--color-primary-500);
  outline-offset: 2px;
}
:root[data-theme="dark"] :focus-visible {
  outline-color: var(--color-primary-400);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) :focus-visible {
    outline-color: var(--color-primary-400);
  }
}
/*
 * Mouse-focus reset only: `:not(:focus-visible)` scopes this to pointer
 * activation, so a mouse click doesn't paint a ring but a keyboard tab
 * still lights up the universal outline above. Without the guard, this
 * reset's specificity (tag + pseudo) beats the naked `:focus-visible`
 * rule and every button/input silently loses its ring on keyboard focus.
 */
button:focus:not(:focus-visible),
input:focus:not(:focus-visible),
select:focus:not(:focus-visible),
textarea:focus:not(:focus-visible),
a:focus:not(:focus-visible) {
  outline: none;
}

/* ─────────────────────── Icon ─────────────────────── */

.icon {
  width: 1.25rem;
  height: 1.25rem;
  flex: 0 0 auto;
  color: currentColor;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-sm { width: 1rem;  height: 1rem;  }
.icon-lg { width: 1.5rem; height: 1.5rem; }

/* ─────────────────────── Shell layout ─────────────────────── */

.sidebar-toggle-cb {
  /*
   * Off-DOM checkbox: the hamburger label toggles it, the sidebar's sibling
   * selector reads its :checked state. Kept visually hidden but focusable-in-
   * spirit — the label is the interactive element users see.
   */
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
  background: var(--surface-page);
}

/* ─────────────────────── Sidebar ─────────────────────── */

.sidebar {
  grid-column: 1;
  display: flex;
  flex-direction: column;
  background: var(--surface-sidebar);
  border-right: var(--border-subtle);
  padding: var(--space-4) 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-4) var(--space-4);
  font-size: var(--text-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  border-bottom: var(--border-subtle);
  margin-bottom: var(--space-3);
}

.sidebar-brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  background: var(--accent);
  color: var(--accent-on);
  border-radius: var(--radius-md);
  font-weight: var(--font-weight-semibold);
  font-size: var(--text-sm);
  padding: 0.25rem;
}

/* QRA brand mark — inherits `color` from parent (`.sidebar-brand-mark` /
   `.auth-brand-mark`) via currentColor in the SVG. Fills the parent box
   preserving aspect ratio; no fixed width so it scales with the container. */
.brand-mark {
  width: 100%;
  height: 100%;
  display: block;
}

.sidebar-nav {
  flex: 1;
  list-style: none;
  padding: 0 var(--space-2);
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-0-5);
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--font-weight-medium);
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.sidebar-nav-item:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
  text-decoration: none;
}

.sidebar-nav-item.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.sidebar-nav-item.is-active .icon {
  color: var(--accent);
}

.sidebar-footer {
  padding: var(--space-3) var(--space-4) 0;
  border-top: var(--border-subtle);
  margin-top: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.user-chip-avatar {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: var(--accent-on);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: var(--font-weight-semibold);
  font-size: var(--text-xs);
}

.user-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-logout {
  margin: 0;
}

.btn-block {
  width: 100%;
  justify-content: flex-start;
}

/* Segmented pill: two icon-only buttons (sun = light, moon = dark). The
 * one matching the current `data-theme` is filled; the other is muted.
 * Wired in theme.js. */
.theme-switcher {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1);
  border-radius: var(--radius-full);
  background: var(--surface-inset);
  border: var(--border-subtle);
}

.theme-switcher-option {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.theme-switcher-option:hover {
  color: var(--text-primary);
}

.theme-switcher-option.is-active {
  background: var(--surface-card);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* ─────────────────────── Topbar + main ─────────────────────── */

.main-column {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-6);
  background: var(--surface-card);
  border-bottom: var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-title {
  font-size: var(--text-xl);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  margin: 0;
}

.hamburger {
  display: none;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
}

.hamburger:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.app-main {
  flex: 1;
  padding: var(--space-6);
  min-width: 0;
}

/* ─────────────────────── Base components ─────────────────────── */

.card {
  background: var(--surface-card);
  border: var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-6);
}

.card-title {
  font-size: var(--text-lg);
  margin-bottom: var(--space-3);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font: inherit;
  font-size: var(--text-sm);
  font-weight: var(--font-weight-medium);
  line-height: 1;
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
  text-decoration: none;
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Focus ring served by the universal `:focus-visible` outline above. */

.btn-primary {
  background: var(--accent);
  color: var(--accent-on);
}

.btn-primary:hover {
  background: var(--accent-hover);
  color: var(--accent-on);
  text-decoration: none;
}

.btn-secondary {
  background: var(--surface-card);
  color: var(--text-primary);
  border-color: var(--color-neutral-300);
}

.btn-secondary:hover {
  background: var(--surface-hover);
  text-decoration: none;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
  text-decoration: none;
}

.input {
  display: block;
  width: 100%;
  padding: var(--space-2) var(--space-3);
  font: inherit;
  font-size: var(--text-sm);
  color: var(--text-primary);
  background: var(--surface-card);
  border: 1px solid var(--color-neutral-300);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

/*
 * Field-focused state: border tints + inner glow ring on every focus
 * (mouse OR keyboard). Keyboard focus additionally gets the universal
 * outline offset ring for keyboard-user visibility — the two rings sit
 * in different Z bands (outline outside the border, box-shadow across
 * the border) so they read as one focused-field indicator, not two.
 */
.input:focus {
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

.form-label {
  display: block;
  margin-bottom: var(--space-1);
  font-size: var(--text-sm);
  font-weight: var(--font-weight-medium);
  color: var(--text-secondary);
}

.form-help {
  color: var(--text-muted);
  font-size: var(--text-sm);
  margin: var(--space-2) 0 0;
}

.form-actions {
  margin-top: var(--space-6);
  display: flex;
  gap: var(--space-3);
}

.upload-card {
  max-width: 36rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-0-5) var(--space-2);
  border-radius: var(--radius-full);
  background: var(--surface-inset);
  color: var(--text-secondary);
  font-size: var(--text-xs);
  font-weight: var(--font-weight-medium);
}

.chip-success { background: var(--color-success-50); color: var(--color-success-700); }
.chip-warning { background: var(--color-warning-50); color: var(--color-warning-700); }
.chip-danger  { background: var(--color-danger-50);  color: var(--color-danger-700);  }
.chip-info    { background: var(--color-info-50);    color: var(--color-info-700);    }

.alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-size: var(--text-sm);
  margin-bottom: var(--space-4);
}

.alert-danger {
  background: var(--color-danger-50);
  color: var(--color-danger-700);
  border-color: var(--color-danger-500);
}

.alert-success {
  background: var(--color-success-50);
  color: var(--color-success-700);
  border-color: var(--color-success-500);
}

/* ─────────────────────── Stat tile ─────────────────────── */

.stat-tiles {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-2);
}

.stat-tile {
  position: relative;
  min-width: 10rem;
  padding: var(--space-4) var(--space-6);
  background: var(--surface-card);
  border: var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  overflow: hidden;
}

/*
 * A left-edge accent bar carries the state colour. Neutral by default so a
 * stat-tile with no variant still reads as first-class chrome; a variant
 * class swaps the bar to success/danger without touching the value's colour
 * (the number stays high-contrast, only the marker is coloured).
 */
.stat-tile::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 4px;
  background: var(--color-neutral-300);
}

.stat-tile-success::before { background: var(--color-success-500); }
.stat-tile-danger::before  { background: var(--color-danger-500);  }

.stat-tile .tile-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: var(--font-weight-medium);
}

.stat-tile .tile-value {
  font-size: var(--text-3xl);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  line-height: var(--line-height-tight);
}

/* ─────────────────────── Data table ─────────────────────── */

.data-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: var(--space-4);
  background: var(--surface-card);
  border: var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border-color);
  font-size: var(--text-sm);
  vertical-align: top;
}

.data-table thead th {
  background: var(--surface-inset);
  color: var(--text-secondary);
  font-weight: var(--font-weight-semibold);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table tbody tr:hover {
  background: var(--surface-hover);
}

/*
 * `.linha` (line number) and `.campo` (field name) are Portuguese-named
 * classes pinned by the ticket-13 UploadResultPageTest regex assertions —
 * renaming would break the test suite. Kept as page-scoped modifiers on
 * `.data-table` cells rather than promoted to generic `.col-*` helpers.
 */
.data-table td.linha {
  width: 4rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.data-table td.campo {
  width: 12rem;
  color: var(--text-muted);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: var(--text-xs);
}

/* ─────────────────────── Page bits (actions, empty, note) ────────── */

.actions-bar {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}

.result-note {
  color: var(--text-muted);
  font-size: var(--text-sm);
  margin: var(--space-2) 0 var(--space-4);
}

.result-empty {
  padding: var(--space-8) var(--space-6);
  text-align: center;
  color: var(--text-muted);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-lg);
  margin-top: var(--space-4);
  background: var(--surface-card);
}

/* Plain text links inside empty states get the accent color as a hint
   they're clickable; scoped with :not(.btn) so button variants render
   with their own foreground (--accent-on, the on-color) instead of
   inheriting --accent (the button's OWN background — text would
   disappear). */
.result-empty a:not(.btn) {
  color: var(--accent);
  font-weight: var(--font-weight-medium);
}

/* 404 page (not_found.php) — big code + subtitle above the empty-state
 * body. Extracted from inline `style=` attributes so the template stays
 * token-only. */
.not-found-code {
  font-size: var(--text-3xl);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  margin: 0 0 var(--space-2);
}
.not-found-title {
  font-size: var(--text-lg);
  color: var(--text-primary);
  margin: 0 0 var(--space-4);
}

/* ─────────────────────── Toast ─────────────────────── */

/*
 * Toast surface for transient error / status messages (ticket 05 replaced
 * `alert()`). `.toast-container` is placement, `.toast` is the pill. Each
 * toast carries `role="status"` (info) or `role="alert"` (error) so screen
 * readers announce it — the JS helper picks the right role when emitting.
 */
.toast-container {
  position: fixed;
  right: var(--space-4);
  bottom: var(--space-4);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-width: min(24rem, calc(100vw - var(--space-8)));
  pointer-events: none;
}

.toast {
  background: var(--surface-card);
  color: var(--text-primary);
  border: var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  pointer-events: auto;
  animation: toast-in var(--transition-fast) both;
}
.toast-error {
  border-color: var(--color-danger-500);
  color: var(--color-danger-700);
  background: var(--color-danger-50);
}
.toast-info {
  border-color: var(--color-info-500);
  color: var(--color-info-700);
  background: var(--color-info-50);
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(0.5rem); }
  to   { opacity: 1; transform: translateY(0); }
}

.result-download {
  margin-top: var(--space-4);
}

/* ─────────────────────── Pagination ─────────────────────── */

.pagination {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  margin-top: var(--space-4);
  font-size: var(--text-sm);
}

.pagination a {
  text-decoration: none;
  color: var(--text-primary);
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--color-neutral-300);
  border-radius: var(--radius-md);
  background: var(--surface-card);
  transition: background-color var(--transition-fast);
}
.pagination a:hover { background: var(--surface-hover); }
.pagination a.disabled {
  color: var(--text-muted);
  border-color: var(--color-neutral-200);
  background: transparent;
  pointer-events: none;
  cursor: not-allowed;
}

.pagination-status {
  color: var(--text-muted);
}

/* ─────────────────────── Auth page (standalone, no shell) ────────── */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  background: var(--surface-page);
}

.auth-card {
  width: 100%;
  max-width: 22rem;
  padding: var(--space-8);
  background: var(--surface-card);
  border: var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  justify-content: center;
  margin-bottom: var(--space-4);
  font-size: var(--text-xl);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
}

.auth-brand-mark {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--accent-on);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: var(--font-weight-semibold);
  padding: 0.35rem;
}

.auth-title {
  font-size: var(--text-sm);
  color: var(--text-muted);
  text-align: center;
  margin: 0 0 var(--space-6);
  font-weight: var(--font-weight-regular);
}

/*
 * Auth-specific modifier classes (opt-in on the template) rather than
 * descendant overrides. A future "Forgot password?" secondary button inside
 * `.auth-card` won't inherit full-width or big top margin by surprise —
 * only elements that ask for `.auth-*` get the auth-page geometry.
 */
.auth-field + .auth-field {
  margin-top: var(--space-3);
}

.auth-submit {
  margin-top: var(--space-6);
}

.auth-alert {
  margin: var(--space-4) 0 0;
}

/* ─────────────────────── Mobile ─────────────────────── */

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .hamburger {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 240px;
    height: 100vh;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 180ms ease;
    box-shadow: var(--shadow-lg);
  }

  .sidebar-toggle-cb:checked ~ .app-shell .sidebar {
    transform: translateX(0);
  }
}
