:root {
  /* ---- Bold Dashboard palette (light) ---- */
  --bg: #EAF0F8;
  --surface: #FFFFFF;
  --surface-2: #F3F7FC;
  --surface-3: #E7EEF8;
  --ink: #101A2C;
  --muted: #56698A;
  --border: #D7E1F0;

  --navy: #1B3B6F;        /* accent - buttons, headings, links, table headers */
  --navy-hover: #14294F;  /* hover/active shade of the accent */
  --navy-ink: #FFFFFF;    /* text color to use on a solid --navy fill */
  --topbar-bg: #16294B;   /* fixed brand bar color - stays dark in both themes */
  --accent-soft: #E3ECF9; /* light accent chip/badge background */
  --accent-soft-ink: #1B3B6F;

  --green: #1E8E56;
  --green-bg: #DEF3E6;
  --red: #C23B31;
  --red-bg: #FBE2DE;
  --yellow-bg: #FBEACB;
  --yellow-ink: #8A5A0C;
  --yellow: #D98324;
  --grey: #56698A;
  --grey-bg: #E7ECF4;

  --font-head: 'Sora', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-num: 'IBM Plex Mono', ui-monospace, monospace;

  --radius-card: 14px;
  --radius-btn: 8px;
  --radius-pill: 8px;
  --shadow-card: 0 6px 18px rgba(13,30,64,.12), 0 1px 3px rgba(13,30,64,.10);
  --card-top-accent: 3px solid var(--navy);
}

/* ---- Dark mode: follows system preference, or the explicit toggle in base.html ---- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0B1526;
    --surface: #121F35;
    --surface-2: #16223B;
    --surface-3: #1B2C4C;
    --ink: #F0F4FA;
    --muted: #8FA0BD;
    --border: #24345A;

    --navy: #82B3EA;
    --navy-hover: #A9CBF2;
    --navy-ink: #0B1526;
    --topbar-bg: #081120;
    --accent-soft: #1B2C4C;
    --accent-soft-ink: #A9CBF2;

    --green: #3BD494;
    --green-bg: #0F3325;
    --red: #F17C71;
    --red-bg: #3A1512;
    --yellow-bg: #3A2A0C;
    --yellow-ink: #F0B84D;
    --yellow: #F0B84D;
    --grey: #8FA0BD;
    --grey-bg: #1C2A47;

    --shadow-card: 0 6px 18px rgba(0,0,0,.45), 0 1px 3px rgba(0,0,0,.3);
  }
}
:root[data-theme="dark"] {
  --bg: #0B1526;
  --surface: #121F35;
  --surface-2: #16223B;
  --surface-3: #1B2C4C;
  --ink: #F0F4FA;
  --muted: #8FA0BD;
  --border: #24345A;

  --navy: #82B3EA;
  --navy-hover: #A9CBF2;
  --navy-ink: #0B1526;
  --topbar-bg: #081120;
  --accent-soft: #1B2C4C;
  --accent-soft-ink: #A9CBF2;

  --green: #3BD494;
  --green-bg: #0F3325;
  --red: #F17C71;
  --red-bg: #3A1512;
  --yellow-bg: #3A2A0C;
  --yellow-ink: #F0B84D;
  --yellow: #F0B84D;
  --grey: #8FA0BD;
  --grey-bg: #1C2A47;

  --shadow-card: 0 6px 18px rgba(0,0,0,.45), 0 1px 3px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }
body {
  font-family: var(--font-body);
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

input, select, textarea {
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
}

.topbar {
  background: var(--topbar-bg);
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 54px;
  position: sticky;
  top: 0;
  z-index: 200;
}
.hamburger-btn {
  background: transparent;
  border: none;
  color: white;
  font-size: 22px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--radius-btn);
  line-height: 1;
}
.hamburger-btn:hover { background: rgba(255,255,255,0.15); }
.brand {
  color: white;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 17px;
}
.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}
.navlink-user { color: #CFE2F3; font-size: 12px; }
.navlink-logout-btn {
  background: transparent; color: white; border: 1px solid rgba(255,255,255,0.4);
  padding: 5px 12px; border-radius: var(--radius-btn); font-size: 12px; cursor: pointer;
}
.navlink-logout-btn:hover { background: rgba(255,255,255,0.15); }

.theme-toggle-btn {
  background: transparent; color: white; border: 1px solid rgba(255,255,255,0.4);
  width: 30px; height: 30px; border-radius: var(--radius-btn); cursor: pointer;
  font-size: 15px; display: flex; align-items: center; justify-content: center; padding: 0;
}
.theme-toggle-btn:hover { background: rgba(255,255,255,0.15); }

/* Sidebar */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 250;
}
.sidebar-overlay.open { display: block; }

