/* ==========================================================
   DEVIXY SUPPORT — full redesign
   Layout: left sidebar · main content area · monochrome
   Fonts: DM Sans (body) · DM Mono (labels/code)
   ========================================================== */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,300;1,9..40,400&family=DM+Mono:wght@300;400;500&display=swap');

/* ── Tokens ─────────────────────────────────────────────── */
:root {
    --bg:   #121214;
    --sur:  #1c1c1f;
    --sur2: #252529;
    --bdr:  #323236;
    --bdr2: #424248;
    --txt:  #f0f0f4;
    --txt2: #a0a0ab;
    --txt3: #6a6a75;
    --acc:  #cccce0;
    --dim:  #70707a;
    --r:    10px;

    /* sidebar width */
    --sb-w: 220px;

    /* status colours */
    --c-open:    #93c5fd;
    --c-prog:    #fbbf24;
    --c-await:   #cccce0;
    --c-closed:  #70707a;
    --c-success: #4ade80;
    --c-danger:  #f87171;
}

/* ── Reset ──────────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box; margin: 0; padding: 0;
}

html, body {
    width: 100%; height: 100%;
    font-family: 'DM Sans', system-ui, sans-serif;
    background: var(--bg);
    color: var(--txt);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    line-height: 1.6;
}

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bdr2); border-radius: 2px; }

/* ── Grain ──────────────────────────────────────────────── */
.grain {
    position: fixed; inset: 0; pointer-events: none; z-index: 999; opacity: .02;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-size: 160px;
}

/* ══════════════════════════════════════════════════════════
   APP SHELL: sidebar + content
   ══════════════════════════════════════════════════════════ */
.app-shell {
    display: flex;
    min-height: 100vh;
}

/* ── Left Sidebar ───────────────────────────────────────── */
.app-sidebar {
    width: var(--sb-w);
    flex-shrink: 0;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    background: var(--sur);
    border-right: 1px solid var(--bdr);
    display: flex;
    flex-direction: column;
    z-index: 500;
    overflow: hidden;
}

/* Logo area */
.sb-logo {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 18px 16px 16px;
    border-bottom: 1px solid var(--bdr);
    text-decoration: none !important;
    flex-shrink: 0;
}

.sb-logo-mark {
    width: 22px; height: 22px;
    border: 1px solid var(--bdr2);
    border-radius: 5px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
}

.sb-logo-mark i {
    width: 9px; height: 9px;
    background: var(--acc);
    border-radius: 2px;
    display: block;
}

.sb-logo-text {
    font-family: 'DM Mono', monospace;
    font-size: 13px;
    font-weight: 400;
    color: var(--txt);
    letter-spacing: .01em;
    line-height: 1.2;
}

.sb-logo-sub {
    font-size: 9px;
    color: var(--txt3);
    letter-spacing: .04em;
    text-transform: uppercase;
    display: block;
    margin-top: 1px;
}

/* Nav section */
.sb-nav {
    flex: 1;
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
}

.sb-nav-label {
    font-size: 9px;
    font-weight: 600;
    color: var(--txt3);
    text-transform: uppercase;
    letter-spacing: .1em;
    font-family: 'DM Mono', monospace;
    padding: 8px 8px 4px;
    margin-top: 4px;
}

.sb-link {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 10px;
    border-radius: 7px;
    color: var(--txt3);
    text-decoration: none !important;
    font-size: 13px;
    font-weight: 400;
    transition: background .15s, color .15s;
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}

.sb-link:hover {
    background: var(--sur2);
    color: var(--txt2);
}

.sb-link.active {
    background: var(--sur2);
    color: var(--txt);
}

.sb-link svg {
    flex-shrink: 0;
    opacity: .6;
    transition: opacity .15s;
}

.sb-link:hover svg,
.sb-link.active svg {
    opacity: 1;
}

.sb-link-badge {
    margin-left: auto;
    background: var(--acc);
    color: var(--bg);
    font-family: 'DM Mono', monospace;
    font-size: 9px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    line-height: 1.4;
}

/* User area at bottom */
.sb-user {
    border-top: 1px solid var(--bdr);
    padding: 12px 14px;
    flex-shrink: 0;
}

.sb-user-info {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-bottom: 10px;
}

.sb-avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--sur2);
    border: 1px solid var(--bdr2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    color: var(--txt2);
    font-family: 'DM Mono', monospace;
    flex-shrink: 0;
}

.sb-user-meta { flex: 1; min-width: 0; }

.sb-user-name {
    font-size: 12px;
    font-weight: 500;
    color: var(--txt);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.sb-user-role {
    font-size: 10px;
    color: var(--txt3);
    font-family: 'DM Mono', monospace;
    display: block;
}

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

.sb-btn {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid var(--bdr);
    border-radius: 6px;
    background: transparent;
    color: var(--txt3);
    font-size: 11px;
    font-family: 'DM Mono', monospace;
    text-decoration: none;
    cursor: pointer;
    text-align: center;
    transition: border-color .15s, color .15s;
    display: block;
}

.sb-btn:hover {
    border-color: var(--bdr2);
    color: var(--txt2);
}

/* Mobile sidebar toggle */
.sb-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 600;
    width: 36px; height: 36px;
    background: var(--sur);
    border: 1px solid var(--bdr2);
    border-radius: 8px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-direction: column;
    gap: 4px;
}

