:root {
    --paper: #f4efe4;
    --surface: #fffcf4;
    --ink: #1c211e;
    --ink-soft: #59605a;
    --line: #d8d0be;
    --accent: #a63a22;
    --success: #2e6b4c;
    --success-bg: #eaf2ec;
    --warning: #7a5200;
    --warning-bg: #f6efdc;
    --danger: #a12b2b;
    --danger-bg: #f7e8e6;
    --serif: Charter, "Bitstream Charter", "Sitka Text", Cambria, serif;
    --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
    --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

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

html {
    color-scheme: light;
}

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--sans);
    font-size: 16px;
    line-height: 1.5;
}

a {
    color: var(--accent);
    text-underline-offset: 2px;
}

a:hover {
    text-decoration-thickness: 2px;
}

h1,
h2 {
    font-family: var(--serif);
    font-weight: 600;
    letter-spacing: normal;
}

h1 {
    margin: 0;
    font-size: 40px;
    line-height: 1.1;
}

h2 {
    margin: 0;
    font-size: 20px;
    line-height: 1.25;
}

.mono {
    font-family: var(--mono);
    font-size: 13px;
}

.muted {
    color: var(--ink-soft);
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 100;
    padding: 10px 14px;
    background: var(--ink);
    color: var(--surface);
    border-radius: 2px;
    transform: translateY(-160%);
}

.skip-link:focus {
    transform: translateY(0);
}

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

.header-inner,
.page,
.site-footer {
    width: 100%;
    max-width: 1120px;
    margin: 0 auto;
    padding-left: 24px;
    padding-right: 24px;
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 64px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    color: var(--ink);
    text-decoration: none;
    font-family: var(--serif);
    font-size: 20px;
    line-height: 1;
}

.brand-mark {
    font-weight: 700;
}

.brand-name {
    color: var(--ink-soft);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-role {
    padding-left: 12px;
    border-left: 1px solid var(--line);
    color: var(--ink-soft);
    font-size: 13px;
}

.logout-form {
    margin: 0;
}

.page {
    padding-top: 32px;
    padding-bottom: 48px;
}

.site-footer {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding-top: 16px;
    padding-bottom: 24px;
    border-top: 1px solid var(--line);
    color: var(--ink-soft);
    font-size: 13px;
}

.page-heading {
    margin-bottom: 24px;
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--ink-soft);
    font-size: 13px;
    font-weight: 600;
}

.page-note {
    max-width: 60ch;
    margin: 8px 0 0;
    color: var(--ink-soft);
    font-size: 14px;
}

.page-grid {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
    grid-template-areas: "list form";
    align-items: start;
    gap: 32px;
}

.tenant-list {
    grid-area: list;
    min-width: 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 4px;
}

.list-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    padding: 20px;
    border-bottom: 1px solid var(--line);
}

.list-count {
    color: var(--ink-soft);
    font-size: 14px;
    white-space: nowrap;
}

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

.tenant-table th {
    padding: 10px 16px;
    border-bottom: 1px solid var(--line);
    color: var(--ink-soft);
    font-size: 13px;
    font-weight: 600;
    text-align: left;
}

.tenant-table td {
    padding: 16px;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
    font-size: 14px;
}

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

.tenant-link {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    color: var(--ink);
    font-size: 16px;
    font-weight: 600;
    text-decoration: none;
}

.tenant-link:hover {
    text-decoration: underline;
}

.tenant-slug {
    display: block;
    margin-top: 2px;
    color: var(--ink-soft);
}

.address {
    display: flex;
    align-items: center;
    width: fit-content;
    min-height: 44px;
    color: var(--ink-soft);
    line-height: 1.5;
    text-decoration: none;
}

.address:hover {
    color: var(--accent);
    text-decoration: underline;
}

.status-line {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
}

.status-dot {
    flex: 0 0 auto;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ink-soft);
}

.status-dot.status-success {
    background: var(--success);
}

.status-dot.status-warning {
    background: var(--warning);
}

.status-dot.status-danger {
    background: var(--danger);
}

.status-dot.status-muted {
    background: var(--ink-soft);
}

.status-message {
    max-width: 36ch;
    margin: 4px 0 0;
    color: var(--ink-soft);
    font-size: 13px;
    overflow-wrap: anywhere;
}

.status-meta {
    margin: 2px 0 0;
    color: var(--ink-soft);
    font-size: 13px;
}

.row-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 8px;
}

.row-actions .button {
    min-height: 44px;
    padding: 0 8px;
    font-size: 13px;
}

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

.empty {
    margin: 0;
    padding: 32px 20px;
    color: var(--ink-soft);
    font-size: 14px;
}

.form-panel {
    grid-area: form;
    position: sticky;
    top: 24px;
    padding: 20px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 4px;
}

