/* Palette and type scale transcribed from the Android app (mobile/THEME.md) so
 * the two products read as one. Brand colours are identical in light and dark;
 * only surfaces, text and borders flip. */

:root {
  /* Brand -- identical in both modes. */
  --primary:       #1E3A5F;
  --primary-dark:  #13243D;
  --accent:        #5B8FBF;
  --accent-border: #4A7DA8;

  /* Status triples -- legible on either background, so also mode-independent. */
  --ok-bg:   #D4F4DD; --ok-fg:   #1D7A36; --ok-border:   #A8DCBB;
  --err-bg:  #F8D7DA; --err-fg:  #8B1F28; --err-border:  #F1B0B6;
  --warn-bg: #FFF3CD; --warn-fg: #856404; --warn-border: #FFE08A;
  --info-bg: #D1E7F5; --info-fg: #155A8A; --info-border: #9DCAEC;

  /* Light surfaces. */
  --bg:             #E8EDF2;
  --surface:        #FFFFFF;
  --surface-tint:   #E3EDF7;
  --surface-muted:  #F0F3F7;
  --filter-row:     #EEF3F8;
  --text-primary:   #111827;
  --text-secondary: #4B5563;
  --text-tertiary:  #6B7280;
  --text-disabled:  #9CA3AF;
  --border:         #C8D6E0;
  --border-input:   #B0C4D8;
  --border-row:     #D0DAE4;
  --border-dashed:  #E0E8F0;
  --row-hover:      #F0F4F8;
  /* Navy on a light card; the dark ramp reassigns it to avoid navy-on-navy. */
  --heading:        #1E3A5F;

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, monospace;

  --radius-card: 12px;
  --radius-btn:  8px;
  --radius-pill: 10px;
}

/* Dark ramp. The header toggle must win in both directions, hence the explicit
 * [data-theme] rules alongside the media query. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:             #0F1722;
    --surface:        #1B2434;
    --surface-tint:   #243650;
    --surface-muted:  #222B3C;
    --filter-row:     #1F2A3C;
    --text-primary:   #E6EAF0;
    --text-secondary: #A3ADBA;
    --text-tertiary:  #7A8494;
    --text-disabled:  #555E6E;
    --border:         #2F3B4F;
    --border-input:   #3A4860;
    --border-row:     #283346;
    --border-dashed:  #243049;
    --row-hover:      #27324A;
    --heading:        #E6EAF0;
  }
}
:root[data-theme="dark"] {
  --bg:             #0F1722;
  --surface:        #1B2434;
  --surface-tint:   #243650;
  --surface-muted:  #222B3C;
  --filter-row:     #1F2A3C;
  --text-primary:   #E6EAF0;
  --text-secondary: #A3ADBA;
  --text-tertiary:  #7A8494;
  --text-disabled:  #555E6E;
  --border:         #2F3B4F;
  --border-input:   #3A4860;
  --border-row:     #283346;
  --border-dashed:  #243049;
  --row-hover:      #27324A;
  --heading:        #E6EAF0;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.5;
  min-height: 100%;
}

[hidden] { display: none !important; }

code, .mono { font-family: var(--mono); }

/* ══ Sign in ══════════════════════════════════════════════════════════════
 * Full navy field with the white wordmark, matching the app's pre-login
 * screens. */

.login-screen {
  min-height: 100vh;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.login-wrap { width: 100%; max-width: 380px; text-align: center; }
.login-logo { height: 56px; width: auto; margin-bottom: 12px; }
.login-eyebrow {
  margin: 0;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 2px;
}
.login-title {
  margin: 4px 0 20px;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1px;
  opacity: .85;
}
.login-card { text-align: left; }
/* Every visual property is conditional on there being text. Applying the
 * background and border unconditionally paints an empty red bar on first load,
 * before anything has gone wrong. */
.login-error {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 12px;
  color: var(--err-fg);
}
.login-error:not(:empty) {
  margin-top: 12px;
  padding: 8px 10px;
  background: var(--err-bg);
  border: 1px solid var(--err-border);
  border-radius: var(--radius-btn);
}
.login-foot {
  margin-top: 20px;
  color: rgba(255, 255, 255, .55);
  font-size: 11px;
  letter-spacing: .5px;
}

/* Header */

.brand-header { position: sticky; top: 0; z-index: 20; }
.brand-bar {
  height: 64px;
  background: var(--primary);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
}
.brand-strip { height: 3px; background: var(--primary-dark); }
.brand-logo { height: 28px; width: auto; }
.brand-sep { width: 1px; height: 24px; background: rgba(255, 255, 255, .25); }
.brand-title {
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .5px;
}
.brand-spacer { flex: 1; }

.session {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, .12);
  color: #fff;
}
.session-label { font-size: 10px; font-weight: 700; letter-spacing: .5px; opacity: .75; }
.session-time  { font-family: var(--mono); font-size: 12px; font-weight: 600; }
/* Amber for the last five minutes, before an upload is half-typed. */
.session.is-low { background: var(--warn-bg); color: var(--warn-fg); }
.session.is-low .session-label { opacity: .9; }

