/* CHIKARA Precision Mining — Application Styles */

@import url('tokens.css');

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: calc(var(--safe-top) + var(--header-h) + 8px);
}

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  min-height: 100dvh;
  padding: 0;
  -webkit-font-smoothing: antialiased;
}

body.nav-visible {
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 8px);
}

/* Typography */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.25;
  margin: 0 0 0.4em;
  color: var(--ink);
}
h1 { font-size: clamp(1.5rem, 4vw, 1.9rem); }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 0.75em; }
.muted { color: var(--ink-muted); }
.faint { color: var(--ink-faint); }
.lead { font-size: 1.05rem; }
.mono { font-family: var(--font-mono); font-size: 0.85em; }
.ui { font-family: var(--font-ui); }

/* Layout */
.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.header {
  position: sticky;
  top: 0;
  z-index: 80;
  height: calc(var(--header-h) + var(--safe-top));
  padding-top: var(--safe-top);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  padding-left: max(1rem, var(--safe-left));
  padding-right: max(1rem, var(--safe-right));
  gap: 0.75rem;
}

[data-perf="light"] .header,
[data-perf="extreme"] .header {
  backdrop-filter: none;
  background: var(--surface);
}

.header .brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: 1;
  min-width: 0;
  cursor: pointer;
  border: 0;
  background: none;
  padding: 0;
  color: inherit;
  text-align: left;
}

.header .mark {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--on-primary);
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  flex-shrink: 0;
}

.header .wordmark {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header .wordmark span {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.header-actions {
  display: flex;
  gap: 0.35rem;
  align-items: center;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  display: grid;
  place-items: center;
  cursor: pointer;
  position: relative;
}
.icon-btn:hover, .icon-btn:focus-visible {
  background: var(--bg-alt);
  outline: none;
}
.icon-btn:focus-visible {
  outline: 2px solid var(--primary-ink);
  outline-offset: 2px;
}
.icon-btn svg { width: 20px; height: 20px; }

/* Main content */
.main {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem max(1rem, var(--safe-left)) 2rem max(1rem, var(--safe-right));
}

@media (min-width: 900px) {
  .app-shell {
    flex-direction: row;
  }
  .sidebar {
    display: flex !important;
    width: 240px;
    flex-shrink: 0;
    border-right: 1px solid var(--line);
    background: var(--surface);
    padding: calc(var(--safe-top) + 1rem) 0.75rem 1rem;
    flex-direction: column;
    gap: 0.25rem;
    position: sticky;
    top: 0;
    height: 100dvh;
    overflow-y: auto;
  }
  .header { display: none; }
  .main {
    max-width: none;
    padding: 1.5rem 2rem 3rem;
  }
  .bottom-nav { display: none !important; }
  body.nav-visible { padding-bottom: 0; }
}

.sidebar {
  display: none;
}
.sidebar .side-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.75rem 1.25rem;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--line);
}
.sidebar .side-brand .mark {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary); color: var(--on-primary);
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700;
}
.sidebar .side-brand strong {
  font-family: var(--font-display);
  font-size: 0.95rem;
  display: block;
}
.sidebar .side-brand small {
  font-family: var(--font-ui);
  font-size: 0.65rem;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.side-nav a, .side-nav button {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
  text-decoration: none;
}
.side-nav a:hover, .side-nav button:hover,
.side-nav a.active, .side-nav button.active {
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  color: var(--primary-ink);
}
.side-nav .section-label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  padding: 1rem 0.75rem 0.35rem;
}

/* Bottom nav (mobile) */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 90;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-around;
  align-items: stretch;
}
.bottom-nav button {
  flex: 1;
  border: 0;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  color: var(--ink-muted);
  font-family: var(--font-ui);
  font-size: 0.62rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0.35rem 0.25rem;
  min-height: 48px;
}
.bottom-nav button.active {
  color: var(--primary-ink);
}
.bottom-nav button svg {
  width: 22px;
  height: 22px;
}
.bottom-nav .halo-slot {
  width: 56px;
  flex: 0 0 56px;
}

/* Cards & surfaces */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1rem 1.1rem;
  margin-bottom: 0.85rem;
}
.card.elevated {
  box-shadow: 0 4px 20px rgba(26, 30, 26, 0.06);
}
.card.critical {
  border-color: color-mix(in srgb, var(--crimson) 35%, var(--line));
  background: color-mix(in srgb, var(--crimson) 5%, var(--surface));
}
.card.ok {
  border-color: color-mix(in srgb, var(--ok) 30%, var(--line));
  background: color-mix(in srgb, var(--ok) 5%, var(--surface));
}

