/* Portal PL de JETAI. Mobile first: the base styles are the phone, and 720 px up is the desktop (DESIGN.md, Phone screens).
   A phone on its side is wider than 720 px but stays a phone: the desktop rules also ask for a height over 500 px or a
   mouse, the same rule as `phone` in portal.js.
   Every color is a token: dark mode only redefines them. */

:root {
  color-scheme: light dark;
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #1b2430;
  --sub: #5b6676;
  --line: #dde2e9;
  --accent: #0f4c81;
  --accent-ink: #ffffff;
  --accent-soft: #e6eef7;
  --ok: #1e7b45;
  --ok-soft: #e3f4ea;
  --warn: #9a6200;
  --warn-soft: #fdf1dc;
  --danger: #b42318;
  --danger-soft: #fdeceb;
  --muted-soft: #eef0f3;
  --radio: 8px;
  --radio-lg: 14px;
  --chrome: #0f4c81;
  --chrome-ink: #ffffff;
  --viewer-bg: #e9ecf1;
  --overlay: rgba(15, 23, 35, .55);
  --shadow: 0 1px 2px rgba(16, 32, 64, .06), 0 4px 14px rgba(16, 32, 64, .05);
  --shimmer: rgba(255, 255, 255, .65);
  --top-h: 56px;
  --bar-h: 60px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101722;
    --panel: #18212e;
    --ink: #e8edf3;
    --sub: #9aa7b7;
    --line: #2b3746;
    --accent: #6db3f2;
    --accent-ink: #0b1a2a;
    --accent-soft: #1d3147;
    --ok: #5fd08f;
    --ok-soft: #16332a;
    --warn: #eab75a;
    --warn-soft: #3a2c12;
    --danger: #f5877d;
    --danger-soft: #3d1c1a;
    --muted-soft: #222c39;
    --chrome: #18212e;
    --chrome-ink: #e8edf3;
    --viewer-bg: #0b1119;
    --overlay: rgba(0, 0, 0, .65);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shimmer: rgba(255, 255, 255, .06);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  overflow-wrap: anywhere;
}
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
h2 { font-size: 17px; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }
ul { list-style: none; margin: 0; padding: 0; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  width: 24px; height: 24px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.icon--lg { width: 32px; height: 32px; }
.noscript { padding: 24px; text-align: center; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 16px;
  border: 1px solid var(--line); border-radius: var(--radio);
  background: var(--panel); color: var(--ink);
  font-weight: 600; text-decoration: none; cursor: pointer; text-align: center;
}
.btn:disabled { opacity: .45; cursor: default; }
.btn--primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn--ghost { background: none; border-color: transparent; color: var(--accent); }
.btn--danger { color: var(--danger); border-color: var(--danger); }
.btn--block { display: flex; width: 100%; }
.btn--more { margin-top: 12px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none;
  border: 0; border-radius: var(--radio); background: none; color: inherit; cursor: pointer;
}

/* ---------- forms ---------- */
.field { display: grid; gap: 4px; color: var(--sub); font-size: 14px; min-width: 0; }
input, select, textarea {
  width: 100%; min-width: 0; min-height: 44px; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: var(--radio);
  background: var(--panel); color: var(--ink);
  font-size: 16px;      /* iOS zooms the page into anything smaller */
}
input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; padding: 0; flex: none; accent-color: var(--accent); }
textarea { resize: vertical; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; color: var(--ink); font-size: 15px; }
.form { display: grid; gap: 14px; }
.form-error { color: var(--danger); font-size: 14px; }
.form-error:empty { display: none; }
.hint { color: var(--sub); font-size: 13px; }