.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 260px;
  background: var(--surface);
  box-shadow: 2px 0 12px rgba(0,0,0,0.15);
  transform: translateX(-100%);
  transition: transform 0.2s ease;
  z-index: 300;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.sidebar.open { transform: translateX(0); }

.sidebar-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 18px;
  background: var(--topbar-bg);
  color: white;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 15px;
}
.sidebar-close {
  background: transparent; border: none; color: white; font-size: 22px;
  cursor: pointer; line-height: 1;
}
.sidebar-link {
  display: block;
  padding: 13px 18px;
  color: var(--ink);
  text-decoration: none;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}
.sidebar-link:hover { background: var(--surface-3); }
.sidebar-divider { height: 8px; background: var(--bg); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }

/* Collapsible nav groups in the sidebar (e.g. "Fabric", "Viewers"). The
   name="navgroup" attribute on each <details> makes them an exclusive
   accordion natively - opening one closes the others, no JS needed. */
.nav-group { border-bottom: 1px solid var(--border); }
.nav-group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 18px;
  font-size: 14px;
  font-weight: bold;
  color: var(--ink);
  cursor: pointer;
  list-style: none;
}
.nav-group-header::-webkit-details-marker { display: none; }
.nav-group-header::after {
  content: "\25BC";
  font-size: 10px;
  color: var(--grey);
  margin-left: 8px;
  transition: transform 0.15s;
}
.nav-group[open] .nav-group-header::after { transform: rotate(180deg); }
.nav-group-header:hover { background: var(--surface-3); }
.nav-group-body { background: var(--surface-2); }
.nav-group-body .sidebar-link { padding-left: 32px; font-size: 13px; border-bottom: 1px solid var(--border); }
.nav-group-body .sidebar-link:last-child { border-bottom: none; }

.auth-page {
  max-width: 420px; margin: 80px auto; padding: 0 20px;
}
.auth-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card);
  box-shadow: var(--shadow-card); padding: 32px;
}
.auth-box h1 { color: var(--navy); margin-top: 0; font-size: 22px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; }
.auth-form label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 5px; }
.auth-form input {
  padding: 9px 10px; border: 1px solid var(--border); border-radius: var(--radius-btn); font-size: 14px;
}
.auth-form button { margin-top: 6px; padding: 10px; font-size: 14px; }

main { max-width: 1200px; margin: 0 auto; padding: 24px 20px 60px; }

h1 { font-family: var(--font-head); color: var(--navy); margin-bottom: 4px; }
h2 { font-family: var(--font-head); color: var(--navy); font-size: 16px; margin-top: 0; }

.hint { color: var(--muted); font-size: 13px; }

.flash { padding: 10px 16px; border-radius: var(--radius-btn); margin-bottom: 16px; font-size: 14px; }
.flash-success { background: var(--green-bg); color: var(--green); }
.flash-error { background: var(--red-bg); color: var(--red); }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 20px 0 28px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: var(--card-top-accent);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 16px;
  text-align: center;
}
.kpi-card.kpi-warn { background: var(--red-bg); border-color: var(--red); border-top-color: var(--red); }
.kpi-card.kpi-info { background: var(--yellow-bg); }
.kpi-value { font-family: var(--font-num); font-variant-numeric: tabular-nums; font-size: 26px; font-weight: 700; color: var(--navy); }
.kpi-card.kpi-warn .kpi-value { color: var(--red); }
.kpi-label { font-size: 12px; color: var(--muted); margin-top: 4px; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  padding: 18px;
  margin-bottom: 16px;
}

.simple-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.simple-table th {
  background: var(--navy);
  color: var(--navy-ink);
  text-align: left;
  padding: 8px 10px;
}
.simple-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.simple-table tr:nth-child(even) td { background: var(--surface-2); }
.bottleneck-row td { background: var(--red-bg) !important; font-weight: bold; }

/* Dashboard per-stage tables: red = overdue at this stage, yellow = due
   tomorrow (one day before the Settings-configured limit). */
