/* =========================================================
   AI Ticket Portal – design system
   ========================================================= */

/* ---------- Tokens ---------- */
:root {
    --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

    --brand-50: #ecfdf5;
    --brand-100: #d1fae5;
    --brand-400: #34d399;
    --brand-500: #10b981;
    --brand-600: #059669;
    --brand-700: #047857;
    --grad: linear-gradient(135deg, #34d399 0%, #10b981 45%, #047857 100%);

    --bg: #f4f6f9;
    --bg-soft: #eef1f5;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e5e8ee;
    --border-strong: #d4d9e1;
    --text: #0f172a;
    --text-2: #475569;
    --text-3: #8a94a6;

    --success: #059669;
    --success-bg: #ecfdf5;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --warning: #b45309;
    --warning-bg: #fffbeb;
    --info: #2563eb;
    --info-bg: #eff6ff;

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 18px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
    --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 8px 24px -8px rgba(15, 23, 42, .08);
    --shadow-lg: 0 24px 60px -12px rgba(15, 23, 42, .25);
    --ring: 0 0 0 4px rgba(16, 185, 129, .18);

    --sidebar-w: 268px;
    --ease: cubic-bezier(.2, .8, .2, 1);
    color-scheme: light;
}

[data-theme="dark"] {
    --bg: #0b1017;
    --bg-soft: #111824;
    --surface: #121a26;
    --surface-2: #162030;
    --border: #1f2a3a;
    --border-strong: #2a3850;
    --text: #e8edf5;
    --text-2: #a3aec2;
    --text-3: #6b778c;

    --success: #34d399;
    --success-bg: rgba(16, 185, 129, .12);
    --danger: #f87171;
    --danger-bg: rgba(248, 113, 113, .12);
    --warning: #fbbf24;
    --warning-bg: rgba(251, 191, 36, .12);
    --info: #60a5fa;
    --info-bg: rgba(96, 165, 250, .12);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow: 0 1px 3px rgba(0, 0, 0, .35), 0 10px 30px -10px rgba(0, 0, 0, .5);
    --shadow-lg: 0 30px 70px -10px rgba(0, 0, 0, .65);
    color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 14.5px;
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; letter-spacing: -.02em; line-height: 1.25; }
p { margin: 0; }
a { color: var(--brand-600); text-decoration: none; }
code {
    font-family: var(--mono);
    font-size: .86em;
    padding: .12em .45em;
    border-radius: 6px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    word-break: break-all;
}
.mono { font-family: var(--mono); font-size: .92em; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.tiny { font-size: 12px; color: var(--text-3); }
.hint { display: block; font-size: 12.5px; color: var(--text-3); margin-top: 6px; }
.t-right { text-align: right; }

.icon { width: 18px; height: 18px; flex: none; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 40px; padding: 0 16px;
    border: 1px solid transparent; border-radius: 10px;
    font: 600 14px/1 var(--font);
    cursor: pointer; white-space: nowrap;
    transition: transform .15s var(--ease), box-shadow .2s var(--ease), background .2s, border-color .2s, color .2s;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn .icon { width: 17px; height: 17px; }
.btn-primary {
    color: #fff;
    background: var(--grad);
    box-shadow: 0 1px 0 rgba(255, 255, 255, .25) inset, 0 6px 16px -6px rgba(5, 150, 105, .6);
}
.btn-primary:hover { box-shadow: 0 1px 0 rgba(255, 255, 255, .25) inset, 0 10px 22px -8px rgba(5, 150, 105, .75); filter: saturate(1.1); }
.btn-ghost { color: var(--text); background: var(--surface); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-soft { color: var(--brand-700); background: var(--brand-50); border-color: var(--brand-100); }
[data-theme="dark"] .btn-soft { color: var(--brand-400); background: rgba(16, 185, 129, .1); border-color: rgba(16, 185, 129, .2); }
.btn-soft:hover { border-color: var(--brand-400); }
.btn-danger { color: #fff; background: linear-gradient(135deg, #f87171, #dc2626); box-shadow: 0 6px 16px -6px rgba(220, 38, 38, .6); }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.btn-lg { height: 46px; font-size: 15px; border-radius: 12px; }
.btn-block { width: 100%; }
.btn.is-loading { pointer-events: none; opacity: .85; }
.btn.is-loading::before {
    content: ""; width: 15px; height: 15px; border-radius: 50%;
    border: 2px solid currentColor; border-right-color: transparent;
    animation: spin .7s linear infinite;
}
.btn.is-loading .icon { display: none; }

.icon-btn {
    display: inline-grid; place-items: center;
    width: 36px; height: 36px;
    border: 1px solid var(--border); border-radius: 10px;
    background: var(--surface); color: var(--text-2);
    cursor: pointer; transition: all .2s var(--ease);
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-2); }
.icon-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.icon-btn-danger:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-bg); }
.inline-form { display: inline; margin: 0; }

/* ---------- Forms ---------- */
.form { display: grid; gap: 18px; }
.field { display: grid; gap: 7px; }
.field-label { font-weight: 600; font-size: 13.5px; }
.field-label em { font-style: normal; font-weight: 400; color: var(--text-3); margin-left: 4px; }
input[type="text"], input[type="password"] {
    width: 100%; height: 44px; padding: 0 14px;
    border: 1px solid var(--border-strong); border-radius: 11px;
    background: var(--surface); color: var(--text);
    font: 400 14.5px var(--font);
    transition: border-color .2s, box-shadow .2s, background .2s;
}
input.mono { font-family: var(--mono); font-size: 13.5px; }
input::placeholder { color: var(--text-3); }
input:hover { border-color: var(--text-3); }
input:focus { outline: none; border-color: var(--brand-500); box-shadow: var(--ring); }
.input-wrap { position: relative; display: block; }
.input-wrap .input-icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.input-wrap input { padding-left: 42px; padding-right: 44px; }
.input-action {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    width: 34px; height: 34px; display: grid; place-items: center;
    border: 0; border-radius: 8px; background: transparent; color: var(--text-3); cursor: pointer;
}
.input-action:hover { color: var(--text); background: var(--bg-soft); }

.switch-list { display: grid; gap: 10px; margin-top: 4px; }
.switch-row {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 14px 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2);
    cursor: pointer;
}
.switch-row strong { display: block; font-size: 14px; }
.switch-row small { color: var(--text-3); font-size: 12.5px; }
.switch {
    appearance: none; -webkit-appearance: none; flex: none;
    width: 44px; height: 26px; border-radius: 99px; margin: 0;
    background: var(--border-strong); position: relative; cursor: pointer;
    transition: background .25s var(--ease);
}
.switch::after {
    content: ""; position: absolute; top: 3px; left: 3px;
    width: 20px; height: 20px; border-radius: 50%; background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .25s var(--ease);
}
.switch:checked { background: var(--brand-500); }
.switch:checked::after { transform: translateX(18px); }
.switch:focus-visible { outline: none; box-shadow: var(--ring); }

/* ---------- Alerts ---------- */
.alert {
    display: flex; gap: 10px; align-items: flex-start;
    padding: 12px 14px; border-radius: 12px; font-size: 13.5px; border: 1px solid transparent;
}
.alert .icon { margin-top: 1px; }
.alert ul { margin: 0; padding-left: 16px; }
.alert-error { background: var(--danger-bg); color: var(--danger); border-color: rgba(220, 38, 38, .18); }
.alert-warning { background: var(--warning-bg); color: var(--warning); border-color: rgba(180, 83, 9, .18); }
.alert-info { background: var(--info-bg); color: var(--info); border-color: rgba(37, 99, 235, .18); }

/* =========================================================
   App layout
   ========================================================= */
.layout-app { min-height: 100vh; }

.sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40;
    width: var(--sidebar-w);
    display: flex; flex-direction: column; gap: 22px;
    padding: 22px 16px;
    background: var(--surface);
    border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px; color: var(--text); }
