:root {
  /* MannaTech Group brand palette — shared with mannachem.com */
  --ink: #1a1a1a;
  --muted: #4a4a4a;
  --line: #e0d8c8;
  --surface: #faf7f2;
  --surface-strong: #ffffff;
  --bg: #f3ede2;
  --accent: #1a5238;          /* MannaChem green-800 */
  --accent-dark: #0f3d2a;     /* MannaChem green-900 */
  --accent-soft: #e3efe7;     /* MannaChem green-100 */
  --gold: #d4a574;            /* MannaChem amber */
  --gold-soft: #f3ede2;
  --sky: #226a48;             /* MannaChem green-700 */
  --danger: #b33838;
  --shadow: 0 18px 45px rgba(15, 61, 42, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Manrope', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  background:
    radial-gradient(circle at top left, rgba(212, 165, 116, 0.14), transparent 34rem),
    linear-gradient(180deg, #faf7f2 0%, #f3ede2 100%);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-weight: 700;
  letter-spacing: -0.02em;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  padding: 14px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.18);
  color: #faf7f2;
  background: linear-gradient(135deg, #0f3d2a 0%, #1a5238 65%, #226a48 100%);
  box-shadow: 0 10px 24px rgba(15, 61, 42, 0.22);
}

h1, h2, p {
  margin-top: 0;
}

h1 {
  margin-bottom: 4px;
  font-size: 19px;
}

.topbar p {
  color: rgba(255, 255, 255, 0.78);
}

h2 {
  font-size: 16px;
}

p {
  color: var(--muted);
}

main {
  max-width: 1360px;
  margin: 0 auto;
  padding: 16px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.hero-panel {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  margin-bottom: 12px;
  padding: 16px;
  border: 1px solid rgba(26, 82, 56, 0.18);
  border-radius: 8px;
  color: #faf7f2;
  background:
    linear-gradient(135deg, rgba(15, 61, 42, 0.97) 0%, rgba(26, 82, 56, 0.94) 60%, rgba(212, 165, 116, 0.85) 100%);
  box-shadow: var(--shadow);
}

.hero-panel h2 {
  margin-bottom: 6px;
  font-size: 21px;
}

.hero-panel p {
  color: rgba(255, 255, 255, 0.78);
}

.hero-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.eyebrow {
  margin-bottom: 6px;
  color: #e8c89a;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.narrow {
  max-width: 560px;
  margin: 28px auto;
}

.grid {
  display: grid;
  gap: 12px;
}

.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.metrics {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 12px;
}

.metric {
  background: linear-gradient(180deg, #ffffff 0%, var(--surface-strong) 100%);
  border: 1px solid rgba(17, 104, 63, 0.12);
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 10px 26px rgba(11, 47, 30, 0.07);
}

.metric span {
  display: block;
  font-size: 23px;
  font-weight: 800;
  color: var(--accent-dark);
}

.metric small, .metric em {
  display: block;
  color: var(--muted);
}

.metric em {
  margin-top: 4px;
  font-size: 11px;
  font-style: normal;
}

.dashboard-grid {
  grid-template-columns: 0.9fr 1.1fr;
  margin-bottom: 12px;
}

.role-dashboard-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 12px;
}

.role-panel {
  min-height: 150px;
}

.collection-correction-grid {
  grid-template-columns: 1.1fr 0.9fr;
  margin-top: 16px;
}

.upload-panel {
  margin-top: 16px;
}

.upload-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr) auto;
  gap: 10px;
  align-items: end;
}

.upload-form label {
  margin-bottom: 0;
}

label {
  display: grid;
  gap: 5px;
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 700;
  color: #405040;
}

input, select, textarea {
  width: 100%;
  min-height: 36px;
  border: 1px solid #c8d5c8;
  border-radius: 6px;
  padding: 7px 9px;
  font: inherit;
  color: var(--ink);
  background: #fbfcfb;
}

textarea {
  min-height: 86px;
  resize: vertical;
}

button {
  border: 0;
  border-radius: 6px;
  padding: 8px 11px;
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  cursor: pointer;
  box-shadow: 0 8px 16px rgba(17, 104, 63, 0.22);
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  padding: 8px 11px;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

button:hover {
  background: var(--accent-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  box-shadow: none;
}

.danger {
  color: #ffffff;
  background: linear-gradient(135deg, #ba4b3f 0%, #8d2525 100%);
  box-shadow: 0 8px 16px rgba(179, 56, 56, 0.18);
}

.danger:hover {
  background: #842020;
}

.secondary {
  color: var(--accent-dark);
  background: var(--gold-soft);
  box-shadow: none;
}

.secondary:hover {
  background: #ffe8a6;
}

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.tab {
  color: var(--ink);
  background: #e9efe8;
  box-shadow: none;
}

.tab.active {
  color: #fff;
  background: linear-gradient(135deg, var(--accent) 0%, var(--sky) 100%);
}

.view, .hidden {
  display: none;
}

.view.active {
  display: block;
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.between {
  justify-content: space-between;
}

.table {
  display: grid;
  gap: 6px;
}

.record {
  display: grid;
  grid-template-columns: 1.1fr 1.1fr 0.6fr 0.7fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid rgba(17, 104, 63, 0.12);
  border-radius: 8px;
  padding: 10px;
  color: var(--muted);
  background: linear-gradient(180deg, #ffffff 0%, #fbfcf7 100%);
}

.record strong {
  display: block;
  color: var(--ink);
}

.record small {
  display: block;
  margin-top: 3px;
  font-size: 11px;
}

.chip {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 26px;
  padding: 3px 7px;
  border-radius: 999px;
  color: #063c27;
  background: linear-gradient(135deg, var(--accent-soft) 0%, var(--gold-soft) 100%);
  font-size: 11px;
  font-weight: 800;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.status-card {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbf4 100%);
}

.status-card span {
  display: block;
  font-size: 20px;
  font-weight: 800;
}

.status-card small {
  color: var(--muted);
  text-transform: capitalize;
}

.summary-list {
  display: grid;
  gap: 6px;
}

.summary-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  color: var(--ink);
  background: #fffdf7;
  border: 1px solid #ead9a6;
}

.summary-item span,
.summary-item small,
.summary-item strong {
  display: block;
  text-align: left;
}

.summary-item small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.correction-list {
  display: grid;
  gap: 8px;
}

.correction-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid rgba(17, 104, 63, 0.12);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfcf7 100%);
}

.correction-row strong,
.correction-row small {
  display: block;
}

.correction-row strong {
  color: var(--accent-dark);
  overflow-wrap: anywhere;
}

.correction-row small {
  margin-top: 3px;
  color: var(--muted);
}

.correction-row-actions,
.correction-actions {
  flex-wrap: wrap;
}

.correction-panel {
  align-self: start;
}

.admin-grid {
  grid-template-columns: 0.8fr 1.2fr;
}

.admin-list {
  display: grid;
  gap: 8px;
}

.admin-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 9px;
  align-items: center;
  padding: 10px;
  border: 1px solid rgba(17, 104, 63, 0.12);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfcf7 100%);
}

.admin-row strong,
.admin-row small {
  display: block;
}

.admin-row strong {
  overflow-wrap: anywhere;
  color: var(--accent-dark);
}

.admin-row small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.pass {
  color: var(--accent);
}

.fail {
  color: var(--danger);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 420px;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
}

.hint {
  font-size: 12px;
}

code {
  background: #e8eee8;
  border-radius: 4px;
  padding: 2px 5px;
}

.dark {
  color: var(--accent-dark);
}

.compact {
  align-items: stretch;
}

.trace-workspace {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.trace-sidebar {
  position: sticky;
  top: 18px;
  display: grid;
  gap: 10px;
  padding: 14px;
}

.trace-sidebar h2 {
  margin-bottom: 0;
  font-size: 20px;
}

.trace-filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-top: 2px;
}

.filter-pill {
  min-height: 30px;
  padding: 6px 9px;
  color: var(--accent-dark);
  background: #edf3ec;
  box-shadow: none;
}

.filter-pill.active {
  color: #ffffff;
  background: linear-gradient(135deg, var(--accent) 0%, var(--sky) 100%);
}

.batch-list {
  display: grid;
  gap: 7px;
  max-height: 58vh;
  overflow: auto;
  padding-right: 2px;
}

.batch-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 70px 82px;
  gap: 8px;
  align-items: center;
  width: 100%;
  min-height: 58px;
  padding: 9px 10px;
  border: 1px solid rgba(17, 104, 63, 0.14);
  border-radius: 8px;
  color: var(--ink);
  text-align: left;
  background: linear-gradient(180deg, #ffffff 0%, #fffdf6 100%);
  box-shadow: 0 8px 18px rgba(11, 47, 30, 0.07);
}

.batch-card:hover {
  border-color: rgba(216, 163, 38, 0.54);
  background: #fff8df;
}

.batch-card strong,
.batch-card small,
.batch-card em {
  display: block;
}

.batch-card strong {
  overflow-wrap: anywhere;
  color: var(--accent-dark);
  font-size: 12px;
  line-height: 1.2;
}

.batch-card small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.batch-card em {
  color: var(--ink);
  font-style: normal;
  font-weight: 800;
}

.trace-report {
  min-width: 0;
}

.empty-trace {
  min-height: 420px;
  display: grid;
  align-content: center;
  justify-items: start;
  gap: 6px;
  padding: 28px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(255, 248, 223, 0.92)),
    radial-gradient(circle at right top, rgba(17, 104, 63, 0.18), transparent 18rem);
}