.stack { display: flex; flex-direction: column; gap: 0.75rem; }
.row { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.gap-1 { gap: 0.35rem; }
.gap-2 { gap: 0.6rem; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 44px;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-family: var(--font-ui);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--duration-fast) var(--ease-out),
              background var(--duration-fast),
              box-shadow var(--duration-fast);
}
.btn:active { transform: scale(0.97); }
.btn:focus-visible {
  outline: 2px solid var(--primary-ink);
  outline-offset: 2px;
}
.btn-primary {
  background: var(--primary);
  color: var(--on-primary);
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-gold {
  background: linear-gradient(135deg, var(--gold-deep), var(--gold));
  color: #1a1e1a;
}
.btn-ghost {
  background: transparent;
  border-color: var(--line-strong);
  color: var(--ink);
}
.btn-ghost:hover { background: var(--bg-alt); }
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-sm {
  min-height: 36px;
  padding: 0.35rem 0.8rem;
  font-size: 0.82rem;
}
.btn-block { width: 100%; }

/* Evidence badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-full);
  line-height: 1.4;
  white-space: nowrap;
}
/* Badge text uses the audited epistemic tokens (tests/contrast-audit checks each against --surface), on the card
   surface with a hairline of the same colour, so contrast never depends on a tint. A text label always accompanies colour. */
.badge { background: var(--surface); border: 1px solid color-mix(in srgb, currentColor 45%, transparent); }
.badge-known, .badge-recorded { color: var(--known); }
.badge-inferred { color: var(--inferred); }
.badge-estimated, .badge-pending { color: var(--estimated); }
.badge-uncertain { color: var(--uncertain); }
.badge-requires { color: var(--requires); }
.badge-user, .badge-illustrative { color: var(--user); }
.badge-demo { color: var(--estimated); }

/* Forms */
label {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-muted);
  margin-bottom: 0.3rem;
}
input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.95rem;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primary-ink);
  outline-offset: 1px;
  border-color: var(--primary-ink);
}
.field { margin-bottom: 0.9rem; }
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
@media (max-width: 420px) {
  .field-row { grid-template-columns: 1fr; }
}

/* Empty & status */
.empty {
  text-align: center;
  padding: 2.5rem 1.25rem;
  color: var(--ink-muted);
}
.empty h3 { color: var(--ink); margin-bottom: 0.4rem; }
.empty p { margin-bottom: 1.25rem; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  background: var(--bg-alt);
  color: var(--ink-muted);
}
.status-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
}
.status-pill.offline .dot { background: var(--ink-faint); }

/* Knowledge / list items */
.list-item {
  display: flex;
  gap: 0.85rem;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  text-align: left;
  width: 100%;
  background: none;
  border-left: 0;
  border-right: 0;
  border-top: 0;
  color: inherit;
  font: inherit;
}
.list-item:last-child { border-bottom: 0; }
.list-item:hover { background: color-mix(in srgb, var(--primary) 4%, transparent); }
.list-item .icon-wrap {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--primary) 10%, transparent);
  color: var(--primary-ink);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.list-item .meta {
  flex: 1;
  min-width: 0;
}
.list-item .meta strong {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.95rem;
}
.list-item .meta span {
  font-size: 0.82rem;
  color: var(--ink-muted);
}

/* Field card */
.field-card {
  display: grid;
  gap: 0.5rem;
}
.field-card .title-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
}
.field-card .title-row strong {
  font-family: var(--font-display);
  font-size: 1.1rem;
}
.field-card .stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  font-size: 0.85rem;
  color: var(--ink-muted);
}
.field-card .stats b {
  color: var(--ink);
  font-weight: 600;
}

/* Diagnosis steps */
.step-indicator {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 1.25rem;
}
.step-indicator span {
  height: 4px;
  flex: 1;
  border-radius: 2px;
  background: var(--line-strong);
}
.step-indicator span.done { background: var(--primary); }
.step-indicator span.current { background: var(--gold); }