.brand img { border-radius: 11px; box-shadow: 0 8px 20px -8px rgba(5, 150, 105, .6); }
.brand strong { display: block; font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.brand small { display: block; font-size: 12px; color: var(--text-3); }

.nav { display: grid; gap: 4px; }
.nav-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); padding: 0 12px 6px; }
.nav-item {
    display: flex; align-items: center; gap: 12px;
    height: 42px; padding: 0 12px; border-radius: 11px;
    color: var(--text-2); font-weight: 500;
    transition: background .2s, color .2s;
}
.nav-item:hover { background: var(--bg-soft); color: var(--text); }
.nav-item.is-active { background: var(--brand-50); color: var(--brand-700); font-weight: 600; }
[data-theme="dark"] .nav-item.is-active { background: rgba(16, 185, 129, .12); color: var(--brand-400); }

.sidebar-footer { margin-top: auto; display: grid; gap: 12px; }
.security-note {
    display: flex; gap: 10px; padding: 14px;
    border-radius: 14px; border: 1px solid var(--border);
    background: linear-gradient(160deg, var(--brand-50), transparent 70%), var(--surface-2);
    color: var(--brand-700); font-size: 12.5px;
}
[data-theme="dark"] .security-note { background: linear-gradient(160deg, rgba(16, 185, 129, .12), transparent 70%), var(--surface-2); color: var(--brand-400); }
.security-note strong { display: block; color: var(--text); font-size: 13px; }
.security-note span { color: var(--text-2); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 12px; }
.avatar {
    width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
    background: var(--grad); color: #fff; font-weight: 700; font-size: 14px;
}
.user-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-backdrop { display: none; }