.empty-trace h2 {
  max-width: 620px;
  margin-bottom: 4px;
  font-size: 23px;
}

.empty-trace p {
  max-width: 680px;
  font-size: 14px;
  line-height: 1.6;
}

.trace-document {
  overflow: hidden;
  border: 1px solid rgba(17, 104, 63, 0.16);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.trace-cover {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  padding: 18px 22px;
  color: #ffffff;
  background:
    linear-gradient(135deg, rgba(6, 47, 33, 0.98) 0%, rgba(17, 104, 63, 0.94) 57%, rgba(29, 111, 135, 0.86) 100%),
    linear-gradient(90deg, transparent, rgba(216, 163, 38, 0.36));
}

.trace-cover-aside {
  display: flex;
  gap: 10px;
  align-items: center;
}

.trace-qr {
  width: 88px;
  height: 88px;
  padding: 5px;
  border-radius: 8px;
  background: #ffffff;
}

.trace-cover h2 {
  margin-bottom: 6px;
  font-size: 25px;
  overflow-wrap: anywhere;
}

.trace-cover p:not(.eyebrow) {
  margin: 0;
  color: rgba(255, 255, 255, 0.78);
}

.release-badge {
  min-width: 118px;
  border-radius: 8px;
  padding: 11px 13px;
  color: #ffffff;
  text-align: center;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.20);
}

