/* ==========================================================================
   USMS Monitor design system
   1. Tokens          2. Tabler remap     3. Base
   4. App shell       5. Primitives       6. Home
   7. Usage           8. Calendar         9. Readings and Activity
   10. Settings       11. Login           12. Motion and print
   Colours, radii, type and spacing come from the tokens below; components must
   not hard-code colours. Dark mode is the same tokens under [data-bs-theme].
   ========================================================================== */

/* 1. Tokens ------------------------------------------------------------- */
:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --fs-caption: .75rem;     /* 12 */
  --fs-footnote: .8125rem;  /* 13 */
  --fs-body: .9375rem;      /* 15 */
  --fs-headline: 1.0625rem; /* 17 */
  --fs-title3: 1.25rem;     /* 20 */
  --fs-title2: 1.5rem;      /* 24 */
  --fs-large: 2.125rem;     /* 34 */
  --fs-hero: 2.5rem;        /* 40 */

  --space-1: .25rem; --space-2: .5rem; --space-3: .75rem; --space-4: 1rem;
  --space-5: 1.25rem; --space-6: 1.5rem; --space-8: 2rem; --space-10: 2.5rem;
  --radius-s: .5rem; --radius-m: .75rem; --radius-l: 1rem; --radius-xl: 1.5rem; --radius-pill: 999px;

  --ease: cubic-bezier(.2, .8, .2, 1);
  --dur: .2s;
  --gutter: 1rem;
  --nav-rail: 5.5rem;
  --nav-side: 15.5rem;
  --content-max: 72rem;

  --meter-electric: var(--electric);
  --meter-water: var(--water);
}
html[data-bs-theme="light"], html:not([data-bs-theme]) {
  color-scheme: light;
  --bg: #f5f5f7; --surface: #ffffff; --surface-2: #f2f2f5; --surface-3: #e7e7ec;
  --text: #1d1d1f; --text-2: #66666b; --text-3: #8e8e93;
  --line: rgba(0, 0, 0, .09); --line-strong: rgba(0, 0, 0, .2);
  --accent: #0066cc; --accent-fill: #0071e3; --accent-hover: #0062c4; --accent-tint: rgba(0, 102, 204, .1); --on-accent: #fff;
  --electric: #f5a300; --electric-ink: #8a5700; --electric-tint: rgba(245, 163, 0, .16);
  --water: #1c9bd6; --water-ink: #00608a; --water-tint: rgba(28, 155, 214, .14);
  --success: #1f7a35; --success-tint: rgba(36, 138, 61, .12);
  --danger: #c4122a; --danger-tint: rgba(201, 22, 43, .1);
  --warn: #9a4a00; --warn-tint: rgba(255, 149, 0, .15);
  --cost: #55648a; --cost-tint: rgba(85, 100, 138, .12);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .04), 0 1px 1px rgba(0, 0, 0, .03);
  --shadow-pop: 0 8px 30px rgba(0, 0, 0, .14);
  --scrim: rgba(0, 0, 0, .38);
  --chart-grid: rgba(0, 0, 0, .06); --chart-tick: #6e6e73;
}
html[data-bs-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0a0c; --surface: #1c1c1e; --surface-2: #2a2a2d; --surface-3: #3a3a3e;
  --text: #f5f5f7; --text-2: #a1a1a8; --text-3: #6f6f76;
  --line: rgba(255, 255, 255, .1); --line-strong: rgba(255, 255, 255, .22);
  --accent: #4da3ff; --accent-fill: #0a74e6; --accent-hover: #5aaeff; --accent-tint: rgba(77, 163, 255, .18); --on-accent: #fff;
  --electric: #ffb340; --electric-ink: #ffc266; --electric-tint: rgba(255, 179, 64, .18);
  --water: #5ac8fa; --water-ink: #7dd3fc; --water-tint: rgba(90, 200, 250, .16);
  --success: #5fd477; --success-tint: rgba(95, 212, 119, .16);
  --danger: #ff7b7b; --danger-tint: rgba(255, 107, 107, .16);
  --warn: #ffb04d; --warn-tint: rgba(255, 149, 0, .18);
  --cost: #a3b4dc; --cost-tint: rgba(163, 180, 220, .16);
  --shadow-1: 0 0 0 1px rgba(255, 255, 255, .02);
  --shadow-pop: 0 10px 40px rgba(0, 0, 0, .6);
  --scrim: rgba(0, 0, 0, .6);
  --chart-grid: rgba(255, 255, 255, .08); --chart-tick: #a1a1a8;
}

/* 2. Tabler remap ------------------------------------------------------- */
/* Tabler reads its own variables; point them at the tokens so every form,
   table, badge, alert and button inherits the system without extra rules. */
html[data-bs-theme], html[data-bs-theme] body {
  --tblr-font-sans-serif: var(--font);
  --tblr-body-font-size: var(--fs-body);
  --tblr-body-bg: var(--bg);
  --tblr-body-color: var(--text);
  --tblr-secondary: var(--text-2);
  --tblr-muted: var(--text-2);
  --tblr-border-color: var(--line);
  --tblr-border-radius: var(--radius-m);
  --tblr-border-radius-lg: var(--radius-l);
  --tblr-bg-surface: var(--surface);
  --tblr-bg-surface-secondary: var(--surface-2);
  --tblr-bg-surface-tertiary: var(--surface-3);
  --tblr-primary: var(--accent);
  --tblr-link-color: var(--accent);
  --tblr-link-hover-color: var(--accent-hover);
  --tblr-success: var(--success);
  --tblr-danger: var(--danger);
  --tblr-warning: var(--warn);
  --tblr-azure: var(--water);
  --tblr-yellow: var(--electric);
  --tblr-orange: var(--cost);
  --tblr-purple: var(--cost);
  --tblr-indigo: var(--cost);
  --tblr-box-shadow: var(--shadow-1);
}
html[data-bs-theme="light"], html:not([data-bs-theme]) { --tblr-primary-rgb: 0, 102, 204; }
html[data-bs-theme="dark"] { --tblr-primary-rgb: 77, 163, 255; }

/* 3. Base --------------------------------------------------------------- */
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 4rem; overscroll-behavior-y: none; }
body {
  min-height: 100vh; min-height: 100dvh; margin: 0; color: var(--text); background: var(--bg);
  font-family: var(--font); font-size: var(--fs-body); line-height: 1.45;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; overflow-x: hidden;
}
h1, h2, h3, h4, h5, h6 { color: var(--text); letter-spacing: -.012em; }
p { margin-block: 0 var(--space-3); }
a { color: var(--accent); text-underline-offset: .15em; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-s); }
::selection { background: var(--accent-tint); }
.num, .tile-hero, .kpi-value, time, .history-placeholder-value, [data-comparison-current], [data-duration-current] { font-variant-numeric: tabular-nums; }
.skip-link { position: fixed; top: -4rem; left: var(--space-4); z-index: 2000; padding: var(--space-2) var(--space-4); color: var(--on-accent); background: var(--accent-fill); border-radius: var(--radius-m); text-decoration: none; transition: top var(--dur) var(--ease); }
.skip-link:focus { top: calc(env(safe-area-inset-top, 0px) + var(--space-2)); }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.icon { width: 1.25rem; height: 1.25rem; flex: none; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 1rem; height: 1rem; }
.text-secondary, .text-muted { color: var(--text-2) !important; }
.small, small { font-size: var(--fs-footnote); }