.shell { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
    position: sticky; top: 0; z-index: 30;
    display: flex; align-items: center; gap: 14px;
    height: 72px; padding: 0 32px;
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    backdrop-filter: saturate(160%) blur(12px);
    -webkit-backdrop-filter: saturate(160%) blur(12px);
    border-bottom: 1px solid var(--border);
}
.topbar-title h1 { font-size: 19px; font-weight: 700; }
.topbar-title p { font-size: 13px; color: var(--text-3); }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; }
.menu-btn { display: none; }
.content { width: 100%; max-width: 1180px; padding: 28px 32px 48px; margin: 0 auto; display: grid; gap: 22px; }

.theme-toggle .when-dark { display: none; }
[data-theme="dark"] .theme-toggle .when-dark { display: inline-grid; }
[data-theme="dark"] .theme-toggle .when-light { display: none; }
.theme-toggle span { display: inline-grid; }

/* ---------- Page head ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.page-head h2 { font-size: 22px; font-weight: 700; }
.page-head p { color: var(--text-2); margin-top: 6px; max-width: 640px; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stat {
    display: flex; align-items: center; gap: 14px;
    padding: 18px; border-radius: var(--radius-lg);
    background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm);
    position: relative; overflow: hidden;
    transition: transform .25s var(--ease), box-shadow .25s var(--ease);
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-icon { width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center; flex: none; }
.stat-icon .icon { width: 21px; height: 21px; }
.stat-label { font-size: 12.5px; color: var(--text-3); font-weight: 500; }
.stat-value { font-size: 24px; font-weight: 750; letter-spacing: -.03em; line-height: 1.2; }
.stat-brand .stat-icon { background: var(--grad); color: #fff; box-shadow: 0 8px 18px -8px rgba(5, 150, 105, .7); }
.stat-success .stat-icon { background: var(--success-bg); color: var(--success); }
.stat-danger .stat-icon { background: var(--danger-bg); color: var(--danger); }
.stat-info .stat-icon { background: var(--info-bg); color: var(--info); }
.stat-muted .stat-icon { background: var(--bg-soft); color: var(--text-3); }
.stat-info .stat-value { font-size: 18px; }

/* ---------- Cards ---------- */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); box-shadow: var(--shadow);
    overflow: hidden;
}
.card-pad { padding: 22px; display: grid; gap: 12px; align-content: start; }
.card-title { display: flex; align-items: center; gap: 12px; }
.card-title h3 { font-size: 16px; font-weight: 650; }
.card-title-action { margin-left: auto; }
.card-icon { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; background: var(--brand-50); color: var(--brand-600); }
[data-theme="dark"] .card-icon { background: rgba(16, 185, 129, .12); color: var(--brand-400); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; min-width: 760px; }
.table th {
    white-space: nowrap;
    text-align: left; font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
    color: var(--text-3); padding: 14px 20px; background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.table td { padding: 18px 20px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr { transition: background .2s; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table td > .mono, .table td > .muted { display: block; white-space: nowrap; }

.server-cell { display: flex; align-items: center; gap: 14px; }
.server-cell strong { font-weight: 650; margin-right: 6px; }
.server-cell .mono { display: block; font-size: 12.5px; margin-top: 2px; }
.server-avatar {
    width: 42px; height: 42px; border-radius: 12px; flex: none; display: grid; place-items: center;
    background: var(--grad); color: #fff; box-shadow: 0 8px 18px -10px rgba(5, 150, 105, .8);
}
.server-avatar.is-off { background: var(--bg-soft); color: var(--text-3); box-shadow: none; }
.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 99px; background: var(--bg-soft); color: var(--text-3); vertical-align: middle; }

.status { display: grid; gap: 4px; max-width: 300px; }
.status-msg { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.pill {
    display: inline-flex; align-items: center; gap: 7px; width: fit-content;
    padding: 3px 10px; border-radius: 99px; font-size: 12.5px; font-weight: 600;
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill-success { background: var(--success-bg); color: var(--success); }
.pill-success .dot { box-shadow: 0 0 0 0 currentColor; animation: pulse 2s infinite; }
.pill-danger { background: var(--danger-bg); color: var(--danger); }
.pill-muted { background: var(--bg-soft); color: var(--text-3); }
.pill-busy { background: var(--info-bg); color: var(--info); }
.pill-busy .dot { animation: blink 1s infinite; }

.row-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 64px 24px; display: grid; justify-items: center; gap: 10px; }
.empty-art {
    width: 76px; height: 76px; border-radius: 22px; display: grid; place-items: center; margin-bottom: 8px;
    background: var(--grad); color: #fff; box-shadow: 0 18px 40px -16px rgba(5, 150, 105, .8);
}
.empty-art .icon { width: 34px; height: 34px; }
.empty h3 { font-size: 18px; }
.empty p { color: var(--text-2); max-width: 420px; margin-bottom: 10px; }

/* ---------- Integration page ---------- */
.copy-field {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 6px 6px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2);
}
.copy-field code { flex: 1; background: none; border: 0; padding: 0; font-size: 13px; }
.chip-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 5px 12px; border-radius: 99px; background: var(--bg-soft); border: 1px solid var(--border); font-size: 12.5px; }
.fn-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.fn-list li { display: flex; justify-content: space-between; gap: 10px; padding: 9px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); font-size: 13px; }
.fn-list small { color: var(--text-3); }
.code {
    margin: 0; padding: 18px; border-radius: 14px; overflow-x: auto;
    background: #0b1220; color: #d1fae5; font: 13px/1.6 var(--mono);
    border: 1px solid #1d2a3f;
}
.code code { background: none; border: 0; padding: 0; color: inherit; }