.release-badge small,
.release-badge strong {
  display: block;
}

.release-badge small {
  color: rgba(255, 255, 255, 0.75);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.release-badge strong {
  margin-top: 4px;
  font-size: 21px;
}

.pass-bg {
  background: linear-gradient(135deg, #13804f 0%, #0a5c39 100%);
}

.fail-bg {
  background: linear-gradient(135deg, #bf4a41 0%, #8f2727 100%);
}

.pending-bg {
  background: linear-gradient(135deg, #b98413 0%, #7b5b10 100%);
}

.trace-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
  background: #fffaf0;
}

.trace-kpis div {
  min-height: 70px;
  padding: 12px 14px;
  border-right: 1px solid var(--line);
}

.trace-kpis div:last-child {
  border-right: 0;
}

.trace-kpis small,
.trace-kpis strong {
  display: block;
}

.trace-kpis small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.trace-kpis strong {
  margin-top: 6px;
  color: var(--accent-dark);
  font-size: 15px;
  overflow-wrap: anywhere;
  text-transform: capitalize;
}

.trace-card-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  padding: 14px;
}

.trace-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfcf7 100%);
}

.trace-card h3,
.trace-timeline h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.trace-card dl {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 7px 10px;
  margin: 0;
}

.trace-card dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.trace-card dd {
  margin: 0;
  min-width: 0;
  color: var(--ink);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.trace-timeline {
  margin: 0 14px 14px;
  padding: 14px;
  border: 1px solid rgba(17, 104, 63, 0.14);
  border-radius: 8px;
  background: #fbfcf8;
}

.trace-evidence,
.trace-audit {
  margin: 0 14px 14px;
  padding: 14px;
  border: 1px solid rgba(17, 104, 63, 0.14);
  border-radius: 8px;
  background: #ffffff;
}

.trace-evidence h3,
.trace-audit h3 {
  margin: 0 0 6px;
  font-size: 15px;
}

.trace-evidence p,
.trace-audit p {
  margin-bottom: 0;
}

.evidence-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.evidence-file {
  display: block;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--accent-dark);
  text-decoration: none;
  background: linear-gradient(180deg, #ffffff 0%, #fffdf6 100%);
}

.evidence-file:hover {
  border-color: rgba(216, 163, 38, 0.6);
  background: #fff8df;
}

.evidence-file small,
.evidence-file strong {
  display: block;
}

.evidence-file small {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.evidence-file strong {
  margin-top: 4px;
  overflow-wrap: anywhere;
  font-size: 12px;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 10px;
}

.audit-list {
  display: grid;
  gap: 7px;
}

.audit-row {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr) 92px;
  gap: 10px;
  align-items: start;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcf8;
}

.audit-row > span {
  width: fit-content;
  padding: 3px 7px;
  border-radius: 999px;
  color: #ffffff;
  background: var(--accent-dark);
  font-size: 10px;
  font-weight: 800;
}

.audit-row strong {
  display: block;
  color: var(--ink);
}

.audit-row p {
  margin: 3px 0 0;
  font-size: 12px;
}

.audit-row time {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-align: right;
}

.timeline-row {
  position: relative;
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 10px;
  padding: 0 0 14px;
}

.timeline-row::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 17px;
  bottom: 0;
  width: 2px;
  background: #cddccd;
}

