/* RANIA · JTM ICT PM — stylesheet
   Colours come from the RANIA logo (red) with neutral greys. Mobile-first. */
:root {
  --red: #e21e26;
  --red-dark: #b8141b;
  --red-soft: #fdeceb;
  --ink: #1d1f24;
  --ink-soft: #3c4049;
  --muted: #6b7079;
  --line: #e4e6ea;
  --paper: #f5f6f8;
  --card: #ffffff;
  --blue: #1f4aa8;
  --green: #17794a;
  --green-soft: #e6f5ed;
  --amber: #8a5a00;
  --amber-soft: #fff4d6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 22, 28, .05), 0 8px 24px rgba(20, 22, 28, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #f2f3f5; --ink-soft: #d4d7dd; --muted: #9aa0ab; --line: #2c3038;
    --paper: #15171b; --card: #1d2026; --red-soft: #3a1617; --green-soft: #173225;
    --amber-soft: #3a2e12; --blue: #7ea3ff; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ink: #f2f3f5; --ink-soft: #d4d7dd; --muted: #9aa0ab; --line: #2c3038;
  --paper: #15171b; --card: #1d2026; --red-soft: #3a1617; --green-soft: #173225;
  --amber-soft: #3a2e12; --blue: #7ea3ff; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px; line-height: 1.55; overflow-x: hidden;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(24px, 4vw, 32px); line-height: 1.2; letter-spacing: -.02em; }
h2 { font-size: 18px; line-height: 1.3; letter-spacing: -.01em; }
img { max-width: 100%; display: block; }
a { color: var(--red-dark); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--red) 55%, transparent); outline-offset: 2px; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small-muted, .small-text { color: var(--muted); font-size: 13px; }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--red-dark); margin-bottom: 6px; }

/* ---------- Header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-logo-main { height: 34px; width: auto; }
.brand-divider { width: 1px; height: 30px; background: var(--line); flex: 0 0 auto; }
.brand-contract { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand-contract img { height: 28px; width: auto; }
.brand-contract small { color: var(--muted); font-size: 12px; line-height: 1.2; }
.brand-contract strong { display: block; font-size: 13px; line-height: 1.2; }
.topbar-actions { flex: 0 0 auto; }

/* ---------- Buttons ---------- */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 18px; border-radius: 10px; border: 1px solid transparent;
  font-weight: 600; cursor: pointer; text-decoration: none; background: transparent;
  transition: background .15s, border-color .15s, opacity .15s; white-space: nowrap;
}
.button:disabled { opacity: .45; cursor: not-allowed; }
.button-primary { background: var(--red); color: #fff; }
.button-primary:not(:disabled):hover { background: var(--red-dark); }
.button-secondary { background: var(--card); border-color: var(--line); color: var(--ink); }
.button-secondary:not(:disabled):hover { border-color: var(--muted); }
.button-quiet { color: var(--ink-soft); padding-left: 12px; padding-right: 12px; }
.button-quiet:not(:disabled):hover { background: var(--line); }
.button-danger { color: var(--red-dark); }
.full-width { width: 100%; }
.button-small { min-height: 36px; padding: 6px 12px; font-size: 14px; }

/* ---------- Layout ---------- */
.page { max-width: 1200px; margin: 0 auto; padding: 24px 16px 48px; display: grid; gap: 20px; }
.intro { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; }
.intro p { color: var(--muted); margin-top: 8px; max-width: 60ch; }
.pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--line); font-size: 13px; color: var(--ink-soft);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; min-width: 0;
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head > div { flex: 1 1 240px; min-width: 0; }
.card-head .muted { margin-top: 4px; }
.step {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; flex: 0 0 auto;
  background: var(--red-soft); color: var(--red-dark); font-weight: 700; font-size: 14px;
}
.grid-2 { display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 960px) {
  .grid-2 { grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); align-items: start; }
}

