:root {
    --bg: #20140f;
    --bg-soft: #2b1b14;
    --text: #fffaf5;
    --muted: #b9aaa1;
    --paper: #fffdf9;
    --paper-soft: #f5f0ea;
    --ink: #100f14;
    --line: #e5ded7;
    --accent: #e8c087;
    --danger: #b34638;
    --green: #15775b;
    --shadow: 0 20px 60px rgba(20, 11, 7, .2);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--paper-soft);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: 0;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
textarea {
    font: inherit;
}

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

textarea {
    resize: vertical;
}

label {
    display: grid;
    gap: 8px;
    color: #4d453f;
    font-weight: 700;
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: clamp(32px, 5vw, 58px);
    line-height: 1.02;
}

h2 {
    font-size: 28px;
    line-height: 1.1;
}

.topbar {
    min-height: 86px;
    padding: 20px 34px;
    background: var(--bg);
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 26px;
    position: sticky;
    top: 0;
    z-index: 5;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 22px;
    font-weight: 900;
    margin-right: auto;
}

.brand-logo-wide {
    width: 210px;
    height: auto;
    display: block;
}

.brand-logo-square {
    width: 38px;
    height: 38px;
    display: none;
    object-fit: contain;
}

.brand-mark {
    width: 38px;
    height: 38px;
    border: 3px solid currentColor;
    display: grid;
    place-items: center;
    font-weight: 900;
    line-height: 1;
}

.main-nav {
    display: flex;
    align-items: center;
    gap: 10px;
}

.main-nav a,
.ghost-link {
    color: var(--text);
    opacity: .82;
    border: 0;
    background: transparent;
    padding: 10px 12px;
    cursor: pointer;
    font-weight: 800;
}

.hidden {
    display: none;
}

.main-nav a.is-active,
.main-nav a:hover,
.ghost-link:hover {
    opacity: 1;
}

.workspace {
    display: grid;
    grid-template-columns: minmax(340px, 430px) minmax(0, 1fr);
    gap: 22px;
    padding: 24px;
}

.settings-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 430px);
    gap: 22px;
    padding: 24px;
}

.settings-layout.single {
    grid-template-columns: 1fr;
}

.panel {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 24px;
}

.panel-head,
.ticket-title {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 18px;
}

.eyebrow {
    color: var(--green);
    font-weight: 900;
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: .08em;
    margin-bottom: 8px;
}

.searchbar {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    margin-bottom: 14px;
}

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-bottom: 10px;
    margin-bottom: 8px;
}

.tabs a,
.chip {
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 9px 13px;
    white-space: nowrap;
    background: #fff;
    font-weight: 800;
    color: #3c342e;
}

.tabs a.is-active {
    background: var(--bg);
    border-color: var(--bg);
    color: var(--text);
}

.ticket-list {
    display: grid;
    gap: 10px;
}

.ticket-row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 6px 12px;
    align-items: center;
    padding: 15px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.ticket-row.is-selected {
    border-color: var(--bg);
    box-shadow: inset 4px 0 0 var(--bg);
}

.ticket-row strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ticket-row small {
    grid-column: 2 / 4;
    color: #776b62;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ticket-number {
    font-weight: 900;
    color: var(--green);
}

.badge {
    border-radius: 999px;
    padding: 6px 9px;
    font-size: 12px;
    font-weight: 900;
    background: #eee6df;
}

.badge.open {
    background: #dff4ea;
    color: #105b43;
}

.badge.reopened {
    background: #dff0ff;
    color: #13527a;
}

.badge.waiting {
    background: #fff1c9;
    color: #72510a;
}

.badge.on_hold {
    background: #efe6ff;
    color: #543184;
}

.badge.closed {
    background: #e9edf2;
    color: #4a5562;
}

.badge.spam {
    background: #ffe0dc;
    color: #8a2d21;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.btn {
    border: 1px solid var(--bg);
    background: var(--bg);
    color: var(--text);
    border-radius: 8px;
    min-height: 44px;
    padding: 10px 16px;
    font-weight: 900;
    cursor: pointer;
}

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

.btn.outline {
    background: transparent;
    color: var(--ink);
}

.btn.compact {
    min-height: 0;
}

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

.message-stream {
    display: grid;
    gap: 14px;
    margin: 22px 0;
}

.message {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
    background: #fff;
}

.message.out {
    background: #f6efe6;
}

.message-meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    color: #6d625a;
    font-size: 14px;
    margin-bottom: 10px;
}

.message-body {
    line-height: 1.55;
    white-space: normal;
}

.attachment-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
}

.attachment {
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 8px 11px;
    background: #fff;
    font-weight: 800;
}

.original-mail {
    margin-top: 14px;
    border-top: 1px solid var(--line);
    padding-top: 12px;
}

.original-mail summary {
    cursor: pointer;
    font-weight: 900;
    color: var(--green);
}

.original-mail pre {
    white-space: pre-wrap;
    overflow: auto;
    max-height: 320px;
    color: #4d453f;
}

.signature-preview {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px 14px;
    background: #fff;
}