.timeline-row:last-child {
  padding-bottom: 0;
}

.timeline-row:last-child::before {
  display: none;
}

.dot {
  position: relative;
  z-index: 1;
  width: 18px;
  height: 18px;
  border: 3px solid #ffffff;
  border-radius: 999px;
  background: var(--gold);
  box-shadow: 0 0 0 2px #d9c072;
}

.timeline-row.pass .dot {
  background: var(--accent);
  box-shadow: 0 0 0 2px rgba(17, 104, 63, 0.30);
}

.timeline-row.fail .dot {
  background: var(--danger);
  box-shadow: 0 0 0 2px rgba(179, 56, 56, 0.28);
}

.timeline-row.pending .dot {
  background: #b98413;
  box-shadow: 0 0 0 2px rgba(185, 132, 19, 0.28);
}

.timeline-row strong,
.timeline-row small {
  display: block;
}

.timeline-row strong {
  color: var(--accent-dark);
  text-transform: capitalize;
}

.timeline-row small {
  margin-top: 2px;
  color: var(--muted);
}

.timeline-row p {
  margin: 5px 0 0;
  font-size: 13px;
}

.trace-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 14px 14px;
}

@media (max-width: 800px) {
  .topbar, .row {
    align-items: stretch;
    flex-direction: column;
  }

  .two, .metrics, .dashboard-grid, .role-dashboard-grid, .collection-correction-grid, .admin-grid, .trace-workspace, .trace-kpis, .trace-card-grid, .evidence-grid, .upload-form {
    grid-template-columns: 1fr;
  }

  .hero-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .tabs {
    overflow-x: auto;
  }

  .record,
  .correction-row,
  .admin-row {
    grid-template-columns: 1fr;
  }

  .trace-sidebar {
    position: static;
  }

  .batch-list {
    max-height: none;
  }

  .trace-cover,
  .trace-actions,
  .trace-cover-aside,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .audit-row {
    grid-template-columns: 1fr;
  }

  .audit-row time {
    text-align: left;
  }

  .trace-kpis div {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .trace-kpis div:last-child {
    border-bottom: 0;
  }
}

/* ---------- Phone-optimised (field agents, ≤ 600px) ---------- */
@media (max-width: 600px) {
  /* Compact topbar with action row beside the title */
  .topbar {
    flex-direction: row;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 14px;
  }
  .topbar > div:first-child {
    flex: 1 1 auto;
    min-width: 0;
  }
  .topbar h1 {
    font-size: 16px;
    margin-bottom: 2px;
  }
  .topbar p {
    font-size: 11px;
    color: rgba(255,255,255,0.7);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .topbar-actions {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }
  .topbar-actions button {
    min-height: 36px;
    padding: 6px 12px;
    font-size: 12px;
    white-space: nowrap;
  }

  main {
    padding: 12px;
  }

  /* Hero panel — tighter on phones */
  .hero-panel {
    padding: 12px;
  }
  .hero-panel h2 {
    font-size: 17px;
  }
  .hero-panel p {
    font-size: 13px;
  }
  .hero-actions {
    justify-content: flex-start;
  }

  /* Tabs — horizontal scroll with proper tap targets */
  .tabs {
    margin: 0 -12px 12px;
    padding: 4px 12px;
    gap: 8px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
  }
  .tab {
    flex: 0 0 auto;
    min-height: 40px;
    padding: 10px 16px;
    font-size: 13px;
    scroll-snap-align: start;
  }

  /* Forms — thumb-friendly inputs, prevent iOS auto-zoom */
  input, select, textarea {
    min-height: 44px;
    padding: 10px 12px;
    font-size: 16px;  /* iOS won't zoom in if >= 16px */
    border-radius: 8px;
  }
  textarea {
    min-height: 100px;
  }
  label {
    font-size: 13px;
    margin-bottom: 14px;
  }

  /* Buttons — 44px tap target minimum */
  button {
    min-height: 44px;
    padding: 11px 16px;
    font-size: 14px;
  }
  .secondary, .tab {
    min-height: 40px;
  }

  /* Login panel — generous spacing for first-time use */
  .narrow {
    max-width: 100%;
    margin: 12px auto;
  }
  #loginPanel {
    padding: 18px 16px;
  }
  #loginPanel h2 {
    font-size: 18px;
    margin-bottom: 12px;
  }
  #loginPanel button {
    width: 100%;
    margin-top: 4px;
  }
  #loginPanel .hint {
    font-size: 12px;
    margin-top: 14px;
  }

  /* Panel padding for breathing room */
  .panel {
    padding: 14px;
  }

  /* Metrics: 2-up on phones instead of 1-up so dashboard still scans */
  .metrics {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .metric {
    padding: 10px;
  }
  .metric span {
    font-size: 20px;
  }
  .metric small, .metric em {
    font-size: 11px;
  }

  /* Records / list rows — more breathing room when stacked */
  .record, .admin-row, .correction-row {
    padding: 12px;
    gap: 8px;
  }
  .admin-row button {
    min-height: 36px;
    padding: 6px 12px;
    font-size: 12px;
  }

  /* Upload form spacing */
  .upload-form {
    gap: 12px;
  }

  /* Modals — fill width on phone for easier tapping */
  .modal {
    padding: 12px;
    align-items: flex-end;
  }
  .modal-card {
    max-width: 100%;
    padding: 18px 16px;
    border-radius: 14px;
  }
  .modal-card label input {
    min-height: 44px;
    font-size: 16px;
  }
  .modal-actions {
    flex-direction: column-reverse;
    gap: 8px;
  }
  .modal-actions button {
    width: 100%;
  }
  .temp-password {
    font-size: 19px;
    letter-spacing: 0.04em;
    padding: 14px 8px;
  }

  /* Toast/status visibility */
  #toast {
    left: 12px;
    right: 12px;
    bottom: 12px;
    font-size: 14px;
  }

  /* Chips */
  .chip {
    font-size: 11px;
    padding: 4px 9px;
    min-height: 24px;
  }
}