/* ---------- Drawer ---------- */
.drawer-backdrop, .modal-backdrop {
    position: fixed; inset: 0; z-index: 60;
    background: rgba(8, 12, 20, .45); backdrop-filter: blur(3px);
    opacity: 0; pointer-events: none; transition: opacity .3s var(--ease);
}
.drawer-backdrop.is-open, .modal-backdrop.is-open { opacity: 1; pointer-events: auto; }
.drawer {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 70;
    width: min(480px, 100%);
    background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg);
    transform: translateX(104%); transition: transform .38s var(--ease);
    visibility: hidden;
}
.drawer.is-open { transform: none; visibility: visible; }
.drawer-form { height: 100%; display: flex; flex-direction: column; }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 24px 24px 18px; border-bottom: 1px solid var(--border); }
.drawer-head h3 { font-size: 18px; }
.drawer-head p { color: var(--text-3); font-size: 13px; margin-top: 3px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 22px 24px; display: grid; gap: 18px; align-content: start; }
.drawer-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px; border-top: 1px solid var(--border); background: var(--surface-2); }

/* ---------- Modal ---------- */
.modal {
    position: fixed; z-index: 80; top: 50%; left: 50%;
    width: min(420px, calc(100% - 32px));
    padding: 28px; border-radius: 20px; text-align: center;
    background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
    transform: translate(-50%, -46%) scale(.96); opacity: 0; pointer-events: none;
    transition: transform .3s var(--ease), opacity .3s var(--ease);
}
.modal.is-open { transform: translate(-50%, -50%) scale(1); opacity: 1; pointer-events: auto; }
.modal-icon { width: 56px; height: 56px; margin: 0 auto 14px; border-radius: 16px; display: grid; place-items: center; background: var(--danger-bg); color: var(--danger); }
.modal-icon .icon { width: 26px; height: 26px; }
.modal h3 { font-size: 18px; margin-bottom: 8px; }
.modal p { color: var(--text-2); font-size: 14px; }
.modal-actions { display: flex; gap: 10px; justify-content: center; margin-top: 22px; }
.modal-actions .btn { flex: 1; }