.icon-btn {
  background: transparent;
  border: 0;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--radius-btn);
  line-height: 1;
}
.icon-btn:hover { background: rgba(255, 255, 255, .12); }

/* Layout */

.page {
  max-width: 1320px;
  margin: 0 auto;
  padding: 20px 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius-card);
  padding: 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-title {
  margin: 0 0 4px;
  color: var(--heading);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .5px;
}
.card-sub { margin: 0 0 12px; color: var(--text-tertiary); font-size: 12px; }
.foot {
  margin-top: 4px;
  padding-top: 12px;
  border-top: 1px solid var(--border-dashed);
  text-align: center;
  color: var(--text-disabled);
  font-size: 11px;
  letter-spacing: .5px;
}

/* Per-family summary */

.family-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}
.family-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  padding: 12px;
}
.family-card.is-empty { border-color: var(--err-border); background: var(--err-bg); }
.family-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.family-name { font-weight: 700; font-size: 13px; }
.family-card.is-empty .family-name,
.family-card.is-empty .family-none { color: var(--err-fg); }
.family-none { font-size: 12px; font-weight: 600; }
.family-active { font-family: var(--mono); font-size: 13px; font-weight: 600; }
.family-meta { color: var(--text-tertiary); font-size: 11px; margin-top: 2px; }
.family-url {
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-tertiary);
  word-break: break-all;
}

/* Drop zone */

.drop {
  border: 2px dashed var(--border-input);
  border-radius: var(--radius-card);
  padding: 28px 16px;
  text-align: center;
  cursor: pointer;
  user-select: none;
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop:focus-visible, .drop.is-dragging {
  border-color: var(--accent);
  background: var(--surface-tint);
  outline: none;
}
.drop-icon { font-size: 32px; line-height: 1; color: var(--accent); }
.drop-text { margin: 8px 0 2px; color: var(--text-secondary); }
.drop-hint { margin: 0; color: var(--text-tertiary); font-size: 11px; }

/* Table */

.filter-row {
  display: flex;
  gap: 8px;
  background: var(--filter-row);
  padding: 8px;
  border-radius: var(--radius-btn) var(--radius-btn) 0 0;
  margin-top: 12px;
  flex-wrap: wrap;
}
.filter-row select { min-width: 150px; }
.filter-row input { flex: 1; min-width: 180px; }

/* Scrolls inside its container, so the page never scrolls sideways. */
.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 12px; }
.table thead th {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .3px;
  text-align: left;
  padding: 8px 10px;
  white-space: nowrap;
}
.table tbody td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border-row);
  vertical-align: top;
  white-space: nowrap;
}
.table tbody tr:hover { background: var(--row-hover); }
.table tbody tr.is-active { background: color-mix(in srgb, var(--ok-bg) 45%, transparent); }
.table tbody tr.is-active:hover { background: color-mix(in srgb, var(--ok-bg) 65%, transparent); }
.col-remark { min-width: 200px; }
.col-actions { width: 1%; }
.cell-mono { font-family: var(--mono); font-weight: 600; }
.cell-muted { color: var(--text-tertiary); }
/* The one column allowed to wrap: it is prose. */
.cell-remark {
  white-space: normal !important;
  max-width: 320px;
  color: var(--text-secondary);
}
.cell-remark:empty::before { content: "—"; color: var(--text-disabled); }
.row-actions { display: flex; gap: 6px; }
.empty { color: var(--text-tertiary); text-align: center; padding: 20px 0; margin: 0; }

