:root {
  --bg: #f4f5f1;
  --panel: #ffffff;
  --ink: #1d2420;
  --ink-2: #4c5a52;
  --muted: #7d8a82;
  --line: #e3e7e1;
  --line-2: #eef1ec;
  --brand: #1f6b45;
  --brand-2: #2f8f5b;
  --brand-soft: #e6f2ea;
  --side: #12291f;
  --side-2: #1b3a2c;
  --side-ink: #c9d8cf;
  --ok: #1f7a4a; --ok-bg: #e3f3e9;
  --warn: #9a6200; --warn-bg: #fdf1d8;
  --bad: #b3261e; --bad-bg: #fbe5e3;
  --info: #255f9e; --info-bg: #e5eef9;
  --mute: #5f6b65; --mute-bg: #edf0ed;
  --tea: #2f8f5b; --milk: #4f7fbf;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(18, 41, 31, .06), 0 1px 1px rgba(18, 41, 31, .04);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

/* ------------------------------------------------------------ layout */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side {
  background: var(--side); color: var(--side-ink); padding: 18px 12px 30px; position: sticky; top: 0;
  height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; color: #fff; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; background: linear-gradient(135deg, #3fae6f, #1f6b45);
  display: grid; place-items: center; font-weight: 800; font-size: 15px; color: #fff;
}
.brand b { display: block; font-size: 14.5px; line-height: 1.2; }
.brand span { font-size: 11.5px; color: #8fae9c; }
.nav-group { margin-top: 14px; }
.nav-group > div { font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em; color: #79968a; padding: 0 10px 4px; }
.nav-group a {
  display: block; color: var(--side-ink); padding: 6px 10px; border-radius: 7px; font-size: 13.5px;
}
.nav-group a:hover { background: var(--side-2); color: #fff; text-decoration: none; }
.nav-group a.active { background: #2a5a43; color: #fff; font-weight: 600; }
.badge-n {
  float: right; background: #e2a72e; color: #2a1d00; border-radius: 10px; font-size: 11px; font-weight: 700; padding: 0 7px; line-height: 18px;
}
.main { min-width: 0; }
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 28px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.top .co { font-weight: 600; }
.top .who { display: flex; align-items: center; gap: 12px; color: var(--ink-2); font-size: 13px; }
.top form { margin: 0; }
.content { padding: 24px 28px 60px; max-width: 1400px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--ink-2); }
.btn.menu-btn { display: none; }
input[type=checkbox], input[type=radio] { min-height: 0; width: 16px; height: 16px; accent-color: var(--brand); vertical-align: -3px; margin: 0 4px 0 0; }

/* ------------------------------------------------------------ panels */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line-2); }
.panel-body { padding: 16px 18px; }
.grid { display: grid; gap: 16px; }
.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)); }
.stack > * + * { margin-top: 16px; }
.grid > * { min-width: 0; }