.row-alert-red td { background: var(--red-bg) !important; }
.row-alert-yellow td { background: var(--yellow-bg) !important; }
.stage-table-summary { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.stage-table-summary .stage-alert-counts { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.badge.alert-red { background: var(--red-bg); color: var(--red); }
.badge.alert-yellow { background: var(--yellow-bg); color: var(--yellow-ink); }

.wide-table { overflow-x: auto; display: block; -webkit-overflow-scrolling: touch; }
.wide-table th, .wide-table td { white-space: nowrap; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: bold;
}
.status-done { background: var(--green-bg); color: var(--green); }
.status-ready { background: var(--yellow-bg); color: var(--yellow-ink); }
.status-locked { background: var(--grey-bg); color: var(--grey); }
.status-progress { background: var(--accent-soft); color: var(--accent-soft-ink); }
.status-delayed { background: var(--red-bg); color: var(--red); font-weight: bold; }
.status-warn { background: var(--yellow-bg); color: var(--yellow-ink); font-weight: bold; }

.alert-panel { border: 2px solid var(--red); background: var(--red-bg); }
.urgency-strip { margin: -4px 0 10px; display: flex; align-items: center; gap: 10px; }

.grid-form {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px 16px;
}
.grid-form label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  color: var(--muted);
  gap: 4px;
}
.grid-form input, .grid-form select {
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  font-size: 13px;
}
.grid-form input:disabled {
  background: var(--grey-bg);
  color: var(--grey);
}
.readonly-field { background: var(--surface-2) !important; font-weight: bold; }
.span-2 { grid-column: span 2; }
.checkbox-label { flex-direction: row !important; align-items: center; gap: 8px !important; font-size: 13px !important; }
.checkbox-label input { width: auto; }

.po-thumb {
  width: 48px; height: 48px; object-fit: cover; border-radius: 6px;
  border: 1px solid var(--border); margin-right: 10px; cursor: zoom-in;
}
.po-thumb-sm {
  width: 32px; height: 32px; object-fit: cover; border-radius: 4px;
  border: 1px solid var(--border); cursor: zoom-in;
}

.lightbox-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 500;
  align-items: center; justify-content: center;
  cursor: zoom-out;
}
.lightbox-overlay.open { display: flex; }
.lightbox-overlay img {
  max-width: 90%; max-height: 90%;
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
}
.po-card-title { display: flex; align-items: center; }
.print-link {
  display: inline-block; margin-left: 8px; font-size: 11px; color: var(--accent-soft-ink);
  background: var(--accent-soft); padding: 2px 8px; border-radius: var(--radius-pill); text-decoration: none;
}
.print-link:hover { background: var(--grey-bg); }

.print-btn-link {
  display: inline-block; background: var(--navy); color: var(--navy-ink); text-decoration: none;
  padding: 9px 18px; border-radius: var(--radius-btn); font-size: 13px;
}
.print-btn-link:hover { background: var(--navy-hover); }

.pps-comments-panel {
  background: var(--yellow-bg); border: 1px solid var(--yellow); border-radius: var(--radius-btn);
  padding: 10px 14px; margin-bottom: 14px;
}
.box-title-inline { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--yellow-ink); font-weight: bold; margin-bottom: 6px; }
.pps-comment-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 5px 0; border-bottom: 1px solid var(--border); font-size: 13px;
}
.pps-comment-row:last-child { border-bottom: none; }

.receive-summary {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px;
  background: var(--surface-2); border-radius: var(--radius-btn); padding: 14px; margin: 12px 0 20px; font-size: 13px;
}
.close-form { margin-top: 16px; text-align: right; }
.btn-close { background: transparent; color: var(--red); border: 1px solid var(--red); font-size: 12px; }
.btn-close:hover { background: var(--red-bg); }

.roll-picker { max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-btn); }
.roll-picker table { margin-bottom: 0; }

.receipt-block { border: 1px solid var(--border); border-radius: var(--radius-btn); padding: 12px 14px; margin-bottom: 12px; }
.receipt-block-header { font-size: 13px; margin-bottom: 8px; display: flex; align-items: center; gap: 10px; }

textarea {
  padding: 8px; border: 1px solid var(--border); border-radius: var(--radius-btn); font-size: 13px; font-family: monospace;
  resize: vertical;
}
code { background: var(--surface-2); color: var(--ink); padding: 1px 5px; border-radius: 3px; font-size: 11px; }

