:root {
    --bg: #f6f6f2;
    --surface: #ffffff;
    --surface-soft: #f0f7f5;
    --ink: #20242a;
    --muted: #667085;
    --line: #d9ded8;
    --accent: #0f766e;
    --accent-dark: #115e59;
    --amber: #b45309;
    --danger: #b42318;
    --danger-bg: #fff1f0;
    --shadow: 0 18px 60px rgba(32, 36, 42, 0.08);
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        linear-gradient(180deg, rgba(15, 118, 110, 0.06), rgba(246, 246, 242, 0) 280px),
        var(--bg);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

button,
input,
textarea {
    font: inherit;
}

button {
    min-height: 42px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    font-weight: 700;
    padding: 0 14px;
    transition: transform 150ms ease, background 150ms ease, border-color 150ms ease;
}

button:hover {
    background: var(--accent-dark);
    transform: translateY(-1px);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
    transform: none;
}

button.danger {
    background: var(--danger-bg);
    border-color: #ffd2ce;
    color: var(--danger);
}

button.danger:hover {
    background: #ffe4e0;
}

input,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    outline: none;
    padding: 11px 12px;
}

input:focus,
textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.app-shell {
    width: min(1180px, calc(100% - 32px));
    margin: 0 auto;
    padding: 28px 0 36px;
}

.topbar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.eyebrow,
.section-label {
    margin: 0;
    color: var(--accent);
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

h1,
h2 {
    margin: 0;
    letter-spacing: 0;
}

h1 {
    font-size: clamp(2rem, 5vw, 4.4rem);
    line-height: 0.96;
}

h2 {
    font-size: 1.08rem;
}

.status-pill {
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface);
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 700;
    padding: 8px 12px;
    white-space: nowrap;
}

.status-pill.is-active {
    border-color: rgba(15, 118, 110, 0.3);
    background: var(--surface-soft);
    color: var(--accent-dark);
}

.status-pill.is-expired {
    border-color: #f8d8a9;
    background: #fff8ed;
    color: var(--amber);
}

.mailbox-band,
.pane,
.challenge-panel,
.test-panel,
.history-panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.88);
    box-shadow: var(--shadow);
}

.mailbox-band {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(280px, 0.8fr);
    gap: 18px;
    padding: 18px;
}

.address-row,
.access-row,
.custom-row {
    display: grid;
    gap: 10px;
}

.address-row {
    grid-template-columns: minmax(0, 1fr) auto;
    margin-top: 8px;
}

.access-row {
    grid-template-columns: minmax(0, 1fr) auto;
    margin-top: 10px;
}

.custom-row {
    grid-template-columns: minmax(0, 1fr) auto;
    margin-top: 8px;
}

.address-input {
    font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
    font-size: clamp(1rem, 3vw, 1.45rem);
    font-weight: 800;
}

.access-input {
    color: var(--muted);
    font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
    font-size: 0.86rem;
}

.helper-text {
    color: var(--muted);
    font-size: 0.88rem;
    margin: 8px 0 0;
}

.meta-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
    color: var(--muted);
    font-size: 0.92rem;
}

.meta-row span {
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    padding: 5px 9px;
}

.custom-form label {
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 700;
}

.trap-field {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.challenge-panel {
    display: grid;
    grid-template-columns: minmax(220px, 0.7fr) minmax(0, 1fr);
    gap: 16px;
    margin-top: 18px;
    padding: 16px;
}

.challenge-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
}

.history-panel {
    margin-top: 18px;
    padding: 16px;
}

.history-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
}

.history-list {
    display: grid;
    gap: 10px;
    margin-top: 14px;
}

.history-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding: 12px;
}

.history-item.is-current {
    border-color: rgba(15, 118, 110, 0.35);
    background: var(--surface-soft);
}

.history-copy strong,
.history-copy span {
    display: block;
    overflow-wrap: anywhere;
}

