/*
 * Default design. Hand-written: design tokens, then base elements, layout and
 * components. There is no build step.
 *
 * Restyle an app by linking a stylesheet after this one that overrides the tokens in
 * :root, and the component rules where needed. Default pages use only the classes
 * below, so a custom layout can style them itself instead of linking this file.
 *
 * Sections: 1 Tokens  2 Base  3 Layout  4 Components  5 Forms  6 Dialogs
 *           7 States  8 Utilities  9 Reduced motion
 */

/* 1 Tokens ---------------------------------------------------------------- */

:root {
    color-scheme: light dark;

    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;

    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.375rem;
    --text-2xl: 1.875rem;

    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-7: 3rem;

    --radius-sm: 4px;
    --radius: 8px;
    --radius-lg: 12px;
    --wrap: 64rem;
    --ease: cubic-bezier(0.2, 0, 0, 1);

    --bg: #f7f7f8;
    --surface: #ffffff;
    --sunken: #f0f0f2;
    --line: #e2e2e6;
    --line-strong: #c9c9d0;
    --text: #18181b;
    --text-soft: #3f3f46;
    --muted: #6b6b75;
    --accent: #2f5bd3;
    --accent-hover: #2449b0;
    --on-accent: #ffffff;
    --focus: #2f5bd3;

    --success: #17703a;
    --success-surface: #eaf7ee;
    --success-line: #b4e0c2;
    --warning: #8a5a00;
    --warning-surface: #fff6e0;
    --warning-line: #f0d48f;
    --danger: #b42318;
    --danger-hover: #93190f;
    --danger-surface: #fdecea;
    --danger-line: #f3b8b2;

    --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 1px 1px rgb(0 0 0 / 0.04);
    --shadow-dialog: 0 20px 50px rgb(0 0 0 / 0.25);
    --backdrop: rgb(15 15 20 / 0.55);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #111114;
        --surface: #1a1a1f;
        --sunken: #141418;
        --line: #2c2c33;
        --line-strong: #3d3d46;
        --text: #ececf0;
        --text-soft: #c8c8d0;
        --muted: #9a9aa6;
        --accent: #7b9cff;
        --accent-hover: #9bb4ff;
        --on-accent: #0b1020;
        --focus: #9bb4ff;

        --success: #6fd58f;
        --success-surface: #12261a;
        --success-line: #24502f;
        --warning: #f2c45a;
        --warning-surface: #2a2210;
        --warning-line: #5a4716;
        --danger: #ff8a7f;
        --danger-hover: #ffb0a8;
        --danger-surface: #2c1513;
        --danger-line: #612a25;

        --shadow: 0 1px 2px rgb(0 0 0 / 0.4);
        --shadow-dialog: 0 20px 50px rgb(0 0 0 / 0.6);
        --backdrop: rgb(0 0 0 / 0.65);
    }
}

/* 2 Base ------------------------------------------------------------------ */

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

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

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: 1.55;
}

h1,
h2,
h3 {
    margin: 0;
    line-height: 1.25;
    color: var(--text);
}

h1 {
    font-size: var(--text-2xl);
}

h2 {
    font-size: var(--text-xl);
}

h3 {
    font-size: var(--text-lg);
}

p {
    margin: 0;
}

a {
    color: var(--accent);
    text-underline-offset: 0.15em;
}

a:hover {
    color: var(--accent-hover);
}

code,
pre,
kbd {
    font-family: var(--font-mono);
    font-size: 0.9em;
}

:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

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

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

.wrap {
    width: 100%;
    max-width: var(--wrap);
    margin-inline: auto;
    padding-inline: var(--space-4);
}

.skip-link {
    position: absolute;
    left: var(--space-2);
    top: -10rem;
    z-index: 10;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
}

.skip-link:focus {
    top: var(--space-2);
}

.site-header {
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}

.site-header .wrap {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3) var(--space-5);
    padding-block: var(--space-3);
}

.brand {
    color: var(--text);
    font-weight: 700;
    font-size: var(--text-lg);
    text-decoration: none;
}

.site-nav ul {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-4);
    margin: 0;
    padding: 0;
    list-style: none;
}

.site-nav a {
    color: var(--text-soft);
    text-decoration: none;
}

.site-nav a:hover,
.site-nav a[aria-current="page"] {
    color: var(--text);
    text-decoration: underline;
    text-decoration-thickness: 2px;
}

.site-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    padding-block: var(--space-6) var(--space-7);
}

.site-footer {
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: var(--text-sm);
}

.site-footer .wrap {
    padding-block: var(--space-5);
}

.page-header {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.lead {
    color: var(--text-soft);
    font-size: var(--text-lg);
}

.stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.cluster {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
}

.narrow {
    width: 100%;
    max-width: 28rem;
    margin-inline: auto;
}

.grid {
    display: grid;
    gap: var(--space-4);
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr));
}

/* 4 Components ------------------------------------------------------------ */

.panel {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    padding: var(--space-5);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.panel.danger {
    border-color: var(--danger-line);
}

.panel-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
}

