/* ============================================================
   MobileDash design system — Termix-style dark theme
   Tokens first; every component below only consumes tokens.
   Bootstrap is loaded before this file; the blocks below retheme
   the bootstrap classes the Identity pages use, so all pages
   share one look without per-page styles.
   ============================================================ */

@font-face {
    font-family: "JetBrains Mono";
    src: url("fonts/jetbrains-mono-latin-wght-normal.woff2") format("woff2");
    font-weight: 100 800;
    font-style: normal;
    font-display: swap;
}

:root {
    --background: oklch(0.155 0.004 128.73);
    --foreground: oklch(0.985 0 0);
    --card: oklch(0.21 0.004 128.68);
    --surface: oklch(0.185 0.004 128.73);
    --surface-dim: oklch(0.165 0.003 128.73);
    --muted: oklch(0.255 0 0);
    --muted-foreground: oklch(0.72 0 0);
    --border: oklch(1 0 0 / 12%);
    --input-border: oklch(1 0 0 / 15%);
    --primary: oklch(0.922 0 0);
    --primary-foreground: oklch(0.2115 0.0042 128.68);
    --destructive: oklch(0.704 0.191 22.216);
    --good: #0ca30c;
    --accent-brand: #f59145;
    --ring: oklch(0.556 0 0);
    --radius: 0.625rem;
    --radius-sm: calc(var(--radius) * 0.6);
    --radius-xl: calc(var(--radius) * 1.4);
    --font-mono: "JetBrains Mono", ui-monospace, monospace;
    --font-sans: system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* ---------- base ---------- */

html, body {
    font-family: var(--font-sans);
    background-color: var(--background);
    color: var(--foreground);
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-mono);
    font-weight: 700;
    letter-spacing: -0.02em;
}

h1 { font-size: 1.5rem; margin-bottom: 1rem; }
h2 { font-size: 1.15rem; margin-top: 1.5rem; }
h3 { font-size: 1rem; }

a, .btn-link {
    color: var(--accent-brand);
    text-decoration: none;
}

a:hover, .btn-link:hover {
    color: var(--accent-brand);
    text-decoration: underline;
}

hr {
    border-color: var(--border);
    opacity: 1;
}

code {
    font-family: var(--font-mono);
    color: var(--muted-foreground);
    font-size: 0.85em;
}

.text-secondary {
    color: var(--muted-foreground) !important;
}

.content {
    padding-top: 1.25rem;
    max-width: 1100px;
    margin: 0 auto;
}

h1:focus {
    outline: none;
}

/* ---------- card (building block) ---------- */

.md-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 1.25rem;
}

/* ---------- buttons ---------- */

.btn {
    border-radius: var(--radius);
    font-weight: 500;
}

.btn-primary {
    background-color: var(--primary);
    border-color: var(--primary);
    color: var(--primary-foreground);
}

.btn-primary:hover, .btn-primary:focus, .btn-primary:active {
    background-color: oklch(0.85 0 0);
    border-color: oklch(0.85 0 0);
    color: var(--primary-foreground);
}

.btn-secondary, .btn-outline-secondary, .btn-outline-primary {
    background-color: transparent;
    border-color: var(--input-border);
    color: var(--foreground);
}

.btn-secondary:hover, .btn-outline-secondary:hover, .btn-outline-primary:hover {
    background-color: var(--muted);
    border-color: var(--input-border);
    color: var(--foreground);
}

.btn-outline-danger {
    background-color: transparent;
    border-color: var(--input-border);
    color: var(--destructive);
}

.btn-outline-danger:hover {
    background-color: color-mix(in oklch, var(--destructive) 15%, transparent);
    border-color: var(--destructive);
    color: var(--destructive);
}

.btn:disabled {
    background-color: var(--muted);
    border-color: var(--border);
    color: var(--muted-foreground);
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
    box-shadow: 0 0 0 0.2rem color-mix(in oklch, var(--accent-brand) 35%, transparent);
}

/* ---------- forms ---------- */