/* 4. App shell ---------------------------------------------------------- */
.app { min-height: 100vh; min-height: 100dvh; }
.wrap { width: 100%; max-width: var(--content-max); margin-inline: auto; padding-inline: calc(var(--gutter) + env(safe-area-inset-left, 0px)) calc(var(--gutter) + env(safe-area-inset-right, 0px)); }
.app-content { min-width: 0; padding-bottom: calc(4.75rem + env(safe-area-inset-bottom, 0px)); }

/* One navigation element: bottom bar on phones, rail on tablets, sidebar on desktop. */
.app-nav {
  position: fixed; inset: auto 0 0 0; z-index: 1040; display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 0px); border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 86%, transparent); -webkit-backdrop-filter: saturate(180%) blur(22px); backdrop-filter: saturate(180%) blur(22px);
}
.app-brand { display: none; align-items: center; gap: var(--space-3); color: var(--text); font-weight: 650; letter-spacing: -.01em; text-decoration: none; }
.app-brand img { width: 2rem; height: 2rem; }
.app-nav-items { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); width: 100%; max-width: 32rem; margin-inline: auto; }
.app-nav-item { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .15rem; min-height: 3.5rem; padding: .35rem .25rem; color: var(--text-2); font-size: var(--fs-caption); font-weight: 600; text-decoration: none; -webkit-tap-highlight-color: transparent; }
.nav-icon { display: grid; place-items: center; min-width: 3.5rem; height: 1.8rem; border-radius: var(--radius-pill); transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease); }
.app-nav-item:hover { color: var(--text); }
.app-nav-item.active { color: var(--accent); }
.app-nav-item.active .nav-icon { background: var(--accent-tint); }
.app-nav-foot { display: none; }

.app-bar { position: sticky; top: 0; z-index: 1030; padding-top: env(safe-area-inset-top, 0px); border-bottom: 1px solid transparent; background: color-mix(in srgb, var(--bg) 82%, transparent); -webkit-backdrop-filter: saturate(180%) blur(22px); backdrop-filter: saturate(180%) blur(22px); transition: border-color var(--dur) var(--ease), background-color var(--dur) var(--ease); }
.app-bar.is-scrolled { border-bottom-color: var(--line); background: color-mix(in srgb, var(--surface) 86%, transparent); }
.app-bar-inner { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); min-height: 3rem; }
.app-bar-title { font-size: var(--fs-headline); font-weight: 650; opacity: 0; transform: translateY(4px); transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease); }
.app-bar.is-scrolled .app-bar-title { opacity: 1; transform: none; }
.app-bar-actions { display: flex; align-items: center; gap: var(--space-1); margin-left: auto; }
.icon-button { display: inline-grid; place-items: center; width: 2.5rem; height: 2.5rem; padding: 0; color: var(--text-2); border: 0; border-radius: var(--radius-pill); background: transparent; cursor: pointer; transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease); -webkit-tap-highlight-color: transparent; }
.icon-button:hover { color: var(--text); background: var(--surface-3); }
.icon-button:disabled { opacity: .45; cursor: default; }
.icon-button.is-spinning .icon { animation: spin 1s linear infinite; }
html[data-bs-theme="dark"] .icon-moon, html[data-bs-theme="light"] .icon-sun, html:not([data-bs-theme]) .icon-sun { display: none; }

.page-head { padding-block: var(--space-2) var(--space-4); }
.page-title { margin: 0 0 var(--space-2); font-size: var(--fs-large); font-weight: 700; letter-spacing: -.025em; line-height: 1.1; }
.status-line { display: inline-flex; align-items: center; gap: var(--space-2); max-width: 100%; min-height: 2rem; padding: .15rem var(--space-3) .15rem var(--space-2); color: var(--text-2); font: inherit; font-size: var(--fs-footnote); border: 0; border-radius: var(--radius-pill); background: transparent; cursor: pointer; text-align: left; transition: background-color var(--dur) var(--ease); -webkit-tap-highlight-color: transparent; }
.status-line:hover { background: var(--surface-3); }
.status-dot { width: .5rem; height: .5rem; flex: none; border-radius: 50%; background: var(--text-3); }
.status-line[data-tone="green"] .status-dot { background: var(--success); }
.status-line[data-tone="yellow"] .status-dot, .status-line[data-tone="orange"] .status-dot { background: var(--warn); }
.status-line[data-tone="red"] .status-dot { background: var(--danger); }
.status-line.is-running .status-dot { background: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
.status-text { color: var(--text); font-weight: 600; white-space: nowrap; }
#status-age { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-foot { margin-top: var(--space-8); color: var(--text-2); font-size: var(--fs-caption); text-align: center; }
#usms-reconnect-notice { margin-bottom: var(--space-4); }
.app-main { min-width: 0; outline: none; }

@media (min-width: 768px) {
  :root { --gutter: 1.5rem; }
  .app-nav { inset: 0 auto 0 0; width: var(--nav-rail); padding: calc(var(--space-6) + env(safe-area-inset-top, 0px)) 0 var(--space-4); border-top: 0; border-right: 1px solid var(--line); background: var(--surface); }
  .app-brand { display: flex; justify-content: center; margin-bottom: var(--space-6); }
  .app-brand span { display: none; }
  .app-nav-items { display: flex; flex-direction: column; gap: var(--space-2); max-width: none; }
  .app-nav-item { min-height: 4rem; gap: .2rem; }
  .app-nav-foot { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); margin-top: auto; }
  .app-content { margin-left: var(--nav-rail); padding-bottom: var(--space-8); }
  .app-bar { background: transparent; }
  .app-bar.is-scrolled { background: color-mix(in srgb, var(--bg) 86%, transparent); }
  .app-bar-title { display: none; }
  .page-head { padding-top: var(--space-4); }
  .page-title { font-size: 2.5rem; }
}
@media (min-width: 1200px) {
  :root { --gutter: 2rem; }
  .app-nav { width: var(--nav-side); padding-inline: var(--space-4); }
  .app-brand { justify-content: flex-start; padding-inline: var(--space-2); }
  .app-brand span { display: inline; }
  .app-nav-items { gap: .15rem; }
  .app-nav-item { flex-direction: row; justify-content: flex-start; gap: var(--space-3); min-height: 2.75rem; padding: .5rem var(--space-3); font-size: var(--fs-body); border-radius: var(--radius-m); }
  .nav-icon { min-width: 0; height: auto; background: none !important; }
  .app-nav-item:hover { background: var(--surface-2); }
  .app-nav-item.active { background: var(--accent-tint); }
  .app-nav-foot { align-items: stretch; }
  .app-content { margin-left: var(--nav-side); }
}