/* ---------- Toasts ---------- */
.toast-stack { position: fixed; z-index: 90; right: 24px; bottom: 24px; display: grid; gap: 10px; width: min(400px, calc(100% - 32px)); }
.toast {
    display: flex; align-items: flex-start; gap: 12px;
    padding: 14px 14px 14px 16px; border-radius: 14px;
    background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
    animation: toast-in .45s var(--ease);
}
.toast p { flex: 1; font-size: 13.5px; padding-top: 2px; }
.toast-icon { width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; flex: none; }
.toast-success .toast-icon { background: var(--success-bg); color: var(--success); }
.toast-warning .toast-icon { background: var(--warning-bg); color: var(--warning); }
.toast-error .toast-icon { background: var(--danger-bg); color: var(--danger); }
.toast-close { border: 0; background: none; color: var(--text-3); cursor: pointer; padding: 2px; border-radius: 6px; }
.toast-close:hover { color: var(--text); }
.toast-close .icon { width: 16px; height: 16px; }
.toast.is-leaving { animation: toast-out .3s var(--ease) forwards; }

/* =========================================================
   Auth layout
   ========================================================= */
.layout-auth { min-height: 100vh; }
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
.auth-hero {
    position: relative; overflow: hidden; color: #ecfdf5;
    background: radial-gradient(1200px 600px at -10% -10%, #10b981 0%, transparent 55%),
                radial-gradient(900px 600px at 110% 110%, #0ea5e9 0%, transparent 50%),
                linear-gradient(160deg, #052e22 0%, #03251c 45%, #021612 100%);
    display: flex; align-items: center; padding: 56px;
}
.auth-hero::before {
    content: ""; position: absolute; inset: 0; opacity: .14;
    background-image: linear-gradient(rgba(255, 255, 255, .5) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, .5) 1px, transparent 1px);
    background-size: 44px 44px;
    -webkit-mask-image: radial-gradient(circle at 30% 40%, #000 0%, transparent 70%);
    mask-image: radial-gradient(circle at 30% 40%, #000 0%, transparent 70%);
}
.auth-hero-glow {
    position: absolute; width: 420px; height: 420px; border-radius: 50%; right: -120px; top: 18%;
    background: radial-gradient(circle, rgba(52, 211, 153, .45), transparent 65%); filter: blur(10px);
    animation: float 9s ease-in-out infinite;
}
.auth-hero-inner { position: relative; max-width: 480px; display: grid; gap: 22px; }
.brand-light { color: #fff; padding: 0; }
.brand-light small { color: rgba(236, 253, 245, .7); }
.auth-hero h2 { font-size: 40px; font-weight: 800; letter-spacing: -.035em; line-height: 1.1; color: #fff; }
.auth-hero p { color: rgba(236, 253, 245, .78); font-size: 16px; }
.hero-points { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 12px; }
.hero-points li {
    display: flex; gap: 14px; align-items: center; padding: 14px 16px; border-radius: 14px;
    background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .1);
    backdrop-filter: blur(6px);
}
.hero-points .icon { width: 22px; height: 22px; color: #6ee7b7; }
.hero-points strong { display: block; color: #fff; font-size: 14px; }
.hero-points span { font-size: 13px; color: rgba(236, 253, 245, .7); }

.auth-panel { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 48px 24px; }
.auth-theme { position: absolute; top: 20px; right: 20px; }
.auth-card { width: 100%; max-width: 420px; display: grid; gap: 22px; }
.auth-head h1 { font-size: 28px; font-weight: 800; letter-spacing: -.03em; }
.auth-head p { color: var(--text-2); margin-top: 8px; }
.step-badge {
    display: inline-block; margin-bottom: 12px; padding: 4px 10px; border-radius: 99px;
    font-size: 12px; font-weight: 600; background: var(--brand-50); color: var(--brand-700);
}
[data-theme="dark"] .step-badge { background: rgba(16, 185, 129, .12); color: var(--brand-400); }
.auth-footer { margin-top: 32px; font-size: 12.5px; color: var(--text-3); }

.secret-block { padding: 16px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow-sm); }
.secret-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; font-weight: 600; font-size: 13.5px; }
.secret-head span { display: inline-flex; align-items: center; gap: 8px; }
.secret-value { display: block; padding: 10px 12px; font-size: 12.5px; line-height: 1.5; }

/* ---------- Animations ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, .5); } 70% { box-shadow: 0 0 0 7px rgba(16, 185, 129, 0); } 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); } }
@keyframes blink { 50% { opacity: .3; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes float { 50% { transform: translateY(-24px); } }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 1080px) {
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 960px) {
    .sidebar { transform: translateX(-100%); transition: transform .35s var(--ease); box-shadow: var(--shadow-lg); }
    .sidebar.is-open { transform: none; }
    .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(8, 12, 20, .45); opacity: 0; pointer-events: none; transition: opacity .3s; }
    .sidebar-backdrop.is-open { opacity: 1; pointer-events: auto; }
    .shell { margin-left: 0; }
    .menu-btn { display: inline-grid; }
    .topbar { padding: 0 16px; height: 64px; }
    .content { padding: 20px 16px 40px; }
    .grid-2 { grid-template-columns: 1fr; }
    .auth { grid-template-columns: 1fr; }
    .auth-hero { padding: 36px 24px; }
    .auth-hero h2 { font-size: 30px; }
    .hero-points { display: none; }
}
@media (max-width: 720px) {
    .topbar-title p { display: none; }
    .stats { gap: 12px; }
    .stat { padding: 14px; gap: 12px; }
    .stat-icon { width: 38px; height: 38px; border-radius: 11px; }
    .stat-value { font-size: 20px; }
    .stat-info .stat-value { font-size: 15px; }

    /* Table rows become cards */
    .table { min-width: 0; }
    .table thead { display: none; }
    .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
    .table tr { padding: 16px; border-bottom: 1px solid var(--border); display: grid; gap: 12px; }
    .table tbody tr:last-child { border-bottom: 0; }
    .table td { padding: 0; border: 0; }
    .table td:nth-child(2) { display: flex; gap: 10px; align-items: baseline; padding-left: 56px; }
    .table td:nth-child(3) { padding-left: 56px; }
    .table td:nth-child(4) { display: none; }
    .row-actions { justify-content: flex-start; padding-left: 56px; }
}
@media (max-width: 560px) {
    .page-head .btn { width: 100%; }
    .toast-stack { right: 16px; bottom: 16px; }
}
@media (max-width: 360px) {
    .stats { grid-template-columns: 1fr; }
}

/* ---------- Utilities ---------- */
.sr-copy { position: fixed; top: -1000px; left: -1000px; opacity: 0; }
.input-action.is-on { color: var(--brand-600); }

/* ---------- Config check (setup page) ---------- */
.config-check { padding: 16px; border-radius: 14px; border: 1px dashed var(--border-strong); background: var(--surface-2); display: grid; gap: 10px; }
.config-check-title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13.5px; }
.config-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-family: var(--mono); font-size: 13px; }

/* =========================================================
   Tickets, settings (v3)
   ========================================================= */
textarea {
    width: 100%; min-height: 96px; padding: 12px 14px; resize: vertical;
    border: 1px solid var(--border-strong); border-radius: 11px;
    background: var(--surface); color: var(--text);
    font: 400 14.5px/1.55 var(--font);
    transition: border-color .2s, box-shadow .2s;
}
textarea::placeholder { color: var(--text-3); }
textarea:focus { outline: none; border-color: var(--brand-500); box-shadow: var(--ring); }
fieldset.field { border: 0; padding: 0; margin: 0; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; }

.nav-badge {
    margin-left: auto; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 99px;
    display: inline-grid; place-items: center; font-size: 12px; font-weight: 700;
    background: #f59e0b; color: #fff; box-shadow: 0 4px 10px -4px rgba(245, 158, 11, .8);
}
.ai-status {
    display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px;
    border-radius: 99px; font-size: 13px; font-weight: 600; border: 1px solid var(--border);
    background: var(--surface); color: var(--text-2); white-space: nowrap;
}
.ai-status .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.ai-status.is-on { color: var(--success); border-color: rgba(5, 150, 105, .25); background: var(--success-bg); }
.ai-status.is-on .dot { animation: pulse 2s infinite; }
.ai-status.is-off { color: var(--danger); border-color: rgba(220, 38, 38, .25); background: var(--danger-bg); }

.stat-warning .stat-icon { background: var(--warning-bg); color: var(--warning); }
.pill-warning { background: var(--warning-bg); color: var(--warning); }
.pill-info { background: var(--info-bg); color: var(--info); }
.pill-lg { padding: 6px 14px; font-size: 13.5px; }
.tag-danger { background: var(--danger-bg); color: var(--danger); }
.card-icon-warning { background: var(--warning-bg) !important; color: var(--warning) !important; }
.card-icon-info { background: var(--info-bg) !important; color: var(--info) !important; }

.banner {
    display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: var(--radius-lg);
    border: 1px solid rgba(220, 38, 38, .25); background: var(--danger-bg);
}
.banner strong { display: block; color: var(--danger); }
.banner span { color: var(--text-2); font-size: 13.5px; }
.banner > div { flex: 1; }
.banner-icon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--surface); color: var(--danger); flex: none; }

