:root {
  --bg: #eef2f6;
  --panel: #ffffff;
  --ink: #16212e;
  --muted: #64748b;
  --line: #dfe6ee;
  --brand: #1e4e79;
  --brand-soft: #e8f0f8;
  --ok: #0f766e;
  --warn: #b45309;
  --danger: #b42318;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--brand); }
h1, h2, h3, h4 { margin: 0 0 .4rem; line-height: 1.25; }
p { margin: 0 0 .6rem; }

.app-loading { padding: 3rem; color: var(--muted); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.login-card {
  width: 100%; max-width: 380px; background: var(--panel); border-radius: 16px;
  box-shadow: var(--shadow); padding: 1.8rem; border: 1px solid var(--line);
}
.login-card h1 { font-size: 1.35rem; }
.login-brand { display: flex; align-items: center; gap: .6rem; margin-bottom: 1.2rem; }
.login-brand .logo { width: 38px; height: 38px; border-radius: 10px; background: var(--brand); display: grid; place-items: center; color: #fff; font-weight: 700; }
.login-note { font-size: .82rem; color: var(--muted); margin-top: 1rem; }

/* ---------- shell ---------- */
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  background: var(--brand); color: #fff; padding: .7rem 1rem; position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: .8rem; box-shadow: 0 1px 3px rgba(0,0,0,.15);
}
.topbar .brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; letter-spacing: .2px; }
.topbar .brand .logo { width: 30px; height: 30px; border-radius: 8px; background: rgba(255,255,255,.16); display: grid; place-items: center; font-size: .85rem; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: .85rem; opacity: .92; }

.tabs { background: var(--panel); border-bottom: 1px solid var(--line); overflow-x: auto; position: sticky; top: 51px; z-index: 25; }
.tabs-inner { display: flex; gap: .2rem; padding: 0 .6rem; min-width: max-content; }
.tab {
  border: 0; background: none; padding: .7rem .85rem; font: inherit; color: var(--muted);
  cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

.page { padding: 1.1rem; max-width: 1180px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: flex-start; gap: .8rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h2 { font-size: 1.2rem; }
.page-head .sub { color: var(--muted); font-size: .86rem; }
.page-head .spacer { flex: 1; }

/* ---------- cards / stats ---------- */
.grid { display: grid; gap: .85rem; }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; }
.stat .label { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.stat .value { font-size: 1.45rem; font-weight: 700; margin-top: .2rem; }
.stat .value.small { font-size: 1.15rem; }
.stat .foot { font-size: .8rem; color: var(--muted); margin-top: .15rem; }
.value.danger { color: var(--danger); }
.value.ok { color: var(--ok); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td { padding: .6rem .7rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data th { background: #f7fafc; font-size: .76rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); white-space: nowrap; }
table.data tr:last-child td { border-bottom: 0; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data .actions { white-space: nowrap; text-align: right; }
table.data .actions button { margin-left: .25rem; }
.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- forms ---------- */
.form-grid { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.field { display: flex; flex-direction: column; gap: .25rem; }
.field-label { font-size: .78rem; font-weight: 600; color: var(--muted); }
.field-hint { font-size: .75rem; color: var(--muted); }
.input {
  width: 100%; padding: .55rem .65rem; border: 1px solid var(--line); border-radius: 9px;
  font: inherit; background: #fff; color: var(--ink);
}
.input:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
textarea.input { min-height: 76px; resize: vertical; }
.check { display: flex; align-items: center; gap: .45rem; font-size: .88rem; }
.check input { width: 16px; height: 16px; }

.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink); padding: .5rem .85rem;
  border-radius: 9px; font: inherit; cursor: pointer;
}
.btn:hover { background: #f6f8fa; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #17405f; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--brand); padding: .35rem .5rem; }
.btn.small { padding: .3rem .55rem; font-size: .82rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn { border: 0; background: none; font-size: 1.15rem; cursor: pointer; color: var(--muted); padding: .1rem .3rem; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

.badge { display: inline-block; padding: .12rem .5rem; border-radius: 999px; font-size: .74rem; font-weight: 600; }
.badge-ok { background: #e3f4f1; color: var(--ok); }
.badge-warn { background: #fdf1e0; color: var(--warn); }
.badge-danger { background: #fdeceb; color: var(--danger); }
.badge-muted { background: #eef1f5; color: var(--muted); }

/* ---------- modal / toast ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(16,24,40,.45); display: grid; place-items: center; padding: 1rem; z-index: 60; }
.modal { background: var(--panel); border-radius: 14px; width: 100%; max-height: 92vh; overflow: auto; box-shadow: 0 24px 60px rgba(0,0,0,.28); }
.modal-head { display: flex; align-items: center; padding: 1rem 1.1rem .4rem; }
.modal-head h3 { flex: 1; font-size: 1.05rem; }
.modal-body { padding: .6rem 1.1rem 1rem; }
.modal-foot { display: flex; justify-content: flex-end; gap: .5rem; padding: .8rem 1.1rem 1.1rem; border-top: 1px solid var(--line); }
.toast-host { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 80; }
.toast { background: #16212e; color: #fff; padding: .6rem .9rem; border-radius: 9px; box-shadow: var(--shadow); opacity: 0; transform: translateY(8px); transition: all .25s; font-size: .9rem; }
.toast.show { opacity: 1; transform: none; }
.toast-error { background: var(--danger); }

/* ---------- meter photo ---------- */
.photo-zone { border: 1px dashed var(--line); border-radius: var(--radius); padding: .9rem; background: #fbfcfe; }
.photo-preview { position: relative; display: inline-block; max-width: 100%; margin-top: .6rem; }
.photo-preview img { display: block; max-width: 100%; max-height: 340px; border-radius: 8px; border: 1px solid var(--line); }
.crop-box { position: absolute; border: 2px solid #16a34a; background: rgba(22,163,74,.12); box-shadow: 0 0 0 9999px rgba(16,24,40,.42); cursor: move; }
.crop-hint { font-size: .8rem; color: var(--muted); margin-top: .5rem; }
.read-result { margin-top: .6rem; padding: .6rem .8rem; border-radius: 9px; background: #f1f6fb; border: 1px solid var(--line); font-size: .9rem; }
.read-result strong { font-size: 1.1rem; }

/* ---------- invoice preview ---------- */
.preview-wrap { overflow-x: auto; padding: .2rem; }
.invoice-toolbar { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .8rem; }

/* ---------- statement ---------- */
.statement-table td.st-num, .statement-table th.st-num { text-align: right; }
.statement-table td.st-date { white-space: nowrap; }
.st-ref { color: var(--muted); font-size: .82rem; }

/* ---------- misc ---------- */
.empty { padding: 2rem 1rem; text-align: center; color: var(--muted); }
.note { background: var(--brand-soft); border: 1px solid #cfe0ef; border-radius: 10px; padding: .7rem .9rem; font-size: .87rem; color: #1b3d5c; margin-bottom: .9rem; }
.warn-note { background: #fdf6e8; border: 1px solid #f2e0bd; color: #7a5312; }
.inline-list { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .86rem; color: var(--muted); }
.spacer { flex: 1; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

@media (max-width: 640px) {
  .page { padding: .8rem; }
  .stat .value { font-size: 1.25rem; }
  .topbar .who { display: none; }
}