.kpi { padding: 16px 18px; }
.kpi .label { color: var(--ink-2); font-size: 12.5px; }
.kpi .value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .value small { font-size: 14px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.kpi .sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.kpi.tea { border-top: 3px solid var(--tea); }
.kpi.milk { border-top: 3px solid var(--milk); }
.kpi.alert { border-top: 3px solid #e2a72e; }
.kpi a.more { font-size: 12.5px; }

/* ------------------------------------------------------------- table */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
.t th, .t td { padding: 9px 12px; border-bottom: 1px solid var(--line-2); text-align: left; vertical-align: middle; }
.t th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: #fafbf9; white-space: nowrap; }
.t tbody tr:hover { background: #f8faf7; }
.t .num, .t th.num { text-align: right; }
.t tfoot td { font-weight: 700; background: #fafbf9; border-top: 1px solid var(--line); }
.t tr.voided td { color: var(--muted); text-decoration: line-through; }
.t tr.voided td .pill { text-decoration: none; }
.t .actions { white-space: nowrap; text-align: right; }
.empty { padding: 36px 18px; text-align: center; color: var(--muted); }

.pill { display: inline-block; padding: 1px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill-ok { color: var(--ok); background: var(--ok-bg); }
.pill-warn { color: var(--warn); background: var(--warn-bg); }
.pill-bad { color: var(--bad); background: var(--bad-bg); }
.pill-info { color: var(--info); background: var(--info-bg); }
.pill-mute { color: var(--mute); background: var(--mute-bg); }
.flag { display: inline-block; font-size: 11.5px; background: var(--warn-bg); color: var(--warn); border-radius: 5px; padding: 0 6px; margin: 1px 2px 1px 0; }
.yes { color: var(--ok); font-weight: 600; }
.no { color: var(--muted); }

/* ------------------------------------------------------------- forms */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 7px 14px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #f4f6f3; text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: #185a3a; }
.btn-danger { color: var(--bad); border-color: #f0c9c5; }
.btn-danger:hover { background: var(--bad-bg); }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-link { background: none; border: none; color: var(--brand); padding: 0; font: inherit; cursor: pointer; }
form.inline { display: inline; margin: 0; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--line-2); }
.filters .grow { flex: 1; }
input, select, textarea {
  font: inherit; color: var(--ink); border: 1px solid #d4dad3; background: #fff; border-radius: 8px; padding: 7px 10px; min-height: 36px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #b7dcc5; border-color: var(--brand-2); }
input[disabled], select[disabled], textarea[disabled] { background: #f3f5f2; color: var(--muted); }
textarea { min-height: 80px; width: 100%; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 20px; }
.field label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; }
.field label .req { color: var(--bad); }
.field input:not([type=checkbox]), .field select, .field textarea { width: 100%; }
.field .help { color: var(--muted); font-size: 12px; margin-top: 4px; }
.field .error { color: var(--bad); font-size: 12.5px; margin-top: 4px; font-weight: 600; }
.field.has-error input, .field.has-error select { border-color: var(--bad); }
.field.full { grid-column: 1 / -1; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; }
.check input { margin-top: 3px; min-height: 0; width: 16px; height: 16px; accent-color: var(--brand); }
.check b { display: block; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line-2); }

.dl { display: grid; grid-template-columns: 200px 1fr; gap: 0; }
.dl > div { padding: 9px 0; border-bottom: 1px solid var(--line-2); }
.dl > div:nth-child(odd) { color: var(--ink-2); }

/* ---------------------------------------------------------- messages */
.msgs { margin-bottom: 16px; }
.msg { padding: 10px 14px; border-radius: 8px; margin-bottom: 8px; font-weight: 500; }
.msg.success { background: var(--ok-bg); color: #145c36; border: 1px solid #c4e5d1; }
.msg.error { background: var(--bad-bg); color: #8d1d16; border: 1px solid #f2c6c1; }
.note { background: var(--brand-soft); border: 1px solid #cfe5d7; color: #1d4d35; border-radius: 8px; padding: 10px 14px; }
.warnbox { background: var(--warn-bg); border: 1px solid #f1d9a6; color: #6b4600; border-radius: 8px; padding: 10px 14px; }

/* ------------------------------------------------------------ charts */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 170px; padding-top: 10px; }
.bars .b { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.bars .bar { width: 100%; max-width: 34px; border-radius: 5px 5px 2px 2px; background: var(--tea); min-height: 2px; position: relative; }
.bars.milk .bar { background: var(--milk); }
.bars .b:hover .bar { filter: brightness(1.12); }
.bars .b .v { font-size: 10.5px; color: var(--ink-2); margin-bottom: 3px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.bars .b .d { font-size: 10.5px; color: var(--muted); margin-top: 5px; white-space: nowrap; }
.bars .b.today .bar { background: #1b5e3c; }
.bars.milk .b.today .bar { background: #2f5f9e; }
.hbar { height: 8px; background: var(--line-2); border-radius: 4px; overflow: hidden; min-width: 80px; }
.hbar > i { display: block; height: 100%; background: var(--tea); border-radius: 4px; }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.dot.on { background: #2fae63; } .dot.off { background: #c3cbc6; } .dot.wait { background: #e2a72e; }
.tabs { display: flex; gap: 4px; }
.tabs a { padding: 6px 12px; border-radius: 7px; color: var(--ink-2); font-weight: 600; }
.tabs a.on { background: var(--brand-soft); color: var(--brand); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 12px 18px; color: var(--ink-2); }
.lines-table input, .lines-table select { width: 100%; }

/* ------------------------------------------------------------- login */
.auth { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(1200px 600px at 20% 0%, #dcefe3, var(--bg)); padding: 20px; }
.auth-card { width: 100%; max-width: 400px; background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 10px 30px rgba(18, 41, 31, .08); padding: 30px; }
.auth-card .brand { color: var(--ink); padding: 0 0 20px; }
.auth-card .brand span { color: var(--muted); }
.auth-card .field { margin-bottom: 14px; }
.auth-card .btn { width: 100%; justify-content: center; padding: 10px; }

@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 20; width: 260px; left: -270px; transition: left .2s; }
  body.nav-open .side { left: 0; }
  .btn.menu-btn { display: inline-flex; }
  .content, .top { padding-left: 16px; padding-right: 16px; }
  .g2, .form-grid { grid-template-columns: 1fr; }
  .dl { grid-template-columns: 1fr; }
  .dl > div:nth-child(odd) { border-bottom: none; padding-bottom: 0; font-size: 12px; }
}
@media (max-width: 520px) { .g4 { grid-template-columns: 1fr; } .top .who .nm { display: none; } .bars { gap: 3px; } .bars .b .v { display: none; } .bars .b .d { font-size: 9px; } }
@media print { .side, .top, .filters, .btn, .pager { display: none !important; } .shell { display: block; } .content { padding: 0; } }