.signature-preview summary {
    cursor: pointer;
    font-weight: 900;
    color: var(--green);
}

.signature-preview pre {
    margin: 12px 0 0;
    max-height: 180px;
    overflow: auto;
    white-space: pre-wrap;
    color: #6d625a;
}

.reply-box,
.stack {
    display: grid;
    gap: 15px;
}

.template-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chip {
    cursor: pointer;
}

.grid-list {
    display: grid;
    gap: 12px;
    margin-top: 18px;
}

.mini-card,
.rule-row,
.empty,
.notice {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding: 14px;
}

.mini-card {
    display: grid;
    gap: 4px;
}

.mini-card span,
.mini-card p {
    color: #6d625a;
}

.template-card-head {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: start;
    gap: 10px;
}

.template-actions {
    display: flex;
    gap: 6px;
}

.icon-link {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-weight: 900;
    background: #fff;
    color: var(--ink);
    cursor: pointer;
}

.icon-link.star.is-active {
    background: var(--accent);
    border-color: var(--accent);
}

.toggle {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toggle input {
    width: auto;
}

.login-screen {
    background: radial-gradient(circle at 70% 20%, #382219 0, var(--bg) 45%, #120d0a 100%);
    color: var(--text);
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-shell {
    width: min(460px, 100%);
    display: grid;
    gap: 18px;
}

.login-logo {
    width: 72px;
    height: 72px;
    object-fit: contain;
}

.login-shell h1 {
    color: var(--text);
}

.login-shell p {
    color: var(--muted);
    font-weight: 700;
}

.login-card {
    background: var(--paper);
    color: var(--ink);
    border-radius: 8px;
    padding: 22px;
    display: grid;
    gap: 16px;
}

.notice.error {
    border-color: #f3b0a7;
    color: #8a2d21;
}

@media (max-width: 980px) {
    .topbar {
        padding: 14px 16px;
        gap: 12px;
        flex-wrap: wrap;
    }

    .brand-word {
        display: none;
    }

    .brand-logo-wide {
        display: none;
    }

    .brand-logo-square {
        display: block;
    }

    .main-nav {
        order: 3;
        width: 100%;
        overflow-x: auto;
    }

    .tabs {
        overflow: visible;
    }

    .tabs a {
        flex: 1 1 calc(50% - 8px);
        text-align: center;
        padding-inline: 10px;
    }

    .import-box {
        margin-bottom: 18px;
    }

    .workspace,
    .settings-layout {
        grid-template-columns: 1fr;
        padding: 14px;
    }

    .panel {
        padding: 18px;
    }

    .panel-head,
    .ticket-title {
        display: grid;
    }

    .ticket-row {
        grid-template-columns: auto 1fr;
        touch-action: pan-y;
        transition: transform .18s ease, background .18s ease;
    }

    .ticket-row.swipe-close {
        transform: translateX(42px);
        background: #e5f6ee;
    }

    .ticket-row.swipe-spam {
        transform: translateX(-42px);
        background: #ffe6e2;
    }

    .ticket-row .badge {
        grid-column: 1 / 3;
        justify-self: start;
    }

    .ticket-row small {
        grid-column: 1 / 3;
    }

    .ticket-detail-panel {
        min-height: 70vh;
    }
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 20px;
    transform: translateX(-50%);
    background: var(--ink);
    color: var(--text);
    border-radius: 8px;
    padding: 12px 16px;
    font-weight: 900;
    box-shadow: var(--shadow);
    z-index: 20;
}

.toast button {
    margin-left: 12px;
    border: 0;
    background: var(--accent);
    color: var(--ink);
    border-radius: 999px;
    padding: 6px 10px;
    font-weight: 900;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(16, 15, 20, .52);
    display: grid;
    place-items: center;
    padding: 18px;
    z-index: 30;
}

.modal[hidden] {
    display: none;
}

.modal-card {
    width: min(560px, 100%);
    max-height: min(760px, 90vh);
    overflow: auto;
    background: var(--paper);
    border-radius: 8px;
    padding: 22px;
    display: grid;
    gap: 16px;
    box-shadow: var(--shadow);
}

.template-modal-card {
    width: min(760px, 100%);
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.template-tabs {
    display: flex;
    gap: 8px;
}

.template-tab {
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 10px 14px;
    background: #fff;
    font-weight: 900;
    cursor: pointer;
}

.template-tab.is-active {
    background: var(--bg);
    border-color: var(--bg);
    color: var(--text);
}

.template-results {
    display: grid;
    gap: 10px;
}

.template-result {
    text-align: left;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding: 13px;
    display: grid;
    gap: 6px;
    cursor: pointer;
}

.template-result span {
    color: #6d625a;
}

.template-result[hidden] {
    display: none;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.log-view {
    background: #100f14;
    color: #f7f0e8;
    border-radius: 8px;
    padding: 16px;
    min-height: 420px;
    max-height: 72vh;
    overflow: auto;
    white-space: pre-wrap;
    font-size: 14px;
    line-height: 1.5;
}
