/* ===== Design tokens ===== */
:root {
  --bg: #f6f7f3;
  --surface: #ffffff;
  --surface-2: #f0f3ec;
  --text: #16211a;
  --muted: #5f6b62;
  --line: #e1e6dc;
  --primary: #1f7a3a;
  --primary-600: #17652f;
  --primary-soft: #e4f2e7;
  --accent: #e08a1e;
  --accent-soft: #fdf1e0;
  --danger: #c0392b;
  --danger-soft: #fbe9e6;
  --warn: #a86a00;
  --warn-soft: #fdf3dc;
  --info: #2563a8;
  --info-soft: #e5eefa;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 32, 20, .05), 0 6px 18px -10px rgba(16, 32, 20, .18);
  --shadow-lg: 0 20px 50px -20px rgba(16, 32, 20, .35);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, "Noto Sans", "Nirmala UI", Roboto, sans-serif;
  --sidebar-w: 240px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 var(--font); }
img { max-width: 100%; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: clamp(1.6rem, 3.5vw, 2.2rem); }
h2 { font-size: clamp(1.25rem, 2.6vw, 1.6rem); }
h3 { font-size: 1.1rem; }
p { margin: 0 0 1em; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 4px; font-size: .9em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
.icon { flex-shrink: 0; vertical-align: -3px; }

/* ===== Layout primitives ===== */
.container { max-width: 1160px; margin: 0 auto; padding: 0 20px; }
.stack > * + * { margin-top: 16px; }
.stack-sm > * + * { margin-top: 8px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.grid-2, .grid-3, .grid-4 { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 620px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.tiny { font-size: .76rem; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mt-0 { margin-top: 0 !important; }
.mb-0 { margin-bottom: 0 !important; }
.hidden { display: none !important; }

/* ===== Cards ===== */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card-flat { box-shadow: none; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h3 { margin: 0; }
.card-link { display: block; color: inherit; transition: transform .12s, box-shadow .12s, border-color .12s; }
.card-link:hover { text-decoration: none; border-color: var(--primary); transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat .stat-label { color: var(--muted); font-size: .82rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .stat-value { font-size: 1.8rem; font-weight: 750; margin-top: 4px; }
.stat .stat-sub { color: var(--muted); font-size: .84rem; }
.callout { border-radius: var(--radius-sm); padding: 12px 14px; display: flex; gap: 10px; align-items: flex-start; font-size: .92rem; }
.callout-info { background: var(--info-soft); color: #173e6b; }
.callout-warn { background: var(--warn-soft); color: #6b4500; }
.callout-danger { background: var(--danger-soft); color: #7a2219; }
.callout-success { background: var(--primary-soft); color: #134d25; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none !important; line-height: 1.2;
  transition: background .12s, border-color .12s, color .12s, box-shadow .12s; white-space: nowrap;
}
.btn:disabled, .btn.disabled { opacity: .55; cursor: not-allowed; pointer-events: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { filter: brightness(.95); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }
.btn-soft { background: var(--primary-soft); color: var(--primary); }
.btn-soft:hover { background: #d4ead9; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.93); }
.btn-link { background: none; border: 0; color: var(--primary); padding: 0; font-weight: 600; }
.btn-sm { padding: 6px 11px; font-size: .86rem; }
.btn-lg { padding: 13px 22px; font-size: 1.02rem; }
.btn-block { width: 100%; }
.icon-btn { background: none; border: 0; padding: 6px; border-radius: 6px; cursor: pointer; color: var(--muted); display: inline-flex; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ===== Forms ===== */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .label { font-weight: 600; font-size: .88rem; }
.field .hint { color: var(--muted); font-size: .8rem; }
.field .error { color: var(--danger); font-size: .82rem; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number], input[type=search], input[type=date], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; outline: none;
  transition: border-color .12s, box-shadow .12s;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31, 122, 58, .15); }
input.invalid, select.invalid, textarea.invalid { border-color: var(--danger); }
.check { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; font-size: .92rem; }
.check input { margin-top: 3px; accent-color: var(--primary); }
.search-box { position: relative; }
.search-box .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-box input { padding-left: 38px; }
.dropzone { border: 2px dashed var(--line); border-radius: var(--radius); padding: 22px; text-align: center; color: var(--muted); cursor: pointer; transition: border-color .12s, background .12s; }
.dropzone:hover, .dropzone.drag { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }

/* ===== Badges / chips ===== */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: .76rem; font-weight: 650; white-space: nowrap; }
.badge-green { background: var(--primary-soft); color: var(--primary); }
.badge-amber { background: var(--warn-soft); color: var(--warn); }
.badge-red { background: var(--danger-soft); color: var(--danger); }
.badge-gray { background: var(--surface-2); color: var(--muted); }
.badge-blue { background: var(--info-soft); color: var(--info); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: .86rem; cursor: pointer; font: inherit; font-size: .86rem; color: var(--text); }
.chip:hover { border-color: var(--primary); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { background: var(--surface-2); font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: #fafcf8; }

/* ===== Page chrome helpers ===== */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head h1 { margin: 0; font-size: clamp(1.4rem, 3vw, 1.8rem); }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.breadcrumb { font-size: .86rem; color: var(--muted); margin-bottom: 6px; }
.breadcrumb a { color: var(--muted); }
.empty { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty .icon { color: var(--primary); margin-bottom: 8px; }
.empty-page { padding: 80px 20px; text-align: center; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tab { padding: 10px 14px; border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.steps-bar { display: flex; gap: 8px; margin-bottom: 22px; flex-wrap: wrap; }
.steps-bar .step { display: flex; align-items: center; gap: 8px; font-size: .88rem; color: var(--muted); font-weight: 600; }
.steps-bar .step .num { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--line); font-size: .8rem; }
.steps-bar .step.done .num { background: var(--primary); color: #fff; border-color: var(--primary); }
.steps-bar .step.current { color: var(--text); }
.steps-bar .step.current .num { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.steps-bar .sep { flex: 0 0 24px; height: 1px; background: var(--line); align-self: center; }
.spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; display: inline-block; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: 999px; transition: width .2s; }

/* ===== Modal ===== */
.modal-bg { position: fixed; inset: 0; background: rgba(12, 20, 14, .5); display: grid; place-items: center; z-index: 100; padding: 16px; animation: fade .15s; }
.modal { background: var(--surface); border-radius: 16px; width: min(520px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: var(--shadow-lg); animation: pop .18s; }
.modal-wide { width: min(820px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(10px) scale(.98); opacity: 0; } }

/* ===== Toasts ===== */
#toasts { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 40px); }
.toast { display: flex; gap: 10px; align-items: center; background: #1c2a20; color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: .92rem; animation: pop .2s; transition: opacity .3s, transform .3s; }
.toast-success .icon { color: #7ee29a; }
.toast-error { background: #6e1d15; }
.toast.out { opacity: 0; transform: translateY(8px); }

@media print {
  #toasts, .no-print { display: none !important; }
  body { background: #fff; }
}