/* 5. Primitives --------------------------------------------------------- */
.btn { min-height: 2.5rem; padding-inline: var(--space-4); font-weight: 600; font-size: var(--fs-body); border-radius: var(--radius-m); transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease), transform .12s var(--ease); }
.btn:active:not(:disabled) { transform: scale(.98); }
.btn-sm { min-height: 2rem; padding-inline: var(--space-3); font-size: var(--fs-footnote); }
.btn-primary { --tblr-btn-bg: var(--accent-fill); --tblr-btn-border-color: var(--accent-fill); --tblr-btn-hover-bg: var(--accent-hover); --tblr-btn-hover-border-color: var(--accent-hover); --tblr-btn-color: var(--on-accent); --tblr-btn-hover-color: var(--on-accent); --tblr-btn-active-bg: var(--accent-hover); --tblr-btn-disabled-bg: var(--accent-fill); --tblr-btn-disabled-border-color: var(--accent-fill); box-shadow: none; }
.btn-outline-primary, .btn-outline-secondary { --tblr-btn-color: var(--accent); --tblr-btn-border-color: var(--line-strong); --tblr-btn-bg: transparent; --tblr-btn-hover-bg: var(--accent-tint); --tblr-btn-hover-color: var(--accent); --tblr-btn-hover-border-color: var(--line-strong); --tblr-btn-active-bg: var(--accent-tint); --tblr-btn-active-color: var(--accent); --tblr-btn-active-border-color: var(--line-strong); }
.btn-outline-secondary { --tblr-btn-color: var(--text); --tblr-btn-hover-color: var(--text); --tblr-btn-hover-bg: var(--surface-3); }
.btn-outline-danger { --tblr-btn-color: var(--danger); --tblr-btn-border-color: var(--line-strong); --tblr-btn-hover-bg: var(--danger-tint); --tblr-btn-hover-color: var(--danger); --tblr-btn-hover-border-color: var(--line-strong); }
.btn-ghost-secondary { --tblr-btn-color: var(--text-2); }
.btn:disabled, .btn.disabled { opacity: .5; }
.btn-group .btn { box-shadow: none; }
.form-control, .form-select { min-height: 2.75rem; color: var(--text); border: 1px solid var(--line-strong); border-radius: var(--radius-m); background-color: var(--surface); font-size: var(--fs-body); transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease); }
.form-control-sm { min-height: 2.25rem; }
.form-control:focus, .form-select:focus { border-color: var(--accent); box-shadow: 0 0 0 .2rem var(--accent-tint); }
.form-label { margin-bottom: var(--space-1); color: var(--text); font-weight: 600; font-size: var(--fs-footnote); }
.form-check-input { border-color: var(--line-strong); }
.form-check-input:checked { background-color: var(--accent-fill); border-color: var(--accent-fill); }
.form-switch .form-check-input { width: 2.5rem; height: 1.5rem; }
.invalid-feedback, .text-danger { color: var(--danger) !important; }

.card { margin: 0; color: var(--text); border: 1px solid var(--line); border-radius: var(--radius-l); background: var(--surface); box-shadow: var(--shadow-1); }
.card-header { padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--line); background: transparent; }
.card-body { padding: var(--space-5); }
.card-footer { border-top: 1px solid var(--line); background: transparent; }
.card-title { margin: 0; font-size: var(--fs-headline); font-weight: 650; }
.card-subtitle { margin: .1rem 0 0; color: var(--text-2); font-size: var(--fs-footnote); }
.card-status-start { display: none; }
.row-cards { --tblr-gutter-x: var(--space-4); --tblr-gutter-y: var(--space-4); }
.stack { display: grid; gap: var(--space-4); }
.section-title { margin: var(--space-6) var(--space-1) var(--space-2); color: var(--text-2); font-size: var(--fs-caption); font-weight: 650; letter-spacing: .04em; text-transform: uppercase; }
.surface { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-l); background: var(--surface); box-shadow: var(--shadow-1); }
.surface-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-4) var(--space-5); }
.surface-head h2 { margin: 0; font-size: var(--fs-headline); font-weight: 650; }
.surface-head a, .link-action { font-size: var(--fs-footnote); font-weight: 600; text-decoration: none; }
.link-action { padding: 0; color: var(--accent); border: 0; background: none; cursor: pointer; }

.badge { font-weight: 600; border-radius: var(--radius-pill); }
.badge.bg-green-lt { color: var(--success) !important; background: var(--success-tint) !important; }
.badge.bg-red-lt { color: var(--danger) !important; background: var(--danger-tint) !important; }
.badge.bg-yellow-lt { color: var(--electric-ink) !important; background: var(--electric-tint) !important; }
.badge.bg-azure-lt { color: var(--water-ink) !important; background: var(--water-tint) !important; }
.badge.bg-secondary-lt, .badge.bg-purple-lt, .badge.bg-blue-lt { color: var(--text-2) !important; background: var(--surface-2) !important; }
.alert { border: 0; border-radius: var(--radius-m); box-shadow: none; }
.alert-warning { color: var(--warn); background: var(--warn-tint); }
.alert-danger { color: var(--danger); background: var(--danger-tint); }
.alert-info { color: var(--text); background: var(--accent-tint); }
.alert-success { color: var(--success); background: var(--success-tint); }
.alert-link { color: inherit; font-weight: 650; }
.progress { height: .4rem; border-radius: var(--radius-pill); background: var(--surface-3); box-shadow: none; }
.progress-bar { border-radius: inherit; background: var(--accent-fill); }

.segmented { display: inline-flex; max-width: 100%; padding: .1875rem; gap: .125rem; border-radius: var(--radius-m); background: var(--surface-3); }
.segmented > button, .segmented > .nav-link { flex: 1 1 auto; min-height: 2.25rem; padding: .35rem var(--space-4); color: var(--text-2); font: inherit; font-size: var(--fs-footnote); font-weight: 600; border: 0; border-radius: calc(var(--radius-m) - .1875rem); background: transparent; cursor: pointer; white-space: nowrap; transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease), box-shadow var(--dur) var(--ease); }
.segmented > button:hover, .segmented > .nav-link:hover { color: var(--text); }
.segmented > button[aria-pressed="true"], .segmented > button[aria-selected="true"], .segmented > .nav-link.active { color: var(--text); background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, .14), 0 0 0 1px var(--line); }
.segmented-full { display: flex; width: 100%; }
.chip { display: inline-flex; align-items: center; gap: var(--space-1); min-height: 1.75rem; padding: .15rem var(--space-3); color: var(--text-2); font-size: var(--fs-caption); font-weight: 600; border: 1px solid var(--line); border-radius: var(--radius-pill); background: var(--surface); }

.banner { display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-radius: var(--radius-l); font-size: var(--fs-body); }
.banner .icon { margin-top: .1rem; }
.banner-title { font-weight: 650; }
.banner-body { margin: 0; opacity: .92; }
.banner-warning { color: var(--warn); background: var(--warn-tint); }
.banner-danger { color: var(--danger); background: var(--danger-tint); }
.banner-info { color: var(--text); background: var(--accent-tint); }
.banner a { color: inherit; font-weight: 650; }

.list { margin: 0; padding: 0; list-style: none; }
.list-row { display: flex; align-items: center; gap: var(--space-3); min-height: 3.5rem; padding: var(--space-3) var(--space-5); border-top: 1px solid var(--line); }
.list-row:first-child { border-top: 0; }
.row-icon { display: grid; place-items: center; width: 2.25rem; height: 2.25rem; flex: none; color: var(--text-2); border-radius: var(--radius-m); background: var(--surface-2); }
.row-icon-topup { color: var(--success); background: var(--success-tint); }
.row-icon-electricity { color: var(--electric-ink); background: var(--electric-tint); }
.row-icon-water { color: var(--water-ink); background: var(--water-tint); }
.row-main { min-width: 0; flex: 1; }
.row-title { font-weight: 600; }
.row-meta { color: var(--text-2); font-size: var(--fs-footnote); }
.row-value { flex: none; font-weight: 650; text-align: right; font-variant-numeric: tabular-nums; }
.row-value-positive { color: var(--success); }
.list-empty { padding: var(--space-6) var(--space-5); color: var(--text-2); text-align: center; }

