/*
 * Shared electricity bill calculator.
 * Mobile-first: one column and card-style results on small screens, a real table from 680px.
 * Uses the site tokens from /assets/style.css, so light and dark mode follow the site.
 */

.eb {
    display: grid;
    gap: 18px;
    margin: 14px 0 8px;
}

.eb-form {
    display: grid;
    gap: 18px;
}

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

.eb-card {
    min-width: 0;
    padding: 16px;
    border: 1px solid var(--line);
    border-top-width: 4px;
    border-radius: var(--radius);
    background: var(--surface);
}

.eb-main { border-top-color: var(--accent); }
.eb-meters { border-top-color: var(--ok-text); }

.eb-card-head { margin-bottom: 14px; }

.eb-card-head h2 {
    margin: 6px 0 2px;
    font-size: 20px;
}

.eb-card-head p {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
}

.eb-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
}

.eb-badge-main { background: var(--accent-soft); color: var(--accent-text); }
.eb-badge-check { background: var(--ok-bg); color: var(--ok-text); border: 1px solid var(--ok-line); }

/* ---------- Fields ---------- */

.eb-fields {
    display: grid;
    gap: 14px;
    margin-bottom: 14px;
}

.eb-fields[hidden] { display: none; }

.eb-field {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.eb-field label {
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
}

.eb-req,
.eb-opt {
    margin-left: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

.eb input[type="text"],
.eb input[type="month"],
.eb select {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    min-height: 48px;
    padding: 8px 12px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: 600 16px var(--font);
}

.eb input:focus-visible,
.eb select:focus-visible,
.eb-btn:focus-visible,
.eb-remove:focus-visible {
    outline: none;
    box-shadow: var(--ring);
}

.eb input[aria-invalid="true"] {
    border-color: var(--err-text);
}

.eb-err {
    margin: 4px 0 0;
    color: var(--err-text);
    font-size: 14px;
    font-weight: 600;
}

.eb-err[hidden] { display: none; }

.eb-readout {
    margin: 0;
    min-height: 1.4em;
    color: var(--accent-text);
    font-size: 15px;
    font-weight: 700;
}

.eb-readout.is-bad { color: var(--err-text); }

/* ---------- Input mode choice ---------- */

.eb-mode {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 0 14px;
    padding: 0;
    border: 0;
}

.eb-mode legend {
    width: 100%;
    margin-bottom: 8px;
    padding: 0;
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
}

.eb-mode label {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 6px 14px;
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}

.eb-mode input { accent-color: var(--accent); width: 18px; height: 18px; margin: 0; }
.eb-mode label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-text); }
.eb-mode label:has(input:focus-visible) { box-shadow: var(--ring); }

/* ---------- Check meter rows ---------- */

.eb-rows {
    display: grid;
    gap: 12px;
    margin: 0 0 14px;
    padding: 0;
    list-style: none;
}

.eb-row {
    display: grid;
    gap: 12px;
    min-width: 0;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--bg-soft);
}

.eb-row.is-common {
    border-style: dashed;
    border-color: var(--line-strong);
}

.eb-row-head {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
}

.eb-num {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--ok-bg);
    border: 1px solid var(--ok-line);
    color: var(--ok-text);
    font-size: 13px;
    font-weight: 800;
}

.eb-remove {
    min-width: 44px;
    min-height: 44px;
    padding: 6px 12px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--err-text);
    font: 700 14px var(--font);
    cursor: pointer;
}

.eb-remove:hover { background: var(--err-bg); border-color: var(--err-line); }

.eb-row-fields {
    display: grid;
    gap: 12px;
}

.eb-by-readings { display: none; }
.eb-rows.is-readings .eb-by-units { display: none; }
.eb-rows.is-readings .eb-by-readings { display: grid; }

.eb-row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
}

.eb-total {
    margin: 0;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--panel);
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
}

/* ---------- Buttons ---------- */

.eb-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 8px 18px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: 700 15px var(--font);
    cursor: pointer;
}

.eb-btn:hover:not(:disabled) { background: var(--panel); }
.eb-btn:disabled { opacity: .55; cursor: not-allowed; }

.eb-btn-primary {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--on-accent);
}

.eb-btn-primary:hover:not(:disabled) { background: var(--accent-hover); color: var(--on-accent); }

.eb-btn-quiet { border-color: transparent; background: transparent; color: var(--accent-text); }
.eb-btn-small { min-height: 40px; padding: 4px 14px; font-size: 14px; }

.eb-submit,
.eb-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.eb-row-actions .eb-btn { flex: 1 1 100%; }

.eb-summary-errors {
    padding: 14px 16px;
    border: 1px solid var(--err-line);
    border-radius: var(--radius-sm);
    background: var(--err-bg);
    color: var(--err-text);
    font-size: 15px;
}

.eb-summary-errors[hidden] { display: none; }
.eb-summary-errors p { margin: 0 0 6px; }
.eb-summary-errors ul { margin: 0; padding-left: 20px; }
.eb-errors-title { font-weight: 800; }

/* ---------- Results ---------- */

.eb-results {
    display: grid;
    gap: 16px;
    padding-top: 6px;
    scroll-margin-top: 80px;
}

.eb-results[hidden] { display: none; }
.eb-results:focus { outline: none; }
.eb-results h2 { margin: 0; font-size: 24px; }

.eb-results.is-stale { border-left: 4px solid var(--warn-text); padding-left: 12px; }

.eb-print-head { display: none; }

.eb-diff {
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    font-size: 15px;
}

.eb-diff p { margin: 0 0 6px; }
.eb-diff p:last-child { margin-bottom: 0; }
.eb-diff-title { font-weight: 800; }
.eb-diff.is-ok { border-color: var(--ok-line); background: var(--ok-bg); color: var(--ok-text); }
.eb-diff.is-warn { border-color: var(--warn-line); background: var(--warn-bg); color: var(--warn-text); }