/* ---------- Notices & status ---------- */
.notice {
  padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); font-size: 14px;
  background: var(--card); scroll-margin-top: 80px;
}
.notice-success { background: var(--green-soft); border-color: transparent; color: var(--green); }
.notice-warning { background: var(--amber-soft); border-color: transparent; color: var(--amber); }
.notice-error { background: var(--red-soft); border-color: transparent; color: var(--red-dark); }

.status-panel { display: flex; gap: 14px; align-items: flex-start; }
.status-panel-icon {
  width: 36px; height: 36px; border-radius: 10px; flex: 0 0 auto; display: grid; place-items: center;
  background: var(--paper); font-weight: 700; color: var(--ink-soft);
}
.status-panel-text { flex: 1; min-width: 0; }
.status-panel-text strong { display: block; margin-bottom: 2px; }

.badge {
  display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; white-space: nowrap; background: var(--line); color: var(--ink-soft);
}
.badge-success { background: var(--green-soft); color: var(--green); }
.badge-warning { background: var(--amber-soft); color: var(--amber); }
.badge-error { background: var(--red-soft); color: var(--red-dark); }
.badge-pending { background: var(--blue); color: #fff; }
.badge-neutral { background: var(--line); color: var(--ink-soft); }

/* ---------- Upload ---------- */
.upload-form { display: grid; gap: 14px; }
.upload-drop {
  display: grid; justify-items: center; gap: 6px; text-align: center; cursor: pointer;
  padding: 28px 16px; border: 2px dashed var(--line); border-radius: var(--radius);
  background: var(--paper); transition: border-color .15s, background .15s;
}
.upload-drop:hover, .upload-drop.dragover { border-color: var(--red); background: var(--red-soft); }
.upload-icon {
  width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center;
  background: var(--card); color: var(--red); font-size: 22px; box-shadow: var(--shadow); margin-bottom: 4px;
}
.file-name { font-size: 13px; color: var(--ink-soft); word-break: break-all; }
.privacy-note { line-height: 1.5; }

/* ---------- Review / fields ---------- */
.empty-state { text-align: center; padding: 28px 12px; display: grid; justify-items: center; gap: 8px; color: var(--muted); }
.empty-state strong { color: var(--ink); }
.empty-icon { font-size: 28px; color: var(--muted); }
.record-meta { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.meta-label { display: block; font-size: 11px; font-weight: 700; letter-spacing: .08em; color: var(--muted); text-transform: uppercase; }
.record-id { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 14px; word-break: break-all; }
.warning-note {
  display: grid; gap: 2px; padding: 12px 14px; border-radius: 10px; margin-bottom: 14px;
  background: var(--amber-soft); color: var(--amber); font-size: 14px;
}
.fields-grid { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 620px) { .fields-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.field { display: grid; gap: 6px; min-width: 0; }
.field-full { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink-soft); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.required-mark { color: var(--red); }
.field-hint {
  font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px;
  background: var(--amber-soft); color: var(--amber); text-transform: uppercase; letter-spacing: .04em;
}
.field.is-uncertain input, .field.is-uncertain select, .field.is-uncertain textarea { border-color: var(--amber); background: var(--amber-soft); }
input, select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; font-size: 16px; /* 16px stops iOS zoom-on-focus */
  border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink);
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--red); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--red) 18%, transparent); }
input:disabled, select:disabled, textarea:disabled { opacity: .7; }
.editor-actions { display: grid; gap: 10px; margin-top: 18px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 620px) { .editor-actions { grid-template-columns: auto auto 1fr; align-items: center; } .editor-actions .button-danger { justify-self: end; } }
.submit-hint { margin-top: 12px; }

/* ---------- Tables (become stacked cards on phones) ---------- */
.table-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.table-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase;
  letter-spacing: .05em; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:hover { background: color-mix(in srgb, var(--red-soft) 40%, transparent); }
tr.clickable { cursor: pointer; }
.cell-message { max-width: 42ch; color: var(--ink-soft); word-break: break-word; }
.table-empty { text-align: center; color: var(--muted); padding: 28px 12px; }

