:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --good: #15803d;
  --good-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --shadow: 0 14px 40px rgba(15, 23, 42, .08);
}
body[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1220;
  --surface: #111827;
  --surface-2: #172033;
  --text: #f8fafc;
  --muted: #94a3b8;
  --border: #243044;
  --accent: #60a5fa;
  --accent-soft: #172554;
  --good: #4ade80;
  --good-soft: #052e16;
  --warn: #fbbf24;
  --warn-soft: #422006;
  --danger: #f87171;
  --danger-soft: #450a0a;
  --shadow: 0 14px 40px rgba(0, 0, 0, .22);
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, Arial, sans-serif;
  line-height: 1.6;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
.app-shell { width: min(1180px, calc(100% - 28px)); margin: 0 auto; padding: 28px 0 60px; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; margin-bottom: 22px; }
.topbar h1, .section-header h2, .panel h2 { margin: 0; letter-spacing: -.02em; }
.topbar h1 { font-size: clamp(2rem, 5vw, 3.2rem); }
.subtitle, .muted { color: var(--muted); }
.subtitle { margin: 6px 0 0; }
.eyebrow { margin: 0 0 4px; font-size: .78rem; font-weight: 800; color: var(--accent); }
.topbar-actions, .section-actions, .modal-actions, .item-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.primary-btn, .secondary-btn, .danger-btn, .file-btn, .icon-btn, .text-btn {
  border: 0; border-radius: 12px; min-height: 44px; padding: 0 16px; transition: .2s ease;
}
.primary-btn { background: var(--accent); color: white; font-weight: 800; }
.secondary-btn, .file-btn { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); font-weight: 700; }
.danger-btn { background: var(--danger); color: white; font-weight: 800; }
.icon-btn { width: 44px; padding: 0; background: var(--surface); color: var(--text); border: 1px solid var(--border); font-size: 1.2rem; }
.text-btn { min-height: auto; padding: 6px 8px; background: transparent; color: var(--accent); font-weight: 800; }
.primary-btn:hover, .secondary-btn:hover, .danger-btn:hover, .file-btn:hover, .icon-btn:hover { transform: translateY(-1px); }
.tabs { display: flex; gap: 8px; overflow-x: auto; padding: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; margin-bottom: 22px; box-shadow: var(--shadow); }
.tab { white-space: nowrap; flex: 1 0 auto; min-height: 44px; border: 0; border-radius: 11px; background: transparent; color: var(--muted); font-weight: 800; padding: 0 16px; }
.tab.active { color: var(--text); background: var(--surface-2); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.metrics-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.metric-card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 18px; box-shadow: var(--shadow); }
.metric-card .label { color: var(--muted); font-size: .86rem; font-weight: 700; }
.metric-card .value { margin-top: 8px; font-size: clamp(1.35rem, 4vw, 2rem); font-weight: 900; direction: ltr; text-align: right; }
.metric-card .hint { margin-top: 4px; color: var(--muted); font-size: .78rem; }
.metric-card.good .value { color: var(--good); }
.metric-card.warn .value { color: var(--warn); }
.metric-card.danger .value { color: var(--danger); }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
.panel-head, .section-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.panel-head { margin-bottom: 14px; }
.section-header { margin-bottom: 16px; }
.pill, .status-badge, .category-badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 5px 9px; font-size: .76rem; font-weight: 800; white-space: nowrap; }
.pill { color: var(--accent); background: var(--accent-soft); }
.status-planned, .status-expected { color: var(--warn); background: var(--warn-soft); }
.status-completed, .status-received { color: var(--good); background: var(--good-soft); }
.status-cancelled { color: var(--muted); background: var(--surface-2); }
.category-badge { color: var(--muted); background: var(--surface-2); }
.progress-track { width: 100%; height: 10px; overflow: hidden; background: var(--surface-2); border-radius: 999px; }
.progress-bar { height: 100%; width: 0%; background: var(--accent); border-radius: inherit; transition: width .25s ease; }
.forecast-grid { margin-top: 14px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.forecast-box { padding: 12px; border-radius: 14px; background: var(--surface-2); }
.forecast-box span { display: block; color: var(--muted); font-size: .78rem; }
.forecast-box strong { display: block; margin-top: 3px; direction: ltr; text-align: right; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.compact-list, .item-list { display: grid; gap: 10px; }
.compact-row { display: flex; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.compact-row:last-child { border-bottom: 0; }
.compact-row strong { direction: ltr; }
.item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 14px; padding: 14px; border: 1px solid var(--border); border-radius: 15px; background: var(--surface); }
.item.cancelled { opacity: .58; }
.item.completed { border-color: color-mix(in srgb, var(--good) 30%, var(--border)); }
.item-main { min-width: 0; }
.item-title-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 5px; }
.item-title { font-weight: 900; overflow-wrap: anywhere; }
.item-meta { display: flex; gap: 8px 14px; flex-wrap: wrap; color: var(--muted); font-size: .82rem; }
.item-values { margin-top: 8px; display: flex; gap: 10px 18px; flex-wrap: wrap; font-size: .9rem; }
.item-values strong { direction: ltr; display: inline-block; }
.diff-good { color: var(--good); font-weight: 800; }
.diff-bad { color: var(--danger); font-weight: 800; }
.item-actions { justify-content: flex-end; align-content: flex-start; }
.mini-btn { border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 10px; min-height: 38px; padding: 0 11px; font-weight: 800; }
.mini-btn.primary { background: var(--accent); color: white; border-color: transparent; }
.mini-btn.danger { color: var(--danger); }
.select, input, textarea, select { width: 100%; min-height: 44px; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 11px; padding: 9px 11px; outline: none; }
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent); }
.settings-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.file-btn { display: inline-flex; justify-content: center; align-items: center; margin-top: 8px; cursor: pointer; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 28%, var(--border)); }
.modal { width: min(620px, calc(100% - 24px)); border: 1px solid var(--border); border-radius: 18px; padding: 0; background: var(--surface); color: var(--text); box-shadow: 0 30px 80px rgba(0, 0, 0, .28); }
.modal::backdrop { background: rgba(2, 6, 23, .62); backdrop-filter: blur(4px); }
.modal form { padding: 18px; }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid label { display: grid; gap: 6px; color: var(--muted); font-size: .86rem; font-weight: 700; }
.form-grid .full { grid-column: 1 / -1; }
.modal-actions { justify-content: flex-start; margin-top: 18px; }
.complete-card, .difference-box { background: var(--surface-2); border-radius: 13px; padding: 12px; margin-bottom: 14px; }
.complete-card { display: flex; justify-content: space-between; gap: 12px; }
.complete-card strong { direction: ltr; }
.difference-box:empty { display: none; }
.form-error { color: var(--danger); font-size: .82rem; font-weight: 700; min-height: 1.25em; margin-top: 8px; }
.compact-modal { width: min(460px, calc(100% - 24px)); }
.toast { position: fixed; left: 18px; bottom: 18px; z-index: 100; max-width: min(360px, calc(100% - 36px)); background: var(--text); color: var(--surface); padding: 11px 14px; border-radius: 12px; opacity: 0; transform: translateY(14px); pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.archive-banner { background: var(--warn-soft); color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 30%, var(--border)); border-radius: 14px; padding: 12px 14px; margin-bottom: 16px; font-weight: 800; }
.hidden { display: none !important; }
.empty-state { padding: 28px 14px; text-align: center; color: var(--muted); background: var(--surface-2); border-radius: 14px; }
@media (max-width: 900px) {
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .two-col, .settings-grid { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
  .app-shell { width: min(100% - 18px, 1180px); padding-top: 16px; }
  .topbar, .section-header, .panel-head { align-items: stretch; flex-direction: column; }
  .topbar-actions { width: 100%; }
  .topbar-actions .primary-btn { flex: 1; }
  .metrics-grid, .metrics-grid.small, .forecast-grid { grid-template-columns: 1fr; }
  .item { grid-template-columns: 1fr; }
  .item-actions { justify-content: flex-start; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .tabs .tab { flex: 0 0 auto; }
  .modal-actions > * { flex: 1; }
}
