/* ==========================================================================
   Marina Power Monitor — design system
   Warm off-white canvas, bronze primary, sand cards. Mobile first.
   All colours, radii and spacing come from these variables.
   ========================================================================== */

:root {
    --c-bg: #fbefe9;
    --c-bg-alt: #f6e6dd;
    --c-surface: #fffaf7;
    --c-card: #faece2;
    --c-card-strong: #f3ddcd;
    --c-line: #e6d1c2;

    --c-primary: #6e3f16;
    --c-primary-strong: #522e0f;
    --c-primary-soft: #a9723c;
    --c-primary-tint: #f0dccb;

    --c-text: #33200f;
    --c-text-muted: #7d6553;
    --c-text-inverse: #fff7f0;

    --c-ok: #2f7d4f;
    --c-ok-soft: #dff0e3;
    --c-warn: #b45f06;
    --c-warn-soft: #fdecc8;
    --c-danger: #a32b1c;
    --c-danger-soft: #fbe0dc;
    --c-info: #2b5d86;
    --c-info-soft: #ddeaf5;

    --r-sm: 10px;
    --r-md: 16px;
    --r-lg: 22px;
    --r-xl: 28px;

    --s-1: 4px;
    --s-2: 8px;
    --s-3: 12px;
    --s-4: 16px;
    --s-5: 24px;
    --s-6: 32px;
    --s-7: 48px;

    --shadow-sm: 0 1px 2px rgba(82, 46, 15, .06);
    --shadow-md: 0 4px 16px rgba(82, 46, 15, .09);
    --shadow-lg: 0 12px 32px rgba(82, 46, 15, .14);

    --font: "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;

    --maxw: 1180px;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.55;
    color: var(--c-text);
    background: var(--c-bg);
    min-height: 100vh;
}

h1, h2, h3, h4 { margin: 0 0 var(--s-3); line-height: 1.25; font-weight: 700; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 var(--s-3); }

a { color: var(--c-primary); text-decoration: underline; text-underline-offset: 2px; }
a:hover { color: var(--c-primary-strong); }

:focus-visible {
    outline: 3px solid var(--c-primary-soft);
    outline-offset: 2px;
    border-radius: var(--r-sm);
}

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    background: var(--c-primary);
    color: var(--c-text-inverse);
    padding: var(--s-3) var(--s-4);
    z-index: 100;
}
.skip-link:focus { left: var(--s-3); top: var(--s-3); }

/* ---------- Layout ---------- */

.shell { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
    background: linear-gradient(135deg, var(--c-primary-strong), var(--c-primary-soft));
    color: var(--c-text-inverse);
    padding: var(--s-3) var(--s-4);
    box-shadow: var(--shadow-md);
}

.topbar__inner {
    max-width: var(--maxw);
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: var(--s-3);
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    font-weight: 700;
    letter-spacing: .02em;
    color: var(--c-text-inverse);
    text-decoration: none;
    font-size: 1.05rem;
}
.brand__mark {
    width: 30px; height: 30px;
    border-radius: 9px;
    background: rgba(255, 247, 240, .18);
    display: grid; place-items: center;
    font-size: 1rem;
}

.topbar__spacer { flex: 1 1 auto; }

.topbar__meta { font-size: .82rem; opacity: .9; }

.nav {
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-line);
    overflow-x: auto;
}
.nav__inner {
    max-width: var(--maxw);
    margin: 0 auto;
    display: flex;
    gap: var(--s-1);
    padding: var(--s-2) var(--s-3);
    white-space: nowrap;
}
.nav a {
    padding: var(--s-2) var(--s-3);
    border-radius: 999px;
    text-decoration: none;
    color: var(--c-text-muted);
    font-weight: 600;
    font-size: .92rem;
}
.nav a:hover { background: var(--c-card); color: var(--c-primary); }
.nav a[aria-current="page"] { background: var(--c-primary-tint); color: var(--c-primary-strong); }

main {
    flex: 1 1 auto;
    width: 100%;
    max-width: var(--maxw);
    margin: 0 auto;
    padding: var(--s-4) var(--s-3) var(--s-7);
}