/* Badges */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge-ok   { background: var(--ok-bg);   color: var(--ok-fg);   border-color: var(--ok-border); }
.badge-err  { background: var(--err-bg);  color: var(--err-fg);  border-color: var(--err-border); }
.badge-warn { background: var(--warn-bg); color: var(--warn-fg); border-color: var(--warn-border); }
.badge-info { background: var(--info-bg); color: var(--info-fg); border-color: var(--info-border); }
.badge-idle {
  background: var(--surface-muted);
  color: var(--text-tertiary);
  border-color: var(--border);
}

/* Buttons */

.btn {
  height: 36px;
  padding: 0 16px;
  border-radius: var(--radius-btn);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .3px;
  cursor: pointer;
  background: var(--surface);
  color: var(--heading);
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-default { border-color: var(--border-input); color: var(--heading); }
.btn-default:hover:not(:disabled) { background: var(--surface-tint); }
.btn-danger { border-color: var(--err-border); color: var(--err-fg); background: var(--surface); }
.btn-danger:hover:not(:disabled) { background: var(--err-bg); }
.btn-ghost { background: transparent; color: #fff; border-color: rgba(255, 255, 255, .35); }
.btn-ghost:hover { background: rgba(255, 255, 255, .12); }
.btn-compact { height: 28px; padding: 0 10px; font-size: 11px; }
.btn-block { width: 100%; }

/* Form fields */

.field { display: block; margin-bottom: 14px; }
.field-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 5px;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
}
.req { color: var(--err-fg); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.field-hint { display: block; margin-top: 5px; color: var(--text-tertiary); font-size: 11px; }
.word-count { color: var(--text-tertiary); font-size: 11px; font-family: var(--mono); }
.word-count.is-over { color: var(--err-fg); font-weight: 700; }

input[type="text"], input[type="password"], input[type="search"], select, textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border-input);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
}
textarea { resize: vertical; min-height: 72px; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}
input[aria-invalid="true"], textarea[aria-invalid="true"], select[aria-invalid="true"] {
  border-color: var(--err-border);
}

/* Dialogs */

.dialog {
  border: 0;
  border-radius: var(--radius-card);
  padding: 20px;
  width: min(520px, calc(100vw - 32px));
  background: var(--surface);
  color: var(--text-primary);
}
.dialog::backdrop { background: rgba(15, 23, 34, .55); }
.dialog-title {
  margin: 0 0 12px;
  color: var(--heading);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .5px;
}
.dialog-body { margin: 0 0 12px; color: var(--text-secondary); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
/* Same rule as .login-error: nothing visible until there is text to show. */
.dialog-error {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 12px;
  color: var(--err-fg);
}
.dialog-error:not(:empty) {
  margin-bottom: 4px;
  padding: 8px 10px;
  background: var(--err-bg);
  border: 1px solid var(--err-border);
  border-radius: var(--radius-btn);
}
.dialog-warn { margin: 0 0 4px; }

/* Preview parsed client-side from the first 80 bytes. */
.preview {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  padding: 12px;
  margin-bottom: 14px;
}
.preview-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
  border-bottom: 1px dashed var(--border-dashed);
}
.preview-row:last-child { border-bottom: 0; }
.preview-label {
  color: var(--text-tertiary);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .3px;
  text-transform: uppercase;
}
.preview-value {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  text-align: right;
  word-break: break-all;
}

.progress {
  height: 6px;
  background: var(--surface-muted);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 12px;
}
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .15s; }

/* Banners & toasts */

.banner {
  border-radius: var(--radius-btn);
  padding: 11px 14px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
}
.banner-err { background: var(--err-bg); color: var(--err-fg); border-color: var(--err-border); }

.toasts {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  min-width: 240px;
  max-width: 380px;
  padding: 11px 14px;
  border-radius: var(--radius-btn);
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .18);
  animation: toast-in .18s ease-out;
}
.toast-ok   { background: var(--ok-bg);   color: var(--ok-fg);   border-color: var(--ok-border); }
.toast-err  { background: var(--err-bg);  color: var(--err-fg);  border-color: var(--err-border); }
.toast-warn { background: var(--warn-bg); color: var(--warn-fg); border-color: var(--warn-border); }
.toast-info { background: var(--info-bg); color: var(--info-fg); border-color: var(--info-border); }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(12px); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media (max-width: 640px) {
  .brand-title, .session-label { display: none; }
  .page { padding: 12px 8px 24px; }
  .card { padding: 12px; }
}