.size-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.size-chip {
  background: var(--accent-soft); color: var(--accent-soft-ink); font-size: 11px; font-weight: bold;
  padding: 3px 9px; border-radius: var(--radius-pill);
}

.final-avg-banner {
  background: var(--green-bg); border: 1px solid var(--green); color: var(--green);
  padding: 10px 14px; border-radius: var(--radius-btn); font-size: 13px; margin-bottom: 16px;
}

.cutting-form-heading { margin: 4px 0 8px; font-size: 13px; color: var(--navy); }
.size-qty-grid { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 8px; }
.size-qty-box {
  display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: bold;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-btn); padding: 8px 10px; min-width: 90px;
}
.size-qty-box input { font-weight: normal; }
.roll-search {
  flex: 1 1 220px; min-width: 0; padding: 7px 8px; border: 1px solid var(--border); border-radius: var(--radius-btn);
  font-size: 12px;
}
.roll-select {
  width: 100%; padding: 6px; border: 1px solid var(--border); border-radius: 0 0 var(--radius-btn) var(--radius-btn); font-size: 12px;
  background: var(--surface); color: var(--ink);
}
.roll-toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 6px; }
.roll-tool-btn { padding: 6px 10px; font-size: 12px; }
.roll-list {
  max-height: 300px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-btn);
  background: var(--surface);
}
.roll-list label.roll-row {
  display: grid; flex-direction: row; color: var(--ink); grid-template-columns: 24px minmax(90px, 1.2fr) 80px minmax(120px, 2fr) minmax(140px, 2fr);
  gap: 8px; align-items: center; padding: 7px 10px; border-bottom: 1px solid var(--border);
  font-size: 12px; cursor: pointer; margin: 0;
}
.roll-list label.roll-row:last-child { border-bottom: none; }
.roll-list label.roll-row:hover { background: var(--surface-2); }
.roll-list label.roll-row.roll-picked { background: var(--accent-soft); color: var(--accent-soft-ink); }
.roll-list .roll-row input[type=checkbox] { width: 18px; height: 18px; margin: 0; padding: 0; }
.roll-no { font-weight: bold; }
.roll-m { font-family: var(--font-num); text-align: right; }
.roll-meta { color: var(--muted); font-size: 11px; }
.roll-dup {
  display: inline-block; margin-left: 4px; padding: 1px 6px; border-radius: 10px;
  background: var(--red-bg); color: var(--red); font-size: 10px; font-weight: bold;
}
.manual-meters { display: block; margin-top: 10px; max-width: 360px; }
@media (max-width: 700px) {
  .roll-list label.roll-row { grid-template-columns: 24px 1fr auto; }
  .roll-list label.roll-row .roll-meta { grid-column: 2 / -1; }
}

.settings-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px;
}
.settings-list {
  list-style: none; padding: 0; margin: 10px 0 0; max-height: 280px; overflow-y: auto;
}
.settings-list li {
  padding: 6px 10px; font-size: 13px; border-bottom: 1px solid var(--border);
}
.settings-list li:nth-child(even) { background: var(--surface-2); }

/* Editable master-data rows (Buyers, Fabric Names/Weights/Types,
   Fabricators, Washing Units, Defect Categories, Fabric Vendors) - a name
   field you can rename in place, plus a Delete button, replacing what used
   to be plain read-only text. */
.settings-list-editable li {
  display: flex; flex-direction: column; align-items: stretch;
  gap: 6px; padding: 10px; border-radius: var(--radius-btn);
}
.settings-list-editable li:nth-child(even) { background: transparent; }
.settings-list-editable li:hover { background: var(--surface-2); }
.edit-row-form {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; width: 100%; margin: 0;
}
.edit-row-form-stacked { flex-direction: column; align-items: stretch; flex-wrap: nowrap; }
.edit-row-form input[type="text"], .edit-row-form input[type="email"] {
  flex: 1 1 120px; min-width: 0; padding: 6px 8px; border: 1px solid var(--border);
  border-radius: var(--radius-btn); font-size: 13px;
}
.edit-row-form input[type="number"] {
  flex: 0 1 80px; min-width: 60px; padding: 6px 8px; border: 1px solid var(--border);
  border-radius: var(--radius-btn); font-size: 13px;
}
.edit-row-form select {
  flex: 0 1 auto; min-width: 0; padding: 6px 8px; border: 1px solid var(--border);
  border-radius: var(--radius-btn); font-size: 13px;
}
.edit-row-form button { flex-shrink: 0; }
.settings-list-editable li > form:last-child:not(.edit-row-form) {
  align-self: flex-end; margin: 0;
}
.settings-list-editable .btn-delete { white-space: nowrap; }