/* ---------- Very small phones (≤ 380px) ---------- */
@media (max-width: 380px) {
  .topbar h1 {
    font-size: 15px;
  }
  .topbar p {
    display: none; /* drop the subtitle on tiny screens */
  }
  .topbar-actions button {
    font-size: 11px;
    padding: 6px 10px;
  }
  .tab {
    padding: 9px 13px;
    font-size: 12px;
  }
}

@media print {
  body {
    background: #ffffff;
  }

  .topbar,
  .tabs,
  .trace-sidebar,
  .trace-actions,
  .trace-qr,
  #toast {
    display: none !important;
  }

  main {
    max-width: none;
    padding: 0;
  }

  #appPanel,
  #trace,
  .trace-workspace,
  .trace-report,
  #traceResult {
    display: block !important;
  }

  .trace-document {
    border: 0;
    box-shadow: none;
  }
}

/* ---------- Password management UI ---------- */
.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 61, 42, 0.55);
  backdrop-filter: blur(4px);
}

.modal.hidden {
  display: none;
}

.modal-card {
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--line);
  box-shadow: 0 30px 60px rgba(15, 61, 42, 0.25);
  padding: 24px;
  width: 100%;
  max-width: 440px;
}

.modal-card h2 {
  margin: 0 0 6px;
  color: var(--accent-dark);
  font-size: 18px;
}

.modal-card p {
  margin: 0 0 14px;
  color: var(--muted);
}

.modal-card label {
  display: block;
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
}

.modal-card label input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
}

.modal-card label input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(26, 82, 56, 0.15);
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 18px;
}

.temp-password {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent-dark);
  background: var(--accent-soft);
  border: 1px dashed var(--accent);
  border-radius: 8px;
  padding: 14px 12px;
  text-align: center;
  margin: 4px 0 14px;
  word-break: break-all;
}

.reset-password-btn {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.reset-password-btn:hover {
  background: var(--accent-soft);
}

#forgotPasswordLink {
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
}
