:root {
  --bg: #eef2f7; --card: #fff; --ink: #0f172a; --muted: #64748b; --line: #dbe2ea;
  --pri: #1e3a8a; --pri-ink: #fff; --acc: #2563eb; --danger: #b91c1c; --warn-bg: #fff7e6; --warn-line: #f5c26b; --ok: #15803d;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220; --card: #141c2e; --ink: #e2e8f0; --muted: #94a3b8; --line: #263247;
    --pri: #3b5bdb; --acc: #60a5fa; --danger: #f87171; --warn-bg: #2a2110; --warn-line: #8a6a2a; --ok: #4ade80;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1220; --card: #141c2e; --ink: #e2e8f0; --muted: #94a3b8; --line: #263247;
  --pri: #3b5bdb; --acc: #60a5fa; --danger: #f87171; --warn-bg: #2a2110; --warn-line: #8a6a2a; --ok: #4ade80;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
a { color: var(--acc); }
h1, h2 { margin: 0; }
h2 { font-size: 15px; margin-bottom: 10px; }

.bar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 8px; padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top)); background: var(--pri); color: var(--pri-ink); }
.bar h1 { font-size: 17px; flex: 1; min-width: 0; }
.bar h1 small { display: block; font-size: 12px; font-weight: 400; opacity: .8; }
.ellip { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { color: inherit; text-decoration: none; font-size: 24px; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 8px; }
.icon-btn:active { background: rgba(255, 255, 255, .15); }

.tabs { position: sticky; top: calc(56px + env(safe-area-inset-top)); z-index: 9; display: flex; overflow-x: auto; background: var(--card); border-bottom: 1px solid var(--line); scrollbar-width: none; }
.tabs a { flex: 1 0 auto; padding: 11px 14px; text-align: center; text-decoration: none; color: var(--muted); font-weight: 600; font-size: 14px; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--acc); border-bottom-color: var(--acc); }

.wrap { max-width: 760px; margin: 0 auto; padding: 12px 16px 80px; }
.wrap[data-tab="docs"] { max-width: 1100px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card.warn { background: var(--warn-bg); border-color: var(--warn-line); }
details.card summary { list-style: none; cursor: pointer; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
details.card summary::-webkit-details-marker { display: none; }
details.card summary h2 { margin: 0; }
details.card summary::after { content: '▾'; margin-left: auto; color: var(--muted); }
details.card[open] summary { margin-bottom: 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.hint { color: var(--muted); font-size: 12.5px; margin: 8px 0 0; }
.ok { color: var(--ok); font-weight: 600; }
.mb { margin-bottom: 8px; }
.mt { margin-top: 12px; }
.row { display: flex; align-items: center; }
.gap { gap: 8px; }
.wrapr { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 420px) { .grid2 { gap: 8px; } }
.f { display: flex; flex-direction: column; gap: 3px; min-width: 0; margin-bottom: 8px; }
.grid2 .f { margin-bottom: 0; }
.f > span { font-size: 12px; color: var(--muted); font-weight: 600; }
.f > b { padding: 9px 0; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 9px 10px; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--acc); outline-offset: -1px; background: var(--card); }
input[type="date"], input[type="time"] { min-height: 40px; }
.search { margin: 10px 0 4px; }

.btn { font: inherit; font-weight: 600; border: 1px solid transparent; border-radius: 10px; padding: 10px 14px; cursor: pointer; background: var(--line); color: var(--ink); display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn.primary { background: var(--pri); color: #fff; }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.tiny { padding: 3px 8px; font-size: 13px; }
.btn:disabled { opacity: .35; }
.btn:active:not(:disabled) { transform: scale(.97); }
.link { background: none; border: 0; color: var(--acc); font: inherit; padding: 0; text-decoration: underline; cursor: pointer; }

.job { display: flex; flex-direction: column; gap: 8px; }
.job-main { text-decoration: none; color: inherit; }
.job-so { font-weight: 700; font-size: 16px; }
.job-actions { display: flex; gap: 8px; justify-content: flex-end; }

.pl-results { display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow-y: auto; }
.pl { text-align: left; font: inherit; background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; cursor: pointer; display: flex; flex-direction: column; }
.pl small { color: var(--muted); }
.pl:active { border-color: var(--acc); }

.item, .logrow { border-top: 1px solid var(--line); padding: 10px 0; }
.item:first-of-type, .logrow:first-of-type { border-top: 0; }
.item-top { display: flex; gap: 8px; margin-bottom: 6px; }
.item-desc { font-weight: 600; }
.item .f.qty { width: 34%; }
.item-act { justify-content: flex-end; margin-top: 4px; }
.num { flex: none; width: 24px; height: 24px; border-radius: 50%; background: var(--bg); border: 1px solid var(--line); display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.total { text-align: right; font-size: 16px; padding-top: 10px; border-top: 1px solid var(--line); }

.logrow-h { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.when { font-weight: 700; color: var(--acc); font-size: 14px; }
.logrow .f.dur { width: 92px; flex: none; }
.ovr summary { font-size: 12.5px; color: var(--muted); cursor: pointer; }
.ovr .grid2 { margin-top: 6px; }
.sumgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.sumgrid div { background: var(--bg); border-radius: 9px; padding: 8px; text-align: center; }
.sumgrid span { display: block; font-size: 11.5px; color: var(--muted); }

.crew { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.marwrap { overflow-x: auto; margin-bottom: 8px; }
.martbl { border-collapse: collapse; font-size: 13px; }
.martbl th { font-weight: 600; color: var(--muted); padding: 4px; white-space: nowrap; }
.martbl td { padding: 3px; }
.martbl td.nm { white-space: nowrap; font-weight: 600; padding-right: 8px; position: sticky; left: 0; background: var(--card); }
.martbl select { width: 64px; padding: 6px; }

.sigbox { border: 2px dashed var(--line); border-radius: 10px; min-height: 110px; display: grid; place-items: center; text-align: center; cursor: pointer; background: #fff; margin-top: 6px; }
.sigbox img { max-height: 100px; max-width: 90%; }
.sigmodal { position: fixed; inset: 0; z-index: 100; background: var(--card); display: flex; flex-direction: column; padding: 12px; padding-top: calc(12px + env(safe-area-inset-top)); gap: 10px; }
.sig-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.sig-area { flex: 1; position: relative; background: #fff; border: 1px solid var(--line); border-radius: 10px; touch-action: none; overflow: hidden; }
.sig-area canvas { position: absolute; inset: 0; touch-action: none; }
.sig-line { position: absolute; left: 8%; right: 8%; bottom: 25%; border-bottom: 1px dashed #94a3b8; pointer-events: none; }
.sig-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; padding-bottom: env(safe-area-inset-bottom); }

#toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(80px); background: #0f172a; color: #fff; padding: 8px 16px; border-radius: 20px; font-size: 13px; transition: transform .2s; z-index: 200; pointer-events: none; }
#toast.show { transform: translateX(-50%) translateY(0); }

.wrap[data-tab="docs"] .preview { margin: 0 -16px; border-radius: 0; }
@media (min-width: 800px) { .wrap[data-tab="docs"] .preview { margin: 0; border-radius: var(--radius); } }