/* ---------- login ---------- */
.gate {
  position: fixed; inset: 0; z-index: 40; overflow: auto;
  display: grid; place-items: center;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  background: var(--bg);
}
.gate-card {
  width: 100%; max-width: 400px; padding: 24px 20px; display: grid; gap: 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radio-lg); box-shadow: var(--shadow);
}
.gate-card h1 { font-size: 20px; text-align: center; }
.gate-note { color: var(--sub); font-size: 14px; text-align: center; }
.logo-chip { display: inline-grid; place-items: center; padding: 3px 6px; background: #fff; border-radius: 6px; flex: none; }
.logo-chip img { height: 26px; width: auto; }
.logo-chip--large { justify-self: center; padding: 8px 14px; border-radius: 10px; }
.logo-chip--large img { height: 56px; }

/* ---------- frame ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  min-height: calc(var(--top-h) + var(--safe-top));
  padding: var(--safe-top) 12px 0;
  background: var(--chrome); color: var(--chrome-ink);
}
.brand { display: flex; align-items: center; gap: 8px; color: inherit; text-decoration: none; font-weight: 600; flex: none; }
.brand-name, .tabs { display: none; }
.topbar-title { flex: 1; min-width: 0; font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app.is-sub .brand { display: none; }

/* the admin's list of users (Account): who already changed the temporary password */
.users-card { display: grid; gap: 8px; }
.users-title { font-size: 15px; }
.users-summary { color: var(--sub); font-size: 14px; }
.users-list { list-style: none; margin: 0; padding: 0; display: grid; }
.users-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.users-who, .users-state { display: grid; gap: 2px; min-width: 0; }
.users-who small, .users-state small { color: var(--sub); font-size: 12px; overflow-wrap: anywhere; }
.users-state { justify-items: end; text-align: right; }

/* the language button (Edna, 7-nov-2026): the other language in its own words, top right */
.lang-switch { display: flex; gap: 6px; flex: none; }
.lang-switch[hidden] { display: none; }
.lang-switch--gate { justify-self: end; margin: -8px -4px -4px 0; }
.lang-btn {
  min-height: 32px; padding: 4px 10px; border-radius: 999px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  background: transparent; color: inherit; border: 1px solid currentColor; opacity: .85;
}
.lang-btn:hover, .lang-btn:focus-visible { opacity: 1; }
.lang-switch--gate .lang-btn { color: var(--accent); }

.main {
  width: 100%; max-width: 1400px; margin: 0 auto;
  padding: 12px 16px calc(var(--bar-h) + var(--safe-bottom) + 20px);
}
.bottombar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: var(--safe-bottom);
  background: var(--panel); border-top: 1px solid var(--line);
}
.bottom-tab {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--bar-h); color: var(--sub); text-decoration: none; font-size: 12px;
}
.bottom-tab[aria-current="page"] { color: var(--accent); font-weight: 600; }
.badge {
  position: absolute; top: 6px; left: calc(50% + 8px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}

.banner {
  position: sticky; top: 0; z-index: 30;
  padding: calc(8px + var(--safe-top)) 16px 8px;
  background: var(--warn-soft); color: var(--warn);
  font-size: 14px; font-weight: 600; text-align: center;
}
.notice {
  display: flex; align-items: center; gap: 10px;
  max-width: 1400px; margin: 12px auto 0; padding: 0 16px;
}
.notice .alert { flex: 1; }

.toast {
  position: fixed; left: 16px; right: 16px; z-index: 50;
  bottom: calc(var(--bar-h) + var(--safe-bottom) + 12px);
  max-width: 480px; margin: 0 auto; padding: 12px 16px;
  background: var(--ink); color: var(--bg); border-radius: var(--radio); font-size: 15px; text-align: center;
}

/* ---------- pieces ---------- */
.card {
  padding: 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radio-lg); box-shadow: var(--shadow);
}
.section { display: grid; gap: 10px; margin-top: 16px; }
.section-title { font-size: 13px; font-weight: 700; color: var(--sub); text-transform: uppercase; letter-spacing: .04em; }
.pill {
  display: inline-block; padding: 3px 10px; border-radius: 99px;
  background: var(--muted-soft); color: var(--sub); font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
.pill--ok { background: var(--ok-soft); color: var(--ok); }
.pill--warn { background: var(--warn-soft); color: var(--warn); }
.pill--info { background: var(--accent-soft); color: var(--accent); }
.pill--danger { background: var(--danger-soft); color: var(--danger); }
.alert { padding: 12px 14px; border-radius: var(--radio); font-size: 15px; display: grid; gap: 8px; justify-items: start; }
.alert--warn { background: var(--warn-soft); color: var(--warn); }
.alert--info { background: var(--accent-soft); color: var(--accent); }
.alert--danger { background: var(--danger-soft); color: var(--danger); }
.alert--ok { background: var(--ok-soft); color: var(--ok); }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; margin: 0; }
.facts div { min-width: 0; }
.facts .wide { grid-column: 1 / -1; }
.facts dt { color: var(--sub); font-size: 13px; }
.facts dd { margin: 0; font-weight: 600; }