.empty-state, .empty-state-compact { display: grid; justify-items: center; align-content: center; gap: var(--space-2); min-height: 14rem; padding: var(--space-8) var(--space-5); color: var(--text-2); text-align: center; }
.empty-state .icon { width: 2.5rem; height: 2.5rem; color: var(--text-3); }
.empty-state strong { color: var(--text); font-size: var(--fs-headline); }
.empty-state p { max-width: 28rem; margin: 0; }
.dashboard-loading { display: grid; place-content: center; justify-items: center; gap: var(--space-3); min-height: 16rem; color: var(--text-2); }

.skeleton, .skeleton-line { display: block; border-radius: var(--radius-s); background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; }
.skeleton-line { height: 1rem; }
.skeleton-tile { min-height: 14rem; border-radius: var(--radius-xl); }

/* Bottom sheet / dialog */
dialog.sheet { width: min(100vw, 34rem); max-width: 100vw; max-height: 88dvh; margin: auto auto 0; padding: 0; color: var(--text); border: 0; border-radius: var(--radius-xl) var(--radius-xl) 0 0; background: var(--surface); box-shadow: var(--shadow-pop); overflow: hidden; }
dialog.sheet[open] { display: flex; flex-direction: column; animation: sheet-up .28s var(--ease); }
dialog.sheet::backdrop { background: var(--scrim); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); animation: fade-in .2s ease; }
.sheet-grabber { width: 2.25rem; height: .25rem; margin: var(--space-2) auto 0; border-radius: var(--radius-pill); background: var(--line-strong); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-3) var(--space-3) var(--space-2) var(--space-5); }
.sheet-head h2 { margin: 0; font-size: var(--fs-title3); font-weight: 700; }
.sheet-body { padding: 0 var(--space-5) calc(var(--space-5) + env(safe-area-inset-bottom, 0px)); overflow-y: auto; overscroll-behavior: contain; }
.sheet-list { margin: 0 0 var(--space-4); }
.sheet-list > div { display: flex; justify-content: space-between; gap: var(--space-4); padding: var(--space-3) 0; border-top: 1px solid var(--line); }
.sheet-list > div:first-child { border-top: 0; }
.sheet-list dt { color: var(--text-2); font-weight: 500; }
.sheet-list dd { margin: 0; font-weight: 600; text-align: right; overflow-wrap: anywhere; }
@media (min-width: 768px) {
  dialog.sheet { margin: auto; border-radius: var(--radius-xl); }
  dialog.sheet .sheet-grabber { display: none; }
}

/* Toasts */
.toast-region { position: fixed; z-index: 2100; left: 50%; bottom: calc(5rem + env(safe-area-inset-bottom, 0px)); display: grid; gap: var(--space-2); width: min(calc(100vw - 2rem), 26rem); transform: translateX(-50%); pointer-events: none; }
.toast-item { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); color: var(--text); font-weight: 500; border: 1px solid var(--line); border-radius: var(--radius-l); background: var(--surface); box-shadow: var(--shadow-pop); pointer-events: auto; animation: toast-in .3s var(--ease); }
.toast-item .icon { color: var(--success); }
.toast-item.is-error .icon { color: var(--danger); }
.toast-item.is-leaving { opacity: 0; transform: translateY(8px); transition: opacity .2s ease, transform .2s ease; }
@media (min-width: 768px) { .toast-region { left: auto; right: var(--space-6); bottom: var(--space-6); transform: none; } }

/* Pull to sync */
.pull-indicator { position: fixed; top: calc(env(safe-area-inset-top, 0px) + .5rem); left: 50%; z-index: 1090; display: flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-4); color: var(--text); font-size: var(--fs-footnote); font-weight: 600; border: 1px solid var(--line); border-radius: var(--radius-pill); background: var(--surface); box-shadow: var(--shadow-pop); opacity: 0; pointer-events: none; transform: translate(-50%, -120%); transition: opacity .15s, transform .15s; }
.pull-indicator.visible { opacity: 1; }
.pull-indicator-icon { color: var(--accent); font-weight: 700; transition: transform .15s; }
.pull-indicator.ready .pull-indicator-icon { transform: rotate(180deg); }

/* 6. Home --------------------------------------------------------------- */
.tile-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-4); }
@media (min-width: 720px) { .tile-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.tile { --tile-ink: var(--text-2); --tile-tint: var(--surface-2); --tile-line: var(--text-3); position: relative; display: flex; flex-direction: column; min-width: 0; padding: var(--space-5); color: var(--text); text-decoration: none; border: 1px solid var(--line); border-radius: var(--radius-xl); background: var(--surface); box-shadow: var(--shadow-1); transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease); -webkit-tap-highlight-color: transparent; }
a.tile, a.tile:hover, a.tile:focus-visible { color: var(--text); }
.tile:hover { border-color: var(--line-strong); box-shadow: var(--shadow-pop); }
.tile-electricity { --tile-ink: var(--electric-ink); --tile-tint: var(--electric-tint); --tile-line: var(--electric); }
.tile-water { --tile-ink: var(--water-ink); --tile-tint: var(--water-tint); --tile-line: var(--water); }
.tile-head { display: flex; align-items: center; gap: var(--space-3); margin-bottom: var(--space-4); }
.tile-icon { display: grid; place-items: center; width: 2.25rem; height: 2.25rem; flex: none; color: var(--tile-ink); border-radius: var(--radius-m); background: var(--tile-tint); }
.tile-name { font-size: var(--fs-headline); font-weight: 650; }
.tile-flag { margin-left: var(--space-1); }
.tile-chevron { margin-left: auto; color: var(--text-3); }
.tile-hero { font-size: var(--fs-hero); font-weight: 700; letter-spacing: -.035em; line-height: 1.05; overflow-wrap: anywhere; }
.tile-hero[data-duration-state="loading"] { color: var(--text-3); }
.tile-sub { margin-top: var(--space-1); color: var(--text-2); }
.tile-dot { margin-inline: var(--space-2); }
.tile-note { min-height: 1.2em; margin-top: var(--space-1); color: var(--text-2); font-size: var(--fs-footnote); }
.tile--no-runway [data-tile-balance], .tile--no-runway .tile-dot { display: none; }
.tile-spark { position: relative; height: 3.5rem; margin: var(--space-3) calc(var(--space-2) * -1) 0; }
.tile-spark canvas { width: 100% !important; height: 100% !important; }
.tile-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-1) var(--space-3); margin-top: var(--space-3); padding-top: var(--space-3); color: var(--text-2); font-size: var(--fs-footnote); border-top: 1px solid var(--line); }
.delta { font-weight: 600; white-space: nowrap; }
.delta-up { color: var(--success); }

/* 7. Usage --------------------------------------------------------------- */
.usage-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
.history-meter-card { --history-meter-color: var(--text-2); --history-meter-ink: var(--text-2); display: grid; gap: var(--space-4); }
.history-meter-card-electricity { --history-meter-color: var(--electric); --history-meter-ink: var(--electric-ink); }
.history-meter-card-water { --history-meter-color: var(--water); --history-meter-ink: var(--water-ink); }
.history-meter-card > [data-history-analytics] { display: flex; flex-direction: column; gap: var(--space-4); }
.history-metrics-region { order: 0; }
.history-tab-region { order: 1; }
.insights-comparisons { order: 2; }

