/* Shared components: buttons, cards, KPI tiles, badges, segmented controls, fields, notices, dialog, drawer. */
.button {
    display: inline-flex;
    min-height: var(--target);
    align-items: center;
    justify-content: center;
    gap: var(--s2);
    padding: 0 20px;
    border: 1px solid transparent;
    border-radius: 12px;
    background: transparent;
    color: var(--ink);
    font-size: var(--text-md);
    font-weight: var(--weight-book);
    line-height: 1.1;
    text-align: center;
    text-decoration: none;
    white-space: nowrap;
    transition: background-color var(--dur-quick) ease, opacity var(--dur-quick) ease,
        border-color var(--dur-quick) ease;
}

.button-light { background: var(--light-fill); color: var(--ink-on-light); }
.button-light:hover { background: var(--light-fill-hover); }
.button-ghost { border-color: var(--wash-strong); }
.button-ghost:hover { background: var(--wash-strong); }
.button-quiet { background: var(--wash); }
.button-quiet:hover { background: var(--wash-strong); }
.button-danger { background: var(--danger-wash); border-color: rgba(255, 141, 141, 0.35); color: var(--danger-text); }
.button-danger:hover { background: rgba(255, 141, 141, 0.2); }
.button-small { min-height: 36px; padding: 0 14px; border-radius: 10px; font-size: var(--text-sm); }
.button-block { width: 100%; min-height: 50px; font-size: var(--text-base); }
.button[disabled], .button[aria-disabled="true"] { cursor: not-allowed; opacity: 0.45; }
.button .icon { width: 16px; height: 16px; }
.button.is-busy .icon { animation: spin 0.9s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

.link-button {
    padding: 0;
    border: 0;
    background: none;
    color: var(--blue-text);
    font-size: inherit;
    text-align: left;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 3px;
}

/* Cards: soft-bordered, near-transparent on the canvas. */
.card {
    min-width: 0;
    padding: var(--s5);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-card);
    background: var(--card);
}

@media (min-width: 768px) {
    .card { padding: var(--s6); }
}

.card-head {
    display: flex;
    margin-bottom: var(--s4);
    align-items: baseline;
    justify-content: space-between;
    gap: var(--s3);
    flex-wrap: wrap;
}

.card-head p { color: var(--ink-secondary); font-size: var(--text-sm); }
.card-flush { padding: 0; overflow: hidden; }
.card-flush > .card-head { padding: var(--s5) var(--s5) 0; }

@media (min-width: 768px) {
    .card-flush > .card-head { padding: var(--s6) var(--s6) 0; }
}

/* KPI tile: label, value (proportional figures), detail line. */
.kpi { display: flex; min-height: 148px; flex-direction: column; gap: var(--s2); }
.kpi-label { color: var(--ink-secondary); font-size: var(--text-sm); font-weight: var(--weight-medium); }

.kpi-value {
    color: var(--ink);
    font-size: 32px;
    font-weight: var(--weight-book);
    line-height: 1.05;
    letter-spacing: -0.02em;
    overflow-wrap: anywhere;
}

.kpi-detail { margin-top: auto; color: var(--ink-secondary); font-size: var(--text-sm); }
.kpi-detail strong { color: var(--ink); font-weight: var(--weight-medium); }

.metric-unknown {
    color: var(--ink-muted);
    font-weight: var(--weight-medium);
    letter-spacing: 0;
}

.kpi-value .metric-unknown, .hero-amount .metric-unknown { font-size: 0.7em; }

.metric-note {
    display: flex;
    gap: 6px;
    color: var(--ink-muted);
    font-size: var(--text-xs);
    line-height: 1.4;
}

.metric-note .icon { flex: none; width: 14px; height: 14px; margin-top: 1px; }
.metric-prefix { color: var(--ink-secondary); font-size: 0.8em; margin-right: 2px; }

/* Badges carry text; colour is never the only signal. */
.badge {
    display: inline-flex;
    max-width: 100%;
    align-items: center;
    gap: 6px;
    padding: 5px 8px;
    border-radius: var(--radius-xs);
    background: var(--wash);
    color: var(--ink-secondary);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    line-height: 1.15;
    white-space: nowrap;
}

.badge::before {
    width: 6px;
    height: 6px;
    flex: none;
    border-radius: 50%;
    background: currentColor;
    content: "";
}

