:root {
  --bg: #f4f5f7; --card: #fff; --text: #111827; --muted: #6b7280; --line: #e5e7eb;
  --accent: #16a34a; --accent-2: #dcfce7; --danger: #dc2626; --warn: #d97706; --warn-bg: #fef3c7;
  --input: #fff; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 1px 8px rgba(0,0,0,.04);
  --radius: 12px; --nav-w: 220px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1120; --card: #111a2e; --text: #e5e7eb; --muted: #94a3b8; --line: #1f2a44;
    --accent: #22c55e; --accent-2: #14351f; --input: #0b1324; --warn-bg: #3a2a0a; --shadow: none; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
.hidden { display: none !important; }
a { color: inherit; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--danger); min-height: 1.2em; font-size: 13px; }

/* layout */
.nav { position: fixed; inset: 0 auto 0 0; width: var(--nav-w); background: var(--card); border-right: 1px solid var(--line);
  padding: 16px 10px; display: flex; flex-direction: column; gap: 2px; z-index: 10; }

.nav .s { display: none; }
.nav .brand { font-weight: 700; font-size: 18px; padding: 4px 10px 16px; color: var(--accent); }
.nav a { display: flex; gap: 10px; align-items: center; padding: 9px 10px; border-radius: 8px; text-decoration: none; color: var(--muted); }
.nav a.active { background: var(--accent-2); color: var(--text); font-weight: 600; }
main { margin-left: var(--nav-w); padding: 24px; max-width: 1100px; }
@media (max-width: 760px) {
  .nav { inset: auto 0 0 0; width: auto; flex-direction: row; padding: 4px 2px calc(4px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--line); justify-content: space-around; overflow-x: auto; }
  .nav .brand { display: none; }
  .nav a { flex-direction: column; gap: 0; font-size: 9.5px; padding: 6px 4px; min-width: 52px; }
  .nav a .ico { font-size: 19px; }
  .nav a .l { display: none; } .nav a .s { display: inline; }
  .nav a { flex: 1; min-width: 0; white-space: nowrap; }
  .nav a.active { background: none; color: var(--accent); }
  main { margin: 0; padding: 14px 12px calc(84px + env(safe-area-inset-bottom)); }
}

.head { display: flex; align-items: center; gap: 10px; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; }
.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); border: 1px solid var(--line); margin-bottom: 12px; }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.cols { display: grid; grid-template-columns: minmax(0,1.3fr) minmax(0,1fr); gap: 12px; align-items: start; }
@media (max-width: 900px) { .cols { grid-template-columns: 1fr; } .side-first { order: -1; } .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 520px) { .g3 { grid-template-columns: 1fr 1fr; } }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 0; }
.sticky-sum { position: sticky; top: 16px; }

/* forms */
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea { width: 100%; padding: 10px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--input);
  color: var(--text); font: inherit; font-size: 16px; min-height: 42px; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=color] { padding: 2px; width: 46px; }
.field { margin-bottom: 10px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 14px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; font-weight: 500; cursor: pointer;
  min-height: 40px; text-decoration: none; white-space: nowrap; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 5px 10px; min-height: 32px; font-size: 13px; }
.btn.icon { padding: 6px 10px; }
.btn:disabled { opacity: .5; }

/* calc */
.ext-row { display: grid; grid-template-columns: minmax(0,1fr) 84px 64px 40px; gap: 6px; margin-bottom: 6px; align-items: center; }
.fil-row { display: grid; grid-template-columns: minmax(0,1fr) 92px 40px; gap: 6px; margin-bottom: 6px; align-items: center; }
.sum-line { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.sum-line:last-child { border: 0; }
.sum-total { font-size: 20px; font-weight: 700; }
.price-big { font-size: 30px; font-weight: 800; color: var(--accent); }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0,0,0,.15); flex: none; }
.warn { background: var(--warn-bg); color: var(--warn); padding: 9px 12px; border-radius: 9px; font-size: 13px; margin-bottom: 10px; }

/* lists */
.list .item { display: flex; gap: 12px; align-items: center; padding: 12px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.list .item:last-child { border: 0; }
.list .item:hover { background: rgba(127,127,127,.05); }
.list { padding: 0; overflow: hidden; }
.thumb { width: 48px; height: 48px; border-radius: 8px; object-fit: cover; background: var(--line); flex: none; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.st-new { background: #dbeafe; color: #1d4ed8; } .st-printing { background: #fef3c7; color: #b45309; }
.st-ready { background: #ede9fe; color: #6d28d9; } .st-shipped { background: #cffafe; color: #0e7490; }
.st-paid { background: #dcfce7; color: #15803d; } .st-cancelled { background: #f3f4f6; color: #6b7280; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; }
.chip { padding: 6px 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--card); cursor: pointer; white-space: nowrap; font-size: 13px; color: var(--text); }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.overdue { color: var(--danger); font-weight: 600; }
.bar { height: 6px; background: var(--line); border-radius: 9px; overflow: hidden; margin-top: 5px; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.bar.low > i { background: var(--danger); }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.cat-card { padding: 0; overflow: hidden; margin: 0; display: flex; flex-direction: column; }
.cat-card .ph { aspect-ratio: 4/3; background: var(--line); display: flex; align-items: center; justify-content: center; font-size: 34px; color: var(--muted); }
.cat-card .ph img { width: 100%; height: 100%; object-fit: cover; }
.cat-card .body .row:last-child { flex-wrap: nowrap; } .cat-card .body .row:last-child .btn { flex: 1; }
.cat-card .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }

.photos { display: flex; gap: 8px; flex-wrap: wrap; }
.photos .ph { position: relative; }
.photos img { width: 92px; height: 92px; object-fit: cover; border-radius: 9px; cursor: zoom-in; }
.photos .x { position: absolute; top: 3px; right: 3px; background: rgba(0,0,0,.6); color: #fff; border: 0; border-radius: 50%; width: 24px; height: 24px; cursor: pointer; }

.kpi .v { font-size: 22px; font-weight: 700; margin-top: 2px; }
.kpi { margin: 0; }
.chart { display: flex; align-items: flex-end; gap: 6px; height: 170px; padding-top: 10px; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; min-width: 0; }
.chart .bars { display: flex; gap: 2px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.chart .b { width: 42%; max-width: 22px; border-radius: 4px 4px 0 0; background: var(--accent); min-height: 2px; }
.chart .b.c { background: var(--muted); opacity: .45; }
.chart .lbl { font-size: 11px; color: var(--muted); }
table { width: 100%; border-collapse: collapse; }
td, th { padding: 7px 4px; border-bottom: 1px solid var(--line); text-align: left; font-size: 14px; }
th { font-size: 12px; color: var(--muted); font-weight: 500; }
td.r, th.r { text-align: right; }

dialog { border: 0; border-radius: 14px; padding: 0; width: min(520px, 94vw); background: var(--card); color: var(--text); max-height: 90vh; }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog form { padding: 18px; }
dialog .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
dialog.img { width: auto; max-width: 96vw; background: transparent; }
dialog.img img { max-width: 94vw; max-height: 86vh; border-radius: 10px; display: block; }

.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: .2s; z-index: 100; font-size: 14px; }
.toast.on { opacity: 1; transform: translateX(-50%); }

.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: min(340px, 100%); display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login .logo { font-size: 26px; font-weight: 800; color: var(--accent); }