.panel-header > div {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.panel-header p,
.hint,
.muted {
    color: var(--muted);
    font-size: var(--text-sm);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 2.5rem;
    padding: var(--space-2) var(--space-4);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 120ms var(--ease), border-color 120ms var(--ease);
}

.btn:hover {
    border-color: var(--text-soft);
    color: var(--text);
}

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

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

.btn.danger {
    border-color: var(--danger);
    background: var(--danger);
    color: var(--surface);
}

.btn.danger:hover {
    border-color: var(--danger-hover);
    background: var(--danger-hover);
}

.btn.ghost {
    border-color: transparent;
    background: transparent;
}

.btn.ghost:hover {
    background: var(--sunken);
}

.btn.small {
    min-height: 2rem;
    padding: var(--space-1) var(--space-3);
    font-size: var(--text-sm);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.link-button {
    padding: 0;
    border: 0;
    background: none;
    color: var(--accent);
    font: inherit;
    text-decoration: underline;
    text-underline-offset: 0.15em;
    cursor: pointer;
}

.notice {
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--sunken);
    color: var(--text-soft);
}

.notice.success {
    border-color: var(--success-line);
    background: var(--success-surface);
    color: var(--success);
}

.notice.warning {
    border-color: var(--warning-line);
    background: var(--warning-surface);
    color: var(--warning);
}

.notice.danger {
    border-color: var(--danger-line);
    background: var(--danger-surface);
    color: var(--danger);
}

.item-list {
    margin: 0;
    padding: 0;
    list-style: none;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2) var(--space-4);
    padding: var(--space-3) var(--space-4);
}

.item + .item {
    border-top: 1px solid var(--line);
}

.item-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.item-main > :first-child {
    font-weight: 600;
    overflow-wrap: anywhere;
}

.item-detail {
    color: var(--muted);
    font-size: var(--text-sm);
}

.empty {
    padding: var(--space-5);
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius);
    color: var(--muted);
    text-align: center;
}

.tag {
    display: inline-block;
    padding: 0 var(--space-2);
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 600;
    vertical-align: middle;
}

.tag.success {
    border-color: var(--success-line);
    color: var(--success);
}

.tag.danger {
    border-color: var(--danger-line);
    color: var(--danger);
}

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.data-table th,
.data-table td {
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

.data-table th {
    color: var(--muted);
    font-size: var(--text-sm);
    font-weight: 600;
}

.data-table tr:last-child td {
    border-bottom: 0;
}

.data-table .number {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.stat {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.stat-value {
    font-size: var(--text-2xl);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.stat-label {
    color: var(--muted);
    font-size: var(--text-sm);
}

/* A price broken down: credit, fee and total, with the total last. */
.receipt {
    display: grid;
    gap: var(--space-1);
    margin: 0;
    color: var(--muted);
    font-size: var(--text-sm);
}

.receipt > div {
    display: flex;
    justify-content: space-between;
    gap: var(--space-4);
}

.receipt > div:last-child {
    padding-top: var(--space-2);
    border-top: 1px solid var(--line);
    color: var(--text);
}

.receipt dd {
    margin: 0;
    font-family: var(--font-mono);
}

.secret {
    display: block;
    padding: var(--space-3);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--sunken);
    font-family: var(--font-mono);
    overflow-wrap: anywhere;
    user-select: all;
}

.pagination {
    display: flex;
    justify-content: space-between;
    gap: var(--space-3);
}

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

.field {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

label {
    font-weight: 600;
}

input:not([type="checkbox"], [type="radio"], [type="hidden"]),
select,
textarea {
    width: 100%;
    min-height: 2.5rem;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    border-color: var(--focus);
    outline-offset: 0;
}

input[aria-invalid="true"] {
    border-color: var(--danger);
}

.field-error {
    color: var(--danger);
    font-size: var(--text-sm);
}

.form-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--space-3);
}

.form-row .field {
    flex: 1 1 14rem;
}

/* 6 Dialogs --------------------------------------------------------------- */

.dialog {
    width: min(32rem, calc(100vw - 2 * var(--space-4)));
    max-height: calc(100vh - 2 * var(--space-4));
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-dialog);
}

.dialog::backdrop {
    background: var(--backdrop);
}

.dialog.danger {
    border-color: var(--danger-line);
}

.dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5) 0;
}

.dialog-body {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    padding: var(--space-4) var(--space-5) var(--space-5);
}

.dialog-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: var(--space-2);
}

.dialog-error:empty {
    display: none;
}

/* 7 States ---------------------------------------------------------------- */

.spinner {
    display: none;
    width: 1em;
    height: 1em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 700ms linear infinite;
}

[aria-busy="true"] > .spinner,
[aria-busy="true"] .btn > .spinner,
.htmx-request > .spinner {
    display: inline-block;
}

[aria-busy="true"] .btn[type="submit"],
.btn[aria-busy="true"] {
    cursor: progress;
}

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

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

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

[hidden] {
    display: none !important;
}

/* 9 Reduced motion -------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 1ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 1ms !important;
    }
}
