:root {
    --bg: #f3f0ea;
    --bg-accent: #e7e1d6;
    --ink: #1c1b19;
    --muted: #5c574f;
    --link: #0f4c5c;
    --rule: #cfc7b8;
    --ok: #1f5c3a;
    --danger: #8a2a2a;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    min-height: 100%;
}

body {
    font-family: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
    color: var(--ink);
    background:
        radial-gradient(1200px 600px at 10% -10%, #fff8ef 0%, transparent 55%),
        radial-gradient(900px 500px at 100% 0%, #dfece8 0%, transparent 50%),
        linear-gradient(180deg, var(--bg) 0%, var(--bg-accent) 100%);
}

.page {
    min-height: 100vh;
    padding: 2.5rem 1.25rem;
}

.page--center {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.brand {
    margin: 0 0 0.75rem;
    font-size: 0.95rem;
    letter-spacing: 0.04em;
    text-transform: lowercase;
    color: var(--muted);
}

.brand__link {
    color: inherit;
    text-decoration: none;
}

.brand__link:hover,
.brand__link:focus-visible {
    color: var(--ink);
    text-decoration: underline;
    text-underline-offset: 0.15em;
}

h1 {
    margin: 0 0 0.75rem;
    font-size: clamp(1.75rem, 4vw, 2.4rem);
    font-weight: 600;
    line-height: 1.15;
}

.lede {
    margin: 0;
    max-width: 36rem;
    font-size: 1.05rem;
    line-height: 1.5;
    color: var(--muted);
}

.link {
    color: var(--link);
    text-decoration: underline;
    text-underline-offset: 0.15em;
}

.link:hover,
.link:focus-visible {
    color: var(--ink);
}

/* --- Auth / admin (Phase 1b+) --- */

.page--auth {
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-panel,
.admin-panel {
    width: 100%;
    max-width: 24rem;
}

.admin-panel--wide {
    max-width: none;
}

.admin-panel--form {
    max-width: 32rem;
}

.page--admin {
    max-width: 42rem;
    margin: 0 auto;
}

.page--admin-wide {
    max-width: 72rem;
}

.admin-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--rule);
}

.admin-bar__meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem 1rem;
}

.muted {
    color: var(--muted);
    font-size: 0.95rem;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1.5rem;
    text-align: left;
}

.auth-form--compact {
    margin-top: 0.75rem;
    max-width: 28rem;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.field--check {
    flex-direction: row;
    align-items: flex-start;
    gap: 0.6rem;
    font-size: 0.98rem;
    line-height: 1.4;
}

.field--check input {
    margin-top: 0.2rem;
}

.field__label {
    font-size: 0.9rem;
    color: var(--muted);
}

.field__hint {
    margin: 0;
    font-size: 0.88rem;
    line-height: 1.4;
    color: var(--muted);
}

.field__error {
    font-size: 0.9rem;
    color: var(--danger);
}

.field__input {
    width: 100%;
    padding: 0.65rem 0.75rem;
    font: inherit;
    color: var(--ink);
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid var(--rule);
    border-radius: 0.35rem;
}

.field__input:focus {
    outline: 2px solid var(--link);
    outline-offset: 1px;
}

.field__input--error {
    border-color: rgba(138, 42, 42, 0.55);
}

.field__input--readonly,
.field__input:disabled {
    opacity: 0.85;
    background: rgba(0, 0, 0, 0.04);
    cursor: not-allowed;
}

.field__input--inline {
    display: inline-block;
    width: auto;
    min-width: 14rem;
    max-width: 100%;
    padding: 0.4rem 0.55rem;
    font-size: 0.9rem;
}

.inline-email-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
}

.btn {
    display: inline-block;
    padding: 0.7rem 1.1rem;
    font: inherit;
    font-size: 1rem;
    color: #fff;
    background: var(--link);
    border: none;
    border-radius: 0.35rem;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
}

.btn:hover,
.btn:focus-visible {
    background: var(--ink);
}

.btn--quiet {
    background: transparent;
    color: var(--link);
    border: 1px solid var(--rule);
    padding: 0.4rem 0.75rem;
    font-size: 0.9rem;
}

.btn--quiet:hover,
.btn--quiet:focus-visible {
    background: rgba(15, 76, 92, 0.08);
    color: var(--ink);
}

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

.btn--danger-solid {
    background: var(--danger);
}

.btn--danger-solid:hover,
.btn--danger-solid:focus-visible {
    background: #5c1a1a;
}

.flash {
    margin: 0 0 1.25rem;
    padding: 0.75rem 0.9rem;
    border-radius: 0.35rem;
    text-align: left;
    font-size: 0.95rem;
    line-height: 1.4;
}

.flash--error {
    color: #5c1a1a;
    background: rgba(180, 60, 60, 0.12);
    border: 1px solid rgba(180, 60, 60, 0.28);
}

.flash--info {
    color: #1a3c3c;
    background: rgba(15, 76, 92, 0.1);
    border: 1px solid rgba(15, 76, 92, 0.22);
}

.flash--success {
    color: #1a3c28;
    background: rgba(31, 92, 58, 0.12);
    border: 1px solid rgba(31, 92, 58, 0.28);
}

.flash--warning {
    color: #5c3d10;
    background: rgba(180, 130, 40, 0.14);
    border: 1px solid rgba(180, 130, 40, 0.32);
}

.auth-footer {
    margin: 1.5rem 0 0;
    font-size: 0.95rem;
    color: var(--muted);
}

.inline-form {
    display: inline;
    margin: 0;
}

.section-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem 1.5rem;
    margin-bottom: 1.5rem;
}

