/* Reusable components. Markup for most of them lives in templates/_ui.html. */

/* ---------- Icon ---------- */

.icon {
    flex: none;
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ---------- Card ---------- */

.card {
    background: var(--surface);
    border-radius: var(--r-card);
    padding: 20px;
    box-shadow: var(--shadow-card);
}

/* ---------- Section head ---------- */

.section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin: 0 4px 10px;
}

.section-title {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.section-aside {
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-2);
    white-space: nowrap;
}

.card .section-head { margin-inline: 0; }

/* ---------- Text helpers ---------- */

.label {
    font-size: 13px;
    font-weight: 500;
    color: var(--ink-2);
}

.note {
    font-size: 12.5px;
    color: var(--ink-2);
    line-height: 1.45;
}

.pos, .row-end small.pos { color: var(--accent); }
.neg, .row-end small.neg { color: var(--down-ink); }
.wide-only { display: none; }

@media (min-width: 760px) {
    .wide-only { display: inline; }
}

/* ---------- Big figure ---------- */

.figure {
    font-size: clamp(36px, 11vw, 46px);
    font-weight: 700;
    letter-spacing: -0.035em;
    line-height: 1.08;
    white-space: nowrap;
}

.figure small {
    font-size: 0.52em;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--ink-3);
}

/* ---------- Chip ---------- */

.chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 11px;
    border-radius: var(--r-pill);
    background: var(--surface-2);
    color: var(--ink-2);
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

.chip-up { background: var(--accent-soft); color: var(--accent-ink); }
.chip-down { background: var(--down-soft); color: var(--down-ink); }

.chip-alert {
    background: var(--butter);
    color: var(--butter-ink);
    font-weight: 500;
}

.chip-alert::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

.chip-alert strong { font-weight: 700; }
button.chip { min-height: 38px; padding-inline: 14px; cursor: pointer; }

/* ---------- Stat tiles ---------- */

.stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.stat {
    min-width: 0;
    padding: 13px 12px 14px;
    border-radius: var(--r-tile);
    background: var(--surface);
}

.stat-label {
    font-size: 12.5px;
    font-weight: 500;
    opacity: 0.78;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stat-value {
    display: block;
    margin-top: 3px;
    font-size: clamp(14px, 4.6vw, 21px);
    font-weight: 700;
    font-variant-numeric: proportional-nums;
    letter-spacing: -0.03em;
    white-space: nowrap;
}

.stat-mint { background: var(--accent-soft); color: var(--accent-ink); }
.stat-peach { background: var(--peach); color: var(--peach-ink); }
.stat-lilac { background: var(--lilac); color: var(--lilac-ink); }
.stat-sky { background: var(--sky); color: var(--sky-ink); }
.stat-rose { background: var(--rose); color: var(--rose-ink); }

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 46px;
    padding: 0 22px;
    border-radius: var(--r-pill);
    background: var(--ink);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    transition: transform 0.12s var(--ease), opacity 0.15s;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-soft { background: var(--surface-2); color: var(--ink); }
.btn-block { width: 100%; }

.icon-btn {
    flex: none;
    display: inline-grid;
    place-items: center;
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--surface);
    color: var(--ink);
    cursor: pointer;
    transition: transform 0.12s var(--ease);
}

