:root {
    color-scheme: light;
    --admin-background: #f5f5f7;
    --admin-surface: #ffffff;
    --admin-surface-soft: #f9f9fb;
    --admin-text: #1d1d1f;
    --admin-muted: #6e6e73;
    --admin-border: #e5e5e7;
    --admin-accent: #111111;
    --admin-blue: #0071e3;
    --admin-green: #248a3d;
    --admin-red: #d70015;
    --admin-radius: 18px;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { background: var(--admin-background); color: var(--admin-text); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }

.admin-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    display: flex;
    width: 248px;
    flex-direction: column;
    padding: 28px 18px 20px;
    border-right: 1px solid var(--admin-border);
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(22px);
}

.admin-brand { display: flex; align-items: center; padding: 0 10px 30px; font-weight: 650; letter-spacing: -.02em; }
.admin-navigation { display: grid; gap: 5px; }
.admin-navigation-link { padding: 11px 12px; border-radius: 11px; color: var(--admin-muted); font-size: 14px; font-weight: 560; }
.admin-navigation-link:hover { background: #f0f0f2; color: var(--admin-text); }
.admin-navigation-link.active { background: #e9e9ec; color: var(--admin-text); }
.admin-logout { margin-top: auto; }
.admin-logout button { width: 100%; padding: 10px 12px; border: 0; background: transparent; color: var(--admin-muted); font-size: 12px; text-align: left; }

.admin-main { min-height: 100vh; margin-left: 248px; padding: 54px clamp(32px, 5vw, 76px) 80px; }
.admin-main > * { max-width: 1280px; margin-right: auto; margin-left: auto; }
.admin-page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 30px; }
.admin-page-header h1 { margin: 3px 0 0; font-size: clamp(32px, 3vw, 44px); line-height: 1.05; letter-spacing: -.045em; }
.admin-eyebrow { margin: 0; color: var(--admin-muted); font-size: 12px; font-weight: 650; letter-spacing: .08em; text-transform: uppercase; }
.admin-page-intro { max-width: 620px; margin: 12px 0 0; color: var(--admin-muted); line-height: 1.55; }
.admin-card { border: 1px solid var(--admin-border); border-radius: var(--admin-radius); background: var(--admin-surface); box-shadow: 0 10px 35px rgba(0, 0, 0, .035); }

.ticket-tabs { display: flex; gap: 4px; margin-bottom: 18px; }
.ticket-tab { padding: 9px 13px; border-radius: 10px; color: var(--admin-muted); font-size: 14px; font-weight: 560; }
.ticket-tab span { display: inline-grid; min-width: 22px; height: 22px; margin-left: 5px; place-items: center; border-radius: 999px; background: #e9e9ec; color: var(--admin-text); font-size: 12px; }
.ticket-tab.active { background: var(--admin-text); color: #fff; }
.ticket-tab.active span { background: rgba(255, 255, 255, .18); color: #fff; }
.ticket-table-card { overflow: hidden; }
.ticket-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ticket-table th { padding: 14px 18px; border-bottom: 1px solid var(--admin-border); color: var(--admin-muted); font-size: 11px; font-weight: 650; letter-spacing: .04em; text-align: left; text-transform: uppercase; }
.ticket-table td { padding: 17px 18px; border-bottom: 1px solid #ededf0; vertical-align: middle; }
.ticket-table tr:last-child td { border-bottom: 0; }
.ticket-table tbody tr:hover { background: var(--admin-surface-soft); }
.ticket-customer { display: grid; gap: 4px; }
.ticket-customer strong { font-size: 14px; }
.ticket-customer span { color: var(--admin-muted); font-size: 12px; }
.status-pill { display: inline-flex; align-items: center; padding: 5px 9px; border-radius: 999px; font-size: 11px; font-weight: 650; }
.status-pill.open { background: #e8f2ff; color: #0564c4; }
.status-pill.resolved { background: #eaf7ed; color: var(--admin-green); }
.status-pill.archived { background: #eeeeef; color: var(--admin-muted); }
.admin-empty-state { padding: 76px 24px; text-align: center; }
.admin-empty-state h2 { margin: 0 0 8px; font-size: 19px; }
.admin-empty-state p { margin: 0; color: var(--admin-muted); }

.admin-back-link { display: inline-block; margin-bottom: 22px; color: var(--admin-muted); font-size: 13px; }
.ticket-detail-header { align-items: center; }
.ticket-detail-layout { display: grid; grid-template-columns: 280px minmax(0, 820px); gap: 22px; align-items: start; }
.ticket-context { position: sticky; top: 28px; padding: 22px; }
.ticket-context h2, .reply-composer h2 { margin: 0; font-size: 17px; letter-spacing: -.02em; }
.ticket-context dl { display: grid; gap: 0; margin: 18px 0 0; }
.ticket-context dl div { display: grid; gap: 5px; padding: 12px 0; border-top: 1px solid #ededf0; }
.ticket-context dt { color: var(--admin-muted); font-size: 11px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase; }
.ticket-context dd { margin: 0; overflow-wrap: anywhere; font-size: 13px; line-height: 1.45; }
.ticket-context dd a { color: var(--admin-blue); }
.ticket-conversation { min-width: 0; }
.conversation-stream { display: grid; gap: 18px; min-height: 280px; padding: 26px; }
.conversation-message { max-width: 82%; }
.conversation-message.admin { justify-self: end; }
.conversation-meta { display: flex; justify-content: space-between; gap: 18px; margin: 0 4px 7px; color: var(--admin-muted); font-size: 11px; }
.conversation-meta strong { color: var(--admin-text); font-weight: 600; }
.conversation-body { padding: 14px 16px; border-radius: 16px; background: #f0f0f2; font-size: 14px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.conversation-message.admin .conversation-body { background: #e7f2ff; }
.conversation-system { margin: 4px 0; color: var(--admin-muted); font-size: 11px; text-align: center; }
.reply-composer { margin-top: 18px; padding: 22px; }
.reply-composer-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 15px; }
.reply-composer-heading p { margin: 5px 0 0; color: var(--admin-muted); font-size: 12px; }
.reply-composer textarea { width: 100%; min-height: 210px; resize: vertical; padding: 16px; border: 1px solid #d8d8dc; border-radius: 14px; outline: none; background: #fff; color: var(--admin-text); font-size: 14px; line-height: 1.6; }
.reply-composer textarea:focus { border-color: #8c8c91; box-shadow: 0 0 0 4px rgba(0, 0, 0, .055); }
.reply-actions { display: flex; justify-content: flex-end; margin-top: 14px; }
.reply-status { min-height: 18px; margin: 8px 2px 0; color: var(--admin-green); font-size: 12px; }
.reply-status.error { color: var(--admin-red); }
.button { min-height: 40px; padding: 0 15px; border: 0; border-radius: 11px; font-size: 13px; font-weight: 620; transition: opacity .15s ease, transform .15s ease; }
.button:hover { opacity: .82; }
.button:active { transform: scale(.98); }
.button:disabled { cursor: wait; opacity: .55; }
.button-primary { background: var(--admin-text); color: #fff; }
.button-secondary { background: #ececef; color: var(--admin-text); }
.button-quiet { background: transparent; color: var(--admin-muted); }
.ticket-management-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

.scenario-layout { display: grid; grid-template-columns: 310px minmax(480px, 780px); gap: 24px; align-items: start; }
.scenario-list { display: grid; overflow: hidden; }
.scenario-link { display: grid; gap: 5px; padding: 16px 18px; border-bottom: 1px solid var(--admin-border); }
.scenario-link:last-child { border-bottom: 0; }
.scenario-link:hover, .scenario-link.active { background: var(--admin-surface-soft); }
.scenario-link.active { box-shadow: inset 3px 0 var(--admin-text); }
.scenario-link strong { font-size: 13px; }
.scenario-link span { color: var(--admin-muted); font-size: 11px; line-height: 1.45; }
.scenario-stage { overflow: hidden; border: 1px solid #d8d8dc; border-radius: 18px; background: #eeeff2; box-shadow: 0 20px 50px rgba(0, 0, 0, .06); }
.scenario-browser-bar { display: flex; align-items: center; gap: 6px; height: 40px; padding: 0 14px; border-bottom: 1px solid #d8d8dc; background: #fafafa; }
.scenario-browser-bar span { width: 9px; height: 9px; border-radius: 50%; background: #d3d3d6; }
.scenario-browser-bar small { margin-left: 8px; color: var(--admin-muted); }
.scenario-preview-card { width: min(88%, 610px); margin: 55px auto 30px; padding: 32px; border-radius: 22px; background: #fff; box-shadow: 0 14px 50px rgba(0, 0, 0, .07); }
.scenario-preview-card h2 { margin: 7px 0 24px; font-size: 28px; letter-spacing: -.04em; }
.scenario-profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.scenario-profile-grid div { display: grid; gap: 7px; padding: 14px; border-radius: 13px; background: #f6f6f8; }
.scenario-profile-grid span { color: var(--admin-muted); font-size: 11px; }
.scenario-profile-grid strong { font-size: 13px; }
.scenario-notice { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-top: 22px; padding: 17px; border-radius: 14px; background: #111; color: #fff; }
.scenario-notice p { margin: 0; font-size: 13px; line-height: 1.45; }
.scenario-notice button { flex: 0 0 auto; padding: 9px 12px; border: 0; border-radius: 9px; background: #fff; color: #111; font-size: 12px; font-weight: 650; }
.scenario-footnote { margin: 0 0 22px; color: var(--admin-muted); font-size: 11px; text-align: center; }

.admin-flashes { position: fixed; z-index: 20; top: 18px; right: 24px; display: grid; gap: 8px; }
.admin-flash { padding: 11px 14px; border: 1px solid var(--admin-border); border-radius: 11px; background: #fff; box-shadow: 0 12px 32px rgba(0, 0, 0, .08); font-size: 13px; }
.admin-flash.error { color: var(--admin-red); }
.admin-flash.success { color: var(--admin-green); }

.admin-auth-page { display: grid; min-height: 100vh; place-items: center; padding: 24px; }
.admin-login-shell { width: min(100%, 360px); text-align: center; }
.admin-login-shell h1 { margin: 0 0 7px; font-size: 28px; letter-spacing: -.04em; }
.admin-login-shell > p { margin: 0 0 30px; color: var(--admin-muted); font-size: 14px; }
.admin-login-form { text-align: left; }
.admin-password-row { position: relative; }
.admin-password-row input { width: 100%; height: 52px; padding: 0 58px 0 15px; border: 1px solid #d8d8dc; border-radius: 15px; outline: none; background: #fff; }
.admin-password-row input:focus { border-color: #8c8c91; box-shadow: 0 0 0 4px rgba(0, 0, 0, .05); }
.admin-password-row button { position: absolute; top: 6px; right: 6px; width: 40px; height: 40px; border: 0; border-radius: 11px; background: #111; color: #fff; font-size: 20px; }
.admin-form-error { min-height: 18px; margin: 9px 3px 0; color: var(--admin-red); font-size: 12px; text-align: right; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 1050px) {
    .ticket-detail-layout, .scenario-layout { grid-template-columns: 1fr; }
    .ticket-context { position: static; }
    .ticket-table-card { overflow-x: auto; }
    .ticket-table { min-width: 900px; }
}
