:root {
  --bg: #f3f6fa;
  --card: #ffffff;
  --text: #15202b;
  --muted: #5d6b7a;
  --line: #e2e8f0;
  --blue: #0b6bcb;
  --blue-soft: #e6f0fb;
  --green: #138a4b;
  --green-soft: #e5f5ec;
  --red: #c62f2f;
  --red-soft: #fdeaea;
  --orange: #b85e00;
  --orange-soft: #fff1df;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419; --card: #18202a; --text: #e8edf2; --muted: #9aa8b6; --line: #2a3542;
    --blue: #4ea1f3; --blue-soft: #16304a; --green: #4cc38a; --green-soft: #143826;
    --red: #f07070; --red-soft: #3e1d1d; --orange: #f0a050; --orange-soft: #3c2a14;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
[hidden] { display: none !important; }
a { color: var(--blue); }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.2; }
h2 { font-size: 20px; }
h3 { font-size: 17px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.num { font-variant-numeric: tabular-nums; }
.red { color: var(--red); } .green { color: var(--green); } .orange { color: var(--orange); }

.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { color: var(--text); text-decoration: none; font-size: 18px; }
main { max-width: 980px; margin: 0 auto; padding: 16px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 10px;
  font-size: 11.5px; color: var(--muted); text-decoration: none; text-align: center;
}
.tabs a span { font-size: 22px; line-height: 1; }
.tabs a.on { color: var(--blue); font-weight: 600; }
.tabs i {
  position: absolute; top: 4px; left: calc(50% + 8px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--red); color: #fff; font: 600 11px/18px system-ui; font-style: normal;
}
@media (min-width: 900px) {
  body { padding-bottom: 0; padding-left: 200px; }
  .tabs { top: 57px; right: auto; width: 200px; display: flex; flex-direction: column; border-top: 0; border-right: 1px solid var(--line); padding: 12px 8px; gap: 4px; }
  .tabs a { flex-direction: row; gap: 10px; font-size: 15px; padding: 12px; border-radius: 10px; }
  .tabs a.on { background: var(--blue-soft); }
  .tabs i { position: static; margin-left: auto; }
}

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.card-head h2, .card-head h3 { margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 16px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text);
  font: 600 15px system-ui, sans-serif; cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--blue); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.danger { color: var(--red); }
.btn.ok { background: var(--green); border-color: var(--green); color: #fff; }
.btn.big { min-height: 52px; font-size: 16px; }
.btn.sm { min-height: 36px; padding: 4px 12px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--text); text-decoration: none; padding: 6px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.quick { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 640px) { .quick { grid-template-columns: repeat(4, 1fr); } }
.quick .btn { min-height: 64px; font-size: 16px; flex-direction: column; gap: 2px; }
.quick .btn span { font-size: 24px; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 640px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; text-decoration: none; color: var(--text); }
.stat b { display: block; font-size: 24px; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat span { font-size: 13px; color: var(--muted); }
.stat.warn { background: var(--orange-soft); border-color: transparent; }
.stat.bad { background: var(--red-soft); border-color: transparent; }
.stat.good { background: var(--green-soft); border-color: transparent; }
.stat.info { background: var(--blue-soft); border-color: transparent; }

.list { display: flex; flex-direction: column; }
.item { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 12px 0; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
.item .main { min-width: 0; flex: 1; }
.item .main b { display: block; }
.item a.main { color: var(--text); text-decoration: none; }
.item .side { text-align: right; white-space: nowrap; }
.item .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 560px) { .item.wrap { flex-wrap: wrap; } .item.wrap .acts { width: 100%; justify-content: stretch; } .item.wrap .acts .btn { flex: 1; } }

.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 13px; font-weight: 600; background: var(--blue-soft); color: var(--blue); white-space: nowrap; }
.pill.pending_approval, .pill.new { background: var(--orange-soft); color: var(--orange); }
.pill.delivered { background: var(--green-soft); color: var(--green); }
.pill.rejected, .pill.cancelled { background: var(--line); color: var(--muted); }
.pill.red { background: var(--red-soft); color: var(--red); }
.pill.green { background: var(--green-soft); color: var(--green); }

.seg { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.seg button { border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 99px; padding: 8px 14px; font: 600 14px system-ui; cursor: pointer; }
.seg button.on { background: var(--blue); border-color: var(--blue); color: #fff; }

label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 12px; }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; min-height: 48px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); font: 17px system-ui, sans-serif;
}
textarea { min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); border-color: transparent; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.stepper { display: flex; gap: 6px; margin-top: 4px; }
.stepper input { margin: 0; text-align: center; font-size: 22px; font-weight: 700; }
.stepper button { min-width: 52px; border-radius: 10px; border: 1px solid var(--line); background: var(--blue-soft); color: var(--blue); font: 700 24px system-ui; cursor: pointer; }
.choice { display: flex; gap: 6px; margin-top: 4px; }
.choice button { flex: 1; min-height: 46px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); font: 600 15px system-ui; cursor: pointer; }
.choice button.on { background: var(--blue); color: #fff; border-color: var(--blue); }
.preview { background: var(--blue-soft); border-radius: 10px; padding: 10px 12px; font-size: 15px; margin-bottom: 4px; }
.preview:empty { display: none; }

dialog {
  width: min(520px, calc(100vw - 16px)); max-height: calc(100dvh - 24px); border: 0; border-radius: 18px; padding: 0;
  background: var(--card); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
dialog::backdrop { background: rgba(10, 20, 30, .45); }
#modalForm { display: flex; flex-direction: column; max-height: calc(100dvh - 24px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 4px 18px; }
.modal-head h2 { margin: 0; }
#modalBody { padding: 8px 18px; overflow-y: auto; }
.modal-foot { display: flex; gap: 8px; padding: 12px 18px 16px; border-top: 1px solid var(--line); }
.modal-foot .btn.primary { flex: 1; }

#toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  width: max-content; max-width: calc(100vw - 32px); padding: 12px 18px; border-radius: 12px; background: #15202b; color: #fff;
  font-size: 15px; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; white-space: pre-line;
}
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--red); }

.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); text-align: center; }
.login-card label { text-align: left; }
.logo { font-size: 48px; }
.big-num { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; }
.kv span { color: var(--muted); }
.kv b { text-align: right; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); padding: 8px 0; }
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; background: var(--green); }
.linkbox { word-break: break-all; background: var(--blue-soft); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
details summary { cursor: pointer; color: var(--blue); font-weight: 600; padding: 6px 0; }