/* Toolbar + tabs */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
    display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 12px; border-radius: 10px;
    color: var(--text-2); font-weight: 500; font-size: 13.5px; white-space: nowrap; transition: background .2s, color .2s;
}
.tab:hover { background: var(--bg-soft); color: var(--text); }
.tab.is-active { background: var(--text); color: var(--surface); }
.tab-count { font-size: 11.5px; font-weight: 700; padding: 1px 7px; border-radius: 99px; background: var(--bg-soft); color: var(--text-3); }
.tab.is-active .tab-count { background: rgba(255, 255, 255, .18); color: inherit; }
[data-theme="dark"] .tab.is-active .tab-count { background: rgba(0, 0, 0, .18); }
.tab-alert .tab-count { background: #f59e0b; color: #fff; }
.search { width: min(300px, 100%); }
.search input { height: 38px; padding-right: 14px; }

/* Ticket list */
.ticket-list { list-style: none; margin: 0; padding: 0; }
.ticket-list li + li { border-top: 1px solid var(--border); }
.ticket-row {
    display: flex; align-items: center; gap: 16px; padding: 16px 20px; color: var(--text);
    transition: background .2s; position: relative;
}
.ticket-row:hover { background: var(--surface-2); }
.ticket-row.ticket-needs_staff::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: #f59e0b; }
.ticket-icon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex: none; background: var(--bg-soft); color: var(--text-2); }
.ticket-needs_staff .ticket-icon { background: var(--warning-bg); color: var(--warning); }
.ticket-ai_drafted .ticket-icon { background: var(--info-bg); color: var(--info); }
.ticket-resolved .ticket-icon { background: var(--success-bg); color: var(--success); }
.ticket-main { flex: 1; min-width: 0; display: grid; gap: 3px; }
.ticket-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12.5px; }
.ticket-subject { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ticket-sub { font-size: 13px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-inline { color: var(--warning); font-weight: 500; }
.ticket-meta { display: grid; justify-items: end; gap: 6px; flex: none; }
.pill-mobile { display: none; }

/* Ticket page */
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); font-weight: 500; font-size: 13.5px; width: fit-content; }
.back-link:hover { color: var(--text); }
.ticket-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; flex-wrap: wrap; }
.ticket-head-main { display: grid; gap: 6px; min-width: 0; flex: 1; }
.ticket-head h2 { font-size: 21px; font-weight: 700; }
.ticket-head-side { display: grid; justify-items: end; gap: 10px; }
.ticket-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.ticket-col { display: grid; gap: 18px; }
.card-task { border-color: rgba(245, 158, 11, .45); background: linear-gradient(160deg, var(--warning-bg), transparent 60%), var(--surface); }
.task-text { font-size: 15px; font-weight: 500; }
.card-wait { border-color: rgba(37, 99, 235, .3); }
.reply-box {
    padding: 16px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border);
    font-size: 14px; line-height: 1.65; max-height: 520px; overflow-y: auto; overflow-wrap: anywhere;
}
.quote { margin: 0; padding: 12px 14px; border-left: 3px solid var(--info); border-radius: 0 10px 10px 0; background: var(--info-bg); font-size: 14px; }
.collapse summary { list-style: none; display: flex; gap: 12px; align-items: center; cursor: pointer; }
.collapse summary::-webkit-details-marker { display: none; }
.collapse summary strong { display: block; font-size: 15px; }
.collapse summary small { color: var(--text-3); font-size: 12.5px; }
.collapse[open] summary { margin-bottom: 12px; }

