/* Inter (SIL OFL 1.1, see /inter-LICENSE.txt): full Vietnamese tone marks, clear digits on small phone screens.
   Self-hosted (CSP allows fonts from this site only), subset to Latin + Vietnamese. */
@font-face { font-family: "Inter"; font-style: normal; font-weight: 400; font-display: swap; src: url("/inter-regular.woff") format("woff"); }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 600; font-display: swap; src: url("/inter-semibold.woff") format("woff"); }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 700; font-display: swap; src: url("/inter-bold.woff") format("woff"); }
:root {
  --bg: #f6f4f0; --surface: #ffffff; --text: #26221d; --muted: #6f675d;
  --primary: #60361e; --primary-text: #ffffff; --border: #ddd6cb;
  --ok: #2e7d4f; --warn: #b26a00; --error: #b3261e;
  --space: 12px; --radius: 8px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 16px;
  color: var(--text); background: var(--bg); }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: var(--space);
  padding: 8px var(--space); background: var(--primary); color: var(--primary-text); }
.app-title { flex: 1; min-width: 0; margin: 0; font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-badge { font-size: 13px; opacity: .9; max-width: 34%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { min-width: 44px; min-height: 44px; border: 0; background: transparent; color: inherit; font-size: 22px; }
.sidebar { position: fixed; top: 60px; bottom: 0; left: 0; width: 240px; overflow-y: auto; background: var(--surface);
  border-right: 1px solid var(--border); transform: translateX(-100%); transition: transform .15s; z-index: 9; }
.sidebar.open { transform: none; }
.sidebar a { display: block; min-height: 44px; padding: 12px 16px; color: var(--text); text-decoration: none;
  border-bottom: 1px solid var(--border); }
.sidebar a.active { background: var(--bg); font-weight: 600; border-left: 4px solid var(--primary); }
.sidebar a.highlight { color: var(--primary); font-weight: 600; }
.main { padding: var(--space); }
.view h2 { margin: 4px 0 12px; font-size: 20px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.muted { color: var(--muted); }
.notice { margin-bottom: var(--space); padding: 10px 12px; border-radius: var(--radius); background: #fdecea;
  color: var(--error); }
.notice.info { background: #e8f1ea; color: var(--ok); }
.loading { position: fixed; right: 12px; bottom: 12px; padding: 8px 12px; border-radius: var(--radius);
  background: var(--text); color: #fff; font-size: 14px; }
.footer { padding: 16px var(--space); color: var(--muted); font-size: 12px; }
button.primary { min-height: 44px; padding: 0 16px; border: 0; border-radius: var(--radius);
  background: var(--primary); color: var(--primary-text); font-size: 16px; }
button[disabled] { opacity: .5; }
@media (min-width: 900px) {
  .sidebar { transform: none; }
  .main, .footer { margin-left: 240px; }
  #menuToggle { display: none; }
}
.link-btn { border: 0; background: transparent; color: inherit; text-decoration: underline; min-height: 44px; font-size: 14px; }
.card { margin-bottom: var(--space); }
.card h3 { margin: 0 0 10px; font-size: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
label.field input, label.field select, label.field textarea { min-height: 44px; padding: 8px 10px; font-size: 16px;
  border: 1px solid var(--border); border-radius: var(--radius); background: #fff; color: var(--text); width: 100%; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
button.secondary { min-height: 44px; padding: 0 14px; border: 1px solid var(--primary); border-radius: var(--radius);
  background: #fff; color: var(--primary); font-size: 15px; }
button.danger { min-height: 44px; padding: 0 14px; border: 1px solid var(--error); border-radius: var(--radius);
  background: #fff; color: var(--error); font-size: 15px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 6px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: #eee7dc; color: var(--text); white-space: nowrap; }
.badge.FIRING, .badge.COOLING { background: #fde8d0; color: var(--warn); }
.badge.AWAITING_QC, .badge.UNLOADED { background: #e3ecf8; color: #23508c; }
.badge.CLOSED, .badge.COMPLETED { background: #e8f1ea; color: var(--ok); }
.badge.CANCELLED, .badge.INACTIVE { background: #fdecea; color: var(--error); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: var(--space); }
.chip { flex: 1 1 110px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px; }
.chip b { display: block; font-size: 22px; }
.chip span { font-size: 12px; color: var(--muted); }
.batch-card { display: block; color: inherit; text-decoration: none; }
.batch-card .row { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; font-size: 14px; }
.kv div { min-width: 0; overflow-wrap: anywhere; }
.kv div span { display: block; color: var(--muted); font-size: 12px; }
.login-overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 16px; }
.login-overlay[hidden] { display: none; }
.login-card { max-width: 360px; width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; text-align: center; }
.login-card h1 { font-size: 20px; margin: 0 0 8px; }
ul.history { margin: 0; padding-left: 18px; font-size: 13px; color: var(--muted); }
.order-line { padding: 8px 0; border-bottom: 1px dashed var(--border); align-items: end; }
.badge.READY_TO_SHIP { background: #e8f1ea; color: var(--ok); }
.badge.IN_PRODUCTION { background: #fde8d0; color: var(--warn); }
.badge.PLANNED, .badge.CONFIRMED { background: #e3ecf8; color: #23508c; }

/* Phones: every table row becomes a small card with "label: value" lines, so nothing scrolls sideways. */
@media (max-width: 640px) {
  .table-wrap { overflow: visible; }
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tr { border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 10px; margin-bottom: 8px; background: #fffdf9; }
  .table-wrap td { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border-bottom: 1px dotted var(--border); text-align: right; }
  .table-wrap td:last-child { border-bottom: 0; }
  .table-wrap td::before { content: attr(data-label); color: var(--muted); text-align: left; flex: 0 0 42%; }
  .table-wrap td:not([data-label])::before { content: none; }
  .table-wrap td:first-child { font-weight: 600; }
}

a.button-link { display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; border-radius: var(--radius);
  background: var(--primary); color: var(--primary-text); text-decoration: none; font-size: 16px; }
.badge.ship-DISPATCHED, .badge.ship-IN_TRANSIT, .badge.PARTIALLY_SHIPPED { background: #fde8d0; color: var(--warn); }
.badge.ship-DELIVERED_REPORTED, .badge.SHIPPED, .badge.ship-READY { background: #e8f1ea; color: var(--ok); }
.badge.ship-FAILED, .badge.ship-CANCELLED { background: #fdecea; color: var(--error); }
@media print {
  .topbar, .sidebar, .footer, .no-print, .demo-bar, form, #notice, .loading { display: none !important; }
  .main { margin: 0 !important; padding: 0; }
  .card { border: 0; padding: 0 0 12px; }
  body { background: #fff; padding: 0 !important; }
}

details > summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; }
@media (max-width: 640px) { .table-wrap td.empty-action { display: none; } }

/* ===== Phones and tablets (v0.4.1) ===== */
html { -webkit-text-size-adjust: 100%; }
body { overscroll-behavior-y: contain; }
a, button, summary, select { -webkit-tap-highlight-color: rgba(138, 75, 42, .15); touch-action: manipulation; }
.topbar { padding-top: calc(8px + env(safe-area-inset-top)); padding-left: calc(var(--space) + env(safe-area-inset-left));
  padding-right: calc(var(--space) + env(safe-area-inset-right)); }
.main { padding-left: calc(var(--space) + env(safe-area-inset-left)); padding-right: calc(var(--space) + env(safe-area-inset-right)); }

/* Side menu: dimmed backdrop, user box with sign-out. */
.backdrop { position: fixed; inset: 0; z-index: 8; background: rgba(38, 34, 29, .45); }
.backdrop[hidden] { display: none; }
body.menu-open { overflow: hidden; }
.menu-user { display: none; padding: 14px 16px; border-bottom: 1px solid var(--border); background: var(--bg); }
.menu-user strong { display: block; }
.menu-user span { display: block; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; margin: 2px 0 10px; }

/* Folding entry forms. */
details.fold > summary { list-style: none; min-height: 0; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary h3 { margin: 0; }
details.fold > summary::after { content: '+'; flex: 0 0 auto; width: 32px; height: 32px; border-radius: 50%; display: inline-flex;
  align-items: center; justify-content: center; background: var(--primary); color: #fff; font-size: 22px; line-height: 1; }
details.fold[open] > summary { margin-bottom: 10px; }
details.fold[open] > summary::after { content: '−'; background: var(--bg); color: var(--primary); }

/* Dashboard figures. */
.kv.stats div { font-size: 20px; font-weight: 700; }
.kv.stats div span { font-size: 12px; font-weight: 400; }

/* Bottom tab bar: phones only. */
.tabbar { display: none; }

@media (max-width: 640px) {
  :root { --space: 10px; }
  .app-title { font-size: 16px; }
  .user-badge { max-width: 38%; font-size: 12px; }
  #signOut { display: none; }
  #menuToggle { display: none; }
  .menu-user { display: block; }
  .sidebar { top: 0; width: 82%; max-width: 320px; z-index: 30; box-shadow: 0 0 24px rgba(0,0,0,.2);
    padding-top: env(safe-area-inset-top); padding-bottom: calc(70px + env(safe-area-inset-bottom)); }
  .backdrop { z-index: 29; }
  .view h2 { font-size: 19px; margin: 2px 0 10px; }
  .card { padding: 12px; }
  .footer { padding-bottom: calc(80px + env(safe-area-inset-bottom)); text-align: center; }

  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--surface);
    border-top: 1px solid var(--border); box-shadow: 0 -2px 10px rgba(0,0,0,.06);
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
  .tabbar a, .tabbar button { flex: 1 1 0; min-width: 0; min-height: 56px; display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 2px; padding: 4px 2px; border: 0; background: transparent; color: var(--muted);
    text-decoration: none; font: inherit; font-size: 11px; }
  .tabbar .tab-icon { font-size: 20px; line-height: 1; }
  .tabbar .active { color: var(--primary); font-weight: 700; }
  .tabbar .active .tab-icon { transform: scale(1.1); }
  .loading { bottom: calc(68px + env(safe-area-inset-bottom)); left: 50%; right: auto; transform: translateX(-50%); }

  /* KPI tiles: one swipeable row instead of a tall wall. */
  .chips { flex-wrap: nowrap; overflow-x: auto; scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch;
    margin: 0 calc(-1 * var(--space)) var(--space); padding: 0 var(--space) 4px; scrollbar-width: none; }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex: 0 0 auto; min-width: 104px; max-width: 150px; padding: 8px 10px; scroll-snap-align: start; }
  .chip b { font-size: 20px; }

  /* Forms: one column, big full-width buttons. */
  .grid { grid-template-columns: 1fr; }
  /* Number boxes (QC, unloading, quantities) sit two per row; everything else keeps the full width. */
  @supports selector(:has(*)) {
    .grid { grid-template-columns: 1fr 1fr; }
    .grid > * { grid-column: 1 / -1; }
    .grid > label.field:has(> input[type="number"]) { grid-column: auto; }
  }
  .kv { grid-template-columns: 1fr 1fr; }
  .actions > button, .actions > a.button-link { flex: 1 1 140px; justify-content: center; }
  form > .actions > button.primary { flex-basis: 100%; }
  label.field input, label.field select, label.field textarea { min-height: 48px; }
  input[type="date"], input[type="datetime-local"] { -webkit-appearance: none; appearance: none; }

  /* List cards. */
  .batch-card .row { align-items: flex-start; }
  .batch-card .row strong { min-width: 0; overflow-wrap: anywhere; }
  .notice { position: sticky; top: calc(60px + env(safe-area-inset-top)); z-index: 5; }
}
@media (min-width: 641px) and (max-width: 899px) {
  .sidebar { z-index: 30; top: 0; }
  .backdrop { z-index: 29; }
}
@media print { .tabbar, .backdrop { display: none !important; } }

/* ===== Phiếu ra lò ===== */
a.button-link.secondary-link { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
.actions a.button-link { flex: 0 1 auto; }
.kiln-form h4 { margin: 18px 0 8px; font-size: 15px; color: var(--primary); }
.kiln-form small.muted { font-size: 12px; }
.kiln-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.kiln-group-row { display: grid; grid-template-columns: 1fr 96px; gap: 8px; align-items: center;
  padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius); background: #fffdf9; }
.kiln-group-row input { min-height: 44px; padding: 6px 8px; font-size: 16px; border: 1px solid var(--border); border-radius: var(--radius); width: 100%; }
.kiln-defect-row { display: grid; grid-template-columns: 1.2fr 1.6fr 90px 1fr 1.4fr auto; gap: 8px; align-items: end;
  padding: 8px 0; border-bottom: 1px dashed var(--border); }
.kiln-defect-row select, .kiln-defect-row input { min-height: 44px; padding: 6px 8px; font-size: 16px; border: 1px solid var(--border);
  border-radius: var(--radius); background: #fff; width: 100%; }
.kiln-summary { position: sticky; bottom: 0; margin-top: 12px; padding: 10px 12px; border-radius: var(--radius);
  background: #f3ece2; border: 1px solid var(--border); z-index: 2; }
.error-text { color: var(--error); font-weight: 600; margin-top: 4px; }
.chip.chip-alert { border-color: var(--error); }
.chip.chip-alert b { color: var(--error); }
.inline { display: flex; gap: 6px; align-items: center; }
.inline input { flex: 1; min-width: 0; }
button.small { min-height: 40px; padding: 0 10px; font-size: 14px; }
.print-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; font-size: 13px; }
.print-table th, .print-table td { border: 1px solid #555; padding: 6px; height: 30px; text-align: left; vertical-align: top; }
.print-table tr.tall td { height: 44px; }
@media (max-width: 640px) {
  .kiln-defect-row { grid-template-columns: 1fr 1fr; padding: 10px; margin-bottom: 8px; border: 1px solid var(--border);
    border-radius: var(--radius); background: #fffdf9; }
  .kiln-defect-row .field.wide { grid-column: 1 / -1; }
  .kiln-defect-row > button { grid-column: 1 / -1; }
  .kiln-groups { grid-template-columns: 1fr; }
  .kiln-summary { bottom: calc(64px + env(safe-area-inset-bottom)); }
  .print-sheet { overflow-x: auto; }
}
@media print {
  .print-sheet { font-size: 12px; }
  .view h2 { font-size: 18px; }
}
.fresh-bar { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 40;
  min-height: 44px; padding: 0 16px; border: 0; border-radius: 999px; background: var(--text); color: #fff; font-size: 14px;
  box-shadow: 0 4px 14px rgba(0,0,0,.25); }
@media (min-width: 641px) { .fresh-bar { bottom: 20px; } }

/* Long lists (product catalogue): a search box in front of the select. */
.select-wrap { display: flex; flex-direction: column; gap: 6px; }
input.select-search { width: 100%; min-height: 44px; padding: 8px 10px; font-size: 16px; border: 1px solid #c9c2b8;
  border-radius: 8px; box-sizing: border-box; margin-bottom: 8px; }
.select-wrap input.select-search { margin-bottom: 0; }

/* Logo Gốm Bụt (kem trên nền nâu thương hiệu #60361e). */
.brand { display: inline-flex; align-items: center; flex: none; line-height: 0; }
.brand img { height: 32px; width: auto; display: block; }
.login-logo { background: #60361e; border-radius: var(--radius); padding: 18px 0 14px; margin: -4px 0 12px;
  display: flex; justify-content: center; }
.login-logo img { height: 120px; width: auto; display: block; }

/* Form controls do not inherit the page font by default. */
input, select, textarea, button { font-family: inherit; }

/* Numbers line up in tables and counters (Inter tabular figures). */
td, .chip b, .kv .stats div, .kiln-summary { font-variant-numeric: tabular-nums; }

/* Ảnh mẫu đơn hàng */
.image-group { border-top: 1px solid var(--border); padding: 10px 0; }
.image-group:first-child { border-top: 0; }
.image-group .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; margin: 10px 0; }
.thumb { margin: 0; display: flex; flex-direction: column; gap: 4px; }
.thumb-open { padding: 0; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; overflow: hidden;
  aspect-ratio: 1 / 1; display: flex; align-items: center; justify-content: center; cursor: zoom-in; }
.thumb-open img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb figcaption { font-size: 12px; color: var(--muted); }
.warn-badge { background: #fff3e0; color: #8a4b00; border: 1px solid #f0c48a; }
.image-viewer { position: fixed; inset: 0; z-index: 60; background: rgba(20, 14, 10, 0.92); display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 12px; color: #fff; cursor: zoom-out; }
.image-viewer img { max-width: 100%; max-height: calc(100vh - 80px); object-fit: contain; border-radius: 6px; }
.image-viewer p { color: #eee; font-size: 13px; text-align: center; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
