:root {
    --surface: rgba(255, 252, 246, 0.92);
    --surface-strong: #fffdf8;
    --border: rgba(35, 32, 23, 0.12);
    --text: #1c1b17;
    --muted: #635c50;
    --accent: #c45a2d;
    --accent-dark: #7b3316;
    --accent-bg: rgba(196, 90, 45, 0.08);
    --success-bg: #e7f4ec;
    --success-text: #215b3c;
    --error-bg: #f8e7e3;
    --error-text: #7f2515;
    --shadow: 0 24px 70px rgba(57, 42, 18, 0.12);
    --sidebar-width: 15rem;
    font-family: "Segoe UI Variable", "Segoe UI", "Trebuchet MS", sans-serif;
}

* {
    box-sizing: border-box;
}

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

body {
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(196, 90, 45, 0.14), transparent 36%),
        radial-gradient(circle at right center, rgba(72, 122, 109, 0.12), transparent 28%),
        linear-gradient(180deg, #f8f3e8 0%, #efe5d3 100%);
}

a {
    color: inherit;
}

/* ─── Shell layout (sidebar + content) ─────────────────────────────────── */

.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    min-height: 100vh;
}

.shell-sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding: 1.5rem 0.75rem;
    border-right: 1px solid var(--border);
    background: rgba(255, 251, 244, 0.9);
    backdrop-filter: blur(24px);
}

.shell-brand-area {
    padding: 0 0.75rem 0.5rem;
    border-bottom: 1px solid var(--border);
}

.shell-nav {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    flex: 1;
}

.shell-nav-section {
    margin-bottom: 0.5rem;
}

.shell-nav-label {
    display: block;
    padding: 0.25rem 0.75rem;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
}

.shell-nav-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.6rem 0.75rem;
    border-radius: 0.75rem;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--muted);
    transition: background 0.12s, color 0.12s;
}

.shell-nav-link:hover {
    background: var(--accent-bg);
    color: var(--text);
}

.shell-nav-link.active {
    background: rgba(196, 90, 45, 0.14);
    color: var(--accent-dark);
}

.shell-nav-link .nav-icon {
    flex-shrink: 0;
    width: 1.1rem;
    height: 1.1rem;
    opacity: 0.75;
}

.shell-nav-link.active .nav-icon {
    opacity: 1;
}

.shell-user-area {
    padding: 0.85rem 0.75rem;
    border-radius: 0.85rem;
    background: rgba(28, 27, 23, 0.05);
    border: 1px solid var(--border);
}

.shell-user-name {
    font-weight: 700;
    font-size: 0.9rem;
    margin-bottom: 0.35rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.shell-link {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent-dark);
    text-decoration: none;
}

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

.shell-content {
    padding: 2rem;
    overflow: hidden;
    min-width: 0;
}

/* ─── Flash messages ─────────────────────────────────────────────────── */