.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.timeline li { display: flex; gap: 12px; padding-bottom: 16px; position: relative; }
.timeline li:not(:last-child)::before { content: ""; position: absolute; left: 5px; top: 16px; bottom: 0; width: 2px; background: var(--border); }
.tl-dot { width: 12px; height: 12px; border-radius: 50%; margin-top: 5px; flex: none; background: var(--info); box-shadow: 0 0 0 3px var(--surface); }
.tl-handoff .tl-dot { background: #f59e0b; }
.tl-done .tl-dot, .tl-closing .tl-dot { background: var(--success); }
.tl-undo .tl-dot, .tl-reopened .tl-dot { background: var(--text-3); }
.timeline strong { display: block; font-size: 13.5px; }
.timeline p { margin-top: 3px; overflow-wrap: anywhere; }

/* Settings */
.power-card { display: flex; align-items: center; gap: 20px; padding: 24px; flex-wrap: wrap; }
.power-icon { width: 64px; height: 64px; border-radius: 20px; display: grid; place-items: center; flex: none; }
.power-icon .icon { width: 30px; height: 30px; }
.power-card.is-on .power-icon { background: var(--grad); color: #fff; box-shadow: 0 14px 30px -12px rgba(5, 150, 105, .8); }
.power-card.is-off .power-icon { background: var(--danger-bg); color: var(--danger); }
.power-text { flex: 1; min-width: 240px; }
.power-text h2 { font-size: 20px; }
.power-card.is-on h2 { color: var(--success); }
.power-card.is-off h2 { color: var(--danger); }
.power-text p { color: var(--text-2); margin-top: 6px; }
.choice-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 4px; }
.choice { position: relative; cursor: pointer; }
.choice input { position: absolute; opacity: 0; }
.choice > span {
    display: grid; gap: 4px; height: 100%; padding: 16px; border-radius: 14px; border: 1px solid var(--border-strong);
    background: var(--surface); transition: border-color .2s, box-shadow .2s, background .2s;
}
.choice > span .icon { color: var(--brand-600); margin-bottom: 4px; }
.choice small { color: var(--text-3); font-size: 12.5px; }
.choice input:checked + span { border-color: var(--brand-500); box-shadow: var(--ring); background: var(--brand-50); }
[data-theme="dark"] .choice input:checked + span { background: rgba(16, 185, 129, .08); }
.choice input:focus-visible + span { box-shadow: var(--ring); }
.rule-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.rule-list li { display: flex; gap: 10px; align-items: flex-start; color: var(--text-2); }
.rule-list .icon { color: var(--success); margin-top: 2px; }

@media (max-width: 960px) {
    .ticket-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
    .ai-status { padding: 0 10px; font-size: 12px; }
    .ticket-row { padding: 14px 16px; gap: 12px; align-items: flex-start; }
    .ticket-icon { width: 34px; height: 34px; border-radius: 10px; }
    .ticket-meta { display: none; }
    .ticket-main .pill-mobile { display: inline-flex; }
    .ticket-subject, .ticket-sub { white-space: normal; }
    .choice-grid { grid-template-columns: 1fr; }
    .ticket-head-side { justify-items: start; }
    .search { width: 100%; }
    .banner { flex-wrap: wrap; }
}
