/* Water meter portal. Mobile-first (BR-22). Brand colours come from brand.json
   via --brand / --brand-dark / --ink, set inline in base.html. */

:root {
  --bg: #f6f6f7;
  --surface: #ffffff;
  --text: #24242a;
  --muted: #6b6b75;
  --line: #e4e4e8;
  --ok: #1f8a4c;
  --ok-bg: #e5f5ec;
  --warn: #9a6200;
  --warn-bg: #fdf1dc;
  --bad: #c0352b;
  --bad-bg: #fbe7e5;
  --info: #2462b5;
  --info-bg: #e5eefb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 20, 30, .06), 0 1px 8px rgba(20, 20, 30, .04);
  --font: "Noto Sans", "Noto Sans Devanagari", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
a { color: var(--brand-dark); }
h1 { font-size: 1.35rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
p { margin: 0 0 .75rem; }
small, .muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mt { margin-top: 1rem; }
.mb0 { margin-bottom: 0; }

/* --- Top bar and navigation --- */
.topbar { background: var(--ink); color: #fff; }
.topbar-inner { max-width: 1180px; margin: 0 auto; padding: .55rem 16px; display: flex; align-items: center; gap: .75rem; }
.brand { display: flex; align-items: center; gap: .6rem; color: #fff; text-decoration: none; min-width: 0; flex: 1 1 auto; overflow: hidden; }
.brand img { height: 22px; width: auto; flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-by { font-size: .72rem; opacity: .75; }
.topbar .spacer { flex: 0; }
.topbar form, .topbar .btn-link { flex: none; }
.topbar select { max-width: 5.5rem; }
.topbar form.logout-top { display: none; }
.brand-name { font-size: .95rem; }
.topbar select, .topbar .btn-link { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.3); border-radius: 6px; padding: .25rem .4rem; font: inherit; font-size: .85rem; }
.topbar select option { color: var(--text); }
.topbar .btn-link { cursor: pointer; text-decoration: none; }
.user-name { font-size: .85rem; opacity: .85; display: none; }

.context-bar { background: var(--surface); border-bottom: 1px solid var(--line); }
.context-inner { max-width: 1180px; margin: 0 auto; padding: .5rem 16px 0; }
.context-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: .25rem .75rem; }
.context-title strong { font-size: 1rem; }
.tabs { display: flex; gap: .25rem; overflow-x: auto; scrollbar-width: none; margin-top: .35rem; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { padding: .5rem .7rem; color: var(--muted); text-decoration: none; border-bottom: 3px solid transparent; white-space: nowrap; font-weight: 500; }
.tabs a.active { color: var(--text); border-bottom-color: var(--brand); }
.tabs a .count { background: var(--bad); color: #fff; border-radius: 99px; font-size: .7rem; padding: 0 .4rem; margin-left: .25rem; }

main { max-width: 1180px; margin: 0 auto; padding: 1rem 16px 3rem; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .5rem 1rem; margin-bottom: 1rem; }
.page-head .actions { display: flex; flex-wrap: wrap; gap: .5rem; }

/* --- Cards and grids --- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem; }
.card > :last-child { margin-bottom: 0; }
.grid { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr); }
.grid > *, .stats > * { min-width: 0; }
.grid-2, .grid-3, .grid-4, .grid-main { grid-template-columns: minmax(0, 1fr); }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem .9rem; box-shadow: var(--shadow); min-width: 0; }
.stat .label { color: var(--muted); font-size: .8rem; }
.stat .value { font-size: 1.35rem; font-weight: 700; margin-top: .1rem; overflow-wrap: anywhere; }
.stat .sub { color: var(--muted); font-size: .8rem; }
.stat.accent { border-top: 3px solid var(--brand); }
.stat.bad .value { color: var(--bad); }

/* --- Tables --- */
.table-wrap { overflow-x: auto; margin: 0 -1rem; padding: 0 1rem; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
tr.row-link { cursor: pointer; }
tr.row-link:hover td { background: #fafafb; }

/* --- Badges --- */
.badge { display: inline-block; font-size: .74rem; font-weight: 600; padding: .1rem .5rem; border-radius: 99px; white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-bad { background: var(--bad-bg); color: var(--bad); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-muted { background: #eeeef1; color: var(--muted); }

/* --- Buttons and forms --- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; min-height: 40px; }
.btn:hover { border-color: #c9c9d0; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn-primary:hover { background: var(--brand); border-color: var(--brand); filter: brightness(.92); }
.btn-danger { color: var(--bad); }
.btn-sm { padding: .3rem .65rem; min-height: 32px; font-size: .85rem; }
.btn-block { width: 100%; }
form.inline { display: inline; }

.form-row { margin-bottom: .9rem; }
.form-row label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .25rem; }
.form-row .help { color: var(--muted); font-size: .8rem; margin-top: .2rem; }
.form-row .errorlist { color: var(--bad); list-style: none; padding: 0; margin: .25rem 0 0; font-size: .85rem; }
input[type=text], input[type=tel], input[type=email], input[type=password], input[type=number], input[type=date], input[type=file], select, textarea {
  width: 100%; padding: .55rem .65rem; border: 1px solid #cfcfd6; border-radius: 8px; font: inherit; background: #fff; color: var(--text); min-height: 42px;
}
textarea { min-height: 90px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 40%, transparent); border-color: var(--brand); }
.checkbox { display: flex; gap: .5rem; align-items: center; font-weight: 500; }
.checkbox input { width: 18px; height: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 0 1rem; }
.errors { background: var(--bad-bg); color: var(--bad); border-radius: 8px; padding: .6rem .8rem; margin-bottom: 1rem; }

/* --- Messages --- */
.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.messages li { padding: .65rem .9rem; border-radius: 8px; margin-bottom: .5rem; background: var(--info-bg); color: var(--info); }
.messages li.success { background: var(--ok-bg); color: var(--ok); }
.messages li.error { background: var(--bad-bg); color: var(--bad); }
.messages li.warning { background: var(--warn-bg); color: var(--warn); }

/* --- Alerts list --- */
.alert-item { display: flex; gap: .75rem; padding: .7rem 0; border-bottom: 1px solid var(--line); }
.alert-item:last-child { border-bottom: 0; }
.alert-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: .45rem; flex: none; background: var(--warn); }
.alert-dot.critical { background: var(--bad); }
.alert-dot.resolved { background: var(--ok); }
.alert-body { flex: 1; min-width: 0; }
.alert-meta { font-size: .8rem; color: var(--muted); }

/* --- Segmented control --- */
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.segmented a { padding: .4rem .8rem; text-decoration: none; color: var(--muted); font-weight: 600; font-size: .88rem; }
.segmented a + a { border-left: 1px solid var(--line); }
.segmented a.active { background: var(--brand); color: var(--on-brand); }

.chart-box { position: relative; height: 240px; }
.empty { color: var(--muted); text-align: center; padding: 1.5rem 0; }

/* --- Auth pages --- */
.auth-wrap { min-height: 100vh; display: flex; align-items: flex-start; justify-content: center; padding: 2.5rem 16px 1.5rem; background: linear-gradient(180deg, var(--ink) 0, var(--ink) 230px, var(--bg) 230px); }
.auth-card { width: 100%; max-width: 420px; }
.auth-brand { text-align: center; color: #fff; margin-bottom: 1.25rem; }
.auth-brand img { height: 44px; }
.auth-brand .name { font-size: 1.4rem; font-weight: 700; margin-top: .4rem; }
.auth-brand .tag { opacity: .8; font-size: .9rem; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; margin: -1rem -1rem 1rem; border-bottom: 1px solid var(--line); }
.auth-tabs a { text-align: center; padding: .8rem; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; }
.auth-tabs a.active { color: var(--text); border-bottom-color: var(--brand); }
.dev-note { background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: .5rem .75rem; font-size: .85rem; margin-bottom: 1rem; }
.lang-row { text-align: center; margin-top: 1rem; }
.lang-row button { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: .25rem .4rem; }
.lang-row button.active { color: var(--text); font-weight: 700; }

.footer { text-align: center; color: var(--muted); font-size: .78rem; padding: 1.5rem 16px; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: .35rem 1rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.chooser { display: grid; gap: .75rem; }
.chooser a { display: block; padding: 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--text); box-shadow: var(--shadow); }
.chooser a:hover { border-color: var(--brand); }
.chooser .role { font-size: .8rem; color: var(--muted); }

.slab-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: .5rem; align-items: end; margin-bottom: .5rem; }

@media (min-width: 640px) {
  .brand img { height: 28px; }
  .brand-name { font-size: 1rem; }
  .topbar select { max-width: 8rem; }
  .topbar form.logout-top { display: inline; }
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .user-name { display: inline; }
  .chooser { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 960px) {
  .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
  .chart-box { height: 280px; }
}

@media print {
  .topbar, .context-bar, .no-print, .footer { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: 0; }
}

/* Login links (D-34) */
.link-box { width: 100%; font-family: ui-monospace, Consolas, monospace; font-size: .85rem; overflow-wrap: anywhere; }
.demo-banner { background: var(--warn-bg); color: var(--warn); text-align: center; padding: .4rem 1rem; font-size: .85rem; }
.demo-logins { font-size: .85rem; margin-top: 1rem; }
.demo-logins td { padding: .2rem .4rem; }