.sb-toggle span {
    display: block;
    width: 16px; height: 1.5px;
    background: var(--txt2);
    border-radius: 2px;
    transition: all .25s;
}

.sb-toggle.open span:nth-child(1) { transform: translateY(5.5px) rotate(45deg); }
.sb-toggle.open span:nth-child(2) { opacity: 0; }
.sb-toggle.open span:nth-child(3) { transform: translateY(-5.5px) rotate(-45deg); }

/* Overlay for mobile sidebar */
.sb-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.55);
    z-index: 790; /* below sidebar (800) but above everything else */
    /* NO backdrop-filter — it creates stacking context that blurs the sidebar */
}

/* ── Main content area ──────────────────────────────────── */
.app-main {
    flex: 1;
    margin-left: var(--sb-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Page topbar (no full navbar — just a slim top strip) */
.page-topbar {
    height: 48px;
    border-bottom: 1px solid var(--bdr);
    display: flex;
    align-items: center;
    padding: 0 28px;
    gap: 12px;
    background: var(--bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    position: sticky;
    top: 0;
    z-index: 400;
    flex-shrink: 0;
}

.topbar-breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--txt3);
    font-family: 'DM Mono', monospace;
}

.topbar-breadcrumb a {
    color: var(--txt3);
    text-decoration: none;
    transition: color .15s;
}

.topbar-breadcrumb a:hover { color: var(--txt2); }
.topbar-breadcrumb .sep { opacity: .4; }
.topbar-breadcrumb .current { color: var(--txt2); }

.topbar-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ── Page content ───────────────────────────────────────── */
.page-content {
    flex: 1;
    padding: 28px;
    max-width: 1100px;
    width: 100%;
}

/* ══════════════════════════════════════════════════════════
   COMPONENTS
   ══════════════════════════════════════════════════════════ */

/* ── Buttons ────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 7px;
    border: 1px solid var(--bdr2);
    background: transparent;
    color: var(--txt2);
    font-family: inherit;
    font-size: 12px;
    font-weight: 400;
    cursor: pointer;
    text-decoration: none !important;
    transition: color .15s, border-color .15s, background .15s;
    white-space: nowrap;
    letter-spacing: .01em;
}

.btn:hover { color: var(--txt); border-color: var(--dim); }

.btn-filled {
    background: var(--sur2);
    color: var(--txt);
    border-color: var(--bdr2);
}

.btn-filled:hover {
    background: var(--bdr);
    border-color: var(--dim);
    color: var(--txt);
}

.btn-danger { color: var(--c-danger); border-color: rgba(248,113,113,0.25); }
.btn-danger:hover { background: rgba(248,113,113,0.05); border-color: rgba(248,113,113,0.4); color: var(--c-danger); }

/* ── Section header ─────────────────────────────────────── */
.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    gap: 12px;
}

.section-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--txt);
    font-family: 'DM Mono', monospace;
    letter-spacing: -.01em;
}

/* ── Stats row ──────────────────────────────────────────── */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1px;
    border: 1px solid var(--bdr);
    border-radius: var(--r);
    overflow: hidden;
    margin-bottom: 24px;
    background: var(--bdr);
}

.stat-card {
    background: var(--sur);
    padding: 20px 22px;
    transition: background .15s;
}

.stat-card:hover { background: var(--sur2); }

.stat-value {
    font-size: 28px;
    font-weight: 300;
    letter-spacing: -.04em;
    color: var(--txt);
    line-height: 1;
    font-family: 'DM Mono', monospace;
    margin-bottom: 4px;
}

.stat-label {
    font-size: 10px;
    color: var(--txt2);
    font-family: 'DM Mono', monospace;
    text-transform: uppercase;
    letter-spacing: .06em;
}

/* ── Filters ────────────────────────────────────────────── */
.filters-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 20px;
    align-items: flex-end;
}

.filter-group { display: flex; flex-direction: column; gap: 4px; }

.filter-label {
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--txt3);
    font-family: 'DM Mono', monospace;
}

.filter-input,
.filter-select {
    height: 34px;
    background: var(--sur);
    border: 1px solid var(--bdr);
    border-radius: 7px;
    color: var(--txt);
    font-family: 'DM Mono', monospace;
    font-size: 12px;
    padding: 0 12px;
    outline: none;
    transition: border-color .15s;
    min-width: 160px;
}

.filter-input::placeholder { color: var(--txt3); }
.filter-input:focus, .filter-select:focus { border-color: var(--bdr2); }
.filter-select { cursor: pointer; -webkit-appearance: none; min-width: 120px; }
.filter-select option { background: var(--sur2); }