.quick-add-row {
  display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px;
  padding-top: 14px; border-top: 1px dashed var(--border);
}
.quick-add-row .inline-form { margin-top: 0; flex: 1; min-width: 180px; }
.calc-readout { font-size: 12px; color: var(--muted); margin-top: 6px; }
.avg-garment-box {
  background: var(--yellow-bg); border: 1px solid var(--yellow); border-radius: var(--radius-btn);
  padding: 12px 16px; text-align: center; margin: 6px 0;
}
.avg-garment-value { font-family: var(--font-num); font-size: 22px; font-weight: bold; color: var(--yellow-ink); margin-top: 4px; }

.edit-core-toggle {
  background: var(--yellow-bg); border: 1px solid var(--yellow); border-radius: var(--radius-btn);
  padding: 8px 12px; font-size: 12px;
}

.viewer-banner {
  background: var(--accent-soft); color: var(--accent-soft-ink); text-align: center;
  font-size: 12px; padding: 6px; border-bottom: 1px solid var(--border);
}

/* Viewer role: hide every form that would change data, leave GET-based
   filters/dropdowns (sort, "select a PO") visible since those are safe. */
.viewer-mode form[method="post"] { display: none; }

.panel-header-row {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 10px; margin-bottom: 10px;
}
.sort-form { display: flex; gap: 12px; align-items: flex-end; }
.sort-form label {
  display: flex; flex-direction: column; font-size: 11px; color: var(--muted); gap: 3px;
}
.sort-form select {
  padding: 5px 6px; border: 1px solid var(--border); border-radius: var(--radius-btn); font-size: 12px;
}

button {
  background: var(--navy);
  color: var(--navy-ink);
  font-family: var(--font-body);
  border: none;
  padding: 8px 18px;
  border-radius: var(--radius-btn);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  margin-top: 4px;
}
button:hover { background: var(--navy-hover); }

.inline-form { display: flex; gap: 8px; margin-top: 12px; }
.inline-form input { flex: 1; padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius-btn); }

.po-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.po-card.po-locked { background: var(--surface-2); opacity: 0.85; }
.po-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 14px;
}
.po-actions { display: flex; justify-content: flex-end; }
.delete-form { margin-top: 4px; text-align: right; }
.btn-delete { background: transparent; color: var(--red); font-size: 11px; padding: 2px 8px; }
.btn-delete:hover { background: var(--red-bg); }

@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .two-col { grid-template-columns: 1fr; }
  .grid-form { grid-template-columns: 1fr 1fr; }
}

/* Phone-specific fixes */
@media (max-width: 600px) {
  main { padding: 16px 12px 50px; }

  .topbar { padding: 0 10px; height: 50px; }
  .brand { font-size: 15px; }
  .hamburger-btn { font-size: 24px; padding: 8px; min-width: 44px; min-height: 44px; }
  .navlink-user { display: none; }
  .navlink-logout-btn { padding: 8px 12px; font-size: 12px; }

  .sidebar { width: 82vw; max-width: 300px; }

  h1 { font-size: 20px; }
  .panel { padding: 14px; }

  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .kpi-value { font-size: 20px; }

  .grid-form { grid-template-columns: 1fr; gap: 10px; }
  .span-2 { grid-column: span 1; }

  .settings-grid { grid-template-columns: 1fr; }
  .receive-summary { grid-template-columns: repeat(2, 1fr); }
  .three-col, .bottom-grid { flex-direction: column; }
  .action-row, .quick-add-row, .no-print { flex-direction: column; align-items: stretch; }
  .sort-form { flex-direction: column; align-items: stretch; }

  /* Inputs at 16px+ stop iOS Safari from auto-zooming when tapped into */
  .grid-form input, .grid-form select, .grid-form textarea,
  .auth-form input, .inline-form input, .sort-form select,
  .roll-search, .roll-select {
    font-size: 16px;
  }

  button, .print-link, .print-btn-link {
    padding: 10px 16px;
    font-size: 14px;
  }
  .btn-delete, .btn-close { padding: 8px 12px; }

  .simple-table { font-size: 12px; }
  .simple-table th, .simple-table td { padding: 7px 8px; }

  .roll-select { height: 160px; }
}