.history-filter { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); }
.range-presets { display: inline-flex; }
.range-custom { position: relative; }
.range-custom > summary { display: inline-flex; align-items: center; gap: var(--space-1); min-height: 2.25rem; padding: .35rem var(--space-3); color: var(--accent); font-size: var(--fs-footnote); font-weight: 600; list-style: none; cursor: pointer; border-radius: var(--radius-m); }
.range-custom > summary::-webkit-details-marker { display: none; }
.range-custom > summary:hover { background: var(--accent-tint); }
.range-custom-panel { position: absolute; z-index: 20; top: calc(100% + var(--space-2)); left: 0; display: grid; gap: var(--space-3); width: min(20rem, calc(100vw - 2rem)); padding: var(--space-4); border: 1px solid var(--line); border-radius: var(--radius-l); background: var(--surface); box-shadow: var(--shadow-pop); }
.range-custom-panel .form-label > span { display: block; margin-bottom: var(--space-1); }
.history-filter .invalid-feedback { margin: 0; font-size: var(--fs-footnote); }
.history-filter .invalid-feedback:empty { display: none !important; }

.history-metrics-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-4); }
.history-kpi { display: block; min-width: 0; padding: var(--space-4) var(--space-5); border: 1px solid var(--line); border-radius: var(--radius-l); background: var(--surface); box-shadow: var(--shadow-1); }
.history-kpi-icon, .history-kpi-unit, .history-kpi-coverage { display: none; }
.history-kpi-content { min-width: 0; }
.metric-label { color: var(--text-2); font-size: var(--fs-footnote); font-weight: 600; letter-spacing: 0; text-transform: none; }
.history-placeholder-value { min-height: 1.9rem; color: var(--text); font-size: var(--fs-title2); font-weight: 700; letter-spacing: -.02em; line-height: 1.25; overflow-wrap: anywhere; }
.history-kpi-total .history-placeholder-value { font-size: var(--fs-large); }
.history-kpi-cost [data-history-metric-value="cost"].is-estimated { color: var(--cost); }
.history-metrics-region.is-loading .history-placeholder-value { width: 60%; min-height: 1rem; margin-top: var(--space-2); color: transparent; border-radius: var(--radius-s); background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; }
.history-metrics-region.is-loading .history-explanation { display: none; }
.history-methodology { margin-top: var(--space-2); }
.history-methodology > summary, .history-reading-disclosure > summary, .advanced-settings > summary { min-height: 2.5rem; padding: var(--space-3) var(--space-1); color: var(--accent); font-size: var(--fs-footnote); font-weight: 600; cursor: pointer; }
.history-explanation { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); padding: var(--space-3) var(--space-4); border-radius: var(--radius-m); background: var(--surface-2); }
.history-explanation-text { line-height: 1.5; }
.history-coverage-status { flex: none; }

.history-tab-region { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-l); background: var(--surface); box-shadow: var(--shadow-1); }
.history-primary-tabs, .history-period-tabs { display: flex; flex-wrap: nowrap; gap: .125rem; margin: var(--space-4) var(--space-4) var(--space-3); padding: .1875rem; border: 0; border-radius: var(--radius-m); background: var(--surface-3); }
.history-period-tabs { display: inline-flex; margin: 0 0 var(--space-3); }
.history-primary-tabs .nav-link, .history-period-tabs .nav-link { display: flex; align-items: center; justify-content: center; flex: 1 1 0; min-height: 2.25rem; margin: 0; padding: .35rem var(--space-3); color: var(--text-2); font-size: var(--fs-footnote); font-weight: 600; text-align: center; border: 0; border-radius: calc(var(--radius-m) - .1875rem); background: transparent; }
.history-primary-tabs .nav-link:hover, .history-period-tabs .nav-link:hover { color: var(--text); }
.history-primary-tabs .nav-link.active, .history-period-tabs .nav-link.active { color: var(--text); background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, .14), 0 0 0 1px var(--line); }
.history-visualization { padding: 0 var(--space-4) var(--space-4); }
.history-visualization[hidden], .history-period-panel[hidden] { display: none !important; }
.history-chart-shell { position: relative; min-height: 14rem; }
.history-chart-frame { position: relative; width: 100%; height: 18rem; overflow: hidden; }
.history-chart-frame canvas { display: block; width: 100% !important; height: 100% !important; touch-action: pan-y; }
.history-chart-frame:has(canvas[hidden]), .history-chart-shell:has(canvas[hidden]) .chart-interaction-toolbar, .history-chart-shell:has(canvas[hidden]) .chart-selection-detail { display: none; }
.chart-interaction-toolbar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-2); color: var(--text-2); font-size: var(--fs-caption); }
.consumption-refresh-status { margin-left: auto; color: var(--text-2); font-size: var(--fs-caption); font-weight: 600; }
.chart-selection-detail { min-height: 2.25rem; margin-top: var(--space-2); padding: var(--space-2) var(--space-3); color: var(--text-2); border-radius: var(--radius-m); background: var(--surface-2); overflow-wrap: anywhere; }
.chart-selection-detail[data-selection-state="selected"] { color: var(--text) !important; }
.history-event-legend { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); margin-bottom: var(--space-3); color: var(--text-2); font-size: var(--fs-footnote); }
.history-event-marker { display: inline-flex; align-items: center; justify-content: center; width: 1.25rem; height: 1.25rem; margin-right: .2rem; border: 1px solid currentColor; border-radius: .25rem; font-weight: 700; line-height: 1; }
.history-event-marker-consumption, .history-event-marker-unchanged { color: var(--text-2); }
.history-event-marker-top-up { color: var(--success); }
.history-event-marker-unchanged { border-radius: 50%; }
.remaining-trend-controls { margin-bottom: var(--space-3); padding: var(--space-3) var(--space-4); border-radius: var(--radius-m); background: var(--surface-2); }
.remaining-trend-controls .form-check { margin: 0; }
.history-trend-status { max-width: 58rem; }
.history-state { display: grid; align-content: center; justify-items: center; gap: var(--space-1); min-height: 14rem; padding: var(--space-5); color: var(--text-2); text-align: center; }
.history-state strong { color: var(--text); }
.history-state-loading::before { content: ""; width: 1.75rem; height: 1.75rem; margin-bottom: var(--space-2); border: .2rem solid var(--surface-3); border-top-color: var(--accent); border-radius: 50%; animation: spin .75s linear infinite; }
.history-state-error { color: var(--danger); }
.history-state-missing { min-height: auto; justify-items: start; text-align: left; font-size: var(--fs-footnote); margin-bottom: var(--space-3); padding: var(--space-3) var(--space-4); color: var(--warn); border-radius: var(--radius-m); background: var(--warn-tint); }
.history-state-missing strong { color: inherit; font-size: var(--fs-footnote); }