.eb-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin: 0;
}

.eb-stat {
    min-width: 0;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
}

.eb-stat dt {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .05em;
    text-transform: uppercase;
}

.eb-stat dd {
    margin: 2px 0 0;
    color: var(--text);
    font-size: 19px;
    font-weight: 800;
    overflow-wrap: anywhere;
}

/* Results table: cards on small screens */

.eb-table { width: 100%; border-collapse: collapse; }

.eb-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.eb-table,
.eb-table tbody,
.eb-table tfoot,
.eb-table tr,
.eb-table th,
.eb-table td { display: block; }

.eb-table tbody tr,
.eb-table tfoot tr {
    margin-bottom: 12px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
}

.eb-table tfoot tr { border-color: var(--accent); background: var(--accent-soft); }

.eb-table th[scope="row"] {
    margin-bottom: 6px;
    padding: 0;
    text-align: left;
    font-size: 17px;
    font-weight: 800;
    overflow-wrap: anywhere;
}

.eb-table td {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 5px 0;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.eb-table td[data-label]::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
    text-align: left;
}

.eb-table td.eb-pay {
    margin-top: 4px;
    padding-top: 8px;
    border-top: 1px solid var(--line);
    color: var(--accent-text);
    font-size: 22px;
    font-weight: 800;
}

.eb-table td.eb-pay::before { color: var(--text); font-size: 15px; font-weight: 700; }

.eb-copy-cell { padding-top: 8px; }
.eb-copy-cell .eb-btn { width: 100%; }
.eb-table tfoot td:last-child { display: none; }

.eb-chip {
    margin-left: 8px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--panel);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    vertical-align: middle;
}

.eb-disclaimer {
    margin: 0;
    padding: 12px 14px;
    border-left: 4px solid var(--line-strong);
    border-radius: 4px;
    background: var(--panel);
    color: var(--muted);
    font-size: 14px;
}

.eb-actions .eb-btn { width: 100%; }

/* ---------- Wider screens ---------- */

@media (min-width: 560px) {
    .eb-card { padding: 22px; }
    .eb-row-actions .eb-btn { flex: 0 0 auto; }
    .eb-submit,
    .eb-actions { flex-direction: row; flex-wrap: wrap; }
    .eb-actions .eb-btn,
    .eb-submit .eb-btn { width: auto; }
    .eb-by-readings { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .eb-by-readings .eb-readout { grid-column: 1 / -1; }
    .eb-by-units { max-width: 280px; }
}

@media (min-width: 680px) {
    .eb-fields { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
    .eb-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }

    .eb-table { display: table; }
    .eb-table thead { position: static; width: auto; height: auto; overflow: visible; clip: auto; display: table-header-group; }
    .eb-table tbody { display: table-row-group; }
    .eb-table tfoot { display: table-footer-group; }
    .eb-table tr { display: table-row; }
    .eb-table th,
    .eb-table td { display: table-cell; }

    .eb-table tbody tr,
    .eb-table tfoot tr { margin: 0; padding: 0; border: 0; border-radius: 0; background: transparent; }
    .eb-table tfoot tr { background: var(--accent-soft); }

    .eb-table th,
    .eb-table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }

    .eb-table thead th {
        color: var(--muted);
        font-size: 13px;
        font-weight: 700;
        letter-spacing: .04em;
        text-align: left;
        text-transform: uppercase;
        border-bottom: 2px solid var(--line-strong);
    }

    .eb-table th.num,
    .eb-table td.num { text-align: right; }
    .eb-table th[scope="row"] { margin: 0; font-size: 16px; }
    .eb-table td { justify-content: normal; }
    .eb-table td[data-label]::before { content: none; }
    .eb-table td.eb-pay { margin: 0; padding: 12px 14px; border-top: 0; border-bottom: 1px solid var(--line); font-size: 19px; }
    .eb-copy-cell { padding-top: 12px; width: 1%; white-space: nowrap; }
    .eb-copy-cell .eb-btn { width: auto; }
    .eb-table tfoot td:last-child { display: table-cell; }
    .eb-table tfoot th,
    .eb-table tfoot td { font-weight: 800; }

    .eb-row-head { grid-template-columns: auto minmax(0, 360px) 1fr; }
    .eb-row-head .eb-remove { justify-self: end; }
}

/* ---------- Print: only the result ---------- */

@media print {
    .sidebar,
    .sidebar-backdrop,
    .topbar,
    .site-footer,
    .tool-breadcrumb,
    .tool-badges,
    .tool-intro,
    .tool-page > .eyebrow,
    .tool-page > h1,
    .tool-info,
    .eb-form,
    .eb-noprint { display: none !important; }

    .app { display: block; }
    .shell { max-width: none; padding: 0; }
    .eb-results { display: block; color: #000; }
    .eb-results[hidden] { display: none; }
    .eb-print-head { display: block; font-size: 18px; font-weight: 800; margin-bottom: 8px; }
    .eb-stats { grid-template-columns: repeat(3, 1fr); }
    .eb-table { page-break-inside: auto; }
    .eb-table tr { page-break-inside: avoid; }
    .eb-diff, .eb-stat, .eb-disclaimer { background: none !important; color: #000 !important; }
}

/* Safari ignores min-height on native selects, so draw our own arrow (keeps the 48px target). */
.eb select {
    -webkit-appearance: none;
    appearance: none;
    padding-right: 38px;
    background-image:
        linear-gradient(45deg, transparent 50%, var(--muted) 50%),
        linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: calc(100% - 20px) 52%, calc(100% - 14px) 52%;
    background-size: 6px 6px;
    background-repeat: no-repeat;
}