.section-head__action {
    margin: 0;
}

.section-title {
    margin: 2rem 0 0.75rem;
    font-size: 1.25rem;
    font-weight: 600;
}

.back-link {
    margin: 0 0 1rem;
    font-size: 0.95rem;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.75rem;
    margin: 0 0 1.75rem;
}

.stat {
    padding: 0.9rem 1rem;
    background: rgba(255, 255, 255, 0.55);
    border: 1px solid var(--rule);
    border-radius: 0.4rem;
}

.stat__value {
    display: block;
    font-size: 1.6rem;
    font-weight: 600;
    line-height: 1.1;
}

.stat__label {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.88rem;
    color: var(--muted);
}

.chart-lede {
    margin: -0.25rem 0 0.75rem;
    font-size: 0.92rem;
}

.visit-chart {
    margin: 0 0 1.75rem;
    padding: 0.75rem 0.5rem 0.25rem;
    border: 1px solid var(--rule);
    border-radius: 0.4rem;
    background: rgba(255, 255, 255, 0.5);
}

.visit-chart__svg {
    display: block;
    width: 100%;
    height: auto;
    max-height: 240px;
}

.visit-chart__grid {
    stroke: var(--rule);
    stroke-width: 1;
    stroke-dasharray: 3 4;
}

.visit-chart__axis {
    fill: var(--muted);
    font-size: 11px;
    font-family: ui-sans-serif, system-ui, sans-serif;
}

.visit-chart__area {
    fill: rgba(15, 76, 92, 0.12);
}

.visit-chart__line {
    stroke: var(--link);
    stroke-width: 2.25;
    stroke-linejoin: round;
    stroke-linecap: round;
}

.visit-chart__dot {
    fill: var(--link);
    stroke: #fff;
    stroke-width: 1.25;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--rule);
    border-radius: 0.4rem;
    background: rgba(255, 255, 255, 0.45);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

.data-table th,
.data-table td {
    padding: 0.7rem 0.85rem;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--rule);
}

.data-table th {
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--muted);
    background: rgba(0, 0, 0, 0.03);
}

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

.permanent-url {
    font-family: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--link);
    word-break: break-all;
}

.destination-url {
    color: var(--muted);
    word-break: break-all;
    font-size: 0.92rem;
}

.permanent-url-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.65rem 0.85rem;
    margin: 0.35rem 0;
}

.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 600;
    line-height: 1.4;
}

.badge--on {
    color: var(--ok);
    background: rgba(31, 92, 58, 0.12);
    border: 1px solid rgba(31, 92, 58, 0.28);
}