/* ── Ticket list (table style, not grid) ─────────────────── */
.ticket-list {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--bdr);
    border-radius: var(--r);
    overflow: hidden;
    background: var(--sur);
}

.ticket-list-header {
    display: grid;
    grid-template-columns: 1fr 120px 110px 100px 90px;
    padding: 8px 18px;
    background: var(--sur2);
    border-bottom: 1px solid var(--bdr);
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--txt3);
    font-family: 'DM Mono', monospace;
    gap: 12px;
}

.ticket-row {
    display: grid;
    grid-template-columns: 1fr 120px 110px 100px 90px;
    padding: 12px 18px;
    border-bottom: 1px solid var(--bdr);
    text-decoration: none !important;
    color: inherit;
    align-items: center;
    gap: 12px;
    transition: background .15s;
    position: relative;
}

.ticket-row:last-child { border-bottom: none; }
.ticket-row:hover { background: var(--sur2); }

.ticket-row--pinned { border-left: 2px solid var(--bdr2); }
.ticket-row--unread { border-left: 2px solid var(--acc); }

.tr-title-wrap { min-width: 0; }

.tr-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--txt);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.tr-desc {
    font-size: 11px;
    color: var(--txt3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    margin-top: 2px;
}

.tr-id {
    font-family: 'DM Mono', monospace;
    font-size: 10px;
    color: var(--txt3);
    display: inline-block;
    margin-right: 6px;
}

.tr-pin-icon {
    font-size: 11px;
    margin-right: 4px;
    opacity: .7;
}

/* Unread count */
.tr-unread {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: var(--acc);
    color: var(--bg);
    font-size: 9px;
    font-weight: 700;
    font-family: 'DM Mono', monospace;
    margin-left: 6px;
}

.tr-user {
    font-size: 11px;
    color: var(--txt2);
    font-family: 'DM Mono', monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tr-date {
    font-size: 10px;
    color: var(--txt3);
    font-family: 'DM Mono', monospace;
    white-space: nowrap;
}

/* Pin button on rows */
.tr-pin-btn {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--sur2);
    border: 1px solid var(--bdr);
    border-radius: 5px;
    padding: 3px 6px;
    font-size: 11px;
    cursor: pointer;
    opacity: 0;
    transition: opacity .15s, border-color .15s;
    z-index: 2;
    color: var(--txt2);
    line-height: 1;
}

.ticket-row:hover .tr-pin-btn { opacity: 1; }
.tr-pin-btn.pinned { opacity: 1; border-color: var(--bdr2); }
.tr-pin-btn:hover { border-color: var(--dim) !important; }

/* Section labels in list */
.ticket-list-sep {
    padding: 7px 18px;
    background: var(--sur2);
    border-bottom: 1px solid var(--bdr);
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--txt3);
    font-family: 'DM Mono', monospace;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Empty state */
.empty-state {
    padding: 48px 24px;
    text-align: center;
    color: var(--txt3);
    font-size: 13px;
}

.empty-state svg { margin-bottom: 12px; opacity: .3; }

/* ── Status badge ───────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 9px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 5px;
    font-family: 'DM Mono', monospace;
    letter-spacing: .03em;
    border: 1px solid;
    white-space: nowrap;
    text-transform: uppercase;
}

.badge::before {
    content: '';
    width: 4px; height: 4px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

.badge-open              { color: var(--c-open);   border-color: rgba(147,197,253,.2);  background: rgba(147,197,253,.05); }
.badge-in_progress       { color: var(--c-prog);   border-color: rgba(251,191,36,.2);   background: rgba(251,191,36,.05);  }
.badge-awaiting_response { color: var(--c-await);  border-color: rgba(204,204,224,.2);  background: rgba(204,204,224,.05); }
.badge-closed            { color: var(--c-closed); border-color: rgba(112,112,122,.2);  background: rgba(112,112,122,.05); }

/* ── Forms ──────────────────────────────────────────────── */
.form-block { margin-bottom: 18px; }

.form-block label {
    display: block;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--txt3);
    margin-bottom: 7px;
    font-family: 'DM Mono', monospace;
}

.form-block input,
.form-block select,
.form-block textarea {
    width: 100%;
    background: var(--sur2);
    border: 1px solid var(--bdr);
    border-radius: 8px;
    color: var(--txt);
    font-family: 'DM Sans', system-ui, sans-serif;
    font-size: 14px;
    padding: 10px 14px;
    outline: none;
    transition: border-color .15s;
}

.form-block input::placeholder,
.form-block textarea::placeholder { color: var(--txt3); }

.form-block input:focus,
.form-block select:focus,
.form-block textarea:focus { border-color: var(--bdr2); }

.form-block textarea { resize: vertical; min-height: 100px; }
.form-block select { cursor: pointer; -webkit-appearance: none; }
.form-block select option { background: var(--sur2); }

/* ── Alerts ─────────────────────────────────────────────── */
.alert {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 16px;
    border: 1px solid;
}

