:root {
  --green-900: #0d2a20; --green-800: #123a2c; --green-700: #155d43; --green-600: #1a7f5a; --green-500: #22a06f;
  --green-100: #e3f3ec; --green-50: #f1f9f5;
  --gold: #d4a72c; --gold-100: #fbf3dc;
  --red: #c0352b; --red-100: #fbe7e5; --amber: #d97706; --amber-100: #fdf0dc; --blue: #2563c9; --blue-100: #e5eefb;
  --ink: #17201c; --ink-2: #4b5852; --ink-3: #7c8984; --line: #e2e7e4; --line-2: #eef1ef;
  --bg: #f5f7f6; --surface: #ffffff;
  --series-income: #1a7f5a; --series-expense: #d97706;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 40, 30, .06), 0 2px 8px rgba(16, 40, 30, .05);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); font-size: 14px; color: var(--ink); background: var(--bg); line-height: 1.45; }
a { color: var(--green-600); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--green-900); color: #d6e5de; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 16px 14px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand img { width: 46px; height: 46px; object-fit: contain; background: #fff; border-radius: 8px; padding: 3px; }
.brand b { display: block; color: #fff; font-size: 16px; letter-spacing: .3px; }
.brand span { font-size: 11px; color: #9fb9ad; display: block; line-height: 1.25; }
.nav { padding: 10px 8px; flex: 1; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: #c9dbd2; font-size: 14px; }
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav a.active { background: var(--green-600); color: #fff; }
.nav a svg { width: 18px; height: 18px; flex: none; opacity: .9; }
.nav .badge { margin-left: auto; background: var(--gold); color: var(--green-900); border-radius: 10px; font-size: 11px; padding: 0 7px; font-weight: 700; }
.nav-section { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #7d9a8d; padding: 12px 10px 4px; }
.sidebar-foot { padding: 12px 14px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; }
.sidebar-foot .who { color: #fff; font-weight: 600; }
.sidebar-foot button { background: none; border: 1px solid rgba(255,255,255,.2); color: #d6e5de; border-radius: 6px; padding: 4px 10px; cursor: pointer; margin-top: 8px; margin-right: 6px; font-size: 12px; }
.sidebar-foot button:hover { background: rgba(255,255,255,.08); }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.content { padding: 22px 26px 60px; max-width: 1400px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; }
.page-head .sub { color: var(--ink-3); margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Cards, grid ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.card-h h3 { font-size: 15px; }
.card-b { padding: 16px; }
.card-b.flush { padding: 0; }
.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)); }
.span2 { grid-column: span 2; }
.stack > * + * { margin-top: 16px; }

.stat { padding: 14px 16px; }
.stat .label { color: var(--ink-3); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.stat .value { font-size: 26px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .note { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.stat.link { cursor: pointer; color: inherit; text-decoration: none; display: block; }
.stat.link:hover { border-color: var(--green-500); }
.stat .value.warn { color: var(--amber); }
.stat .value.bad { color: var(--red); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; }
.t th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: .03em; padding: 9px 12px; border-bottom: 1px solid var(--line); background: #fafbfa; white-space: nowrap; }
.t td { padding: 9px 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.t tr:last-child td { border-bottom: 0; }
.t tbody tr.click { cursor: pointer; }
.t tbody tr.click:hover td { background: var(--green-50); }
.t tfoot td { font-weight: 700; border-top: 2px solid var(--line); background: #fafbfa; }
.empty { padding: 28px; text-align: center; color: var(--ink-3); }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line-2); color: var(--ink-3); font-size: 13px; }

/* ---------- Pills ---------- */
.pill { display: inline-block; padding: 1px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.pill.green { background: var(--green-100); color: var(--green-700); }
.pill.amber { background: var(--amber-100); color: #9a4f00; }
.pill.red { background: var(--red-100); color: var(--red); }
.pill.blue { background: var(--blue-100); color: var(--blue); }
.pill.gold { background: var(--gold-100); color: #7a5b06; }

/* ---------- Buttons & 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; cursor: pointer; font-weight: 550; white-space: nowrap; }
.btn:hover { border-color: #c4cec9; background: #fafbfa; text-decoration: none; }
.btn.primary { background: var(--green-600); border-color: var(--green-600); color: #fff; }
.btn.primary:hover { background: var(--green-700); }
.btn.danger { color: var(--red); border-color: #efc9c5; }
.btn.danger:hover { background: var(--red-100); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.link-btn { background: none; border: 0; color: var(--green-600); cursor: pointer; padding: 0; font-weight: 550; }
.link-btn.danger { color: var(--red); }

.form { display: grid; grid-template-columns: repeat(12, 1fr); gap: 12px 14px; }
.f { grid-column: span 6; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.f.s3 { grid-column: span 3; } .f.s4 { grid-column: span 4; } .f.s8 { grid-column: span 8; } .f.s12 { grid-column: span 12; } .f.s2 { grid-column: span 2; }
.f label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.f label .req { color: var(--red); }
.input, .f input, .f select, .f textarea, select.input {
  border: 1px solid #cfd8d3; border-radius: 8px; padding: 8px 10px; background: #fff; width: 100%; min-width: 0;
}
.f textarea { min-height: 70px; resize: vertical; }
.input:focus, .f input:focus, .f select:focus, .f textarea:focus { outline: 2px solid var(--green-100); border-color: var(--green-500); }
.f .hint { font-size: 12px; color: var(--ink-3); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.form-section { grid-column: span 12; font-weight: 700; font-size: 13px; color: var(--green-700); border-bottom: 1px solid var(--line); padding-bottom: 4px; margin-top: 6px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar .input { width: auto; }
.toolbar input.input[type=search] { min-width: 240px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--ink-2); border-bottom: 2px solid transparent; font-weight: 550; white-space: nowrap; }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.tabs a.active { color: var(--green-700); border-color: var(--green-600); }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; }
.kv dt { color: var(--ink-3); font-size: 13px; }
.kv dd { margin: 0; }

/* ---------- Modal & toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(13, 30, 24, .45); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 640px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 920px; }
.modal-h { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-h h3 { font-size: 17px; }
.modal-x { background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--ink-3); line-height: 1; }
.modal-b { padding: 18px 20px; }
.modal-f { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; background: #fafbfa; border-radius: 0 0 12px 12px; }
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--green-800); color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 380px; }
.toast.error { background: var(--red); }

/* ---------- Picker ---------- */
.picker { position: relative; }
.picker-list { position: absolute; left: 0; right: 0; top: 100%; z-index: 20; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); max-height: 260px; overflow-y: auto; margin-top: 2px; }
.picker-list div { padding: 8px 10px; cursor: pointer; border-bottom: 1px solid var(--line-2); }
.picker-list div:hover, .picker-list div.on { background: var(--green-50); }
.chosen { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border: 1px solid var(--green-500); background: var(--green-50); border-radius: 8px; }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, var(--green-900), var(--green-700)); }
.auth-card { background: #fff; border-radius: 14px; width: 100%; max-width: 420px; padding: 28px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.auth-card .crest { display: block; width: 120px; margin: 0 auto 10px; }
.auth-card h1 { text-align: center; font-size: 19px; }
.auth-card .motto { text-align: center; color: var(--ink-3); font-style: italic; font-size: 13px; margin: 4px 0 18px; }
.auth-card .form { grid-template-columns: 1fr; }
.auth-card .f { grid-column: auto; }
.auth-foot { text-align: center; color: #b9d3c7; font-size: 12px; margin-top: 14px; }

/* ---------- Beds ---------- */
.beds { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.bed { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; min-height: 78px; }
.bed.free { border-style: dashed; background: #fbfcfb; cursor: pointer; }
.bed.free:hover { border-color: var(--green-500); }
.bed.busy { border-color: #f0d9a8; background: var(--gold-100); cursor: pointer; }
.bed .lbl { font-weight: 700; font-size: 13px; }
.bed .who { font-size: 13px; margin-top: 4px; }

/* ---------- Charts ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis { fill: var(--ink-3); font-size: 11px; }
.chart .grid-line { stroke: var(--line-2); }
.chart .tip { position: absolute; pointer-events: none; background: var(--green-900); color: #fff; font-size: 12px; padding: 6px 9px; border-radius: 6px; white-space: nowrap; transform: translate(-50%, -110%); opacity: 0; transition: opacity .1s; z-index: 5; }
:root { --c1: #2a78d6; --c2: #eb6834; --c3: #1baf7a; --c4: #eda100; --c5: #e87ba4; --c6: #008300; --c7: #6250d6; --c8: #e34948; --c-other: #a7aca9; --good: #0ca30c; --warning: #fab219; --critical: #d03b3b; }
.donut { display: grid; grid-template-columns: 1fr; gap: 12px; }
.donut .chart { width: 100%; max-width: 180px; margin: 0 auto; }
.donut svg path { stroke: #fff; stroke-width: 2; transition: opacity .12s; }
.donut svg .dim { opacity: .25; }
.donut-v { font-size: 17px; font-weight: 700; fill: var(--ink); }
.donut-l { font-size: 10px; fill: var(--ink-3); text-transform: uppercase; letter-spacing: .06em; }
.donut-legend { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.donut-legend li { display: grid; grid-template-columns: 12px 1fr auto 38px; gap: 8px; align-items: center; padding: 4px 6px; border-radius: 6px; }
.donut-legend li.on { background: var(--line-2); }
.donut-legend i { width: 10px; height: 10px; border-radius: 3px; }
.donut-legend span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.donut-legend b { font-variant-numeric: tabular-nums; font-weight: 600; }
.donut-legend em { font-style: normal; color: var(--ink-3); text-align: right; font-variant-numeric: tabular-nums; }
.chart.line .xhair { stroke: var(--ink-3); stroke-dasharray: 3 3; opacity: 0; }
.chart.line .dots circle { opacity: 0; transition: opacity .1s; }
.chart.line .dots circle.on { opacity: 1; }
.meter { margin-bottom: 14px; }
.meter-h { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.meter-track { height: 10px; background: var(--green-100); border-radius: 5px; overflow: hidden; }
.meter-fill { height: 100%; background: var(--green-600); border-radius: 0 5px 5px 0; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.hbar { display: grid; grid-template-columns: minmax(120px, 38%) 1fr 40px; gap: 8px; align-items: center; margin: 7px 0; font-size: 13px; }
.hbar .track { height: 10px; background: var(--line-2); border-radius: 4px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--series-income); border-radius: 0 4px 4px 0; }

/* ---------- Print ---------- */
#print-root { display: none; }
.doc { font-family: var(--font); color: #000; font-size: 12.5px; }
.doc .lh { display: grid; grid-template-columns: 80px 1fr 80px; align-items: center; gap: 12px; border-bottom: 3px double var(--green-700); padding-bottom: 8px; margin-bottom: 12px; }
.doc .lh img { width: 80px; height: 70px; object-fit: contain; }
.doc .lh .c { text-align: center; }
.doc .lh .c b { font-size: 18px; letter-spacing: .5px; display: block; color: var(--green-800); }
.doc .lh .c .op { font-size: 11px; font-weight: 600; }
.doc .lh .c .ad { font-size: 11px; }
.doc h2 { text-align: center; font-size: 15px; margin: 6px 0 12px; text-transform: uppercase; letter-spacing: .05em; }
.doc table { width: 100%; border-collapse: collapse; margin: 8px 0; }
.doc th, .doc td { border: 1px solid #999; padding: 4px 6px; text-align: left; }
.doc th { background: #eef3f0; }
.doc .sig { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 40px; }
.doc .sig div { border-top: 1px solid #000; padding-top: 4px; font-size: 11.5px; }
.doc .meta { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 20px; margin-bottom: 8px; }
.doc .foot { text-align: center; font-size: 11px; margin-top: 16px; font-style: italic; }
.doc.receipt { max-width: 80mm; margin: 0 auto; font-size: 11.5px; }
.doc.receipt .lh { grid-template-columns: 1fr; text-align: center; }
.doc.receipt .lh img { margin: 0 auto; width: 56px; height: 50px; }
.doc.receipt .lh img:last-child { display: none; }
.page-break { page-break-after: always; }

@media print {
  @page { margin: 12mm; }
  body { background: #fff; }
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block; }
  .doc th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 40; width: 250px; left: -260px; transition: left .2s; }
  .sidebar.open { left: 0; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--green-900); color: #fff; position: sticky; top: 0; z-index: 30; }
  .topbar button { background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; }
  .content { padding: 16px 16px 60px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .f, .f.s3, .f.s4, .f.s8, .f.s2 { grid-column: span 12; }
  .kv { grid-template-columns: 110px 1fr; }
  .toolbar input.input[type=search] { min-width: 0; width: 100%; }
}