.badge-plain::before { display: none; }
.badge-mint { background: var(--mint-wash); color: var(--mint-text); }
.badge-violet { background: var(--violet-wash); color: var(--violet-text); }
.badge-blue { background: var(--blue-wash); color: var(--blue-text); }
.badge-amber { background: var(--amber-wash); color: var(--amber-text); }
.badge-danger { background: var(--danger-wash); color: var(--danger-text); }
.badge-outline { border: 1px solid var(--card-border-strong); background: transparent; }
.store-meta { display: block; margin-top: 4px; font-size: var(--text-xs); }

.delta {
    display: inline-flex;
    align-items: center;
    padding: 6px 7px;
    border-radius: var(--radius-xs);
    background: var(--wash-strong);
    color: var(--ink);
    font-size: var(--text-sm);
    font-weight: var(--weight-book);
    line-height: 1;
    white-space: nowrap;
}

.delta-up { background: var(--mint-wash); color: var(--mint-text); }
.delta-down { background: var(--danger-wash); color: var(--danger-text); }

/* Segmented control and pills (radio semantics through aria-pressed buttons). */
.segmented {
    display: inline-flex;
    max-width: 100%;
    align-self: flex-start;
    padding: 3px;
    overflow-x: auto;
    gap: 2px;
    border: 1px solid var(--card-border);
    border-radius: 12px;
    background: var(--canvas-raised);
    scrollbar-width: none;
}

.segmented::-webkit-scrollbar { display: none; }

.segment {
    min-height: 36px;
    padding: 0 14px;
    flex: none;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: var(--ink-secondary);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    white-space: nowrap;
    transition: background-color var(--dur-quick) ease, color var(--dur-quick) ease;
}

.segment:hover { color: var(--ink); }
.segment[aria-pressed="true"], .segment[aria-selected="true"] { background: var(--wash-strong); color: var(--ink); }
.segment[disabled] { cursor: not-allowed; opacity: 0.4; }

/* Fields */
.field { display: flex; min-width: 0; flex-direction: column; gap: 6px; }
.field-label { color: var(--ink-secondary); font-size: var(--text-sm); font-weight: var(--weight-medium); }
.field-hint { color: var(--ink-muted); font-size: var(--text-xs); }

.input, .select {
    width: 100%;
    min-height: var(--target);
    padding: 0 14px;
    border: 1px solid var(--field-border);
    border-radius: 12px;
    background: var(--field);
    color: var(--ink);
    font-size: var(--text-base);
    transition: border-color var(--dur-quick) ease, background-color var(--dur-quick) ease;
}

.input::placeholder { color: var(--ink-muted); }
.input:hover, .select:hover { border-color: var(--wash-strong); }
.input:focus-visible, .select:focus-visible { outline-offset: 1px; border-color: var(--focus); }
.input[aria-invalid="true"] { border-color: var(--danger-text); }
.select { padding-right: 34px; appearance: none; background-image: url("../select.svg");
    background-position: right 12px center; background-repeat: no-repeat; background-size: 12px; }
.select option { background: var(--field); color: var(--ink); }
.input[type="date"] { color-scheme: dark; }

.search { position: relative; }
.search .icon { position: absolute; top: 50%; left: 14px; color: var(--ink-muted); transform: translateY(-50%); }
.search .input { padding-left: 40px; }

/* Notices and states */
.notice {
    display: flex;
    gap: var(--s3);
    align-items: flex-start;
    padding: var(--s3) var(--s4);
    border-radius: var(--radius-md);
    background: var(--wash);
    color: var(--ink);
    font-size: var(--text-md);
}

.notice .icon { flex: none; margin-top: 1px; }
.notice-error { background: var(--danger-wash); color: var(--danger-text); }
.notice-success { background: var(--mint-wash); color: var(--mint-text); }
.notice-warn { background: var(--amber-wash); color: var(--amber-text); }
.notice p + p { margin-top: 4px; }

.state {
    display: flex;
    padding: var(--s10) var(--s5);
    flex-direction: column;
    align-items: center;
    gap: var(--s3);
    color: var(--ink-secondary);
    text-align: center;
}

.state h2 { color: var(--ink); }
.state .icon { width: 28px; height: 28px; color: var(--ink-muted); }
.state .button { margin-top: var(--s2); }

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--wash-strong);
    border-top-color: var(--ink);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.is-refetching { opacity: 0.5; transition: opacity 200ms ease; pointer-events: none; }