.alert-error   { color: var(--c-danger);  border-color: rgba(248,113,113,.2); background: rgba(248,113,113,.05); }
.alert-success { color: var(--c-success); border-color: rgba(74,222,128,.2);  background: rgba(74,222,128,.05);  }

/* ── Auth card ──────────────────────────────────────────── */
.auth-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
    background: var(--bg);
}

.auth-card {
    background: var(--sur);
    border: 1px solid var(--bdr);
    border-radius: 12px;
    padding: 32px;
    width: 100%;
    max-width: 400px;
}

.auth-logo {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-bottom: 28px;
    text-decoration: none !important;
}

.auth-logo-mark {
    width: 22px; height: 22px;
    border: 1px solid var(--bdr2);
    border-radius: 5px;
    display: grid;
    place-items: center;
}

.auth-logo-mark i {
    width: 9px; height: 9px;
    background: var(--acc);
    border-radius: 2px;
    display: block;
}

.auth-logo-text {
    font-family: 'DM Mono', monospace;
    font-size: 13px;
    color: var(--txt);
}

.auth-title {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -.02em;
    margin-bottom: 6px;
    color: var(--txt);
}

.auth-sub {
    font-size: 12px;
    color: var(--txt3);
    margin-bottom: 24px;
    line-height: 1.5;
}

.auth-footer {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--bdr);
    text-align: center;
    font-size: 12px;
    color: var(--txt3);
}

.auth-footer a {
    color: var(--txt2);
    text-decoration: none;
    margin-left: 4px;
}

.auth-footer a:hover { color: var(--txt); }

/* ═══════════════════════════════════════════════════════════
   TICKET DETAIL PAGE
   ═══════════════════════════════════════════════════════════ */
.ticket-page {
    display: grid;
    grid-template-columns: 1fr 270px;
    gap: 0;
    height: calc(100vh - 48px);
    overflow: hidden;
}

/* Chat panel */
.chat-panel {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--bdr);
    overflow: hidden;
}

/* Chat top bar */
.chat-topbar {
    padding: 14px 20px;
    border-bottom: 1px solid var(--bdr);
    flex-shrink: 0;
    background: var(--sur);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.chat-topbar-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--txt);
    letter-spacing: -.01em;
    font-family: 'DM Mono', monospace;
}

.chat-topbar-sub {
    font-size: 10px;
    color: var(--txt3);
    font-family: 'DM Mono', monospace;
    margin-top: 2px;
}

.chat-topbar-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
    align-items: flex-start;
}

/* Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    scrollbar-width: thin;
    scrollbar-color: var(--bdr2) transparent;
}

/* Date separator */
.msg-date-sep {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 14px 0 10px;
    font-size: 9px;
    font-weight: 600;
    color: var(--txt3);
    text-transform: uppercase;
    letter-spacing: .08em;
    font-family: 'DM Mono', monospace;
}

.msg-date-sep::before, .msg-date-sep::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--bdr);
}

/* Message rows */
.msg-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    padding: 1px 0;
}

.msg-row.mine { flex-direction: row-reverse; }
.msg-row.grouped .msg-avatar { visibility: hidden; }
.msg-row.grouped { padding-top: 0; }

.msg-avatar {
    width: 24px; height: 24px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    font-weight: 700;
    border: 1px solid var(--bdr);
    font-family: 'DM Mono', monospace;
    background: var(--sur2);
    color: var(--txt3);
}

.avatar-user    { color: var(--c-open); }
.avatar-helper  { color: var(--c-await); }
.avatar-curator { color: var(--txt); }
.avatar-system  { color: var(--dim); }

.msg-content { max-width: 68%; display: flex; flex-direction: column; gap: 2px; }
.msg-row.mine .msg-content { align-items: flex-end; }

.msg-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 10px;
    color: var(--txt3);
    padding: 0 2px;
    margin-bottom: 2px;
    font-family: 'DM Mono', monospace;
}

.msg-row.grouped .msg-meta { display: none; }

.role-badge {
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 8px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    border: 1px solid;
    font-family: 'DM Mono', monospace;
}

.role-user    { color: var(--c-open);  border-color: rgba(147,197,253,.2); background: rgba(147,197,253,.05); }
.role-helper  { color: var(--c-await); border-color: rgba(204,204,224,.2); background: rgba(204,204,224,.05); }
.role-curator { color: var(--txt);     border-color: var(--bdr);           background: var(--sur2); }
.role-system  { color: var(--dim);     border-color: var(--bdr);           background: transparent; }

.msg-bubble {
    padding: 9px 13px;
    border-radius: 11px;
    font-size: 13px;
    line-height: 1.6;
    word-break: break-word;
    position: relative;
}

.msg-row.mine .msg-bubble {
    background: var(--sur2);
    color: var(--txt);
    border: 1px solid var(--bdr2);
    border-radius: 11px 11px 3px 11px;
}

.msg-row.other .msg-bubble {
    background: var(--bg);
    color: var(--txt);
    border: 1px solid var(--bdr);
    border-radius: 11px 11px 11px 3px;
}