.history-summary-row { --tblr-gutter-y: var(--space-3); --tblr-gutter-x: var(--space-3); }
.history-summary-card { height: 100%; }
.history-summary-card .card-body { padding: var(--space-4); }
.history-comparison-current, .history-duration-current { font-size: var(--fs-title2); font-weight: 700; letter-spacing: -.02em; overflow-wrap: anywhere; }
.history-comparison-previous { min-height: 1.25rem; overflow-wrap: anywhere; }
.history-comparison-status { min-height: 2.25rem; color: var(--text-2); overflow-wrap: anywhere; }
.history-comparison-cost { display: flex; flex-direction: column; gap: .1rem; }
.history-comparison-cost-current { color: var(--cost); font-weight: 650; }
.history-duration-card { border-color: color-mix(in srgb, var(--history-meter-color) 45%, var(--line)); }
.history-duration-estimate, .history-duration-average, .history-duration-coverage { min-height: 1.25rem; overflow-wrap: anywhere; }
.comparison-direction { display: inline-flex; align-items: flex-start; gap: .25rem; font-weight: 600; }
.comparison-direction-higher { color: var(--danger); }
.comparison-direction-lower { color: var(--success); }
.comparison-direction-unchanged, .comparison-direction-unavailable { color: var(--text-2); }

.history-reading-disclosure { border: 1px solid var(--line); border-radius: var(--radius-l); background: var(--surface); box-shadow: var(--shadow-1); overflow: hidden; }
.history-reading-disclosure > summary { padding: var(--space-4) var(--space-5); color: var(--text); font-size: var(--fs-body); font-weight: 650; }
.history-log-heading { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-3) var(--space-5); border-top: 1px solid var(--line); background: var(--surface-2); }
.history-log-loading { padding: var(--space-5); color: var(--text-2); }
.history-reading-historical { background: var(--cost-tint); }
.history-source-badge { color: var(--cost); background: var(--cost-tint); }
.history-usage-value, .history-estimated-cost, .history-estimated-rate { color: var(--cost); font-weight: 650; white-space: nowrap; }
.history-balance-unavailable { margin-top: .2rem; color: var(--text-2); font-size: var(--fs-footnote); }

/* 8. Calendar ----------------------------------------------------------- */
.calendar-shell { --calendar-accent: var(--history-meter-color, var(--accent)); min-height: 18rem; }
.calendar-controls { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); }
.calendar-current-month, .calendar-month-title { flex: 1; margin: 0; color: var(--text); font-size: var(--fs-headline); font-weight: 650; text-align: center; }
.calendar-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-3); }
.calendar-meter-badge { flex: none; padding: .25rem var(--space-3); color: var(--history-meter-ink, var(--text-2)); font-size: var(--fs-caption); font-weight: 650; border-radius: var(--radius-pill); background: color-mix(in srgb, var(--calendar-accent) 14%, transparent); }
.calendar-grid-wrap { overflow-x: auto; padding: .25rem; border-radius: var(--radius-m); background: var(--surface-2); }
.calendar-weekdays, .calendar-week { display: grid; grid-template-columns: repeat(7, minmax(2.4rem, 1fr)); gap: .3rem; min-width: 20rem; }
.calendar-weekdays { padding: .35rem .35rem .5rem; color: var(--text-2); font-size: var(--fs-caption); font-weight: 650; text-align: center; }
.calendar-grid { display: grid; gap: .3rem; min-width: 20rem; }
.calendar-week { min-height: 3.5rem; }
.calendar-cell { min-width: 0; }
.calendar-day { position: relative; display: grid; place-items: center; width: 100%; min-height: 3.5rem; padding: .4rem .15rem; color: var(--text); font-weight: 650; border: 1px solid transparent; border-radius: var(--radius-m); background: var(--surface); transition: border-color var(--dur) var(--ease), background-color var(--dur) var(--ease); }
.calendar-day:hover { border-color: var(--line-strong); }
.calendar-day[aria-current="date"]::after { content: ""; position: absolute; right: .3rem; bottom: .3rem; width: .35rem; height: .35rem; border-radius: 50%; background: var(--accent); }
.calendar-day-number { font-variant-numeric: tabular-nums; }
.calendar-day-cost { display: block; max-width: 100%; margin-top: .1rem; overflow: hidden; color: var(--cost); font-size: var(--fs-caption); font-weight: 650; line-height: 1.1; text-overflow: ellipsis; white-space: nowrap; }
.calendar-intensity-none { background: var(--surface); }
.calendar-intensity-low { background: color-mix(in srgb, var(--calendar-accent) 22%, var(--surface)); }
.calendar-intensity-medium { background: color-mix(in srgb, var(--calendar-accent) 42%, var(--surface)); }
.calendar-intensity-high { color: #1d1d1f; background: color-mix(in srgb, var(--calendar-accent) 68%, var(--surface)); }
.calendar-intensity-very-high { color: #1d1d1f; background: color-mix(in srgb, var(--calendar-accent) 90%, var(--surface)); }
.calendar-intensity-high .calendar-day-cost, .calendar-intensity-very-high .calendar-day-cost { color: #1d1d1f; }
.calendar-day-zero { border-style: double; border-color: var(--line-strong); }
.calendar-day-missing { color: var(--text-2); border: 1px dashed var(--line-strong); background: repeating-linear-gradient(135deg, var(--surface-2), var(--surface-2) .3rem, transparent .3rem, transparent .6rem); }
.calendar-day-partial { color: var(--warn); border: 1px dotted var(--warn); background: var(--warn-tint); }
.calendar-day-future { color: var(--text-2); border: 1px dashed var(--line); opacity: .55; background: transparent; }
.calendar-day-unusually-high { border: 2px solid var(--danger); }
.calendar-legend { display: grid; gap: var(--space-2); margin-top: var(--space-4); color: var(--text-2); font-size: var(--fs-caption); }
.calendar-legend-group, .calendar-legend-items { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-3); }
.calendar-legend-title { color: var(--text); font-weight: 650; }
.calendar-legend-item { display: inline-flex; align-items: center; gap: .3rem; }
.calendar-swatch, .calendar-state-marker { display: inline-block; width: .9rem; height: .9rem; border: 1px solid var(--line-strong); border-radius: .2rem; }
.calendar-state-marker { background: var(--surface); }
.calendar-state-zero { border-style: double; }
.calendar-state-missing { border-style: dashed; background: repeating-linear-gradient(135deg, var(--surface-3), var(--surface-3) .2rem, transparent .2rem, transparent .4rem); }
.calendar-state-partial { border-style: dotted; background: var(--warn-tint); }
.calendar-state-future { border-style: dashed; }
.calendar-state-unusually-high { border: 2px solid var(--danger); }
.calendar-note { margin-top: var(--space-3); }

/* 9. Readings, Activity and reports ------------------------------------ */
.table { --tblr-table-bg: transparent; margin: 0; color: var(--text); }
.table > :not(caption) > * > * { padding: var(--space-3) var(--space-5); border-bottom-color: var(--line); background: transparent; }
.table thead th { color: var(--text-2); font-size: var(--fs-caption); font-weight: 650; letter-spacing: 0; text-transform: none; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.table-responsive { position: relative; max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; }
.table tbody tr:last-child > * { border-bottom: 0; }
.meter-icon { display: inline-grid; place-items: center; width: 2.25rem; height: 2.25rem; flex: none; color: var(--text-2); border-radius: var(--radius-m); background: var(--surface-2); }
.reading-meter-electricity .meter-icon { color: var(--electric-ink); background: var(--electric-tint); }
.reading-meter-water .meter-icon { color: var(--water-ink); background: var(--water-tint); }
.reading-meter-time { display: flex; align-items: center; gap: var(--space-3); min-width: 11rem; }
.reading-meter-details { display: flex; flex-direction: column; align-items: flex-start; gap: .25rem; }
.reading-time-primary { color: var(--text); font-weight: 600; overflow-wrap: anywhere; }
.reading-time-secondary { margin-top: .2rem; color: var(--text-2); font-size: var(--fs-caption); }
.reading-delta { display: inline-flex; align-items: center; gap: .2rem; font-weight: 650; white-space: nowrap; }
.reading-delta-up { color: var(--success); }
.reading-delta-down, .reading-delta-neutral { color: var(--text-2); }
.reading-comparison-time { color: var(--text-2); font-size: var(--fs-caption); font-weight: 500; white-space: nowrap; }
.reading-cost, .reading-balance { display: inline-flex; align-items: center; gap: .3rem; font-size: var(--fs-footnote); font-weight: 650; white-space: nowrap; }
.reading-balance { margin-top: .2rem; color: var(--text-2); }
.reading-cost-consumption, .reading-cost-unchanged { color: var(--cost); }
.reading-cost-top-up { color: var(--success); }
.reading-change-cost { margin-top: .2rem; min-height: 1.2rem; }
.reading-rate { font-weight: 650; white-space: nowrap; }
.latest-readings-pagination { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-3) var(--space-5); border-top: 1px solid var(--line); }
.history-readings-pagination { background: var(--surface-2); }

.report-section { border-top: 1px solid var(--line); }
.report-section:first-child { border-top: 0; }
.report-section > summary { display: flex; align-items: center; gap: var(--space-3); min-height: 3.5rem; padding: var(--space-3) var(--space-5); font-weight: 600; list-style: none; cursor: pointer; }
.report-section > summary::-webkit-details-marker { display: none; }
.report-section > summary::after { content: ""; width: .5rem; height: .5rem; margin-left: var(--space-2); border: solid var(--text-3); border-width: 0 2px 2px 0; transform: rotate(-45deg); transition: transform var(--dur) var(--ease); }
.report-section[open] > summary::after { transform: rotate(45deg); }
.report-section-title { flex: 1; min-width: 0; }
.report-section-meta { padding: 0 var(--space-5) var(--space-3); color: var(--text-2); font-size: var(--fs-footnote); }
.report-table { font-size: var(--fs-footnote); white-space: nowrap; }
.report-table th { position: sticky; top: 0; z-index: 1; }
.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: var(--space-3); }
.field-item { padding: var(--space-3) var(--space-4); border-radius: var(--radius-m); background: var(--surface-2); overflow-wrap: anywhere; }
.run-dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; }
.run-dot.bg-green { background: var(--success); }
.run-dot.bg-red { background: var(--danger); }