.panel-note {
    margin: 6px 0 20px;
    color: var(--ink-soft);
    font-size: 13px;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.field label {
    color: var(--ink);
    font-size: 14px;
    font-weight: 600;
}

.field input {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 2px;
    color: var(--ink);
    font: inherit;
    font-size: 16px;
}

.field input:hover {
    border-color: var(--ink-soft);
}

.field input:focus {
    border-color: var(--accent);
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

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

.field-help,
.field-error {
    margin: 0;
    font-size: 13px;
}

.field-help {
    color: var(--ink-soft);
}

.field-error {
    color: var(--danger);
}

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
}

.form-actions .button-primary {
    flex: 1 1 180px;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 2px;
    color: var(--ink);
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

.button:hover {
    background: var(--paper);
}

.button-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.button-primary:hover {
    background: var(--accent);
    filter: brightness(0.92);
}

.button-quiet {
    background: transparent;
    border-color: transparent;
    color: var(--ink-soft);
}

.button-quiet:hover {
    background: var(--paper);
    color: var(--ink);
}

.button-block {
    width: 100%;
}

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

button:focus-visible,
a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.flash {
    margin-bottom: 24px;
    padding: 12px 16px;
    border: 1px solid;
    border-radius: 2px;
    font-size: 14px;
}

.flash-success {
    background: var(--success-bg);
    border-color: var(--success);
    color: var(--success);
}

.flash-error {
    background: var(--danger-bg);
    border-color: var(--danger);
    color: var(--danger);
}

.login-shell {
    display: grid;
    place-items: center;
    min-height: calc(100vh - 64px - 100px);
}

.login-card {
    width: min(360px, 100%);
    padding: 28px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 4px;
}

.login-card h1 {
    font-size: 28px;
}

.login-note {
    margin: 8px 0 20px;
    color: var(--ink-soft);
    font-size: 14px;
}

.log-dialog {
    width: min(760px, calc(100vw - 32px));
    max-height: calc(100vh - 32px);
    padding: 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 4px;
    color: var(--ink);
    box-shadow: 0 18px 50px rgba(28, 33, 30, 0.18);
    overflow: auto;
}

.log-dialog::backdrop {
    background: rgba(28, 33, 30, 0.38);
}

.dialog-head {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 20px 12px;
    border-bottom: 1px solid var(--line);
}

.dialog-tenant {
    margin: 4px 0 0;
    color: var(--ink-soft);
}

.dialog-body {
    padding: 16px 20px 20px;
}

#log-content {
    min-height: 160px;
    max-height: 50vh;
    margin: 0;
    padding: 12px;
    overflow: auto;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 2px;
    color: var(--ink);
    font-family: var(--mono);
    font-size: 13px;
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.dialog-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
}

#log-updated {
    margin-left: auto;
    font-size: 13px;
}

.detail-head {
    margin-bottom: 24px;
}

.detail-head .eyebrow {
    margin-top: 16px;
}

.back-link {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    font-size: 14px;
}

.detail-panel {
    padding: 24px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 4px;
}

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

.detail-grid h2 {
    margin-bottom: 10px;
    font-size: 20px;
}

.detail-grid p {
    margin: 0 0 6px;
}

.detail-note {
    margin: 20px 0 0;
    padding-top: 12px;
    border-top: 1px solid var(--line);
    color: var(--ink-soft);
    font-size: 13px;
}

.noscript-note {
    margin: 16px 0 0;
    color: var(--ink-soft);
    font-size: 13px;
}

@media (max-width: 900px) {
    .page-grid {
        grid-template-columns: 1fr;
        grid-template-areas:
            "form"
            "list";
        gap: 24px;
    }

    .form-panel {
        position: static;
    }

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

@media (max-width: 720px) {
    .header-inner,
    .page,
    .site-footer {
        padding-left: 16px;
        padding-right: 16px;
    }

    h1,
    .detail-head h1 {
        font-size: 28px;
    }

    .site-footer {
        flex-direction: column;
        gap: 4px;
    }

    .list-head {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
        padding: 16px;
    }

    .tenant-table thead {
        display: none;
    }

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

    .tenant-table tr {
        padding: 16px;
        border-bottom: 1px solid var(--line);
    }

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

    .tenant-table td {
        padding: 4px 0;
        border: 0;
    }

    .tenant-table td::before {
        display: block;
        margin-bottom: 2px;
        color: var(--ink-soft);
        content: attr(data-label);
        font-size: 13px;
        font-weight: 600;
    }

    .tenant-table td:first-child::before {
        display: none;
    }

    .tenant-table td:first-child {
        margin-bottom: 8px;
    }

    .tenant-table td:last-child {
        margin-top: 12px;
        padding-top: 12px;
        border-top: 1px solid var(--line);
    }

    .tenant-table td:last-child::before {
        display: none;
    }

    .field-row {
        grid-template-columns: 1fr;
    }

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

    .dialog-actions #log-updated {
        flex-basis: 100%;
        margin-left: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        scroll-behavior: auto !important;
        transition: none !important;
    }
}