@media (max-width: 720px) {
  .records-table thead { display: none; }
  .records-table, .records-table tbody, .records-table tr, .records-table td { display: block; width: 100%; }
  .records-table tr { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 12px; padding: 6px 0; background: var(--card); }
  .records-table td { border: 0; padding: 6px 14px; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  .records-table td::before { content: attr(data-label); font-weight: 600; color: var(--muted); font-size: 12px; text-align: left; text-transform: uppercase; letter-spacing: .04em; }
  .records-table td.table-empty { display: block; text-align: center; border: 0; }
  .records-table td.table-empty::before { content: none; }
  .cell-message { max-width: none; text-align: right; }
  tbody tr:hover { background: var(--card); }
}

/* ---------- Footer ---------- */
.page-footer {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 16px;
  color: var(--muted); font-size: 13px; padding-top: 8px; border-top: 1px solid var(--line);
}

/* ---------- Mobile polish ---------- */
@media (max-width: 720px) {
  body { font-size: 15px; }
  .page { padding: 16px 16px 40px; gap: 16px; }
  .card { padding: 16px; }
  .topbar-inner { padding: 10px 16px; }
  .brand-divider, .brand-contract small { display: none; }
  .brand-logo-main { height: 26px; }
  .brand-contract img { height: 22px; }
  .brand-contract strong { font-size: 12px; }
  .card-head .history-actions, .card-head .table-tools { width: 100%; }
  .card-head .table-tools .button { flex: 1; }
  .button { min-height: 46px; }
}
@media (max-width: 380px) {
  .brand-contract { display: none; }
}

/* ---------- Login ---------- */
.login-body { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px 16px; }
.login-shell { width: 100%; max-width: 400px; display: grid; gap: 16px; }
.login-logos { display: flex; align-items: center; justify-content: center; gap: 16px; }
.login-logos img:first-child { height: 44px; width: auto; }
.login-jtm { height: 36px; width: auto; }
.login-card { display: grid; gap: 12px; padding: 24px; }
.login-form { display: grid; gap: 8px; margin-top: 4px; }
.login-form label { font-size: 13px; font-weight: 600; color: var(--ink-soft); margin-top: 6px; }
.login-form .button { margin-top: 14px; }
.login-error { background: var(--red-soft); color: var(--red-dark); padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.login-foot, .login-copy { text-align: center; }


/* ---------- Destructive data management ---------- */
.danger-zone { border-color: color-mix(in srgb, var(--red) 30%, var(--line)); }
.danger-zone .eyebrow { color: var(--red-dark); }
.danger-zone-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.danger-zone-actions .button { flex: 0 0 auto; }

/* ---------- PM workspace with left navigation ---------- */
.app-shell {
  min-height: calc(100vh - 60px);
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
}
.sidebar {
  position: sticky;
  top: 60px;
  height: calc(100vh - 60px);
  min-height: 460px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 24px 12px 16px;
  border-right: 1px solid var(--line);
  background: var(--card);
}
.sidebar-label { padding: 0 12px; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .12em; }
.side-nav { display: grid; gap: 5px; }
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 46px;
  padding: 10px 12px 10px 16px;
  text-align: left;
  color: var(--ink-soft);
  background: transparent;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
}
.nav-item:hover { background: var(--paper); }
.nav-item.active { background: var(--red-soft); color: var(--red-dark); }
.nav-item.active::before { content: ""; position: absolute; left: 0; top: 9px; bottom: 9px; width: 3px; border-radius: 0 5px 5px 0; background: var(--red); }
.nav-icon { flex: 0 0 23px; width: 23px; text-align: center; font-size: 21px; line-height: 1; }
.nav-label { flex: 1; font-size: 14px; white-space: nowrap; }
.nav-count { display: inline-flex; min-width: 23px; height: 22px; padding: 0 6px; align-items: center; justify-content: center; background: var(--line); color: var(--ink-soft); border-radius: 20px; font-size: 11px; font-weight: 800; }
.nav-item.active .nav-count { background: var(--card); color: var(--red-dark); }
.sidebar-bottom { display: flex; align-items: center; gap: 9px; margin-top: auto; padding: 14px 10px 4px; border-top: 1px solid var(--line); }
.sidebar-bottom strong, .sidebar-bottom small { display: block; }
.sidebar-bottom strong { font-size: 12px; }
.sidebar-bottom small { color: var(--muted); font-size: 11px; }
.sidebar-status-dot { width: 8px; height: 8px; flex: 0 0 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px var(--green-soft); }
.workspace { min-width: 0; width: 100%; max-width: 1600px; padding: 28px clamp(18px, 2.7vw, 42px) 40px; display: grid; align-content: start; gap: 22px; }
.workspace-heading { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; }
.workspace-heading .muted { margin-top: 6px; }
.page-view { display: grid; gap: 20px; min-width: 0; }
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat-card { min-width: 0; display: grid; gap: 6px; padding: 18px 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow); }
.stat-label { font-size: 13px; font-weight: 650; color: var(--muted); }
.stat-card strong { font-size: clamp(26px, 2.5vw, 34px); line-height: 1.1; font-weight: 750; letter-spacing: -.04em; }
.stat-foot { font-size: 12px; color: var(--muted); }
.quick-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.record-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 2px 0 15px; }
.search-box { display: flex; align-items: center; gap: 9px; flex: 1 1 320px; min-width: 0; min-height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); }
.search-box span { color: var(--muted); font-size: 22px; line-height: 1; }
.search-box input { width: 100%; border: 0; outline: 0; background: transparent; min-width: 0; }
.search-box input:focus-visible { outline: none; }
.filter-box { display: flex; align-items: center; gap: 8px; }
.filter-box select { min-height: 42px; padding: 7px 28px 7px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.live-refresh-note { margin-top: 12px; }
.excel-hero { display: flex; align-items: center; gap: 18px; }
.excel-hero > div:last-child { display: grid; gap: 6px; }
.excel-icon { display: grid; place-items: center; width: 66px; height: 66px; flex: 0 0 66px; border-radius: 15px; background: var(--green-soft); color: var(--green); font-size: 18px; font-weight: 850; letter-spacing: -.06em; }
.workbook-path { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 12px 14px; border: 1px dashed var(--line); border-radius: 10px; background: var(--paper); }
.path-label { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.workbook-path code { overflow-wrap: anywhere; }
.settings-list { display: grid; gap: 0; margin-top: 16px; border-top: 1px solid var(--line); }
.settings-list > div { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.settings-list span { color: var(--muted); font-size: 13px; }
.settings-list strong { font-size: 13px; text-align: right; }
.workspace .page-footer { margin-top: 8px; }

@media (min-width: 1200px) {
  .grid-2 { grid-template-columns: minmax(330px, .82fr) minmax(460px, 1.18fr); }
}
@media (max-width: 1080px) {
  .app-shell { grid-template-columns: 210px minmax(0, 1fr); }
  .sidebar { padding-left: 9px; padding-right: 9px; }
  .workspace { padding: 24px 20px 34px; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 721px) and (max-width: 1080px) {
  .pm-records-table { min-width: 1000px; }
}
@media (max-width: 720px) {
  .topbar-inner { padding: 9px 12px; }
  .brand { gap: 8px; }
  .brand-logo-main { height: 25px; }
  .brand-contract img { height: 22px; }
  .brand-contract strong { font-size: 11px; }
  .app-shell { grid-template-columns: 64px minmax(0, 1fr); }
  .sidebar { top: 56px; height: calc(100vh - 56px); min-height: 400px; padding: 16px 6px 10px; gap: 10px; }
  .sidebar-label, .nav-label, .nav-count, .sidebar-bottom > div { display: none; }
  .side-nav { gap: 6px; }
  .nav-item { justify-content: center; gap: 0; min-height: 46px; padding: 9px 4px; border-radius: 9px; }
  .nav-item.active::before { top: 8px; bottom: 8px; }
  .nav-icon { flex-basis: auto; width: auto; font-size: 22px; }
  .sidebar-bottom { justify-content: center; padding: 13px 0 0; }
  .workspace { gap: 16px; padding: 18px 12px 28px; }
  .workspace-heading { align-items: flex-start; }
  .workspace-heading .pill { display: none; }
  .stats-grid { gap: 9px; }
  .stat-card { padding: 13px 12px; gap: 5px; }
  .stat-label { font-size: 11px; }
  .stat-foot { font-size: 10px; }
  .stat-card strong { font-size: 27px; }
  .excel-hero { align-items: flex-start; gap: 12px; }
  .excel-icon { width: 48px; height: 48px; flex-basis: 48px; border-radius: 11px; font-size: 13px; }
  .record-filters { align-items: stretch; }
  .filter-box { justify-content: space-between; flex: 1 1 100%; }
  .filter-box select { flex: 1; }
  .records-results-count { width: 100%; }
  .workspace .page-footer { font-size: 11px; }
}


.method-divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.12em; }
.method-divider::before, .method-divider::after { content: ""; height: 1px; flex: 1; background: var(--line); }


/* =====================================================================
   PHONE LAYOUT (<= 720px)
   - sidebar becomes a bottom tab bar (thumb reach)
   - tables become stacked cards (no sideways scrolling)
   - filters / buttons stack full width, safe-area aware for notched phones
   Desktop and tablet (> 720px) are untouched.
   ===================================================================== */
body { -webkit-tap-highlight-color: transparent; }
button, .nav-item, .upload-drop { touch-action: manipulation; }

@media (max-width: 720px) {
  html { scroll-padding-top: 72px; }
  .topbar { padding-top: env(safe-area-inset-top); }
  .topbar-inner { padding: 8px max(12px, env(safe-area-inset-left)) 8px max(12px, env(safe-area-inset-right)); }
  .topbar-actions .button { min-height: 40px; padding: 6px 12px; font-size: 14px; }

  /* ---- Bottom tab bar ---- */
  .app-shell { display: block; min-height: 0; }
  .sidebar {
    position: fixed; top: auto; left: 0; right: 0; bottom: 0; z-index: 20;
    height: auto; min-height: 0; padding: 0; gap: 0; flex-direction: row;
    border-right: 0; border-top: 1px solid var(--line);
    background: var(--card);
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -6px 20px rgba(20, 22, 28, .07);
  }
  .sidebar-label, .sidebar-bottom { display: none; }
  .side-nav { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 0; width: 100%; }
  .nav-item {
    flex-direction: column; justify-content: center; gap: 2px;
    min-height: 58px; padding: 7px 2px 6px; border-radius: 0; text-align: center;
  }
  .nav-item:hover { background: transparent; }
  .nav-item.active { background: transparent; color: var(--red-dark); }
  .nav-item.active::before { left: 22%; right: 22%; top: 0; bottom: auto; width: auto; height: 3px; border-radius: 0 0 4px 4px; }
  .nav-icon { flex: 0 0 auto; width: auto; font-size: 21px; }
  .nav-label {
    display: block; flex: 0 0 auto; max-width: 100%; min-width: 0; overflow: hidden;
    white-space: normal; overflow-wrap: anywhere; text-align: center;
    font-size: 10.5px; font-weight: 650; line-height: 1.15;
  }
  .nav-count {
    display: inline-flex; position: absolute; top: 4px; left: calc(50% + 6px);
    min-width: 18px; height: 18px; padding: 0 5px; font-size: 10px;
    background: var(--red); color: #fff;
  }
  .nav-item.active .nav-count { background: var(--red); color: #fff; }

  /* ---- Workspace ---- */
  .workspace {
    padding: 16px max(12px, env(safe-area-inset-left)) calc(86px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-right));
    gap: 14px; max-width: 100%;
  }
  .page-view { gap: 14px; }
  h1 { font-size: 24px; }
  .workspace-heading .muted { font-size: 14px; }
  .card { padding: 14px; border-radius: 12px; }
  .card-head { margin-bottom: 12px; }
  .card-head > div { flex-basis: 100%; }
  .card-head .step { display: none; }
  .card-head .badge { align-self: flex-start; }
  #preview-section { scroll-margin-top: 72px; }

  /* Stats: 2 x 2 */
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat-card { padding: 12px; }
  .stat-label { font-size: 12px; }
  .stat-foot { font-size: 11px; }
  .stat-card strong { font-size: 28px; }

  /* Quick actions / button groups stack full width */
  .quick-actions { display: grid; grid-template-columns: 1fr; }
  .quick-actions .button, .danger-zone-actions .button { width: 100%; }
  .danger-zone-actions { display: grid; gap: 10px; }
  .card-head .table-tools { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
  .card-head .table-tools .button { width: 100%; }

  /* Upload */
  .upload-drop { padding: 24px 12px; }

  /* Editor actions: primary first, full width */
  .editor-actions { grid-template-columns: 1fr; }
  .editor-actions #save-record-button { order: -1; }
  .editor-actions .button-danger { justify-self: stretch; }

  /* Filters */
  .record-filters { display: grid; grid-template-columns: 1fr; gap: 10px; align-items: stretch; }
  .search-box { flex: none; min-height: 46px; }
  .filter-box { display: grid; grid-template-columns: 96px minmax(0, 1fr); align-items: center; gap: 10px; }
  .filter-box select { width: 100%; min-height: 46px; }
  .records-results-count { width: auto; }

  /* ---- Tables as cards ---- */
  .table-wrap { overflow: visible; margin: 0; padding: 0; }
  .records-table, .pm-records-table { min-width: 0 !important; width: 100%; }
  .records-table thead { display: none !important; }
  .records-table, .records-table tbody, .records-table tr, .records-table td { display: block; width: 100%; }
  .records-table tr {
    margin: 0 0 10px; padding: 8px 0; background: var(--card);
    border: 1px solid var(--line); border-radius: 12px;
  }
  .records-table tr.draft-row { border-left: 4px solid var(--amber); }
  .records-table td {
    display: flex; align-items: center; justify-content: space-between; gap: 14px;
    padding: 6px 14px; border: 0; text-align: right; overflow-wrap: anywhere;
  }
  .records-table td::before { flex: 0 0 38%; max-width: 38%; }
  .records-table td > * { min-width: 0; }
  .records-table td .badge { white-space: normal; text-align: right; line-height: 1.3; padding: 4px 10px; }
  .records-table td[data-label="Action"] { padding-top: 10px; }
  .records-table td[data-label="Action"]::before { display: none; }
  .records-table td[data-label="Action"] .button { width: 100%; min-height: 44px; background: var(--paper); border-color: var(--line); }
  .records-table td.table-empty { padding: 24px 12px; display: block; }
  .cell-message { max-width: none; }

  .settings-list > div { flex-direction: column; align-items: flex-start; }
  .settings-list strong { text-align: left; }
  .workbook-path { flex-direction: column; align-items: flex-start; gap: 6px; }

  .excel-hero { flex-direction: row; }
  .page-footer { flex-direction: column; gap: 4px; }
}

@media (max-width: 360px) {
  .nav-label { font-size: 9.5px; }
  .nav-item { min-height: 62px; }
  .stat-card strong { font-size: 24px; }
  .filter-box { grid-template-columns: 1fr; gap: 4px; }
}

/* Phones turned sideways: keep the bar short */
@media (max-width: 900px) and (max-height: 480px) and (orientation: landscape) {
  .sidebar .nav-item { min-height: 48px; flex-direction: row; gap: 6px; }
  .workspace { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
}