.form-control, .form-select {
    background-color: var(--surface-dim);
    border-color: var(--input-border);
    color: var(--foreground);
    border-radius: var(--radius);
}

.form-control:focus, .form-select:focus {
    background-color: var(--surface-dim);
    border-color: var(--accent-brand);
    color: var(--foreground);
}

.form-control::placeholder {
    color: var(--ring);
}

.form-select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23b8b8b8' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}

.form-label, .form-check-label, label {
    color: var(--muted-foreground);
}

.form-text {
    color: var(--ring);
}

.form-floating > .form-control ~ label {
    color: var(--ring);
}

.form-floating > .form-control:focus ~ label,
.form-floating > .form-control:not(:placeholder-shown) ~ label {
    color: var(--muted-foreground);
}

.form-floating > .form-control ~ label::after {
    background-color: transparent !important;
}

.form-check-input, .darker-border-checkbox.form-check-input {
    background-color: var(--surface-dim);
    border-color: var(--input-border);
}

.form-check-input:checked {
    background-color: var(--accent-brand);
    border-color: var(--accent-brand);
}

.valid.modified:not([type=checkbox]) {
    outline: 1px solid var(--good);
}

.invalid {
    outline: 1px solid var(--destructive);
}

.validation-message, .text-danger {
    color: var(--destructive) !important;
}

/* ---------- tables ---------- */

.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--foreground);
    --bs-table-border-color: var(--border);
    color: var(--foreground);
}

.table > thead {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted-foreground);
}

/* ---------- alerts ---------- */

.alert {
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background-color: var(--surface);
    color: var(--foreground);
}

.alert-success {
    border-color: color-mix(in oklch, var(--good) 45%, transparent);
    background-color: color-mix(in oklch, var(--good) 12%, var(--surface));
    color: var(--foreground);
}

.alert-danger {
    border-color: color-mix(in oklch, var(--destructive) 45%, transparent);
    background-color: color-mix(in oklch, var(--destructive) 12%, var(--surface));
    color: var(--foreground);
}

.alert-info {
    border-color: var(--border);
    background-color: var(--surface);
    color: var(--muted-foreground);
}

/* ---------- topbar layout ---------- */

.topbar {
    background: var(--surface-dim);
    border-bottom: 1px solid var(--border);
    padding: 0 1rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-wrap: wrap;
    min-height: 3.25rem;
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar-brand {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--foreground);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-right: 1rem;
    padding: 0.6rem 0;
}

.topbar-brand:hover {
    color: var(--foreground);
    text-decoration: none;
}

.brand-mark {
    width: 1.35rem;
    height: 1.35rem;
    border-radius: var(--radius-sm);
    background: var(--accent-brand);
    color: var(--primary-foreground);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: 800;
    flex: none;
}

.topbar .nav-link {
    color: var(--muted-foreground);
    border-radius: var(--radius);
    padding: 0.35rem 0.75rem;
    font-size: 0.9rem;
    background: none;
    border: none;
}

.topbar .nav-link:hover {
    color: var(--foreground);
    background: var(--muted);
}

.topbar .nav-link.active {
    color: var(--foreground);
    background: var(--muted);
}

.topbar-spacer {
    flex: 1;
}

/* ---------- auth pages ---------- */

.auth-page {
    display: flex;
    justify-content: center;
    padding: 8vh 0 2rem;
}

.auth-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 1.75rem;
    width: 100%;
    max-width: 24rem;
}

.auth-card h1 {
    margin-bottom: 0.25rem;
}

.auth-subtitle {
    color: var(--muted-foreground);
    font-size: 0.9rem;
    margin-bottom: 1.25rem;
}

.auth-links {
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    font-size: 0.88rem;
}

/* ---------- dashboard tiles ---------- */

.dash-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.75rem;
}

.tile {
    position: relative;
    overflow: hidden;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 0.85rem 1rem;
    min-height: 6.5rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.tile-label {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--muted-foreground);
    position: relative;
}