.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}
@media (max-width: 380px) {
  .choice-grid { grid-template-columns: 1fr; }
}
.choice {
  min-height: 48px;
  padding: 0.75rem;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  font-family: var(--font-ui);
  font-size: 0.88rem;
  text-align: left;
  cursor: pointer;
  color: var(--ink);
}
.choice:hover, .choice.selected {
  border-color: var(--primary-ink);
  background: color-mix(in srgb, var(--primary) 8%, var(--surface));
}
.choice.selected {
  box-shadow: inset 0 0 0 1px var(--primary-ink);
}

/* Result block */
.result-block {
  border-left: 3px solid var(--primary-ink);
  padding: 0.75rem 0 0.75rem 1rem;
  margin: 1rem 0;
}
.result-block h3 { margin-bottom: 0.25rem; }
.result-block .why {
  font-size: 0.9rem;
  color: var(--ink-muted);
  margin-top: 0.5rem;
}
.result-block ul {
  margin: 0.4rem 0 0;
  padding-left: 1.1rem;
  font-size: 0.88rem;
  color: var(--ink-muted);
}

/* Calculator result */
.calc-result {
  text-align: center;
  padding: 1.5rem 1rem;
}
.calc-result .value {
  font-family: var(--font-display);
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--primary-ink);
  line-height: 1.1;
}
.calc-result .unit {
  font-family: var(--font-ui);
  font-size: 0.9rem;
  color: var(--ink-muted);
  margin-top: 0.25rem;
}
.calc-result .assumptions {
  text-align: left;
  margin-top: 1.25rem;
  font-size: 0.85rem;
  color: var(--ink-muted);
}

/* Modal / sheet */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(12, 16, 14, 0.45);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.overlay[hidden] { display: none; }
.sheet {
  background: var(--surface);
  width: 100%;
  max-width: 520px;
  max-height: min(88dvh, 720px);
  border-radius: 20px 20px 0 0;
  padding: 0.75rem 1.15rem calc(1.25rem + var(--safe-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--line-strong);
  border-radius: 2px;
  margin: 0.25rem auto 1rem;
}
@media (min-width: 600px) {
  .overlay { align-items: center; }
  .sheet {
    border-radius: var(--radius-xl);
    max-height: 80vh;
  }
  .sheet-handle { display: none; }
}

/* Toast */
.toast-host {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  pointer-events: none;
  width: min(360px, calc(100% - 2rem));
}
.toast {
  background: var(--ink);
  color: var(--bg);
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  font-family: var(--font-ui);
  font-size: 0.88rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  pointer-events: auto;
}

/* Splash */
.splash {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  transition: opacity 0.5s var(--ease-out);
}
.splash.hide {
  opacity: 0;
  pointer-events: none;
}
.splash .logo-mark {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--on-primary);
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--primary) 20%, transparent),
              0 12px 40px color-mix(in srgb, var(--primary) 30%, transparent);
}
.splash h1 {
  font-size: 1.4rem;
  margin: 0;
}
.splash p {
  color: var(--ink-muted);
  margin: 0;
  font-size: 0.9rem;
}
.splash .credit {
  position: absolute;
  bottom: calc(1.5rem + var(--safe-bottom));
  left: 0;
  right: 0;
  text-align: center;
  font-family: var(--font-ui);
  font-size: 0.68rem;
  color: var(--ink-faint);
  padding: 0 1rem;
}