.history-copy strong {
    font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
}

.history-copy span {
    color: var(--muted);
    font-size: 0.88rem;
    margin-top: 2px;
}

.history-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.icon-button.subtle {
    color: var(--muted);
}

.empty-state.compact {
    padding: 12px 0 0;
}

.workspace-grid {
    display: grid;
    grid-template-columns: minmax(320px, 0.9fr) minmax(0, 1.3fr);
    gap: 18px;
    margin-top: 18px;
}

.pane {
    min-height: 420px;
    overflow: hidden;
}

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

.toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.toolbar button,
.icon-button {
    background: #fff;
    border-color: var(--line);
    color: var(--ink);
}

.toolbar button:hover,
.icon-button:hover {
    background: var(--surface-soft);
    border-color: rgba(15, 118, 110, 0.35);
}

.empty-state,
.message-detail {
    color: var(--muted);
    padding: 18px;
}

.message-list {
    display: grid;
    gap: 0;
}

.message-item {
    width: 100%;
    min-height: auto;
    border: 0;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    background: #fff;
    color: var(--ink);
    padding: 14px 16px;
    text-align: left;
    transform: none;
}

.message-item:hover,
.message-item.is-selected {
    background: var(--surface-soft);
    transform: none;
}

.message-item strong,
.message-item span {
    display: block;
    overflow-wrap: anywhere;
}

.message-item span {
    color: var(--muted);
    font-size: 0.9rem;
}

.detail-meta {
    display: grid;
    gap: 4px;
    border-bottom: 1px solid var(--line);
    color: var(--muted);
    padding: 0 0 14px;
}

.detail-body {
    color: var(--ink);
    margin-top: 14px;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.detail-frame {
    width: 100%;
    min-height: 280px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.test-panel {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 18px;
    margin-top: 18px;
    padding: 18px;
}

.test-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr)) auto;
    gap: 10px;
}

.test-form textarea {
    grid-column: 1 / 3;
    resize: vertical;
}

.test-form button {
    grid-row: 1 / 3;
    grid-column: 3;
    align-self: stretch;
}

.footer-links {
    display: flex;
    gap: 16px;
    margin-top: 18px;
    color: var(--muted);
}

a {
    color: var(--accent-dark);
    font-weight: 700;
}

.toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    max-width: min(360px, calc(100% - 36px));
    border: 1px solid rgba(15, 118, 110, 0.25);
    border-radius: 8px;
    background: #112522;
    color: #fff;
    opacity: 0;
    padding: 12px 14px;
    transform: translateY(8px);
    transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.legal-page {
    width: min(760px, calc(100% - 32px));
    margin: 0 auto;
    padding: 48px 0;
}

.legal-page h1 {
    margin: 20px 0 14px;
}

.legal-page p {
    color: var(--muted);
}

.back-link {
    display: inline-flex;
    margin-bottom: 16px;
}

@media (max-width: 840px) {
    .topbar,
    .mailbox-band,
    .workspace-grid,
    .challenge-panel,
    .test-panel,
    .test-form {
        grid-template-columns: 1fr;
    }

    .topbar {
        align-items: flex-start;
    }

    .address-row,
    .access-row,
    .custom-row,
    .challenge-form {
        grid-template-columns: 1fr;
    }

    .history-head,
    .history-item {
        grid-template-columns: 1fr;
    }

    .history-head {
        display: grid;
    }

    .history-buttons {
        justify-content: stretch;
    }

    .history-buttons button {
        flex: 1;
    }

    .test-form textarea,
    .test-form button {
        grid-column: auto;
        grid-row: auto;
    }
}

@media (max-width: 520px) {
    .app-shell {
        width: min(100% - 20px, 1180px);
        padding-top: 18px;
    }

    .pane-head {
        flex-direction: column;
    }

    .toolbar {
        width: 100%;
        justify-content: stretch;
    }

    .toolbar button {
        flex: 1;
    }
}