.tile-value {
    font-family: var(--font-mono);
    font-size: 2rem;
    font-weight: 700;
    color: var(--foreground);
    line-height: 1.15;
    position: relative;
}

.tile-unit {
    font-size: 1rem;
    font-weight: 400;
    color: var(--muted-foreground);
    margin-left: 0.2rem;
}

.tile-meta {
    font-size: 0.72rem;
    color: var(--ring);
    position: relative;
}

/* Sparkline sits behind the text as a background layer */
.tile-sparkline {
    position: absolute;
    inset: auto 0 0 0;
    width: 100%;
    height: 60%;
    pointer-events: none;
}

.spark-line {
    fill: none;
    stroke: var(--accent-brand);
    stroke-width: 2px;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.spark-area {
    fill: var(--accent-brand);
    opacity: 0.10;
    stroke: none;
}

/* Comparison tile spans the full row and leads with the verdict */
.tile-compare {
    grid-column: 1 / -1;
}

.tile-verdict {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-family: var(--font-mono);
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--foreground);
    padding: 0.35rem 0;
}

.verdict-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    font-size: 1.1rem;
    flex: none;
    color: #fff;
    background: var(--muted);
}

.compare-agree .verdict-icon {
    background: var(--good);
}

.compare-agree .tile-verdict {
    color: var(--good);
}

.compare-disagree .verdict-icon {
    background: var(--muted);
    color: var(--muted-foreground);
}

/* Climate tile spans the full row like the comparison tile */
.tile-climate {
    grid-column: 1 / -1;
    gap: 0.75rem;
    justify-content: flex-start;
}

.climate-temps {
    display: flex;
    align-items: flex-end;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.climate-temp-label {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--muted-foreground);
}

.climate-target-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.climate-target-value {
    min-width: 4.2rem;
    text-align: center;
}

.climate-step {
    width: 2.4rem;
    height: 2.4rem;
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 1.3rem;
    line-height: 1;
    color: var(--foreground);
    background: var(--muted);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
}

.climate-step:hover:not(:disabled) {
    border-color: var(--accent-brand);
}

.climate-step:disabled {
    color: var(--muted-foreground);
    background: transparent;
    cursor: default;
}

.climate-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.climate-chip {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    padding: 0.35rem 0.75rem;
    color: var(--muted-foreground);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
}

.climate-chip:hover:not(:disabled) {
    color: var(--foreground);
}

.climate-chip.active {
    color: var(--foreground);
    background: var(--muted);
    border-color: var(--accent-brand);
}

.climate-chip:disabled {
    cursor: default;
    opacity: 0.6;
}