footer {
    border-top: 1px solid var(--c-line);
    padding: var(--s-4) var(--s-3);
    color: var(--c-text-muted);
    font-size: .82rem;
    text-align: center;
}

/* ---------- Cards ---------- */

.card {
    background: var(--c-surface);
    border: 1px solid var(--c-line);
    border-radius: var(--r-lg);
    padding: var(--s-4);
    box-shadow: var(--shadow-sm);
    margin-bottom: var(--s-4);
}

.card--sand { background: var(--c-card); }

.card__header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--s-3);
    margin-bottom: var(--s-3);
    flex-wrap: wrap;
}

.hero {
    background: linear-gradient(140deg, var(--c-primary-strong), var(--c-primary-soft));
    color: var(--c-text-inverse);
    border-radius: var(--r-xl);
    padding: var(--s-5);
    box-shadow: var(--shadow-lg);
    margin-bottom: var(--s-4);
}
.hero__top {
    display: flex; align-items: center; justify-content: space-between;
    gap: var(--s-3); flex-wrap: wrap; margin-bottom: var(--s-4);
}
.hero__source { display: flex; align-items: center; gap: var(--s-3); font-weight: 700; font-size: 1.1rem; }
.hero__icon {
    width: 42px; height: 42px; border-radius: 12px;
    background: rgba(255, 247, 240, .2);
    display: grid; place-items: center; font-size: 1.2rem;
}
.hero__label { font-size: .85rem; opacity: .85; margin-bottom: var(--s-1); }
.hero__value { font-size: clamp(2rem, 9vw, 3rem); font-weight: 800; letter-spacing: -.02em; line-height: 1.05; }
.hero__unit { font-size: .95rem; font-weight: 700; opacity: .85; margin-left: var(--s-2); }
.hero__footer {
    display: flex; justify-content: space-between; gap: var(--s-4);
    margin-top: var(--s-4); padding-top: var(--s-3);
    border-top: 1px solid rgba(255, 247, 240, .25);
    font-size: .85rem; flex-wrap: wrap;
}
.hero__footer dt { opacity: .8; margin-bottom: 2px; }
.hero__footer dd { margin: 0; font-weight: 700; }

/* ---------- Grid of metric cards ---------- */

.metrics {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
    gap: var(--s-3);
    margin-bottom: var(--s-4);
}

.metric {
    background: var(--c-card);
    border: 1px solid var(--c-line);
    border-radius: var(--r-md);
    padding: var(--s-3) var(--s-4);
}
.metric__label {
    display: flex; align-items: center; gap: var(--s-1);
    font-size: .78rem; text-transform: uppercase; letter-spacing: .05em;
    color: var(--c-text-muted); font-weight: 700; margin-bottom: var(--s-2);
}
.metric__value { font-size: 1.4rem; font-weight: 800; letter-spacing: -.01em; }
.metric__unit { font-size: .75rem; font-weight: 700; color: var(--c-text-muted); margin-left: 4px; }
.metric__hint { font-size: .78rem; color: var(--c-text-muted); margin-top: var(--s-1); }

/* A ledger that is being tracked but is not currently billed (national credit on a
   generator-billed meter). Still fully readable — de-emphasised, never hidden. */
.metric--dormant { background: transparent; border-style: dashed; }
.metric--dormant .metric__value { font-weight: 700; color: var(--c-text-muted); }
.hero__footer .is-dormant dd { opacity: .7; font-weight: 600; }

/* ---------- Status pills & alerts ---------- */