.icon-btn:active { transform: scale(0.94); }
.icon-btn-dark { background: var(--ink); color: #fff; }
.icon-btn-lg { width: 46px; height: 46px; }

@media (min-width: 760px) {
    .icon-btn:not(.icon-btn-lg) { width: 40px; height: 40px; }
}
.icon-btn.htmx-request .icon { animation: spin 0.9s linear infinite; }

.badge {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: var(--r-pill);
    border: 2px solid var(--bg);
    background: var(--accent);
    color: #fff;
    font-size: 10.5px;
    font-weight: 700;
    line-height: 14px;
    text-align: center;
}

/* ---------- Segmented control ---------- */

.seg {
    display: inline-flex;
    padding: 3px;
    border-radius: var(--r-pill);
    background: var(--surface-2);
}

.seg-btn {
    flex: 1;
    min-height: 38px;
    padding: 9px 13px;
    border-radius: var(--r-pill);
    color: var(--ink-2);
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
}

.seg-btn:hover { color: var(--ink); }

.seg-btn.is-active,
.seg input:checked + .seg-btn {
    background: var(--surface);
    color: var(--ink);
    box-shadow: 0 1px 2px rgba(28, 36, 32, 0.12);
}

.seg input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.seg input:focus-visible + .seg-btn { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg-block { display: flex; }
.seg-on-bg { background: rgba(255, 255, 255, 0.6); }

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

.field {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
    height: 46px;
    padding: 0 16px;
    border-radius: var(--r-pill);
    background: var(--surface);
    color: var(--ink-3);
}

.field input {
    flex: 1;
    min-width: 0;
    height: 100%;
    border: 0;
    outline: 0;
    background: none;
    color: var(--ink);
    font-size: 16px;
}

.field input::placeholder { color: var(--ink-3); }
.field:focus-within { box-shadow: 0 0 0 2px var(--accent); }
.field input[type="search"]::-webkit-search-cancel-button { cursor: pointer; }

.input,
.select {
    display: block;
    width: 100%;
    min-width: 0;
    height: 46px;
    padding: 0 14px;
    border: 0;
    border-radius: var(--r-input);
    background-color: var(--surface-2);
    color: var(--ink);
    font-size: 16px;
    font-weight: 500;
}

.input::placeholder { color: var(--ink-3); font-weight: 400; }
.input:focus-visible, .select:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }

.select {
    appearance: none;
    padding-right: 38px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b948e' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 13px center;
    background-size: 16px;
    text-overflow: ellipsis;
    cursor: pointer;
}

.form-label {
    display: block;
    margin: 16px 0 8px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--ink-2);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.captioned {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    padding-left: 12px;
    border-radius: var(--r-input);
    background: var(--surface-2);
    font-size: 13px;
    font-weight: 600;
    color: var(--ink-2);
}

.captioned .input {
    flex: 1;
    padding-left: 0;
    background: none;
}

.captioned:focus-within { outline: 2px solid var(--accent); }
.captioned .input:focus-visible { outline: 0; }

/* ---------- List rows ---------- */

.list {
    background: var(--surface);
    border-radius: var(--r-tile);
    padding: 2px 14px;
}

.row {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    padding: 11px 0;
}

.row-main { flex: 1; min-width: 0; }

.row-title {
    display: block;
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.row-title .soft { font-weight: 400; color: var(--ink-2); }

.row-sub {
    display: block;
    margin-top: 1px;
    font-size: 12.5px;
    color: var(--ink-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.row-end {
    flex: none;
    font-size: 15px;
    font-weight: 600;
    text-align: right;
    white-space: nowrap;
}

.row-end small {
    display: block;
    margin-top: 1px;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--ink-2);
}

.list > * + *,
.list > details + details { border-top: 1px solid var(--line); }

.chevron {
    flex: none;
    width: 16px;
    height: 16px;
    color: var(--ink-3);
}

/* ---------- Category dot: pastel disc tinted from the category colour ---------- */

.cat-dot {
    --c: var(--ink-3);
    flex: none;
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--c) 16%, #fff);
    color: color-mix(in srgb, var(--c) 82%, #000);
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
}

.cat-dot-sm { width: 28px; height: 28px; font-size: 12px; }

.swatch {
    --c: var(--ink-3);
    flex: none;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--c) 78%, #fff);
}

/* ---------- Progress ---------- */

.progress {
    height: 8px;
    border-radius: var(--r-pill);
    background: var(--surface-2);
    overflow: hidden;
}

.progress > span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--accent);
}

/* ---------- Status pill ---------- */

.status-pill {
    flex: none;
    padding: 4px 10px;
    border-radius: var(--r-pill);
    background: var(--surface-2);
    color: var(--ink-2);
    font-size: 12px;
    font-weight: 600;
}

.status-pill-ok { background: var(--accent-soft); color: var(--accent-ink); }
.status-pill-broken { background: var(--down-soft); color: var(--down-ink); }

/* ---------- Empty state ---------- */

.empty {
    padding: 28px 20px;
    border-radius: var(--r-tile);
    background: rgba(255, 255, 255, 0.5);
    color: var(--ink-2);
    font-size: 14px;
    text-align: center;
}

.empty code {
    display: block;
    margin-top: 8px;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 12.5px;
    overflow-wrap: anywhere;
}

.card .empty { background: var(--surface-2); }

/* ---------- Sparkline ---------- */

.spark-line {
    fill: none;
    stroke: var(--accent);
    stroke-width: 2.5;
    stroke-linejoin: round;
    stroke-linecap: round;
    vector-effect: non-scaling-stroke;
}

/* ---------- Sheet: bottom sheet on phones, inline on wide screens ---------- */

.sheet-grab,
.sheet-title { display: none; }

@media (max-width: 759px) {
    .sheet {
        position: fixed;
        z-index: 60;
        inset: 0;
        display: flex;
        align-items: flex-end;
        background: var(--scrim);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.2s, visibility 0.2s;
    }

    .sheet[data-open] { opacity: 1; visibility: visible; }

    .sheet-panel {
        width: 100%;
        max-height: 92dvh;
        overflow-y: auto;
        padding: 10px 20px calc(22px + env(safe-area-inset-bottom));
        border-radius: 28px 28px 0 0;
        background: var(--surface);
        transform: translateY(100%);
        transition: transform 0.28s var(--ease);
    }

    .sheet[data-open] .sheet-panel { transform: none; }

    .sheet-grab {
        display: block;
        width: 38px;
        height: 4px;
        margin: 0 auto 14px;
        border-radius: var(--r-pill);
        background: var(--line-strong);
    }

    .sheet-title {
        display: block;
        font-size: 19px;
        font-weight: 700;
        letter-spacing: -0.01em;
    }

    .sheet-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        margin-top: 22px;
    }
}

/* ---------- Dialog ---------- */

.dialog {
    width: min(440px, calc(100vw - 24px));
    padding: 22px 20px 20px;
    border: 0;
    border-radius: 28px;
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow-float);
}

.dialog::backdrop { background: var(--scrim); }
.dialog[open] { animation: pop 0.2s var(--ease); }

.dialog-title {
    font-size: 19px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.dialog-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 22px;
}

.file-input {
    display: block;
    width: 100%;
    padding: 12px 14px;
    border-radius: var(--r-input);
    background: var(--surface-2);
    font-size: 14px;
}

.file-input::file-selector-button {
    margin-right: 12px;
    padding: 6px 12px;
    border: 0;
    border-radius: var(--r-pill);
    background: var(--ink);
    color: #fff;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