.climate-preset {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.climate-preset-select {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    padding: 0.3rem 0.6rem;
    color: var(--foreground);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.climate-action {
    text-transform: lowercase;
}

.dash-error {
    background: color-mix(in oklch, var(--destructive) 12%, var(--surface));
    color: var(--foreground);
    border: 1px solid color-mix(in oklch, var(--destructive) 45%, transparent);
    border-radius: var(--radius);
    padding: 0.6rem 0.9rem;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
}

.dash-empty, .dash-footer {
    color: var(--muted-foreground);
}

.dash-footer {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    margin-top: 1rem;
}

@media (min-width: 641px) {
    .dash-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 1rem;
    }
}

/* ---------- blazor plumbing ---------- */

.blazor-error-boundary {
    background: color-mix(in oklch, var(--destructive) 15%, var(--surface));
    border: 1px solid var(--destructive);
    border-radius: var(--radius);
    padding: 1rem;
    color: var(--foreground);
}

.blazor-error-boundary::after {
    content: "An error has occurred.";
}

#blazor-error-ui {
    background: var(--card);
    border-top: 2px solid var(--destructive);
    color: var(--foreground);
    bottom: 0;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.4);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.topbar-user {
    max-width: 11rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* account manage pages (nav-pills sidebar) */
.nav-pills .nav-link {
    color: var(--muted-foreground);
    border-radius: var(--radius);
}

.nav-pills .nav-link:hover {
    color: var(--foreground);
    background: var(--muted);
}

.nav-pills .nav-link.active {
    color: var(--foreground);
    background: var(--muted);
}

.form-control:disabled, .form-control[readonly] {
    background-color: var(--muted);
    border-color: var(--border);
    color: var(--muted-foreground);
}

/* chart tiles: text clusters at the top so it clears the background sparkline */
.tile-chart {
    min-height: 9.5rem;
    justify-content: flex-start;
    gap: 0.15rem;
}

.tile-chart-button {
    width: 100%;
    text-align: left;
    color: inherit;
    cursor: pointer;
    font: inherit;
}

.tile-chart-button:hover {
    border-color: color-mix(in oklch, var(--accent-brand) 65%, var(--border));
    transform: translateY(-1px);
}

.tile-chart-button:focus-visible {
    outline: 2px solid var(--accent-brand);
    outline-offset: 2px;
}

.tile-chart .tile-sparkline {
    height: 42%;
}

/* ---------- energy history tile ---------- */

.tile-energy {
    grid-column: 1 / -1;
    min-height: 15rem;
    width: 100%;
    gap: 0.7rem;
    color: inherit;
    text-align: left;
    cursor: pointer;
    font: inherit;
}

.tile-energy:hover {
    border-color: color-mix(in oklch, var(--accent-brand) 65%, var(--border));
    transform: translateY(-1px);
}

.tile-energy:focus-visible {
    outline: 2px solid var(--accent-brand);
    outline-offset: 2px;
}

.energy-tile-header,
.energy-summary,
.energy-tile-meta {
    display: flex;
    align-items: center;
}

.energy-tile-header,
.energy-tile-meta {
    justify-content: space-between;
    gap: 0.75rem;
}

.energy-period {
    padding: 0.2rem 0.45rem;
    color: var(--muted-foreground);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    font-family: var(--font-mono);
    font-size: 0.64rem;
    white-space: nowrap;
}

.energy-summary {
    align-items: baseline;
    gap: 0.55rem;
}

.energy-summary-label {
    color: var(--muted-foreground);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    text-transform: uppercase;
}

.energy-bars {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    align-items: end;
    gap: clamp(0.3rem, 2vw, 0.85rem);
    height: 6rem;
}

.energy-bar-column {
    display: grid;
    grid-template-rows: 1fr auto;
    align-items: end;
    gap: 0.3rem;
    height: 100%;
    min-width: 0;
}

.energy-bar-track {
    position: relative;
    display: flex;
    align-items: flex-end;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--surface-dim);
    border-radius: var(--radius-sm) var(--radius-sm) 2px 2px;
}

.energy-bar {
    display: block;
    width: 100%;
    min-height: 0;
    background: color-mix(in oklch, var(--accent-brand) 65%, var(--muted));
    border-radius: var(--radius-sm) var(--radius-sm) 2px 2px;
}

.energy-bar.is-today {
    background: var(--accent-brand);
}

.energy-day {
    color: var(--ring);
    font-family: var(--font-mono);
    font-size: 0.62rem;
    text-align: center;
    text-transform: uppercase;
}

.energy-open-hint {
    color: var(--accent-brand);
}

.energy-empty {
    display: grid;
    min-height: 8rem;
    place-items: center;
    color: var(--muted-foreground);
    font-size: 0.85rem;
}

/* ---------- energy history detail ---------- */

.energy-range-picker {
    display: flex;
    gap: 0.35rem;
    margin: -0.25rem 0 1rem;
}

.energy-range-button {
    padding: 0.38rem 0.75rem;
    color: var(--muted-foreground);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    cursor: pointer;
}

.energy-range-button:hover:not(:disabled),
.energy-range-button:focus-visible {
    color: var(--foreground);
    border-color: var(--accent-brand);
}

.energy-range-button.active {
    color: var(--primary-foreground);
    background: var(--accent-brand);
    border-color: var(--accent-brand);
}

.energy-range-button:disabled {
    cursor: wait;
    opacity: 0.65;
}