/* 10. Settings ---------------------------------------------------------- */
.account-head { display: flex; align-items: center; gap: var(--space-4); padding: var(--space-5); }
.avatar-lg { display: grid; place-items: center; width: 3.5rem; height: 3.5rem; flex: none; color: var(--accent); font-size: var(--fs-title3); font-weight: 700; border-radius: 50%; background: var(--accent-tint); }
.account-name { font-size: var(--fs-headline); font-weight: 650; }
.list-link { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); width: 100%; min-height: 3.5rem; padding: var(--space-3) var(--space-5); color: var(--text); font: inherit; font-weight: 500; text-align: left; text-decoration: none; border: 0; border-top: 1px solid var(--line); background: transparent; cursor: pointer; }
.list-link:hover { color: var(--text); background: var(--surface-2); }
.list-link-danger:hover { color: var(--danger); }
.list-link .icon:last-child { color: var(--text-3); }
.list-link-danger { color: var(--danger); }
.settings-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-4) var(--space-5); border-top: 1px solid var(--line); }
.settings-row:first-child { border-top: 0; }
.settings-row-label { font-weight: 600; }
.settings-note { margin: 0; padding: 0 var(--space-5) var(--space-4); color: var(--text-2); font-size: var(--fs-footnote); }
.form-hint { margin-top: var(--space-1); color: var(--text-2); font-size: var(--fs-footnote); }
.advanced-settings { border-top: 1px solid var(--line); }
.advanced-settings > summary { padding: var(--space-3) var(--space-5); }
details.card.advanced-settings > summary { padding: var(--space-4) var(--space-5); color: var(--text); font-weight: 650; }
.notification-email-chips { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); min-height: 2rem; }
.notification-email-chip { display: inline-flex; align-items: center; gap: var(--space-1); max-width: 100%; padding: .3rem .5rem .3rem var(--space-3); border-radius: var(--radius-pill); background: var(--surface-2); overflow-wrap: anywhere; }
.notification-email-chip button { padding: 0 .2rem; color: var(--text-2); font-size: 1.15rem; line-height: 1; border: 0; background: transparent; cursor: pointer; }
#settings-form .form-check-input.is-invalid { border-color: var(--danger); }

.history-sync-card { overflow: hidden; }
.history-sync-kpi { display: flex; flex-direction: column; gap: .25rem; padding: var(--space-4); border-radius: var(--radius-m); background: var(--surface-2); }
.history-sync-kpi span { color: var(--text-2); font-size: var(--fs-caption); font-weight: 600; }
.history-sync-kpi strong { font-size: var(--fs-title3); }
.history-sync-progress { padding: var(--space-4) var(--space-5); border-radius: var(--radius-l); background: var(--surface-2); }
.history-sync-progress-heading { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-3); }
.history-sync-progress-state { display: flex; align-items: center; gap: var(--space-2); font-weight: 650; }
.history-sync-progress-copy { margin-top: .2rem; color: var(--text-2); font-size: var(--fs-footnote); }
.history-sync-progress-percent { font-size: var(--fs-title2); font-variant-numeric: tabular-nums; }
.history-sync-progress-dot { width: .6rem; height: .6rem; border-radius: 50%; background: var(--text-3); }
.history-sync-progress-track { height: .5rem; background: var(--surface-3); }
.history-sync-progress.is-running .history-sync-progress-dot { background: var(--accent); box-shadow: 0 0 0 .25rem var(--accent-tint); }
.history-sync-progress.is-completed .history-sync-progress-dot, .history-sync-progress.is-completed .progress-bar { background: var(--success); }
.history-sync-progress.is-failed .history-sync-progress-dot, .history-sync-progress.is-failed .progress-bar { background: var(--warn); }
.history-sync-progress.is-stopped .history-sync-progress-dot, .history-sync-progress.is-stopped .progress-bar { background: var(--text-3); }
.history-sync-explainer { padding: var(--space-4); border-radius: var(--radius-m); background: var(--accent-tint); }
.history-sync-explainer p { margin-top: var(--space-1); color: var(--text-2); }
.history-sync-failure-summary { margin-top: var(--space-4); padding: var(--space-4); border-radius: var(--radius-m); background: var(--danger-tint); }
.history-sync-failure-summary li + li { margin-top: .45rem; }
.history-sync-activity-heading { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); margin-top: var(--space-5); padding: var(--space-3) 0; }
.history-sync-tabs { display: inline-flex; gap: .125rem; padding: .1875rem; border-radius: var(--radius-m); background: var(--surface-3); }
.history-sync-tabs .nav-link { min-height: 2.25rem; padding: .35rem var(--space-3); color: var(--text-2); font-size: var(--fs-footnote); font-weight: 600; border-radius: calc(var(--radius-m) - .1875rem); }
.history-sync-tabs .nav-link.active { color: var(--text); background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, .14), 0 0 0 1px var(--line); }
.history-sync-tab-panel { margin-top: var(--space-4); }
.history-sync-tab-panel[hidden] { display: none; }
.history-sync-activity td { vertical-align: top; }
.history-sync-activity th, .history-sync-activity td { min-width: 7rem; }
.history-sync-activity th:nth-child(4), .history-sync-activity td:nth-child(4) { min-width: 18rem; }
.history-sync-error-code { display: inline-block; margin-top: .3rem; color: var(--danger); font-family: var(--font-mono); font-size: var(--fs-caption); }