.msg-bubble::after {
    content: attr(data-time);
    position: absolute;
    bottom: -15px;
    font-size: 9px;
    color: var(--txt3);
    white-space: nowrap;
    opacity: 0;
    transition: opacity .15s;
    pointer-events: none;
    font-family: 'DM Mono', monospace;
}

.msg-row.mine  .msg-bubble::after { right: 2px; }
.msg-row.other .msg-bubble::after { left: 2px; }
.msg-row:hover .msg-bubble::after { opacity: 1; }

/* System messages */
.msg-row.system-msg { justify-content: center; margin: 8px 0; }
.msg-row.system-msg .msg-content { max-width: 85%; align-items: center; }
.msg-row.system-msg .msg-bubble {
    background: transparent;
    border: 1px solid var(--bdr);
    border-radius: 20px;
    color: var(--txt3);
    font-size: 11px;
    text-align: center;
    padding: 4px 14px;
    font-family: 'DM Mono', monospace;
}
.msg-row.system-msg .msg-bubble::after { display: none; }
.msg-row.system-msg .msg-bubble p { margin: 0; }

/* File attachments */
.msg-file { margin-top: 6px; }
.msg-file img { max-width: 100%; max-height: 220px; border-radius: 8px; border: 1px solid var(--bdr); display: block; }
.msg-file-link { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; background: var(--sur2); border-radius: 6px; color: inherit; text-decoration: none; font-size: 11px; border: 1px solid var(--bdr); }

/* Markdown */
.msg-bubble p { margin: 0 0 .3em; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble strong { font-weight: 600; }
.msg-bubble em { font-style: italic; }
.msg-bubble code { font-family: 'DM Mono', monospace; font-size: .78em; background: rgba(0,0,0,.3); border-radius: 4px; padding: .1em .35em; }
.msg-bubble pre { background: rgba(0,0,0,.3); border-radius: 7px; padding: .6em 1em; overflow-x: auto; margin: .4em 0; font-size: .75em; border: 1px solid var(--bdr); }
.msg-bubble pre code { background: none; padding: 0; }
.msg-bubble ul, .msg-bubble ol { padding-left: 1.3em; margin: .25em 0; }
.msg-bubble li { margin: .1em 0; }
.msg-bubble blockquote { border-left: 2px solid var(--bdr2); margin: .3em 0; padding: .1em .7em; opacity: .8; }
.msg-bubble a { color: inherit; text-decoration: underline; opacity: .8; }

/* Pinned bar */
#pinned-bar { border-bottom: 1px solid var(--bdr); background: var(--sur2); padding: 7px 16px; flex-shrink: 0; }
.pinned-bar-inner { display: flex; align-items: center; gap: 8px; }
.pinned-bar-icon { font-size: 11px; flex-shrink: 0; }
.pinned-bar-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pinned-bar-label { font-size: 8px; font-weight: 700; color: var(--txt3); text-transform: uppercase; letter-spacing: .08em; font-family: 'DM Mono', monospace; }
.pinned-bar-preview { font-size: 11px; color: var(--txt2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pinned-bar-goto { background: none; border: 1px solid var(--bdr2); border-radius: 5px; color: var(--txt2); padding: 2px 8px; font-size: 10px; cursor: pointer; flex-shrink: 0; transition: border-color .15s, color .15s; font-family: 'DM Mono', monospace; }
.pinned-bar-goto:hover { border-color: var(--dim); color: var(--txt); }

/* Unread bubble */
.msg-bubble.msg-unread { border-left: 2px solid var(--acc); }

/* Pin on messages */
.msg-pin-btn { background: none; border: none; padding: 2px 4px; cursor: pointer; color: var(--txt3); border-radius: 4px; transition: color .15s; vertical-align: middle; margin-left: 4px; line-height: 1; }
.msg-pin-btn:hover { color: var(--txt2); }
.msg-pin-btn.pinned { color: var(--acc); }
.msg-pinned-label { font-size: 9px; color: var(--txt3); font-weight: 600; letter-spacing: .04em; margin-bottom: 2px; opacity: .8; font-family: 'DM Mono', monospace; }
.msg-row--pinned .msg-bubble { border-color: var(--bdr2) !important; }

/* Chat input area */
.chat-input-area {
    border-top: 1px solid var(--bdr);
    background: var(--sur);
    padding: 12px 16px;
    flex-shrink: 0;
}

.chat-form { display: flex; align-items: flex-end; gap: 8px; }

.chat-input-wrap {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--bdr);
    border-radius: 9px;
    padding: 8px 10px;
    display: flex;
    align-items: flex-end;
    gap: 6px;
    transition: border-color .15s;
}

.chat-input-wrap:focus-within { border-color: var(--bdr2); }

.chat-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--txt);
    font-family: 'DM Sans', system-ui, sans-serif;
    font-size: 13px;
    line-height: 1.55;
    resize: none;
    min-height: 22px;
    max-height: 130px;
    overflow: hidden;
    overflow-y: auto;
    padding: 1px 0;
}

.chat-input::placeholder { color: var(--txt3); }