/* Collapsible reference/history sections (mobile-collapsed via JS above) */
details.mobile-collapsible summary {
  cursor: pointer;
  list-style: none;
  color: var(--navy);
  font-size: 16px;
  font-weight: bold;
  margin: 0;
  padding: 4px 0;
}
details.mobile-collapsible summary::-webkit-details-marker { display: none; }
details.mobile-collapsible summary::before {
  content: "\25BC ";
  font-size: 11px;
  display: inline-block;
  transition: transform 0.15s;
}
details.mobile-collapsible:not([open]) summary::before {
  transform: rotate(-90deg);
}
details.mobile-collapsible .details-body { margin-top: 12px; }

/* Per-PO collapsible cards on PO Acknowledge / Check & Pack: the summary
   reuses the existing .po-card-header look (photo + text + badge row)
   instead of the plain bold-text summary style used elsewhere. */
details.mobile-collapsible summary.po-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: inherit;
  font-weight: normal;
  font-size: 14px;
  list-style: none;
  cursor: pointer;
  margin-bottom: 0;
}
details.mobile-collapsible summary.po-card-header::-webkit-details-marker { display: none; }
details.mobile-collapsible summary.po-card-header::before {
  content: "\25BC";
  font-size: 11px;
  color: var(--navy);
  margin-right: 10px;
  flex-shrink: 0;
  transition: transform 0.15s;
}
details.mobile-collapsible:not([open]) summary.po-card-header::before {
  transform: rotate(-90deg);
}

/* ---- PO Viewer: card grid (photo on top, details underneath) ---- */
.view-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-btn); overflow: hidden; align-self: center; }
.view-toggle a { padding: 6px 14px; font-size: 13px; color: var(--muted); text-decoration: none; background: var(--surface); }
.view-toggle a.active { background: var(--navy); color: var(--navy-ink); font-weight: bold; }

.po-tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 18px; margin-top: 14px; }
.po-tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card);
  box-shadow: var(--shadow-card); overflow: hidden; display: flex; flex-direction: column;
}
.po-tile-alert { border: 2px solid var(--red); }
.po-tile-photo { position: relative; aspect-ratio: 4 / 3; background: var(--surface-3); overflow: hidden; }
.po-tile-photo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.po-tile-nophoto { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; }
.po-tile-badge {
  position: absolute; top: 10px; right: 10px; padding: 4px 12px; border-radius: 999px; font-size: 12px;
  font-weight: bold; box-shadow: 0 2px 8px rgba(0,0,0,.25); border: 1px solid rgba(255,255,255,.55);
  max-width: calc(100% - 20px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.po-tile-body { padding: 14px 16px 8px; flex: 1; }
.po-tile-title { font-size: 19px; font-weight: bold; color: var(--ink); word-break: break-word; }
.po-tile-tags { margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px; }
.po-tile-tags .badge { font-size: 10px; }
.po-tile-sub { margin-top: 6px; font-size: 14px; color: var(--muted); }
.po-tile-sub2 { margin-top: 2px; font-size: 13px; color: var(--ink); opacity: .8; word-break: break-all; }
.po-tile .dot { opacity: .6; margin: 0 2px; }
.po-tile-rate { margin-top: 10px; font-size: 14px; color: var(--muted); }
.po-tile-lines { margin-top: 8px; display: grid; gap: 5px; font-size: 13px; }
.po-tile-lines > div { display: flex; justify-content: space-between; gap: 10px; }
.po-tile-lines span:first-child { color: var(--muted); flex: 0 0 auto; }
.po-tile-lines b { text-align: right; font-weight: 600; color: var(--ink); }
.po-late { color: var(--red); }
.po-tile-warn { margin-top: 8px; padding: 5px 8px; border-radius: 6px; background: var(--red-bg); color: var(--red); font-size: 12px; font-weight: bold; }
.po-tile-foot {
  display: flex; justify-content: space-between; gap: 8px; padding: 9px 16px; margin-top: 6px;
  border-top: 1px solid var(--border); font-size: 12px; color: var(--muted);
}
@media (max-width: 600px) { .po-tile-grid { grid-template-columns: 1fr; } }