/* ---------- filters ---------- */
.filters { display: grid; gap: 10px; }
.searchbox {
  display: flex; align-items: center; gap: 8px; min-height: 46px; padding: 0 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radio-lg); color: var(--sub);
}
.searchbox input { border: 0; background: none; padding: 8px 0; min-height: 44px; }
.searchbox input:focus-visible { outline: none; }
.searchbox:focus-within { border-color: var(--accent); }
.chips { display: flex; align-items: center; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-height: 44px; padding: 6px 14px;
  border: 1px solid var(--line); border-radius: 99px; background: var(--panel); color: var(--ink);
  font-size: 14px; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chip[aria-expanded="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip-note { color: var(--sub); font-size: 13px; white-space: nowrap; }
.filter-panel { display: none; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.filter-panel.is-open { display: grid; }

.listbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 12px 2px 8px; }
.summary { color: var(--sub); font-size: 14px; }
.bulk { display: none; }

/* ---------- lists: cards on a phone, a table from 720 px up ---------- */
.table { width: 100%; border-collapse: collapse; display: block; }
.table thead { display: none; }
.table tbody { display: grid; gap: 10px; }
.table tr {
  position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; padding: 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radio-lg); box-shadow: var(--shadow);
}
.table td { display: block; padding: 0; min-width: 0; }
.table td:empty { display: none; }
.c-check, .c-actions { display: none !important; }
.c-client { grid-area: 1 / 1; color: var(--sub); font-size: 13px; }
.c-title { grid-area: 2 / 1; font-size: 18px; font-weight: 700; line-height: 1.25; }
.c-seal { grid-area: 1 / 2 / span 2; justify-self: end; }
.c-date { grid-area: 3 / 1; margin-top: 4px; color: var(--sub); font-size: 14px; }
.c-pieces { grid-area: 3 / 2; margin-top: 4px; color: var(--sub); font-size: 14px; justify-self: end; }
.c-unit { grid-column: 1 / -1; font-size: 14px; }
.c-po { grid-column: 1 / -1; color: var(--sub); font-size: 13px; }
.c-pieces::after { content: " " attr(data-unit); }
.row-link { color: inherit; text-decoration: none; }
.row-link::after { content: ""; position: absolute; inset: 0; border-radius: var(--radio-lg); }
.row-link:focus-visible { outline: none; }
.row-link:focus-visible::after { outline: 3px solid var(--accent); outline-offset: 2px; }
.pl-tag { display: inline-block; margin-left: 6px; }
tr.is-retired { opacity: .6; }

.table--docs tr { grid-template-columns: 40px minmax(0, 1fr) auto; }
.c-icon { grid-area: 1 / 1 / span 3; color: var(--accent); }
.table--docs .c-title { grid-area: 1 / 2 / auto / span 2; font-size: 16px; font-weight: 600; }
.c-type { grid-area: 2 / 2; font-size: 14px; color: var(--sub); }
.table--docs .c-date { grid-area: 2 / 3; margin-top: 0; justify-self: end; font-size: 13px; }
.c-client2 { grid-area: 3 / 2 / auto / span 2; font-size: 14px; }

/* ---------- states ---------- */
.state { display: grid; justify-items: center; gap: 6px; padding: 32px 16px; text-align: center; color: var(--sub); }
.state-icon { width: 40px; height: 40px; }
.state-title { color: var(--ink); font-weight: 600; font-size: 17px; }
.state .btn { margin-top: 8px; }
.skeleton { display: grid; gap: 10px; }
.skeleton-card {
  position: relative; height: 92px; overflow: hidden;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radio-lg);
}
.skeleton-card::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, var(--shimmer), transparent);
  transform: translateX(-100%); animation: shimmer 1.3s infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }
.spinner {
  width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .skeleton-card::after, .spinner { animation: none; }
}