.badge--off {
    color: var(--muted);
    background: rgba(0, 0, 0, 0.06);
    border: 1px solid var(--rule);
}

.badge--mine {
    color: #1a4a6e;
    background: rgba(26, 74, 110, 0.1);
    border: 1px solid rgba(26, 74, 110, 0.28);
}

.badge--shared {
    color: #5a4a1a;
    background: rgba(90, 74, 26, 0.1);
    border: 1px solid rgba(90, 74, 26, 0.28);
}

.share-panel {
    margin: 1.5rem 0;
}

.share-add-form,
.share-role-form {
    margin-top: 1rem;
}

.share-role-select {
    min-width: 7rem;
}

.status-line {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
    margin: 0;
}

.action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
}

.empty-state {
    margin: 0;
    padding: 1.25rem 1rem;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.4);
    border: 1px dashed var(--rule);
    border-radius: 0.4rem;
}

.callout {
    margin: 1.25rem 0 0;
    padding: 1rem 1.1rem;
    background: rgba(15, 76, 92, 0.06);
    border: 1px solid rgba(15, 76, 92, 0.18);
    border-radius: 0.4rem;
}

.callout__label {
    margin: 0 0 0.35rem;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--muted);
}

.detail-grid {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.detail-block {
    padding: 1rem 1.1rem;
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid var(--rule);
    border-radius: 0.4rem;
}

.detail-block--primary {
    border-color: rgba(15, 76, 92, 0.28);
    background: rgba(15, 76, 92, 0.06);
}

.detail-block__title {
    margin: 0 0 0.5rem;
    font-size: 1rem;
    font-weight: 600;
}

.qr-preview {
    margin: 0.75rem 0 1rem;
    padding: 0;
}

.qr-preview__img {
    display: block;
    width: 220px;
    max-width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
    background: #fff;
    border: 1px solid var(--rule);
    border-radius: 0.25rem;
}

.qr-preview__img--transparent {
    background-color: #fff;
    background-image:
        linear-gradient(45deg, #ddd 25%, transparent 25%),
        linear-gradient(-45deg, #ddd 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #ddd 75%),
        linear-gradient(-45deg, transparent 75%, #ddd 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

.qr-download {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.85rem;
    margin: 0.85rem 0 0.5rem;
}

.qr-download__colors {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1rem;
}

.qr-download__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
}

.qr-color {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    margin: 0;
    font-size: 0.88rem;
    color: var(--muted);
}

.qr-color--check {
    justify-content: flex-end;
    min-width: 9rem;
}

.qr-color--check input {
    width: 1.1rem;
    height: 1.1rem;
    margin: 0.2rem 0 0;
}

.qr-color--disabled {
    opacity: 0.45;
}

.qr-color__input {
    width: 2.75rem;
    height: 2rem;
    padding: 0;
    border: 1px solid var(--rule);
    border-radius: 0.25rem;
    background: #fff;
    cursor: pointer;
}

.meta-line {
    margin: 0.35rem 0 0;
}

.cell-truncate {
    max-width: 14rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.danger-zone {
    margin-top: 2.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--rule);
}

@media (max-width: 900px) {
    .stat-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 720px) {
    .data-table thead {
        display: none;
    }

    .data-table,
    .data-table tbody,
    .data-table tr,
    .data-table td {
        display: block;
        width: 100%;
    }

    .data-table tr {
        padding: 0.75rem 0.85rem;
        border-bottom: 1px solid var(--rule);
    }

    .data-table td {
        padding: 0.25rem 0;
        border-bottom: none;
    }

    .data-table td::before {
        content: attr(data-label);
        display: block;
        font-size: 0.78rem;
        font-weight: 600;
        color: var(--muted);
        margin-bottom: 0.1rem;
    }

    .cell-truncate {
        max-width: none;
        white-space: normal;
    }
}

@media (max-width: 480px) {
    .admin-bar {
        flex-direction: column;
        align-items: flex-start;
    }

    .stat-grid {
        grid-template-columns: 1fr 1fr;
    }
}
