:root {
    --bg: #fdfcf8;
    --surface: #ffffff;
    --surface-alt: #f6f3ec;
    --ink: #1a1814;
    --ink-soft: #545049;
    --muted: #8a8478;
    --line: #e7e2d6;
    --accent: #d44b1e;
    --accent-ink: #ffffff;
    --ok: #2f7a3a;
    --warn: #b86b00;
    --err: #c0322c;
    --radius: 6px;
    --max-w: 1080px;
    --narrow-w: 720px;
    --shadow-sm: 0 1px 2px rgba(20, 14, 4, 0.04);
    font-size: 16px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", system-ui, sans-serif;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    /* Sticky-footer scaffold: body fills the viewport, #main grows, footer is pushed down */
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

#main { flex: 1 0 auto; }

a { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { color: var(--accent); }

h1, h2, h3 { font-weight: 600; line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: 2.4rem; margin: 0.4em 0 0.6em; }
h2 { font-size: 1.4rem; margin: 1.6em 0 0.6em; }
h3 { font-size: 1.1rem; }

code, pre {
    font-family: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.92em;
}
pre {
    background: var(--surface-alt);
    padding: 1rem 1.2rem;
    border-radius: var(--radius);
    overflow-x: auto;
    border: 1px solid var(--line);
}
code {
    background: var(--surface-alt);
    padding: 0.1em 0.35em;
    border-radius: 4px;
}
pre code { background: transparent; padding: 0; }

.container { max-width: var(--max-w); margin: 0 auto; padding: 0 1.5rem; }
.narrow { max-width: var(--narrow-w); }

.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: 0.9rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
.skip-link { position: absolute; left: -9999px; top: 0; }
.skip-link:focus { left: 0; padding: 0.5rem 1rem; background: var(--ink); color: var(--bg); z-index: 999; }

/* Header / nav */
.site-header {
    border-bottom: 1px solid var(--line);
    background: var(--bg);
    position: sticky; top: 0; z-index: 10;
}
.nav { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.5rem; }
.nav nav { display: flex; align-items: center; gap: 1.5rem; }
.nav nav a { text-decoration: none; color: var(--ink-soft); font-weight: 500; }
.nav nav a:hover { color: var(--accent); }
.brand {
    text-decoration: none;
    font-weight: 700;
    font-size: 1.25rem;
    letter-spacing: -0.02em;
    display: inline-flex; align-items: baseline;
}
.brand-mark { color: var(--accent); }
.brand-tail { color: var(--ink); }

/* Hero */
.hero { padding: 4rem 0 3rem; }
.hero h1 { font-size: clamp(1.4rem, 5vw, 3.4rem); margin-top: 0; white-space: nowrap; }
.lede { font-size: 1.15rem; color: var(--ink-soft); margin: 0 0 2rem; }

.shorten-form {
    display: flex; gap: 0.6rem; flex-wrap: wrap;
    background: var(--surface);
    padding: 0.6rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.shorten-form input {
    flex: 1 1 320px;
    border: 0;
    padding: 0.85rem 1rem;
    font-size: 1rem;
    background: transparent;
    color: var(--ink);
    outline: none;
}
.shorten-form input::placeholder { color: var(--muted); }

.result {
    margin-top: 1.5rem;
    padding: 1rem 1.2rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
}
.result a { color: var(--accent); font-weight: 600; }

.errors {
    margin-top: 1rem;
    background: #fff3f1;
    border: 1px solid #f4cdc6;
    color: var(--err);
    padding: 0.75rem 1rem; border-radius: var(--radius);
    list-style: none;
}

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid transparent;
    padding: 0.7rem 1.2rem;
    border-radius: var(--radius);
    font-weight: 600; font-size: 0.95rem; cursor: pointer;
    text-decoration: none;
    transition: transform 0.05s ease, background 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #b53d15; color: var(--accent-ink); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-secondary:hover { background: var(--surface-alt); }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: var(--line); }
.btn-ghost:hover { color: var(--ink); }
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.85rem; }
.btn-block { width: 100%; }

.link-button {
    background: none; border: none; padding: 0;
    font: inherit; cursor: pointer; color: var(--ink-soft);
    text-decoration: underline;
}
.link-button.danger { color: var(--err); }

.inline-form { display: inline; }

/* Features grid */
.features {
    display: grid; gap: 1.5rem; padding: 2rem 1.5rem 4rem;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    max-width: var(--max-w);
}
.features article {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.5rem;
}
.features h2 { margin-top: 0; font-size: 1.1rem; }
.features p { color: var(--ink-soft); margin: 0; font-size: 0.95rem; }

/* Footer */
.site-footer {
    border-top: 1px solid var(--line);
    margin-top: auto; /* pin to bottom when content is short; flush after content otherwise */
    padding: 2rem 0;
    background: var(--surface-alt);
}
.footer-grid {
    display: grid; gap: 1.5rem;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    align-items: center;
}
.footer-brand { font-weight: 600; margin: 0; }
.footer-tagline { white-space: nowrap; margin: 0.25rem 0 0; }
.site-footer nav { display: flex; gap: 1.2rem; flex-wrap: wrap; }
.site-footer nav a { color: var(--ink-soft); text-decoration: none; }
.site-footer nav a:hover { color: var(--accent); }

/* Auth */
.auth-box { padding: 3rem 0; }
.auth-box h1 { text-align: center; }
.form-stack { display: grid; gap: 1rem; margin: 1.5rem 0; }
.field { display: grid; gap: 0.3rem; }
.field input:not([type=checkbox]) {
    padding: 0.7rem 0.9rem; font-size: 1rem;
    border: 1px solid var(--line); border-radius: var(--radius);
    background: var(--surface); color: var(--ink);
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field textarea {
    padding: 0.7rem 0.9rem; font-size: 1rem;
    border: 1px solid var(--line); border-radius: var(--radius);
    background: var(--surface); color: var(--ink);
    font-family: inherit; line-height: 1.5; resize: vertical;
}
.field textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field label { font-weight: 500; font-size: 0.95rem; }
.field-inline { display: flex; align-items: center; gap: 0.5rem; }
.field span.field-validation-error { color: var(--err); font-size: 0.85rem; }

.divider { display: flex; align-items: center; gap: 0.6rem; color: var(--muted); margin: 1rem 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.external-login { margin-bottom: 1rem; }

/* Dashboard */
.page-header {
    display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between;
    gap: 1rem; padding: 2rem 0 1rem;
    border-bottom: 1px solid var(--line);
    margin-bottom: 1.5rem;
}
.page-header h1 { margin: 0; font-size: 1.8rem; }
.tabs { display: flex; gap: 0.5rem; }
.tab {
    text-decoration: none; padding: 0.4rem 0.9rem; border-radius: var(--radius);
    color: var(--ink-soft); font-weight: 500; font-size: 0.95rem;
}
.tab:hover { background: var(--surface-alt); color: var(--ink); }
.tab.active { background: var(--ink); color: var(--bg); }

.row-form {
    display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: stretch;
    margin-bottom: 1.5rem;
}
.row-form input:not([type=checkbox]) {
    flex: 1 1 220px;
    padding: 0.6rem 0.9rem;
    border: 1px solid var(--line); border-radius: var(--radius);
    background: var(--surface);
}
.row-checkbox {
    display: inline-flex; align-items: center; gap: 0.4rem;
    color: var(--ink-soft); font-size: 0.95rem;
    padding: 0 0.5rem;
}

.data-table {
    width: 100%; border-collapse: collapse;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    overflow: hidden;
}
.data-table th, .data-table td {
    padding: 0.7rem 0.9rem; text-align: left; border-bottom: 1px solid var(--line);
    font-size: 0.95rem; vertical-align: top;
}
.data-table th { background: var(--surface-alt); font-weight: 600; color: var(--ink-soft); }
.data-table tr:last-child td { border-bottom: none; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .truncate { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
    display: inline-block; padding: 0.15rem 0.55rem;
    border-radius: 999px; font-size: 0.8rem; font-weight: 500;
}
.badge-ok { background: #e6f3e9; color: var(--ok); }
.badge-pending { background: #fcf2dc; color: var(--warn); }

.callout {
    padding: 1rem 1.2rem; border-radius: var(--radius);
    border: 1px solid var(--line); background: var(--surface-alt);
    margin-bottom: 1.5rem;
}
.callout-warn { background: #fff5db; border-color: #f3dba1; }

.flash {
    margin: 1rem 0; padding: 0.75rem 1rem; border-radius: var(--radius);
    border: 1px solid var(--line);
}
.flash-ok { background: #e6f3e9; border-color: #c6e3cd; color: var(--ok); }
.flash-error { background: #fff3f1; border-color: #f4cdc6; color: var(--err); }

@media (max-width: 640px) {
    .nav { padding: 0.8rem 1rem; }
    .nav nav { gap: 1rem; }
    .nav nav a:not(.btn) { display: none; }
    .hero { padding: 2rem 0; }
    .data-table .truncate { max-width: 140px; }
}

/* Selects — native control, themed to match inputs (matches the sibling apps' approach) */
select,
.domain-select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    font: inherit;
    font-size: 1rem;
    color: var(--ink);
    background-color: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0.7rem 2.3rem 0.7rem 0.9rem;
    line-height: 1.3;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a8478' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.8rem center;
    background-size: 0.85rem;
}
select:hover,
.domain-select:hover { border-color: var(--muted); }
select:focus,
.domain-select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
select option,
.domain-select option { background: var(--surface); color: var(--ink); }
/* In the public shorten form the select sits inline with the URL input + button */
.shorten-form .domain-select { flex: 0 0 auto; }

/* Confirmation modal — replaces native confirm(); hand-rolled like the sibling apps, no JS lib */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(26, 24, 20, 0.45);
    animation: modal-fade 0.12s ease;
}
.modal-overlay[hidden] { display: none; }
.modal-box {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 16px 48px rgba(20, 14, 4, 0.18);
    width: 100%;
    max-width: 400px;
    padding: 1.6rem 1.6rem 1.3rem;
    animation: modal-pop 0.14s ease;
}
.modal-title { margin: 0 0 0.5rem; font-size: 1.15rem; }
.modal-msg { margin: 0 0 1.4rem; color: var(--ink-soft); font-size: 0.95rem; line-height: 1.55; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }
.modal-btn {
    padding: 0.5rem 1.1rem;
    font: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    cursor: pointer;
}
.modal-btn-cancel { background: var(--surface); color: var(--ink-soft); }
.modal-btn-cancel:hover { border-color: var(--muted); color: var(--ink); }
.modal-btn-confirm { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.modal-btn-confirm:hover { background: #b53e18; }
.modal-btn-confirm.danger { background: var(--err); border-color: var(--err); }
.modal-btn-confirm.danger:hover { background: #a52a25; }
@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-pop {
    from { opacity: 0; transform: scale(0.96) translateY(4px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
    .modal-overlay, .modal-box { animation: none; }
}

/* Copy-to-clipboard icon button (mask defines the shape; background-color fills it, so it follows the theme) */
.copy-icon {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    margin-left: 0.45rem;
    vertical-align: middle;
    border: 0;
    padding: 0;
    cursor: pointer;
    background-color: var(--muted);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='9' y='9' width='13' height='13' rx='2'/%3E%3Cpath d='M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1'/%3E%3C/svg%3E") no-repeat center / contain;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='9' y='9' width='13' height='13' rx='2'/%3E%3Cpath d='M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1'/%3E%3C/svg%3E") no-repeat center / contain;
    transition: background-color 0.12s;
}
.copy-icon:hover { background-color: var(--accent); }
.copy-icon:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.copy-icon.copied {
    background-color: var(--ok);
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
}