.energy-detail-plot {
    min-height: 15rem;
    padding: 0.25rem 0;
    overflow: hidden;
    background: var(--surface-dim);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.energy-detail-plot svg {
    display: block;
    width: 100%;
    height: clamp(15rem, 45vw, 22rem);
}

.energy-detail-bar {
    fill: color-mix(in oklch, var(--accent-brand) 62%, var(--muted));
}

.energy-detail-bar.is-today {
    fill: var(--accent-brand);
}

.energy-stat-date {
    font-size: 0.94rem !important;
}

.energy-loading {
    min-height: 15rem;
}

/* ---------- chart detail dialog ---------- */

.chart-dialog-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: end center;
    padding: 0.75rem;
    background: rgb(0 0 0 / 65%);
}

.chart-dialog {
    width: min(100%, 58rem);
    max-height: calc(100dvh - 1.5rem);
    overflow: auto;
    padding: 1rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: 0 1.5rem 4rem rgb(0 0 0 / 45%);
}

.chart-dialog-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.chart-dialog-header h2 {
    margin: 0;
    font-size: 1.15rem;
}

.chart-dialog-kicker {
    margin: 0 0 0.2rem;
    color: var(--muted-foreground);
    font-family: var(--font-mono);
    font-size: 0.72rem;
    text-transform: uppercase;
}

.chart-dialog-close {
    width: 2.75rem;
    height: 2.75rem;
    flex: none;
    color: var(--foreground);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 50%;
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
}

.chart-dialog-close:hover, .chart-dialog-close:focus-visible {
    border-color: var(--accent-brand);
}

.chart-detail-plot {
    min-height: 15rem;
    padding: 0.25rem 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-dim);
}

.chart-detail-plot svg {
    display: block;
    width: 100%;
    height: clamp(15rem, 45vw, 22rem);
}

.chart-detail-grid {
    stroke: var(--border);
    stroke-dasharray: 3 4;
    vector-effect: non-scaling-stroke;
}

.chart-detail-axis {
    fill: var(--muted-foreground);
    font-family: var(--font-mono);
    font-size: 15px;
}

.chart-detail-area {
    fill: url(#chart-detail-fill);
}

.chart-detail-fill-top { stop-color: var(--accent-brand); stop-opacity: 0.35; }
.chart-detail-fill-bottom { stop-color: var(--accent-brand); stop-opacity: 0.02; }

.chart-detail-line {
    fill: none;
    stroke: var(--accent-brand);
    stroke-width: 3px;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.chart-detail-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.5rem;
    margin: 1rem 0;
}

.chart-detail-stats > div {
    padding: 0.65rem;
    background: var(--surface);
    border-radius: var(--radius-sm);
}

.chart-detail-stats dt {
    color: var(--muted-foreground);
    font-family: var(--font-mono);
    font-size: 0.68rem;
    text-transform: uppercase;
}

.chart-detail-stats dd {
    margin: 0.15rem 0 0;
    color: var(--foreground);
    font-family: var(--font-mono);
    font-size: 1.05rem;
    font-weight: 700;
}

.chart-detail-stats dd span {
    margin-left: 0.18rem;
    color: var(--muted-foreground);
    font-size: 0.72rem;
    font-weight: 400;
}

.chart-dialog-footer {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    color: var(--muted-foreground);
    font-size: 0.75rem;
}

.chart-detail-empty {
    display: grid;
    gap: 0.3rem;
    min-height: 10rem;
    place-content: center;
    padding: 1rem;
    color: var(--muted-foreground);
    text-align: center;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-dim);
}

.chart-detail-empty strong { color: var(--foreground); }

@media (min-width: 641px) {
    .chart-dialog-backdrop { place-items: center; padding: 1.5rem; }
    .chart-dialog { padding: 1.5rem; }
}

@media (max-width: 420px) {
    .chart-detail-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .chart-dialog-footer { flex-direction: column; gap: 0.25rem; }
    .energy-tile-meta { align-items: flex-start; flex-wrap: wrap; }
    .energy-open-hint { width: 100%; }
}