.flash {
    max-width: 56rem;
    margin: 0 auto 1.25rem;
    padding: 0.85rem 1.1rem;
    border-radius: 0.85rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.flash-success {
    background: var(--success-bg);
    color: var(--success-text);
    border: 1px solid rgba(33, 91, 60, 0.18);
}

.flash-error {
    background: var(--error-bg);
    color: var(--error-text);
    border: 1px solid rgba(127, 37, 21, 0.18);
}

.flash-warning {
    background: #fff2da;
    color: #7d4b00;
    border: 1px solid rgba(125, 75, 0, 0.18);
}

/* ─── Auth page ─────────────────────────────────────────────────────── */

.auth-layout {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 2rem 1rem;
}

.auth-card {
    width: min(100%, 28rem);
    padding: 2.5rem;
    border: 1px solid var(--border);
    border-radius: 2rem;
    background: var(--surface);
    box-shadow: var(--shadow);
    backdrop-filter: blur(20px);
}

.auth-title {
    margin: 0;
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(2.5rem, 9vw, 3.5rem);
    line-height: 1;
}

.auth-copy,
.muted {
    color: var(--muted);
}

.auth-form {
    margin-top: 1.5rem;
    display: grid;
    gap: 1rem;
}

/* ─── Dashboard ─────────────────────────────────────────────────────── */

.dashboard-wrap {
    max-width: 72rem;
    margin: 0 auto;
}

.dashboard-card {
    display: grid;
    gap: 2rem;
    padding: 2rem;
    border: 1px solid var(--border);
    border-radius: 2rem;
    background: var(--surface);
    box-shadow: var(--shadow);
    backdrop-filter: blur(20px);
}

.dashboard-title {
    margin: 0;
    font-family: Georgia, "Times New Roman", serif;
    line-height: 1;
}

.dashboard-copy {
    color: var(--muted);
}

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

.metric {
    padding: 1.25rem 1.25rem 1.25rem 1.5rem;
    border: 1px solid var(--border);
    border-radius: 1.25rem;
    background: rgba(255, 255, 255, 0.75);
    border-left-width: 3px;
}

.metric.metric-tickets  { border-left-color: #4a7fc1; }
.metric.metric-emails   { border-left-color: var(--accent); }
.metric.metric-smtp     { border-left-color: #4da374; }
.metric.metric-sites    { border-left-color: #9b6bd6; }

.metric-label {
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

.metric-value {
    display: block;
    margin: 0.4rem 0 0.2rem;
    font-size: 2rem;
    font-family: Georgia, "Times New Roman", serif;
    font-weight: 700;
    line-height: 1;
}

.metric-desc {
    font-size: 0.82rem;
    color: var(--muted);
}

/* ─── Layout helpers ─────────────────────────────────────────────────── */

.panel-grid,
.two-col {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.panel {
    padding: 1.5rem;
    border: 1px solid var(--border);
    border-radius: 1.5rem;
    background: rgba(255, 255, 255, 0.72);
}

.panel h2 {
    margin: 0 0 1rem;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 1.2rem;
}

.stack {
    display: grid;
    gap: 0.75rem;
}

.command-list {
    display: grid;
    gap: 0.6rem;
}

/* ─── Page layout ────────────────────────────────────────────────────── */

.page-wrap {
    max-width: 80rem;
    margin: 0 auto;
    display: grid;
    gap: 1.25rem;
}

.page-hero {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.page-title {
    margin: 0;
    font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(1.8rem, 3.5vw, 2.5rem);
}

.page-copy,
.subtle {
    color: var(--muted);
}

/* ─── Badges ─────────────────────────────────────────────────────────── */

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

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 1.75rem;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 700;
    white-space: nowrap;
}

.badge-muted {
    background: rgba(28, 27, 23, 0.07);
    color: var(--text);
}

.badge-warning {
    background: #fff2da;
    color: #7d4b00;
}

/* Status — tickets */
.badge-status-open       { background: #ebf2ff; color: #284d94; }
.badge-status-answered   { background: #ddeeff; color: #1a4f8a; }
.badge-status-pending    { background: #fff2da; color: #7d4b00; }
.badge-status-resolved   { background: var(--success-bg); color: var(--success-text); }
.badge-status-closed     { background: rgba(28, 27, 23, 0.07); color: var(--muted); }

/* Status — emails */
.badge-status-queued     { background: #ebf2ff; color: #284d94; }
.badge-status-sending    { background: #e8f0fe; color: #1a4f8a; }
.badge-status-sent       { background: var(--success-bg); color: var(--success-text); }
.badge-status-failed     { background: var(--error-bg); color: var(--error-text); }
.badge-status-retry_wait { background: #fff2da; color: #7d4b00; }
.badge-status-cancelled  { background: rgba(28, 27, 23, 0.07); color: var(--muted); }

/* Category */
.badge-category-bug      { background: #fde8e8; color: #8b1f1f; }
.badge-category-feature  { background: #eaf1ff; color: #2a4f9e; }
.badge-category-billing  { background: #e8f8ef; color: #1d6640; }
.badge-category-other    { background: rgba(28, 27, 23, 0.07); color: var(--muted); }

/* Priority */
.badge-priority-high     { background: #fde8e8; color: #8b1f1f; }
.badge-priority-normal   { background: rgba(28, 27, 23, 0.07); color: var(--muted); }
.badge-priority-low      { background: #f0f0ef; color: var(--muted); }

/* ─── Forms ──────────────────────────────────────────────────────────── */

.form-row {
    display: grid;
    gap: 0.4rem;
}

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

.form-row input,
.select,
textarea {
    width: 100%;
    padding: 0.75rem 0.9rem;
    border: 1px solid rgba(38, 31, 23, 0.18);
    border-radius: 0.75rem;
    background: var(--surface-strong);
    color: var(--text);
    font: inherit;
    font-size: 0.95rem;
    transition: border-color 0.12s, box-shadow 0.12s;
}

.form-row input:focus,
.select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(196, 90, 45, 0.15);
}

textarea {
    resize: vertical;
}

.filter-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.85rem;
    align-items: end;
}

.form-row-wide {
    grid-column: span 2;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    align-items: flex-end;
}

.form-compact {
    max-width: 26rem;
}

/* ─── Buttons ────────────────────────────────────────────────────────── */

.button {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    min-height: 2.75rem;
    padding: 0.7rem 1.2rem;
    border: 0;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--accent) 0%, #df8b40 100%);
    color: #fffdf7;
    font: inherit;
    font-size: 0.9rem;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    transition: filter 0.12s;
}

.button:hover {
    filter: brightness(0.92);
}

.button-secondary {
    background: linear-gradient(135deg, #42554c 0%, #647e71 100%);
}

.button-ghost {
    background: rgba(28, 27, 23, 0.07);
    color: var(--text);
}

.button-ghost:hover {
    background: rgba(28, 27, 23, 0.12);
    filter: none;
}

/* ─── Tables ─────────────────────────────────────────────────────────── */

.table-wrap {
    overflow-x: auto;
}

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

.data-table th {
    padding: 0.6rem 0.9rem;
    border-bottom: 2px solid var(--border);
    text-align: left;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    white-space: nowrap;
}

.data-table td {
    padding: 0.85rem 0.9rem;
    border-bottom: 1px solid rgba(38, 31, 23, 0.06);
    vertical-align: middle;
}

.data-table tbody tr {
    cursor: pointer;
    transition: background 0.1s;
}

.data-table tbody tr:hover {
    background: rgba(196, 90, 45, 0.05);
}

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

.empty-state {
    padding: 2rem 0;
    color: var(--muted);
    text-align: center;
    font-style: italic;
    cursor: default;
}

.cell-primary {
    font-weight: 600;
}

.cell-secondary {
    font-size: 0.83rem;
    color: var(--muted);
    margin-top: 0.15rem;
}

/* ─── Definition list ────────────────────────────────────────────────── */

.definition-list {
    display: grid;
    gap: 0;
    margin-bottom: 1.25rem;
}

.definition-list div {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.6rem 0;
    border-bottom: 1px solid rgba(38, 31, 23, 0.07);
}

.definition-list div:last-child {
    border-bottom: 0;
}

.definition-list strong {
    flex: 0 0 9rem;
    font-size: 0.85rem;
    color: var(--muted);
    font-weight: 600;
}

/* ─── Timeline ───────────────────────────────────────────────────────── */

.timeline {
    display: grid;
    gap: 0.85rem;
}

.timeline-item {
    padding: 1rem 1.25rem;
    border-radius: 1rem;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.85);
}

.timeline-item-internal {
    background: #fffbef;
    border-color: rgba(196, 90, 45, 0.18);
}

.timeline-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.timeline-author {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
}

.timeline-date {
    font-size: 0.82rem;
    color: var(--muted);
    white-space: nowrap;
}

.timeline-body {
    margin: 0.5rem 0 0;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ─── Misc components ────────────────────────────────────────────────── */

.checkbox-row,
.toggle-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: center;
}

.message-box {
    padding: 1rem 1.25rem;
    border-radius: 1rem;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.8);
}

.message-box pre {
    margin: 0.5rem 0 0;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: Consolas, "Courier New", monospace;
    font-size: 0.9rem;
}

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

.code {
    display: inline-block;
    margin-top: 0.4rem;
    padding: 0.2rem 0.5rem;
    border-radius: 0.4rem;
    background: rgba(28, 27, 23, 0.08);
    font-family: Consolas, "Courier New", monospace;
    font-size: 0.85rem;
}

.alert {
    margin: 0 0 1rem;
    padding: 0.9rem 1rem;
    border-radius: 0.85rem;
}

.alert-error {
    background: var(--error-bg);
    color: var(--error-text);
}

/* ─── Responsive ─────────────────────────────────────────────────────── */

@media (max-width: 900px) {
    .app-shell {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
    }

    .shell-sidebar {
        position: static;
        height: auto;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        padding: 0.75rem 1rem;
        gap: 0.5rem;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .shell-brand-area {
        border-bottom: 0;
        padding: 0;
        flex: 0 0 auto;
    }

    .shell-nav {
        flex-direction: row;
        flex: 0 0 auto;
        gap: 0.25rem;
    }

    .shell-nav-label {
        display: none;
    }

    .shell-nav-link {
        font-size: 0.88rem;
        padding: 0.45rem 0.65rem;
    }

    .shell-user-area {
        margin-left: auto;
        padding: 0.5rem 0.75rem;
        display: flex;
        align-items: center;
        gap: 0.75rem;
    }

    .shell-user-name {
        margin-bottom: 0;
    }

    .shell-content {
        padding: 1.25rem;
    }

    .dashboard-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .panel-grid,
    .two-col,
    .config-grid,
    .filter-grid {
        grid-template-columns: 1fr;
    }

    .form-row-wide {
        grid-column: auto;
    }

    .page-hero,
    .timeline-meta {
        flex-direction: column;
        align-items: flex-start;
    }

    .auth-card,
    .dashboard-card {
        border-radius: 1.5rem;
    }
}