.file-upload-btn {
    width: 24px; height: 24px;
    display: flex; align-items: center; justify-content: center;
    background: transparent; border: none; border-radius: 5px;
    color: var(--txt3); cursor: pointer; transition: color .15s;
    flex-shrink: 0; padding: 0;
}

.file-upload-btn:hover { color: var(--txt2); }

.chat-send-btn {
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    background: var(--sur2); border: 1px solid var(--bdr2);
    border-radius: 8px; color: var(--txt); cursor: pointer;
    transition: border-color .15s, background .15s; flex-shrink: 0;
}

.chat-send-btn:hover { background: var(--bdr); border-color: var(--dim); }
.chat-send-btn:active { transform: scale(.94); }
.chat-send-btn svg { width: 14px; height: 14px; }
.chat-send-btn:disabled { opacity: .3; cursor: not-allowed; pointer-events: none; }

.chat-closed-notice {
    padding: 12px 16px;
    text-align: center;
    color: var(--txt3);
    font-size: 11px;
    border-top: 1px solid var(--bdr);
    font-family: 'DM Mono', monospace;
}

/* File preview bar */
#file-preview-bar { padding: 8px 12px; background: var(--sur2); border-top: 1px solid var(--bdr); }
#file-preview-inner { display: flex; align-items: center; gap: 10px; }
#file-preview-thumb { width: 36px; height: 36px; border-radius: 5px; overflow: hidden; background: var(--bg); display: flex; align-items: center; justify-content: center; flex-shrink: 0; border: 1px solid var(--bdr); }
.file-preview-img { width: 100%; height: 100%; object-fit: cover; }
.file-preview-icon { font-size: 9px; font-weight: 700; color: var(--acc); font-family: 'DM Mono', monospace; }
.file-preview-spinner { width: 16px; height: 16px; border: 2px solid var(--bdr2); border-top-color: var(--acc); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#file-preview-info { flex: 1; min-width: 0; }
#file-preview-name { font-size: 11px; font-weight: 500; color: var(--txt); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; font-family: 'DM Mono', monospace; }
#file-preview-size { font-size: 10px; color: var(--txt3); display: block; font-family: 'DM Mono', monospace; }
#file-preview-remove { background: none; border: none; color: var(--txt3); cursor: pointer; padding: 4px 6px; border-radius: 4px; font-size: 12px; transition: color .15s; flex-shrink: 0; }
#file-preview-remove:hover { color: var(--c-danger); }

/* ── Ticket info panel (right column) ─────────────────────── */
.ticket-info-panel {
    background: var(--sur);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--bdr2) transparent;
}

.tip-section {
    border-bottom: 1px solid var(--bdr);
}

.tip-section:last-child { border-bottom: none; }

.tip-head {
    padding: 12px 16px;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--txt3);
    font-family: 'DM Mono', monospace;
}

.tip-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 16px;
    border-top: 1px solid var(--bdr);
    transition: background .15s;
}

.tip-row:hover { background: var(--sur2); }

.tip-icon { color: var(--txt3); flex-shrink: 0; margin-top: 1px; }

.tip-content { flex: 1; min-width: 0; }

.tip-label {
    font-size: 9px;
    color: var(--txt3);
    text-transform: uppercase;
    letter-spacing: .05em;
    font-family: 'DM Mono', monospace;
    font-weight: 600;
    margin-bottom: 1px;
}

.tip-value {
    font-size: 11px;
    color: var(--txt2);
    font-family: 'DM Mono', monospace;
    word-break: break-all;
}

.tip-value.hi { color: var(--txt); }

.tip-select {
    background: var(--sur2);
    border: 1px solid var(--bdr);
    border-radius: 6px;
    color: var(--txt);
    font-family: 'DM Mono', monospace;
    font-size: 11px;
    padding: 4px 8px;
    cursor: pointer;
    outline: none;
    width: 100%;
    margin-top: 4px;
}

.tip-select:focus { border-color: var(--bdr2); }
.tip-select option { background: var(--sur2); }