.pill {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 10px; border-radius: 999px;
    font-size: .76rem; font-weight: 700; letter-spacing: .01em;
    background: var(--c-card-strong); color: var(--c-primary-strong);
    border: 1px solid var(--c-line);
}
.pill--ok { background: var(--c-ok-soft); color: var(--c-ok); border-color: transparent; }
.pill--warn { background: var(--c-warn-soft); color: var(--c-warn); border-color: transparent; }
.pill--danger { background: var(--c-danger-soft); color: var(--c-danger); border-color: transparent; }
.pill--info { background: var(--c-info-soft); color: var(--c-info); border-color: transparent; }
.pill--onhero { background: rgba(255, 247, 240, .18); color: var(--c-text-inverse); border-color: transparent; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: 0 0 auto; }
.dot--ok { background: #4fb477; }
.dot--warn { background: #e28413; }
.dot--danger { background: #d1493a; }

.alert {
    display: flex; gap: var(--s-3); align-items: flex-start;
    border-radius: var(--r-md); padding: var(--s-3) var(--s-4);
    margin-bottom: var(--s-4); font-size: .92rem;
    border: 1px solid transparent;
}
.alert__icon { font-size: 1.1rem; line-height: 1.3; }
.alert--warn { background: var(--c-warn-soft); color: var(--c-warn); border-color: #f0d59a; }
.alert--ok { background: var(--c-ok-soft); color: var(--c-ok); border-color: #b9dcc4; }
.alert--danger { background: var(--c-danger-soft); color: var(--c-danger); border-color: #eebfb8; }
.alert--info { background: var(--c-info-soft); color: var(--c-info); border-color: #bdd6e9; }

/* ---------- Info tooltip ---------- */

.info {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 17px; height: 17px;
    border-radius: 50%;
    border: 1px solid var(--c-primary-soft);
    background: transparent;
    color: var(--c-primary);
    font-size: .68rem; font-weight: 800;
    cursor: help;
    padding: 0;
    flex: 0 0 auto;
}
.info__bubble {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    width: min(280px, 70vw);
    background: var(--c-primary-strong);
    color: var(--c-text-inverse);
    padding: var(--s-3);
    border-radius: var(--r-sm);
    font-size: .8rem;
    font-weight: 400;
    line-height: 1.45;
    text-align: left;
    box-shadow: var(--shadow-lg);
    z-index: 40;
    display: none;
}
.info[aria-expanded="true"] .info__bubble,
.info:hover .info__bubble,
.info:focus-visible .info__bubble { display: block; }

/* ---------- Forms ---------- */

.form { max-width: 520px; }
.form--wide { max-width: 100%; }

.field { margin-bottom: var(--s-4); }
.field > label {
    display: block; font-weight: 700; font-size: .88rem;
    margin-bottom: var(--s-2); color: var(--c-text);
}
.field__hint { font-size: .8rem; color: var(--c-text-muted); margin-top: var(--s-1); }

input[type="text"], input[type="email"], input[type="password"], input[type="date"],
input[type="search"], select, textarea {
    width: 100%;
    padding: 11px var(--s-3);
    border: 1px solid var(--c-line);
    border-radius: var(--r-sm);
    background: var(--c-surface);
    color: var(--c-text);
    font-size: 1rem;
    font-family: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--c-primary-soft); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
    padding: 11px var(--s-4);
    border-radius: var(--r-sm);
    border: 1px solid transparent;
    background: linear-gradient(135deg, var(--c-primary-strong), var(--c-primary-soft));
    color: var(--c-text-inverse);
    font-weight: 700; font-size: .95rem;
    cursor: pointer; text-decoration: none;
    font-family: inherit;
}
.btn:hover { filter: brightness(1.07); color: var(--c-text-inverse); }
.btn:disabled { opacity: .55; cursor: not-allowed; filter: none; }
.btn--secondary {
    background: var(--c-card); color: var(--c-primary-strong); border-color: var(--c-line);
}
.btn--secondary:hover { background: var(--c-card-strong); color: var(--c-primary-strong); }
.btn--danger { background: var(--c-danger); }
.btn--sm { padding: 6px 12px; font-size: .82rem; }
.btn--block { width: 100%; }

.btn-row { display: flex; gap: var(--s-2); flex-wrap: wrap; align-items: center; }

/* ASP.NET renders the summary container unconditionally and hides the placeholder item with an
   inline style="display:none". The Content-Security-Policy blocks inline styles, so visibility is
   driven entirely by the validation-summary-valid / -errors classes the framework also emits. */
.validation-summary { display: none; }

.validation-summary.validation-summary-errors {
    display: block;
    background: var(--c-danger-soft);
    border: 1px solid #eebfb8;
    color: var(--c-danger);
    border-radius: var(--r-md);
    padding: var(--s-3) var(--s-4);
    margin-bottom: var(--s-4);
    font-size: .9rem;
}
.validation-summary ul { margin: 0; padding-left: var(--s-4); }
.validation-summary.validation-summary-valid ul,
.validation-summary ul:empty { display: none; }

/* Same reasoning for per-field messages: only show them once they actually carry an error. */
.field-error { color: var(--c-danger); font-size: .82rem; margin-top: var(--s-1); display: none; }
.field-error.field-validation-error { display: block; }

/* ---------- Filters ---------- */

.filters {
    display: flex; flex-wrap: wrap; gap: var(--s-2);
    align-items: flex-end;
    background: var(--c-card);
    border: 1px solid var(--c-line);
    border-radius: var(--r-md);
    padding: var(--s-3);
    margin-bottom: var(--s-4);
}
.filters .field { margin-bottom: 0; }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
    padding: 6px 12px; border-radius: 999px;
    background: var(--c-surface); border: 1px solid var(--c-line);
    color: var(--c-text-muted); font-size: .84rem; font-weight: 600;
    text-decoration: none;
}
.chip:hover { border-color: var(--c-primary-soft); color: var(--c-primary); }
.chip[aria-current="true"] {
    background: var(--c-primary); border-color: var(--c-primary); color: var(--c-text-inverse);
}

/* ---------- Charts ---------- */

.chart-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--s-4);
}

.chart-card { margin-bottom: 0; }
.chart-box { position: relative; height: 280px; }
.chart-box--tall { height: 340px; }

.chart-state {
    display: grid; place-items: center;
    height: 100%; text-align: center;
    color: var(--c-text-muted); font-size: .9rem; padding: var(--s-4);
}

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: .88rem;
    min-width: 520px;
}
table.data caption {
    text-align: left; font-size: .82rem; color: var(--c-text-muted);
    padding-bottom: var(--s-2);
}
table.data th, table.data td {
    padding: 9px var(--s-3);
    text-align: left;
    border-bottom: 1px solid var(--c-line);
    vertical-align: top;
}
table.data th {
    font-size: .76rem; text-transform: uppercase; letter-spacing: .04em;
    color: var(--c-text-muted); font-weight: 700;
    background: var(--c-card);
    position: sticky; top: 0;
}
table.data tbody tr:hover { background: var(--c-bg-alt); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); font-size: .85em; }

.empty {
    padding: var(--s-6) var(--s-4);
    text-align: center;
    color: var(--c-text-muted);
    background: var(--c-card);
    border-radius: var(--r-md);
}

/* ---------- Progress / completeness bar ---------- */

.bar {
    height: 8px; border-radius: 999px;
    background: var(--c-card-strong);
    overflow: hidden;
    margin-top: var(--s-2);
}
.bar__fill { height: 100%; background: var(--c-primary-soft); border-radius: 999px; }

/* ---------- Utilities ---------- */

.muted { color: var(--c-text-muted); }
.small { font-size: .84rem; }
.tiny { font-size: .76rem; }
.strong { font-weight: 700; }
.right { text-align: right; }
.mb-0 { margin-bottom: 0; }
.mb-3 { margin-bottom: var(--s-3); }
.mt-3 { margin-top: var(--s-3); }
.mt-4 { margin-top: var(--s-4); }
.stack > * + * { margin-top: var(--s-3); }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: var(--s-3); flex-wrap: wrap; }
.nowrap { white-space: nowrap; }

.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;
}

dl.kv { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: var(--s-2) var(--s-3); }
dl.kv dt { color: var(--c-text-muted); font-size: .88rem; }
dl.kv dd { margin: 0; font-weight: 700; text-align: right; font-size: .9rem; }

/* ---------- Responsive ---------- */

@media (min-width: 700px) {
    main { padding: var(--s-5) var(--s-4) var(--s-7); }
    h1 { font-size: 1.9rem; }
    .chart-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .chart-grid > .span-2 { grid-column: 1 / -1; }
}

@media (min-width: 1000px) {
    .metrics { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}

@media print {
    .topbar, .nav, footer, .filters, .btn { display: none !important; }
    body { background: #fff; }
    .card, .hero { box-shadow: none; border: 1px solid #ccc; }
}