/* Halo (floating) */
.chikara-halo {
  /* Layer 1 — shell: position owned by JS as literal left/top */
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
  transform: translateX(-50%);
  width: var(--halo-size, 75px);
  height: var(--halo-size, 75px);
  z-index: 250;                /* Canon 16.6 stacking ladder: Halo 250, petals 249, Island 200, modals 150 */
  border: 0;
  padding: 0;
  background: none;
  cursor: grab;
  touch-action: none;
  filter:
    drop-shadow(0 4px 10px rgba(26, 30, 26, 0.28))
    drop-shadow(0 0 12px color-mix(in srgb, var(--primary) 35%, transparent));
  animation: halo-breathe 3.6s ease-in-out infinite;
}
.chikara-halo.dragging,
.chikara-halo.open {
  animation-play-state: paused;
}
.chikara-halo:active { cursor: grabbing; }
.chikara-halo .halo-ring {
  /* Layer 2 — brand conic ring */
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  background: conic-gradient(
    from 0deg,
    var(--halo-a, #c9a227),
    var(--halo-b, #f0d98a),
    var(--halo-c, #0f766e),
    var(--halo-a, #c9a227)
  );
  animation: halo-spin 3.4s linear infinite;
}
.chikara-halo.open .halo-ring {
  animation-duration: 0.7s;
}
.chikara-halo .halo-core {
  /* Layer 3 — mark */
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: var(--surface);
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: calc(var(--halo-size, 75px) * 0.32);
  color: var(--primary-ink);
  box-shadow: inset 0 0 0 1px var(--line);
}
@keyframes halo-spin { to { transform: rotate(360deg); } }
@keyframes halo-breathe {
  0%, 100% { filter: drop-shadow(0 4px 10px rgba(26,30,26,0.28)) drop-shadow(0 0 10px color-mix(in srgb, var(--primary) 30%, transparent)); }
  50% { filter: drop-shadow(0 4px 10px rgba(26,30,26,0.28)) drop-shadow(0 0 18px color-mix(in srgb, var(--primary) 50%, transparent)); }
}
@media (prefers-reduced-motion: reduce) {
  .chikara-halo { animation: none; }
  .chikara-halo .halo-ring { animation: none; }
}
[data-theme="outdoor"] .chikara-halo .halo-core {
  border: 2px solid #000;
  background: #fff;
  color: #000;
}
[data-theme="outdoor"] .chikara-halo .halo-ring {
  background: conic-gradient(from 0deg, #000, #0a3d24, #8a6a20, #000);
}

.halo-petals {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 249;
}
.halo-petal {
  /* Canon 5.1: glass petal - blur(8px), subtle white gradient, 1px inset top highlight,
     overshoot easing. Size is set inline from the live Halo size (0.8x), never hard-coded. */
  position: absolute;
  width: var(--petal-size, 60px);
  height: var(--petal-size, 60px);
  border-radius: 50%;
  background: linear-gradient(160deg, rgba(255,255,255,0.92), rgba(255,255,255,0.72));
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1.5px solid var(--primary-ink);
  color: var(--primary-ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 0;
  font-family: var(--font-mono);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.9), 0 4px 14px rgba(26,30,26,0.18);
  pointer-events: auto;
  cursor: pointer;
  transform: scale(0);
  transition: transform 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
}
[data-theme="dark"] .halo-petal { background: linear-gradient(160deg, rgba(28,36,32,0.94), rgba(22,28,25,0.8)); }
.halo-petal.show { transform: scale(1); }
.halo-petal svg { width: 24px; height: 24px; flex: none; }
.halo-petal .petal-label { font-size: 0.5rem; letter-spacing: 0.02em; line-height: 1; max-width: 90%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (prefers-reduced-motion: reduce) { .halo-petal { transition: none; } }

/* Hero on home */
.home-hero {
  margin-bottom: 1.25rem;
}
.home-hero .greeting {
  font-family: var(--font-display);
  font-size: 1.35rem;
  margin-bottom: 0.25rem;
}
.home-hero .context {
  color: var(--ink-muted);
  font-size: 0.9rem;
}

.section-title {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 1.5rem 0 0.65rem;
}

/* Next best action */
.nba {
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--primary) 12%, var(--surface)),
    color-mix(in srgb, var(--gold) 10%, var(--surface)));
  border: 1px solid color-mix(in srgb, var(--primary) 22%, var(--line));
  border-radius: var(--radius-lg);
  padding: 1.1rem 1.15rem;
  margin-bottom: 1rem;
}
.nba .label {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--primary-ink);
  margin-bottom: 0.35rem;
}
.nba strong {
  font-family: var(--font-display);
  font-size: 1.1rem;
  display: block;
  margin-bottom: 0.35rem;
}
.nba p {
  font-size: 0.88rem;
  color: var(--ink-muted);
  margin: 0 0 0.85rem;
}

/* Search */
.search-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.search-bar input {
  flex: 1;
}

/* Utility */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}
.sr-only { /* alias */ }

.hidden { display: none !important; }

/* Desktop workspace */
@media (min-width: 900px) {
  .chikara-halo {
    bottom: 28px;
    left: auto;
    right: 28px;
    transform: none;
  }
  .toast-host {
    bottom: 28px;
    left: auto;
    right: 28px;
    transform: none;
    width: 320px;
  }
}

/* ===== v1.1 Quality layer: interaction, motion, recovery ===== */

.btn {
  position: relative;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none !important;
}
.btn.is-loading {
  pointer-events: none;
  color: transparent !important;
}
.btn.is-loading::after {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  top: 50%;
  left: 50%;
  margin: -9px 0 0 -9px;
  color: var(--on-primary);
  animation: spin 0.7s linear infinite;
}
.btn-ghost.is-loading::after { color: var(--primary-ink); }
@keyframes spin { to { transform: rotate(360deg); } }

.btn:active:not(:disabled) {
  transform: scale(0.97);
  transition-duration: 80ms;
}

/* Focus ring — never colour-only */
:focus-visible {
  outline: 2px solid var(--primary-ink);
  outline-offset: 2px;
}

/* Update banner (service worker) */
.update-banner {
  position: fixed;
  top: calc(var(--safe-top) + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 400;
  width: min(420px, calc(100% - 1.5rem));
  background: var(--ink);
  color: var(--bg);
  border-radius: var(--radius-lg);
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
  font-family: var(--font-ui);
  font-size: 0.88rem;
}
.update-banner[hidden] { display: none; }
.update-banner .ub-actions {
  display: flex;
  gap: 0.4rem;
  margin-left: auto;
  flex-shrink: 0;
}
.update-banner button {
  min-height: 36px;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-md);
  border: 0;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
.update-banner .ub-update {
  background: var(--gold);
  color: #1a1e1a;
}
.update-banner .ub-later {
  background: transparent;
  color: inherit;
  border: 1px solid rgba(255,255,255,0.25);
}

/* Photo thumb in observations */
.obs-photo {
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  border-radius: var(--radius-md);
  margin-top: 0.5rem;
  background: var(--bg-alt);
}

/* Why panel (trust architecture) */
.why-panel {
  margin-top: 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.why-panel summary {
  cursor: pointer;
  padding: 0.65rem 0.85rem;
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 600;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg-alt);
}
.why-panel summary::-webkit-details-marker { display: none; }
.why-panel .why-body {
  padding: 0.75rem 0.85rem;
  font-size: 0.85rem;
  color: var(--ink-muted);
}
.why-panel .why-body h4 {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0.65rem 0 0.25rem;
}
.why-panel .why-body h4:first-child { margin-top: 0; }
.why-panel ul { margin: 0.2rem 0 0; padding-left: 1.1rem; }

/* Field form sheet */
.photo-preview {
  position: relative;
  margin: 0.5rem 0 0.85rem;
}
.photo-preview img {
  width: 100%;
  max-height: 160px;
  object-fit: cover;
  border-radius: var(--radius-md);
}
.photo-preview .remove-photo {
  position: absolute;
  top: 8px;
  right: 8px;
}

/* NBA elevated */
.nba-list { display: flex; flex-direction: column; gap: 0.65rem; }
.nba-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1rem 1.1rem;
  display: grid;
  gap: 0.35rem;
}
.nba-item.priority-high {
  border-color: color-mix(in srgb, var(--primary) 28%, var(--line));
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--primary) 10%, var(--surface)),
    var(--surface));
}
.nba-item .nba-num {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--primary-ink);
}
.nba-item strong {
  font-family: var(--font-display);
  font-size: 1.05rem;
}
.nba-item .nba-detail {
  font-size: 0.88rem;
  color: var(--ink-muted);
  margin: 0;
}
.nba-item .nba-why {
  font-size: 0.78rem;
  color: var(--ink-faint);
  font-style: italic;
}