/* ---------- PL file ---------- */
.file-head { display: grid; gap: 12px; }
.file-head-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.file-client { color: var(--sub); font-size: 14px; }
.file-label { font-size: 24px; font-weight: 700; line-height: 1.2; }
.doc-rows { display: grid; }
.doc-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.doc-row:first-child { border-top: 0; padding-top: 0; }
.doc-row:last-child { padding-bottom: 0; }
.doc-row-icon { color: var(--accent); flex: none; }
.doc-row-text { flex: 1; min-width: 0; display: grid; gap: 1px; }
.doc-row-title { font-weight: 600; }
.doc-row-title a { color: inherit; text-decoration: none; }
.doc-row-sub { color: var(--sub); font-size: 13px; }
.doc-row-actions { display: flex; gap: 6px; flex: none; }
.doc-row .alert { margin-top: 6px; }
.checklist { display: grid; gap: 10px; }
.checklist li { display: flex; gap: 10px; align-items: flex-start; }
.checklist .icon { width: 22px; height: 22px; margin-top: 1px; }
.is-ok { color: var(--ok); }
.is-check { color: var(--warn); }
.is-missing { color: var(--danger); }
.checklist small { display: block; color: var(--sub); font-size: 13px; }
.sticky-action {
  position: sticky; z-index: 5; display: grid; gap: 4px; margin-top: 14px; padding: 8px 0;
  bottom: calc(var(--bar-h) + var(--safe-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}

/* ---------- upload ---------- */
.pickers { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.picker {
  position: relative; display: grid; justify-items: center; gap: 6px; padding: 18px 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radio-lg); box-shadow: var(--shadow);
  color: var(--accent); font-weight: 600; text-align: center; cursor: pointer; min-height: 96px;
}
.picker--camera { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.picker:focus-within { outline: 3px solid var(--accent); outline-offset: 2px; }
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.upload-hint { margin: 10px 2px 0; color: var(--sub); font-size: 13px; }
.queue { display: grid; gap: 8px; margin-top: 12px; }
.queue:empty { display: none; }
.queue-item {
  display: grid; grid-template-columns: 48px minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; padding: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radio-lg);
}
.queue-thumb {
  grid-row: 1 / span 2; width: 48px; height: 48px; display: grid; place-items: center; overflow: hidden;
  background: var(--muted-soft); border-radius: var(--radio); color: var(--sub);
}
.queue-thumb img { width: 100%; height: 100%; object-fit: cover; }
.queue-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.queue-status { grid-column: 2; font-size: 13px; color: var(--sub); }
.queue-status.is-ok { color: var(--ok); }
.queue-status.is-error { color: var(--danger); }
.queue-status.is-warn { color: var(--warn); }
.queue-actions { grid-column: 3; grid-row: 1 / span 2; display: flex; }
.queue-progress { grid-column: 1 / -1; width: 100%; height: 6px; accent-color: var(--accent); }
.queue-pls { display: block; color: var(--sub); font-size: 13px; }
#upload-form { margin-top: 12px; }

.pl-picker { display: grid; gap: 8px; position: relative; }
.pl-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.pl-chip {
  display: inline-flex; align-items: center; gap: 2px; padding-left: 12px;
  background: var(--accent-soft); color: var(--accent); border-radius: 99px; font-weight: 600; font-size: 14px;
}
.pl-chip button { width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: none; color: inherit; cursor: pointer; }
.pl-chip .icon { width: 16px; height: 16px; }
.pl-results { display: grid; border: 1px solid var(--line); border-radius: var(--radio); overflow: hidden; background: var(--panel); }
.pl-results:empty { display: none; }
.pl-result {
  display: flex; justify-content: space-between; gap: 12px; min-height: 44px; padding: 8px 12px; width: 100%;
  border: 0; border-top: 1px solid var(--line); background: none; color: var(--ink); text-align: left; cursor: pointer;
}
.pl-result:first-child { border-top: 0; }
.pl-result small { color: var(--sub); }
.pl-empty { padding: 10px 12px; color: var(--sub); font-size: 14px; }

/* ---------- document ---------- */
.doc-title { font-size: 19px; font-weight: 700; line-height: 1.25; }
.doc-head { display: grid; gap: 10px; }
.doc-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.history { display: grid; gap: 8px; font-size: 14px; }
.history small { display: block; color: var(--sub); font-size: 12.5px; }
.pl-links { display: flex; flex-wrap: wrap; gap: 6px; }
.pl-links a { display: inline-flex; align-items: center; min-height: 44px; padding: 6px 12px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-weight: 600; text-decoration: none; }
.erp-parts { display: grid; gap: 6px; font-size: 14px; }

/* ---------- account ---------- */
.account-name { font-size: 20px; font-weight: 700; }
.account-actions { display: grid; gap: 8px; }

/* BOM (portal_parts) */
.bom-filters { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.bom-list { display: grid; gap: 8px; }
.part-row { position: relative; display: grid; gap: 4px; }
.part-row-title { font-weight: 700; }
.part-row-sub { color: var(--sub); font-size: 13px; overflow-wrap: anywhere; }
.part-row-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.part-upload { display: grid; gap: 10px; }
.part-file-current { font-weight: 600; }

/* ---------- viewer. On a phone it is the page itself, so pinching zooms as in any page ---------- */
.viewer { min-height: 100vh; min-height: 100dvh; background: var(--viewer-bg); }
body.is-viewing .app { display: none; }
.viewer-bar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
  padding: var(--safe-top) 8px 6px;
  background: var(--chrome); color: var(--chrome-ink);
}
.viewer-title { flex: 1; min-width: 0; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-actions { display: flex; gap: 6px; flex-basis: 100%; }
.viewer-actions .btn { flex: 1; min-height: 44px; padding: 6px 8px; font-size: 14px; }
.viewer-body { display: grid; gap: 10px; padding: 10px 8px calc(16px + var(--safe-bottom)); justify-items: center; }
.viewer-page { position: relative; width: 100%; max-width: 1400px; aspect-ratio: 8.5 / 11; background: var(--panel); border-radius: 4px; overflow: hidden; }
.viewer-page.is-loaded { aspect-ratio: auto; }
.viewer-page img { width: 100%; height: auto; }
.viewer-page-no {
  position: absolute; top: 6px; right: 6px; padding: 1px 8px; border-radius: 99px;
  background: var(--overlay); color: #fff; font-size: 12px;
}
.viewer-page-error { width: 100%; padding: 32px 16px; display: grid; justify-items: center; gap: 8px; color: var(--sub); text-align: center; }
.viewer-message { display: grid; justify-items: center; gap: 12px; padding: 48px 16px; text-align: center; color: var(--sub); max-width: 460px; }
.viewer-frame { width: 100%; height: 100%; border: 0; display: block; background: #fff; }
.viewer-photo { max-width: 100%; height: auto; }

/* ---------- sheet ---------- */
.sheet {
  width: 100%; max-width: none; margin: auto 0 0; padding: 20px 16px calc(16px + var(--safe-bottom));
  border: 0; border-radius: var(--radio-lg) var(--radio-lg) 0 0;
  background: var(--panel); color: var(--ink);
}
.sheet::backdrop { background: var(--overlay); }
.sheet form { display: grid; gap: 12px; }
.sheet-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }

/* a small window: the table gives up what the PL file already shows, so the page never scrolls sideways. 1100 and not
   1000: with the PL column at its 150 px, all nine columns need about 1080 px (measured at 1024 px: 38 px sideways) */
@media (min-width: 720px) and (max-width: 1100px) and (min-height: 500.02px), (min-width: 720px) and (max-width: 1100px) and (pointer: fine),
       (min-width: 720px) and (max-width: 1100px) and (pointer: none) {
  .c-po, .c-pieces { display: none !important; }
  .table--docs .c-client2 { display: none !important; }
  .table--docs .c-title { min-width: 180px; }
}

/* ---------- desktop ---------- */
@media (min-width: 720px) and (min-height: 500.02px), (min-width: 720px) and (pointer: fine), (min-width: 720px) and (pointer: none) {
  body { font-size: 14px; }
  input, select, textarea { min-height: 36px; padding: 6px 9px; font-size: 14px; }
  .btn { min-height: 36px; padding: 6px 12px; }
  .icon-btn { width: 36px; height: 36px; }
  .field { font-size: 12px; }

  .topbar { gap: 16px; padding: 8px 16px; min-height: 52px; background: var(--panel); color: var(--ink); border-bottom: 1px solid var(--line); }
  .app.is-sub .brand { display: flex; }
  .logo-chip img { height: 30px; }
  .brand-name { display: inline; }
  .topbar-title { display: none; }
  .tabs { display: flex; gap: 4px; flex: 1; }
  .topbar .lang-switch { order: 1; }      /* after the tabs, at the right end */
  .tab { padding: 8px 12px; border-radius: 6px; color: var(--sub); text-decoration: none; }
  .tab[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
  .bottombar { display: none; }
  .main { padding: 16px; }
  .banner { padding: 8px 16px; }
  .toast { bottom: 24px; }

  .chips { margin: 0; padding: 0; overflow: visible; flex-wrap: wrap; }
  .chip { min-height: 32px; padding: 4px 12px; font-size: 13px; }
  .chip--more { display: none; }
  .filters { grid-template-columns: minmax(240px, 1fr) auto; align-items: center; padding: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radio); }
  .filter-panel, .filter-panel.is-open { display: flex; grid-column: 1 / -1; flex-wrap: wrap; align-items: end; }
  .filter-panel .field { flex: 0 1 170px; }
  .searchbox { min-height: 36px; border-radius: var(--radio); }
  .searchbox input { min-height: 34px; padding: 4px 0; }
  .searchbox .icon { width: 18px; height: 18px; }

  .bulk { display: flex; align-items: center; gap: 8px; }
  .bulk select { width: auto; }
  .bulk-count { color: var(--sub); white-space: nowrap; }

  .table { display: table; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radio); }
  .table thead { display: table-header-group; }
  .table tbody { display: table-row-group; }
  .table tr { display: table-row; padding: 0; background: none; border: 0; border-radius: 0; box-shadow: none; }
  .table th, .table td { display: table-cell; padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
  .table th {
    position: sticky; top: 52px; z-index: 1;
    background: var(--muted-soft); color: var(--sub); font-size: 12px; font-weight: 600; white-space: nowrap;
  }
  .table tbody tr:hover { background: var(--muted-soft); }
  .table td:empty { display: table-cell; }
  .c-check, .c-actions { display: table-cell !important; }
  .c-check { width: 36px; }
  .c-check input { width: 18px; height: 18px; }
  .c-client, .c-type, .c-unit, .c-po, .c-date, .c-pieces, .c-client2 { color: var(--ink); font-size: 14px; margin: 0; }
  /* .table, not just .c-title: the phone's ".table td { min-width: 0 }" outranks a single class, and at 1024 px the PL
     column then shrank to 61 px and broke "TCL MOKA" in the middle of the word */
  .table .c-title { font-size: 14px; min-width: 150px; }
  .table--docs .c-title { min-width: 240px; }
  .c-client, .c-type { overflow-wrap: normal; }
  .c-date { white-space: nowrap; }
  .c-pieces { text-align: right; font-variant-numeric: tabular-nums; }
  .c-pieces::after { content: none; }
  .c-unit, .c-po { color: var(--sub); font-size: 13px; }
  .c-po { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .c-actions { text-align: right; white-space: nowrap; }
  .c-actions .btn { min-height: 30px; padding: 3px 10px; font-size: 13px; position: relative; z-index: 1; }
  .c-actions .btn + .btn { margin-left: 4px; }
  .c-icon { width: 34px; }
  .table--docs .c-title { font-size: 14px; }
  .table--docs .c-date { font-size: 14px; }
  .row-link { color: var(--accent); }
  .row-link::after { content: none; }

  .skeleton-card { height: 44px; border-radius: var(--radio); }

  .view--narrow { max-width: 760px; margin: 0 auto; }
  .filters + .listbar { flex-wrap: wrap; }
  .pickers { grid-template-columns: minmax(0, 1fr); max-width: 760px; margin: 0 auto; }
  .picker--camera { display: none; }
  .picker { padding: 28px 16px; border-style: dashed; box-shadow: none; }
  .picker.is-over { background: var(--accent-soft); border-color: var(--accent); }
  .upload-hint, #upload-empty, #upload-alert, .queue, #upload-form, #upload-actions { max-width: 760px; margin-left: auto; margin-right: auto; }
  .sticky-action { position: static; background: none; }
  .form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form h2, .form .wide { grid-column: 1 / -1; }
  .pl-chip button { width: 32px; height: 32px; }
  .pl-links a { min-height: 32px; }

  .doc-actions, .account-actions { display: flex; flex-wrap: wrap; }
  .facts { grid-template-columns: repeat(4, minmax(0, 1fr)); }

  /* the viewer goes back to being a window over the page, with the PDF in an iframe */
  body.is-viewing .app { display: block; }
  .viewer {
    position: fixed; inset: 0; z-index: 20; min-height: 0; padding: 16px;
    display: grid; place-items: center; background: var(--overlay);
  }
  .viewer-window {
    width: min(1100px, 100%); height: min(92vh, 1200px);
    display: grid; grid-template-rows: auto minmax(0, 1fr); overflow: hidden;
    background: var(--panel); border-radius: var(--radio);
  }
  .viewer-bar { position: static; flex-wrap: nowrap; padding: 8px 12px; background: var(--panel); color: var(--ink); border-bottom: 1px solid var(--line); }
  .viewer-actions { flex-basis: auto; }
  .viewer-actions .btn { flex: none; min-height: 32px; padding: 4px 12px; font-size: 13px; }
  .viewer-body { display: block; height: 100%; padding: 0; overflow: auto; background: var(--viewer-bg); }
  .viewer-message { margin: 0 auto; }

  .sheet { width: 440px; max-width: calc(100vw - 32px); margin: auto; border-radius: var(--radio-lg); padding: 20px; }
}