/* Status actions */
.tip-actions {
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Status dropdown */
.status-dd-wrap { position: relative; }

.status-dd-btn {
    width: 100%;
    min-width: 160px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 12px;
    border: 1px solid var(--bdr2);
    border-radius: 7px;
    background: transparent;
    color: var(--txt2);
    font-family: 'DM Mono', monospace;
    font-size: 11px;
    cursor: pointer;
    transition: border-color .15s, color .15s;
    white-space: nowrap;
    gap: 8px;
}

.status-dd-btn:hover { color: var(--txt); border-color: var(--dim); }

.status-dd {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0; right: 0;
    background: var(--sur2);
    border: 1px solid var(--bdr2);
    border-radius: 7px;
    overflow: hidden;
    z-index: 50;
    flex-direction: column;
    box-shadow: 0 8px 24px rgba(0,0,0,.4);
}

.status-dd.open { display: flex; }

.status-dd-item {
    padding: 9px 12px;
    font-size: 11px;
    font-family: 'DM Mono', monospace;
    cursor: pointer;
    border: none;
    background: none;
    text-align: left;
    color: var(--txt2);
    border-bottom: 1px solid var(--bdr);
    transition: background .15s;
}

.status-dd-item:last-child { border-bottom: none; }
.status-dd-item:hover { background: var(--bdr); }
.item-progress { color: var(--c-prog); }
.item-progress:hover { background: rgba(251,191,36,.07); }
.item-await    { color: var(--c-await); }
.item-await:hover { background: rgba(204,204,224,.07); }
.item-close    { color: var(--c-danger); }
.item-close:hover { background: rgba(248,113,113,.07); }

/* ── Admin page ─────────────────────────────────────────── */
.admin-table-wrap {
    border: 1px solid var(--bdr);
    border-radius: var(--r);
    overflow: hidden;
    background: var(--sur);
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.admin-table th {
    text-align: left;
    padding: 9px 16px;
    font-size: 9px;
    font-weight: 700;
    color: var(--txt3);
    text-transform: uppercase;
    letter-spacing: .08em;
    border-bottom: 1px solid var(--bdr);
    background: var(--sur2);
    font-family: 'DM Mono', monospace;
}

.admin-table td {
    padding: 10px 16px;
    border-bottom: 1px solid var(--bdr);
    color: var(--txt2);
    vertical-align: middle;
    font-family: 'DM Mono', monospace;
}

.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: var(--sur2); }

.admin-table select {
    background: var(--sur2);
    border: 1px solid var(--bdr);
    border-radius: 5px;
    color: var(--txt);
    font-family: 'DM Mono', monospace;
    font-size: 10px;
    padding: 3px 7px;
    cursor: pointer;
    outline: none;
}

.admin-table select:focus { border-color: var(--bdr2); }

/* ── Notifications ──────────────────────────────────────── */
#notif-banner {
    position: fixed;
    bottom: 20px; right: 20px;
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 340px;
    width: calc(100vw - 40px);
    padding: 14px 16px;
    border-radius: 12px;
    background: var(--sur);
    border: 1px solid var(--bdr2);
    box-shadow: 0 12px 40px rgba(0,0,0,.5);
    transform: translateY(calc(100% + 2rem));
    opacity: 0;
    transition: transform .4s cubic-bezier(.34,1.56,.64,1), opacity .3s;
    pointer-events: none;
}

#notif-banner.notif-banner--visible { transform: translateY(0); opacity: 1; pointer-events: auto; }

.notif-banner-icon { font-size: 18px; flex-shrink: 0; }
.notif-banner-text { flex: 1; min-width: 0; }
.notif-banner-text strong { font-size: 12px; font-weight: 600; color: var(--txt); display: block; margin-bottom: 2px; }
.notif-banner-text span { font-size: 11px; color: var(--txt3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.notif-banner-actions { display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; }

.notif-btn-allow {
    padding: 5px 10px;
    border-radius: 6px; border: 1px solid var(--bdr2);
    background: var(--sur2); color: var(--txt);
    font-size: 11px; cursor: pointer;
    font-family: 'DM Mono', monospace; white-space: nowrap;
    transition: border-color .15s;
}

.notif-btn-allow:hover { border-color: var(--dim); }

.notif-btn-deny {
    padding: 4px 10px;
    border-radius: 6px; border: 1px solid var(--bdr);
    background: transparent; color: var(--txt3);
    font-size: 11px; cursor: pointer;
    font-family: 'DM Mono', monospace; text-align: center;
    transition: color .15s;
}

.notif-btn-deny:hover { color: var(--txt2); }

.notif-toast {
    position: fixed; bottom: 20px; right: 20px; z-index: 10000;
    padding: 7px 14px; border-radius: 8px;
    background: var(--sur); border: 1px solid var(--bdr2);
    color: var(--txt); font-size: 12px; font-weight: 500;
    box-shadow: 0 4px 20px rgba(0,0,0,.4);
    transform: translateY(calc(100% + 2rem)); opacity: 0;
    transition: transform .35s cubic-bezier(.34,1.56,.64,1), opacity .25s;
    font-family: 'DM Mono', monospace;
}

.notif-toast.notif-toast--visible { transform: translateY(0); opacity: 1; }
.notif-toast--error { border-color: rgba(248,113,113,.3); color: #fca5a5; }

/* Support status */
.sidebar-support-status { display: flex; align-items: center; gap: 5px; font-size: 11px; font-family: 'DM Mono', monospace; }
.sidebar-support-status .dot { width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0; }
.sidebar-support-status .dot.online  { background: var(--c-success); }
.sidebar-support-status .dot.offline { background: var(--dim); }

/* ══════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
    .ticket-page { grid-template-columns: 1fr; }
    .ticket-info-panel { display: none; }
}

@media (max-width: 860px) {
    :root { --sb-w: 0px; }

    .app-sidebar {
        transform: translateX(-220px);
        width: 220px;
        transition: transform .3s cubic-bezier(.65,0,.35,1);
        z-index: 900; /* must be above overlay (790) */
    }

    .app-sidebar.open {
        transform: translateX(0);
        width: 220px;
    }

    /* Sidebar links: tappable */
    .app-sidebar .sb-link,
    .app-sidebar .sb-user-actions a,
    .app-sidebar .sb-logo {
        -webkit-tap-highlight-color: rgba(255,255,255,0.05);
        touch-action: manipulation;
    }

    .sb-toggle { display: flex; }

    /* Overlay must NOT physically cover the sidebar — starts at 220px */
    .sb-overlay.open {
        display: block;
        left: 220px;
    }

    .app-main { margin-left: 0; }

    .page-topbar { padding-left: 60px; }

    .ticket-list-header { display: none; }

    .ticket-row {
        grid-template-columns: 1fr 90px;
    }

    .ticket-row > *:nth-child(3),
    .ticket-row > *:nth-child(4) { display: none; }
}

@media (max-width: 540px) {
    .ticket-row { grid-template-columns: 1fr; }
    .ticket-row > *:nth-child(2) { display: none; }
    .page-content { padding: 16px; }
    .stats-row { grid-template-columns: 1fr 1fr; }
    .chat-messages { padding: 12px 14px; }
}

/* ── Pin button inside bubble ───────────────────────────── */
.msg-bubble .msg-pin-btn {
    position: absolute;
    top: 5px; right: 5px;
    font-size: 11px;
    background: var(--sur2);
    border: 1px solid var(--bdr);
    border-radius: 5px;
    padding: 2px 5px;
    cursor: pointer;
    opacity: 0;
    transition: opacity .15s, border-color .15s;
    line-height: 1;
    color: var(--txt3);
    vertical-align: unset;
    margin-left: 0;
}

.msg-bubble:hover .msg-pin-btn { opacity: 1; }
.msg-bubble .msg-pin-btn.pinned { opacity: 1 !important; border-color: var(--bdr2); }
.msg-bubble .msg-pin-btn:hover  { border-color: var(--dim); }

/* ── Inactivity warning banner ──────────────────────────── */
#inactivity-warning {
    animation: slideUp .3s ease;
}