/* Timeline */
.timeline {
  border-left: 2px solid var(--line-strong);
  margin: 0.5rem 0 0 0.5rem;
  padding-left: 1rem;
}
.timeline-item {
  position: relative;
  padding-bottom: 1rem;
}
.timeline-item::before {
  content: '';
  position: absolute;
  left: -1.22rem;
  top: 0.35rem;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--surface);
}
.timeline-item .tl-date {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ink-faint);
}
.timeline-item .tl-body {
  font-size: 0.9rem;
}

/* Skeleton for perceived performance */
.skeleton {
  background: linear-gradient(90deg, var(--bg-alt) 25%, var(--surface) 50%, var(--bg-alt) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s ease-in-out infinite;
  border-radius: var(--radius-md);
  height: 1em;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
  .btn.is-loading::after { animation: none; border-right-color: currentColor; }
}

/* Double-submit guard visual */
.btn[aria-busy="true"] {
  pointer-events: none;
  opacity: 0.7;
}

/* Visual symptom pickers */
.symptom-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}
.symptom-card {
  min-height: 88px;
  border: 2px solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink);
  text-align: center;
}
.symptom-card.selected {
  border-color: var(--primary-ink);
  background: color-mix(in srgb, var(--primary) 12%, var(--surface));
  box-shadow: inset 0 0 0 1px var(--primary-ink);
}
.symptom-card .sym-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  font-weight: 700;
  background: var(--bg-alt);
  color: var(--primary-ink);
  border: 1.5px solid var(--line-strong);
}
.symptom-card.selected .sym-icon {
  background: var(--primary);
  color: var(--on-primary);
  border-color: var(--primary);
}