/* Collection progress inside the sync sheet */
.collection-progress { margin-bottom: var(--space-4); padding: var(--space-3) var(--space-4); color: var(--text-2); font-size: var(--fs-footnote); border-radius: var(--radius-m); background: var(--surface-2); }
.collection-progress-copy { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-2); line-height: 1.3; }
.collection-live-dot { width: .5rem; height: .5rem; flex: none; border-radius: 50%; background: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
.collection-command-card.is-slow .collection-live-dot { background: var(--warn); }
.progress-bar-indeterminate { width: 100%; transform-origin: left; animation: indeterminate 1.1s ease-in-out infinite; }
.sheet-actions { display: grid; gap: var(--space-2); }
.sheet-actions .btn { width: 100%; min-height: 3rem; }

/* 11. Login ------------------------------------------------------------- */
.login-page { display: grid; place-items: center; min-height: 100vh; min-height: 100dvh; margin: 0; padding: calc(var(--space-6) + env(safe-area-inset-top, 0px)) var(--space-4) calc(var(--space-6) + env(safe-area-inset-bottom, 0px)); background: var(--bg); }
.login-shell { display: grid; justify-items: center; gap: var(--space-6); width: min(26rem, 100%); }
.login-brand { display: inline-flex; align-items: center; gap: var(--space-3); color: var(--text); font-size: var(--fs-headline); font-weight: 650; text-decoration: none; }
.login-brand img { width: 2.25rem; height: 2.25rem; }
.login-card { width: 100%; padding: var(--space-8) var(--space-6) var(--space-6); border: 1px solid var(--line); border-radius: var(--radius-xl); background: var(--surface); box-shadow: var(--shadow-1); }
.login-card h1 { margin: 0 0 var(--space-1); font-size: var(--fs-title1, 1.75rem); font-weight: 700; letter-spacing: -.025em; text-align: center; }
.login-card .login-lede { margin: 0 0 var(--space-5); color: var(--text-2); text-align: center; }
.login-field { margin-bottom: var(--space-4); }
.login-field .form-control { min-height: 3rem; }
.login-password { position: relative; }
.login-password .form-control { padding-right: 4.5rem; }
.login-password button { position: absolute; top: 50%; right: .35rem; min-height: 2.25rem; padding: 0 var(--space-3); color: var(--accent); font-size: var(--fs-footnote); font-weight: 650; border: 0; border-radius: var(--radius-s); background: transparent; transform: translateY(-50%); cursor: pointer; }
.login-submit { display: flex; align-items: center; justify-content: center; gap: var(--space-2); width: 100%; min-height: 3rem; color: var(--on-accent); font-size: var(--fs-headline); font-weight: 650; border: 0; border-radius: var(--radius-m); background: var(--accent-fill); cursor: pointer; transition: background-color var(--dur) var(--ease), transform .12s var(--ease); }
.login-submit:hover:not(:disabled) { background: var(--accent-hover); }
.login-submit:active:not(:disabled) { transform: scale(.985); }
.login-submit:disabled { opacity: .55; cursor: default; }
.login-switch { display: block; margin-top: var(--space-4); text-align: center; font-weight: 600; text-decoration: none; }
.login-assurance { margin-top: var(--space-4); color: var(--text-2); font-size: var(--fs-footnote); line-height: 1.5; text-align: center; }
.login-trust { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-1) var(--space-4); margin: 0; padding: 0; color: var(--text-2); font-size: var(--fs-caption); list-style: none; }
.login-trust li { display: inline-flex; align-items: center; gap: .35rem; }
.login-trust .icon { width: .9rem; height: .9rem; color: var(--success); }

/* Phones: tighter metrics and charts */
@media (max-width: 767.98px) {
  .history-metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
  .history-kpi-total { grid-column: 1 / -1; }
  .history-kpi { padding: var(--space-4); }
  .history-chart-frame { height: 16rem; }
  .tile { padding: var(--space-4); }
  .tile-hero { font-size: 2.25rem; }
  .table > :not(caption) > * > * { padding: var(--space-3) var(--space-4); }
  .surface-head, .list-row, .list-link, .settings-row, .account-head { padding-inline: var(--space-4); }
  .latest-readings-pagination, .history-log-heading { padding-inline: var(--space-4); }
  .history-summary-row > [class*="col-"] { flex: 0 0 50%; width: 50%; }
  .calendar-weekdays, .calendar-week { gap: .2rem; }
  .calendar-grid { gap: .2rem; }
  .calendar-week { min-height: 2.9rem; }
  .calendar-day { min-height: 2.9rem; }
  .btn, summary { min-height: 2.75rem; }
  .history-placeholder-value { font-size: 1.25rem; }
  .history-kpi-total .history-placeholder-value { font-size: var(--fs-large); }
  .history-kpi-cost [data-history-metric-value="cost"] { white-space: nowrap; }
  .report-section > summary, .report-section-meta { padding-inline: var(--space-4); }

  /* Readings become two-line rows instead of a table that scrolls sideways. */
  .reading-table thead { display: none; }
  .reading-table, .reading-table tbody { display: block; }
  .reading-table tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "time reading" "change rate"; gap: var(--space-1) var(--space-3); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--line); }
  .reading-table tbody tr:last-child { border-bottom: 0; }
  .reading-table td { display: block; padding: 0; border: 0; }
  .reading-table td:nth-child(1) { grid-area: time; min-width: 0; }
  .reading-table td:nth-child(2) { grid-area: reading; text-align: right; }
  .reading-table td:nth-child(3) { grid-area: change; }
  .reading-table td:nth-child(4) { grid-area: rate; text-align: right; color: var(--text-2); font-size: var(--fs-footnote); }
  .reading-table td:nth-child(4)::before { content: "Rate "; color: var(--text-2); }
  .reading-table .reading-meter-time { min-width: 0; }
  .reading-table .reading-meter-icon { display: none; }
}

/* 12. Motion, reduced motion and print ---------------------------------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .4; transform: scale(.8); } }
@keyframes shimmer { to { background-position: -100% 0; } }
@keyframes indeterminate { 50% { transform: scaleX(.35); } }
@keyframes sheet-up { from { transform: translateY(100%); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } }
@keyframes view-enter { from { opacity: .3; transform: translateY(6px); } }
.view-enter { animation: view-enter .24s var(--ease); }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
@media print {
  .app-nav, .app-bar, .toast-region, .pull-indicator, .status-line, dialog { display: none !important; }
  .app-content { margin: 0; padding: 0; }
  body { background: #fff; }
}

/* Meter identity: accounts can hold several meters, so the number is always visible. */
.meter-number { margin-left: var(--space-2); color: var(--text-2); font-size: var(--fs-footnote); font-weight: 500; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.tile-name { display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: 0 var(--space-1); }
.tile-name .meter-number { margin-left: var(--space-1); }
.meter-heading { display: flex; align-items: baseline; gap: var(--space-2); margin-bottom: var(--space-3); font-size: var(--fs-headline); font-weight: 650; }
.meter-heading .meter-number { margin-left: 0; }