@keyframes slideUp {
    from { transform: translateY(10px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

/* ── s1-grid background ─────────────────────────────────── */
.page-bg-grid {
    position: fixed;
    top: -50px;
    left: -50px;
    width: calc(100% + 100px);
    height: calc(100% + 100px);
    pointer-events: none;
    z-index: 0;
    background-image:
        linear-gradient(var(--bdr) 1px, transparent 1px),
        linear-gradient(90deg, var(--bdr) 1px, transparent 1px);
    background-size: 36px 36px;
    mask-image: radial-gradient(ellipse 80% 80% at 60% 40%, rgba(0,0,0,0.18) 0%, transparent 80%);
    -webkit-mask-image: radial-gradient(ellipse 80% 80% at 60% 40%, rgba(0,0,0,0.18) 0%, transparent 80%);
    animation: gridDrift 4s linear infinite;
}

@keyframes gridDrift {
    0%   { transform: translate(0, 0); }
    100% { transform: translate(36px, 36px); }
}

/* Ensure content above grid */
/* app-shell: no z-index — avoids stacking context that can trap fixed children */
.app-shell { position: relative; }

/* ── Image thumbnails in chat ───────────────────────────── */
.msg-img-thumb {
    max-width: 100%;
    max-height: 260px;
    border-radius: 8px;
    border: 1px solid var(--bdr);
    display: block;
    object-fit: cover;
    cursor: zoom-in;
    transition: opacity .15s, border-color .15s;
}

.msg-img-thumb:hover {
    opacity: .9;
    border-color: var(--bdr2);
}

/* ══════════════════════════════════════════════════════════
   MOBILE PERFORMANCE — kill all GPU-heavy effects
   ══════════════════════════════════════════════════════════ */
@media (max-width: 860px) {
    /* Kill grain overlay entirely */
    .grain { display: none; }

    /* Kill animated grid */
    .page-bg-grid { display: none; }

    /* Kill all backdrop-filters */
    .page-topbar,
    .app-sidebar,
    .chat-box,
    .status-dd,
    #lightbox {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        background: var(--bg) !important;
    }

    /* Topbar solid */
    .page-topbar { background: var(--sur) !important; }

    /* Sidebar solid */
    .app-sidebar { background: var(--sur) !important; }

    /* Kill all transitions except sidebar slide */
    * {
        transition-duration: 0ms !important;
    }
    .app-sidebar {
        transition: transform .25s ease !important;
    }
    .sb-toggle span {
        transition: all .2s !important;
    }

    /* Kill msg animations */
    .msg-row { animation: none !important; }

    /* Kill send button scale */
    .chat-send-btn:active { transform: none !important; }
}

@media (max-width: 860px) and (prefers-reduced-motion: no-preference) {
    /* Re-enable sidebar slide only */
    .app-sidebar {
        transition: transform .25s cubic-bezier(.65,0,.35,1) !important;
    }
}