/* Confidence bar */
.conf-bar {
  height: 8px;
  background: var(--bg-alt);
  border-radius: 4px;
  overflow: hidden;
  margin: 0.35rem 0;
}
.conf-bar > span {
  display: block;
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
}
.conf-bar.low > span { background: var(--warning); }
.conf-bar.mid > span { background: var(--gold-deep); }
.conf-bar.high > span { background: var(--ok); }

/* Simple SVG chart */
.trend-chart {
  width: 100%;
  height: 120px;
  background: var(--bg-alt);
  border-radius: var(--radius-md);
  margin: 0.5rem 0;
}

/* Voice row */
.voice-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.75rem;
}
.voice-row .btn { flex-shrink: 0; }

/* Risk badge with geometry */
.risk-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.25rem 0.55rem;
  border-radius: 4px;
  border: 1.5px solid currentColor;
}
.risk-badge::before {
  content: '';
  width: 8px;
  height: 8px;
  flex-shrink: 0;
}
.risk-high { color: var(--danger); }
.risk-high::before { background: var(--danger); clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.risk-mid { color: var(--warning); }
.risk-mid::before { background: var(--warning); border-radius: 1px; }
.risk-low { color: var(--ok); }
.risk-low::before { background: var(--ok); border-radius: 50%; }

.chart-block { margin-bottom: 1rem; }
.chart-title {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}
.chart-meta {
  font-size: 0.75rem;
  color: var(--ink-faint);
  margin: 0.25rem 0 0;
}
.trend-chart {
  width: 100%;
  height: auto;
  color: var(--ink-muted);
  background: var(--bg-alt);
  border-radius: var(--radius-md);
}

/* ===== CHIKARA Precision Mining components (v1.0.0) ===== */
.small { font-size: 0.82rem; }
.tiny { font-size: 0.7rem; }
.struck { text-decoration: line-through; text-decoration-thickness: 1px; opacity: 0.8; }
ul.plain { list-style: none; padding: 0; margin: 0.4rem 0; }
ul.plain li { padding: 0.15rem 0; }
.list-card { display: block; width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer; margin-bottom: 0.6rem; }
.list-card:hover { border-color: var(--primary-ink); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.3rem 0.9rem; margin: 0; }
.kv dt { color: var(--ink-muted); font-size: 0.8rem; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.rec-line { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.75rem; padding: 0.6rem 0; border-bottom: 1px solid var(--line); }
.rec-line:last-child { border-bottom: 0; }
.tabs, .chips { display: flex; gap: 0.4rem; overflow-x: auto; margin: 0.5rem 0 1rem; padding-bottom: 0.25rem; }
.tab, .chip { font-family: var(--font-ui); font-size: 0.82rem; padding: 0.45rem 0.9rem; border-radius: var(--radius-full); border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); cursor: pointer; white-space: nowrap; min-height: 40px; }
.tab.active, .chip.active { background: var(--primary); color: var(--on-primary); border-color: var(--primary); font-weight: 600; }
.timeline-list { list-style: none; margin: 0; padding: 0 0 0 0.9rem; border-left: 2px solid var(--teal); }
.timeline-list li.tl { position: relative; padding: 0 0 1rem 0.9rem; }
.timeline-list li.tl::before { content: ''; position: absolute; left: -1.3rem; top: 0.35rem; width: 0.65rem; height: 0.65rem; border-radius: 50%; background: var(--teal); }
.tl-head { display: flex; gap: 0.5rem; align-items: baseline; flex-wrap: wrap; }
.tl-actions { margin-top: 0.25rem; display: inline-block; margin-right: 0.4rem; }
.calc-result { margin-bottom: 0.6rem; }
.calc-big { font-family: var(--font-display); font-size: 1.35rem; font-weight: 700; overflow-wrap: anywhere; }
.table-wrap { overflow-x: auto; }
.tbl { border-collapse: collapse; width: 100%; font-size: 0.78rem; font-family: var(--font-mono); }
.tbl th, .tbl td { padding: 0.35rem 0.5rem; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl th:first-child, .tbl td:first-child { text-align: left; }
.field-row3 { display: grid; grid-template-columns: 1.1fr 1fr 1fr; gap: 0.5rem; align-items: end; }
@media (max-width: 420px) { .field-row3 { grid-template-columns: 1fr 1fr; } .field-row3 > :first-child { grid-column: 1 / -1; } }
fieldset.field { border: 1px solid var(--line); border-radius: var(--radius-md); padding: 0.6rem 0.8rem; }
.nba-why { color: var(--ink-muted); font-size: 0.82rem; }
.mono { font-family: var(--font-mono); overflow-wrap: anywhere; }
@media print {
  .header, .sidebar, .bottom-nav, .chikara-halo, .halo-petals, .island, .update-banner, .toast-host, .btn, .back { display: none !important; }
  body { background: #fff; color: #000; }
  .card { break-inside: avoid; border-color: #999; }
}
.nba-item .badge { width: fit-content; }

/* ===== v1.1.0: notices, fingerprint QR, camera scan, bag label, device check ===== */
.notice { background: var(--bg-alt); color: var(--ink); border-left: 3px solid var(--primary-ink); border-radius: var(--radius-md); padding: 0.65rem 0.8rem; margin: 0 0 0.85rem; font-size: 0.88rem; line-height: 1.5; }
.qr-card { display: grid; grid-template-columns: minmax(150px, 240px) 1fr; gap: 1rem; align-items: start; }
@media (max-width: 520px) { .qr-card { grid-template-columns: 1fr; } .qr-box { max-width: 300px; margin: 0 auto; width: 100%; } }
/* A QR is always black on white with its quiet zone, whatever the theme: readers need that contrast. */
.qr-box { background: #fff; padding: 0.4rem; border-radius: var(--radius-md); border: 1px solid var(--line-strong); }
.qr-svg { display: block; width: 100%; height: auto; }
.code-line { word-break: break-all; font-size: 0.72rem; line-height: 1.4; background: var(--bg-alt); color: var(--ink); padding: 0.45rem 0.55rem; border-radius: 6px; margin: 0.5rem 0; user-select: all; }
.scan-box { display: flex; flex-direction: column; gap: 0.6rem; }
.scan-box video { width: 100%; max-height: 55vh; background: #000; border-radius: var(--radius-md); object-fit: cover; }
.label-sheet, .label-sheet * { color: #111 !important; }
.label-sheet { width: 100%; max-width: 380px; background: #fff; border: 2px solid #111; border-radius: 10px; padding: 0.9rem; margin: 0 auto 1rem; }
.label-head { display: flex; gap: 0.6rem; align-items: center; border-bottom: 1px solid #111; padding-bottom: 0.5rem; margin-bottom: 0.6rem; }
.label-head img { border-radius: 6px; }
.label-code { font-family: var(--font-mono); font-size: 2rem; font-weight: 700; letter-spacing: 0.02em; margin: 0.2rem 0 0.5rem; word-break: break-all; }
.label-foot { margin: 0.6rem 0 0; }
.label-sheet .qr-card { grid-template-columns: 1fr; }
.label-sheet .qr-box { max-width: 260px; margin: 0 auto; }
.label-sheet .code-line { background: #eee; }
.dc-list { list-style: none; padding: 0; margin: 0.25rem 0 0.5rem; }
.dc-list li { padding: 0.45rem 0; border-bottom: 1px solid var(--line); font-size: 0.85rem; overflow-wrap: anywhere; }
.dc-list li:last-child { border-bottom: 0; }
.dc-warn strong { color: var(--warning); }
.dc-ok strong { color: var(--ok); }
@media print {
  main:has(.label-sheet) > :not(.label-sheet) { display: none !important; }
  .label-sheet { max-width: 80mm; border-color: #000; }
  .code-line { background: #fff; border: 1px solid #999; }
}
