@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Roboto:wght@400;500;700&display=swap');

:root, [data-theme="dark"] {
    color-scheme: dark;
    --bg: #0E1013;
    --panel: #16181D;
    --panel-2: #1B1E24;
    --border: #2A2D34;
    --text: #E8E9EB;
    --text-muted: #8B9099;
    --text-faint: #5C6068;

    --blue: #4C8DFF;
    --blue-text: #08101F;
    --blue-bg: #17233D;
    --red: #FF5C5C;
    --red-bg: #3B1B1E;
    --amber: #E8A33D;
    --amber-bg: #3A2A12;
    --green: #4ADE80;
    --green-bg: #16301F;
    --gray: #9AA0AA;
    --gray-bg: #23262C;

    --radius: 8px;
}

/* Light theme — same structure, light backgrounds / dark text. Accent
   colors stay recognizable but their -bg tints lighten to suit a white
   surface instead of a dark one. */
[data-theme="light"] {
    color-scheme: light;
    --bg: #F5F6F8;
    --panel: #FFFFFF;
    --panel-2: #F0F1F3;
    --border: #E1E3E8;
    --text: #1A1D23;
    --text-muted: #6B7280;
    --text-faint: #9CA3AF;

    --blue: #2563EB;
    --blue-text: #FFFFFF;
    --blue-bg: #DBEAFE;
    --red: #DC2626;
    --red-bg: #FEE2E2;
    --amber: #B45309;
    --amber-bg: #FEF3C7;
    --green: #16A34A;
    --green-bg: #DCFCE7;
    --gray: #6B7280;
    --gray-bg: #F3F4F6;

    --radius: 8px;
}

/* Classic — light main content, dark sidebar/chrome-bar. Achieved by
   re-declaring the same variables scoped to those two containers only;
   every descendant that reads var(--panel)/var(--text)/etc. picks up
   these overrides automatically via normal CSS cascade — no change
   needed to any existing sidebar/chrome-bar rule. */
[data-theme="classic"] {
    color-scheme: light;
    --bg: #F5F6F8;
    --panel: #FFFFFF;
    --panel-2: #F0F1F3;
    --border: #E1E3E8;
    --text: #1A1D23;
    --text-muted: #6B7280;
    --text-faint: #9CA3AF;

    --blue: #2563EB;
    --blue-text: #FFFFFF;
    --blue-bg: #DBEAFE;
    --red: #DC2626;
    --red-bg: #FEE2E2;
    --amber: #B45309;
    --amber-bg: #FEF3C7;
    --green: #16A34A;
    --green-bg: #DCFCE7;
    --gray: #6B7280;
    --gray-bg: #F3F4F6;

    --radius: 8px;
}
[data-theme="classic"] .sidebar {
    --bg: #0E1013;
    --panel: #16181D;
    --panel-2: #1B1E24;
    --border: #2A2D34;
    --text: #E8E9EB;
    --text-muted: #8B9099;
    --text-faint: #5C6068;
}
[data-theme="classic"] .chrome-bar { border-bottom: 1px solid var(--border); }

/* Light (Card) — sidebar and header stay light like the rest of the
   page (unlike classic, which keeps them dark), while the main content
   area renders as a distinct white card against a light gray page
   background — the .content-card mechanism already built for
   light/classic themes applies here too (see the selector below). */
[data-theme="light-card"] {
    color-scheme: light;
    --bg: #F1F3F4;
    --panel: #FFFFFF;
    --panel-2: #F1F3F4;
    --border: #E1E3E8;
    --text: #1A1D23;
    --text-muted: #6B7280;
    --text-faint: #9CA3AF;

    --blue: #2563EB;
    --blue-text: #FFFFFF;
    --blue-bg: #DBEAFE;
    --red: #DC2626;
    --red-bg: #FEE2E2;
    --amber: #B45309;
    --amber-bg: #FEF3C7;
    --green: #16A34A;
    --green-bg: #DCFCE7;
    --gray: #6B7280;
    --gray-bg: #F3F4F6;

    --radius: 8px;
}
[data-theme="light-card"] .content-card {
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
/* Direct background override, not a --panel re-declaration — the
   sidebar/chrome-bar have nested dropdown panels (notifications,
   avatar menu) that also read var(--panel) and need to stay white/
   floating, not inherit this same light gray. */
[data-theme="light-card"] .sidebar,
[data-theme="light-card"] .chrome-bar {
    background: #F1F3F4;
}

/* RTL — the sidebar/main layout is a flex row (see .app-shell), so
   reversing it is one property; the sidebar's separating border needs
   to flip to whichever edge is now actually touching the main content.
   Component-level mirroring beyond this (icons, specific paddings) is
   handled case-by-case as issues surface, not attempted exhaustively here. */
html[dir="rtl"] body { direction: rtl; }
html[dir="rtl"] .app-shell { flex-direction: row-reverse; }
html[dir="rtl"] .sidebar { border-right: none; border-left: 1px solid var(--border); }

/* Explicit sidebar position — overrides the RTL-following default
   above. Only ever rendered when the preference isn't "default" (see
   header-app.php), so these rules only apply when someone has
   deliberately pinned the sidebar regardless of text direction. */
html[data-sidebar="left"] .app-shell { flex-direction: row; }
html[data-sidebar="left"] .sidebar { border-right: 1px solid var(--border); border-left: none; }
html[data-sidebar="right"] .app-shell { flex-direction: row-reverse; }
html[data-sidebar="right"] .sidebar { border-right: none; border-left: 1px solid var(--border); }

* { box-sizing: border-box; }

/* Font family — inherits everywhere via body's font-family using this
   variable (see body rule below); monospace code blocks are unaffected
   since they don't reference --font-family. "inter" needs no rule
   (it's the default fallback in body's own declaration already). */
html[data-font="system"] { --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
html[data-font="roboto"] { --font-family: 'Roboto', sans-serif; }
html[data-font="georgia"] { --font-family: Georgia, 'Times New Roman', serif; }

/* Wraps the filter bar + ticket list on Inbox/My tickets/Unassigned —
   only actually styled under light theme (a plain white card
   distinguishes the content from the page's own light-gray
   background); a no-op wrapper everywhere else, since dark/classic
   already give .ticket-list its own card look directly. */
[data-theme="light"] .content-card, [data-theme="classic"] .content-card, [data-theme="light-card"] .content-card {
    background: var(--panel); border: 1px solid var(--border);
    border-radius: 12px; padding: 20px;
}
[data-theme="light"] .content-card .ticket-list, [data-theme="classic"] .content-card .ticket-list, [data-theme="light-card"] .content-card .ticket-list {
    background: none; border: none; border-radius: 0;
}

body {
    margin: 0;
    font-family: var(--font-family, 'Inter'), -apple-system, BlinkMacSystemFont, sans-serif;
    color: var(--text);
    background: var(--bg);
    font-size: 14px;
    line-height: 1.5;
}

/* Embedded detail page (inside a split-view panel) — same detail.php,
   just without the sidebar/chrome-bar wrapper. */
.embed-shell { padding: 16px; }

/* Split view — reusable list+detail layout, module-agnostic (see
   partials/split-view.php). Ratio: list gets the narrower column,
   detail the wider one — a detail pane needs the room, the list is
   just for scanning/picking the next item. */
.split-view { display: grid; grid-template-columns: 3fr 9fr; gap: 16px; height: 0; /* set inline by JS to the real measured height */ }
.split-view-list-col { display: flex; flex-direction: column; height: 100%; min-height: 0; }
#split-view-list { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding-right: 4px; }
.split-view-load-more { width: 100%; justify-content: center; margin-top: 8px; flex-shrink: 0; }
.split-view-detail {
    min-height: 100%; height: auto; border: 1px solid var(--border); border-radius: 12px; overflow: visible;
    background: var(--panel); position: relative; align-self: start;
}
.split-view-iframe { width: 100%; height: 100%; border: none; display: none; }
.split-view-empty { display: flex; align-items: center; justify-content: center; min-height: 100%; color: var(--text-faint); font-size: 13px; }
.split-view-list .ticket-row.split-selected { background: var(--panel-2); border: 1px solid var(--blue); }
.split-view-list tr.split-selected td { background: var(--panel-2); }

/* Tick mark on the currently-open item — an extra, clearer cue beyond
   the background/border highlight above, since that alone can be easy
   to miss in a fast-scrolling list. */
.split-view-list .ticket-row.split-selected::after,
.split-view-list tr.split-selected td:nth-child(3)::after {
    content: "✓"; color: var(--blue); font-weight: 700; font-size: 14px; margin-left: 8px; flex-shrink: 0;
}
.split-view-list tr.split-selected td:nth-child(3) { position: relative; }

.split-view-close {
    position: absolute; top: 10px; right: 10px; z-index: 3;
    width: 28px; height: 28px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--border);
    color: var(--text-muted); display: flex; align-items: center; justify-content: center;
}
.split-view-close:hover { background: var(--border); color: var(--text); }
.split-view-iframe-loader {
    display: none; position: absolute; inset: 0; align-items: center; justify-content: center;
    background: var(--panel); z-index: 2;
}
.list-loading-overlay { border-radius: 12px; }

/* Compact rows in the split list — a 3fr-wide column has no room for
   full card/table content, so only the identifying info shows.
   Table: keep dot + first 2 labeled columns (#, Subject), hide the rest. */
.split-view-list td:nth-child(n+4),
.split-view-list th:nth-child(n+4) { display: none; }
/* Card: keep the dot + subject link, hide the meta line and every badge/rating/time sibling. */
.split-view-list .row-main a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.split-view-list .ticket-row .row-meta,
.split-view-list .ticket-row .badge,
.split-view-list .ticket-row .row-rating,
.split-view-list .ticket-row .row-time { display: none; }

h1, h2, h3 { font-weight: 600; margin: 0; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

input, select, textarea, button { font-family: inherit; font-size: 14px; }

input[type=text], input[type=email], input[type=password], input[type=search], input[type=number], input[type=date], input[type=month], input[type=tel], input[type=file], select, textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--panel-2);
    color: var(--text);
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px var(--blue-bg);
}
textarea { resize: vertical; min-height: 90px; }
select { appearance: none; -webkit-appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238B9099' stroke-width='1.5' fill='none'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }

label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 14px; font-weight: 500; }
label input, label select, label textarea { margin-top: 4px; }

button, .btn, .btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    background: var(--blue);
    color: var(--blue-text);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 600;
}
button:hover, .btn:hover { filter: brightness(1.12); text-decoration: none; }
button:disabled, .btn:disabled {
    background: var(--panel-2); color: var(--text-faint); cursor: not-allowed;
    opacity: 0.6; border: 1px solid var(--border);
}
button:disabled:hover, .btn:disabled:hover { filter: none; background: var(--panel-2); }
button.btn-secondary, .btn-secondary {
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--border);
    font-weight: 500;
}
button.btn-secondary:hover, a.btn-secondary:hover { background: var(--border); filter: none; text-decoration: none; }

.icon { width: 16px; height: 16px; flex-shrink: 0; vertical-align: -3px; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 220px;
    flex-shrink: 0;
    background: var(--panel);
    border-right: 1px solid var(--border);
    padding: 20px 14px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    transition: width 0.15s ease, padding 0.15s ease;
    position: relative;
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 20px 10px; }
.sidebar .brand { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; }
.sidebar-top-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.sidebar-top-actions button, #sidebar-expand-btn {
    background: none; border: none; color: var(--text-muted); padding: 6px;
    border-radius: 6px; display: inline-flex; align-items: center; justify-content: center;
}
.sidebar-top-actions button:hover, #sidebar-expand-btn:hover { background: var(--panel-2); color: var(--text); }
#sidebar-expand-btn { display: none; position: absolute; top: 20px; left: 14px; }
.sidebar a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
}
.sidebar a:hover { background: var(--panel-2); text-decoration: none; color: var(--text); }
.sidebar a.active { background: var(--panel-2); color: var(--text); }
.sidebar a .count { margin-left: auto; color: var(--text-faint); font-size: 12px; }
.sidebar a .count.count-badge, .sidebar-submenu a .count.count-badge { background: #d97706; color: #fff; font-weight: 600; font-size: 11px; line-height: 18px; min-width: 18px; padding: 0 6px; border-radius: 9px; text-align: center; }
.sidebar .nav-spacer { margin-top: auto; }

/* Sidebar status/filter submenu (Inbox, My tickets) */
.sidebar-item-wrap { display: flex; align-items: center; gap: 2px; }
.sidebar-item-wrap a { flex: 1; min-width: 0; }
.sidebar-submenu-toggle {
    background: none; border: none; color: var(--text-faint); padding: 6px; border-radius: 6px;
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.sidebar-submenu-toggle:hover { background: var(--panel-2); color: var(--text); }
.sidebar-submenu-toggle svg { transition: transform 0.15s ease; }
.sidebar-submenu-toggle.open svg { transform: rotate(180deg); }
.sidebar-submenu { display: flex; flex-direction: column; padding-left: 14px; margin-bottom: 4px; }
.sidebar-submenu a {
    display: flex; align-items: center; padding: 6px 10px; border-radius: var(--radius);
    color: var(--text-muted); font-size: 12px; font-weight: 500;
}
.sidebar-submenu a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.sidebar-submenu a .count { margin-left: auto; color: var(--text-faint); font-size: 11px; }
/* Collapsed sidebar has no room for submenus — same rule set already
   hides .nav-label/.count there, extend it to the submenu machinery too. */
.sidebar.collapsed .sidebar-submenu-toggle,
.sidebar.collapsed .sidebar-submenu { display: none; }
.sidebar .divider { border: none; border-top: 1px solid var(--border); margin: 12px 4px; }

/* Collapsed sidebar — icon-only rail, matching the familiar dashboard-app pattern */
.sidebar.collapsed { width: 60px; padding: 64px 10px 20px; }
.sidebar.collapsed .sidebar-top { display: none; }
.sidebar.collapsed #sidebar-expand-btn { display: inline-flex; }
.sidebar.collapsed .nav-label,
.sidebar.collapsed .count { display: none; }
.sidebar.collapsed a { justify-content: center; padding: 9px; }
.sidebar.collapsed .divider { margin-left: 0; margin-right: 0; }

#sidebar-search-input {
    width: 100%; background: var(--panel-2); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 10px 12px; font-size: 14px;
}

.main { flex: 1; min-width: 0; padding: 24px 28px; }

/* Chrome tab bar — sticky to the top of the main content area (not the
   whole viewport; the sidebar stays fixed-width alongside it). Pulled
   out to the edges via negative margins to counteract .main's own
   padding, then repadded internally. */
.chrome-bar {
    position: sticky; top: 0; z-index: 30;
    margin: -24px -28px 0; padding: 0 16px;
    background: var(--panel);
    display: flex; align-items: center; gap: 12px; height: 46px;
}
.chrome-tabs-viewport { flex: 1; min-width: 0; display: flex; align-items: center; gap: 4px; overflow: hidden; }

/* Sub-navigation row — one shared row for whatever module the current
   page belongs to (see config/navigation.php + partials/subnav.php).
   Sits directly under the chrome bar; pulled to the edges the same way. */
.subnav {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    margin: 0 -28px 20px; padding: 6px 28px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}
/* Takes the subnav's place whenever it doesn't render (hidden by
   preference, config, or no items for this role) — preserves the same
   gap below the chrome-bar rather than letting content sit flush
   against it. See partials/subnav.php. */
.subnav-spacer { margin-bottom: 20px; }
.subnav-items { display: flex; align-items: center; gap: 4px; }
.subnav-actions { display: flex; align-items: center; gap: 8px; }
.subnav a { padding: 6px 12px; border-radius: var(--radius); font-size: 13px; color: var(--text-muted); }
.subnav a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.subnav a.active { background: var(--panel-2); color: var(--text); font-weight: 600; }
.chrome-tabs { display: flex; align-items: center; gap: 4px; min-width: 0; }
.chrome-tab {
    display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 8px 0 12px;
    border-radius: 8px 8px 0 0; background: var(--panel-2); color: var(--text-muted);
    font-size: 12px; max-width: 170px; flex-shrink: 0; border-bottom: 2px solid transparent;
}
.chrome-tab:hover { color: var(--text); text-decoration: none; }
.chrome-tab.active { background: var(--bg); color: var(--text); border-bottom-color: var(--blue); }
.chrome-tab-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chrome-tab-close {
    background: none; border: none; color: var(--text-faint); flex-shrink: 0;
    width: 16px; height: 16px; border-radius: 4px; font-size: 14px; line-height: 1;
    display: inline-flex; align-items: center; justify-content: center;
}
.chrome-tab-close:hover { background: var(--border); color: var(--text); }

.chrome-tabs-overflow { position: relative; flex-shrink: 0; }
#chrome-overflow-btn {
    display: inline-flex; align-items: center; gap: 4px; height: 32px; padding: 0 10px;
    background: var(--panel-2); border: none; border-radius: 8px; color: var(--text-muted); font-size: 12px;
}
#chrome-overflow-btn:hover { color: var(--text); }
.chrome-overflow-menu {
    display: none; position: absolute; top: 100%; left: 0; margin-top: 4px; z-index: 31;
    background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
    min-width: 200px; max-width: 280px; box-shadow: 0 8px 24px rgba(0,0,0,0.35); overflow: hidden;
}
.chrome-overflow-menu.open { display: block; }
.chrome-overflow-item { display: block; padding: 9px 12px; font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chrome-overflow-item:hover { background: var(--panel-2); text-decoration: none; }
.chrome-overflow-item.active { color: var(--blue); }

.chrome-tab-add {
    display: inline-flex; align-items: center; gap: 4px; height: 32px; padding: 0 10px;
    color: var(--text-faint); font-size: 12px; border-radius: 8px; flex-shrink: 0;
}
.chrome-tab-add:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.chrome-tab-menu { background: transparent; }
.chrome-tab-menu.active { background: var(--bg); }

.chrome-bar-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

/* Expanding search — icon-only by default, click expands the input inline */
.chrome-search-wrap { display: flex; align-items: center; position: relative; }
#chrome-search-icon-btn {
    background: none; border: none; color: var(--text-muted);
    width: 30px; height: 30px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; z-index: 1;
}
#chrome-search-icon-btn:hover { background: var(--panel-2); color: var(--text); }
#chrome-search-input {
    width: 0; opacity: 0; padding: 0; border: none; background: var(--panel-2);
    border-radius: 6px; font-size: 13px; color: var(--text);
    transition: width 0.15s ease, opacity 0.15s ease, padding 0.15s ease, margin 0.15s ease;
}
.chrome-search-wrap.expanded #chrome-search-input {
    width: 200px; opacity: 1; padding: 7px 10px 7px 32px; margin-left: -28px;
}

.chrome-notif-wrap, .chrome-avatar-wrap { position: relative; }
#chrome-notif-btn {
    background: none; border: none; color: var(--text-muted);
    width: 30px; height: 30px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; position: relative;
}
#chrome-notif-btn:hover { background: var(--panel-2); color: var(--text); }
.chrome-notif-badge {
    position: absolute; top: -3px; right: -3px; background: var(--red); color: #fff;
    font-size: 10px; font-weight: 700; min-width: 16px; height: 16px; border-radius: 20px;
    display: flex; align-items: center; justify-content: center; padding: 0 3px;
    border: 2px solid var(--panel); box-sizing: content-box;
}

/* Larger icons specifically in the chrome-bar's action row (search,
   notification bell) — the default 16px icon size read as too small
   next to the 30px avatar circle. */
#chrome-search-icon-btn svg, #chrome-notif-btn svg, #chrome-settings-btn svg { width: 20px; height: 20px; }

#chrome-settings-btn {
    background: none; border: none; color: var(--text-muted);
    width: 30px; height: 30px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center;
}
#chrome-settings-btn:hover { background: var(--panel-2); color: var(--text); }
#chrome-settings-btn.active { background: var(--panel-2); color: var(--blue); }

/* Settings drawer — a flex sibling of .sidebar/.main inside .app-shell
   (see footer-app.php), width-transitions from 0, so opening it
   naturally pushes .main left via normal flex reflow rather than
   overlaying on top of it. */
/* Always light, regardless of the active theme — re-declared here the
   same way classic theme scopes the sidebar dark above, just inverted:
   every descendant using var(--panel)/var(--text)/etc. picks these up
   automatically, no per-element overrides needed. */
.settings-drawer {
    --bg: #F5F6F8;
    --panel: #FFFFFF;
    --panel-2: #F0F1F3;
    --border: #E1E3E8;
    --text: #1A1D23;
    --text-muted: #6B7280;
    --text-faint: #9CA3AF;
    --blue: #2563EB;
    --blue-text: #FFFFFF;
    --blue-bg: #DBEAFE;
}
.settings-drawer {
    width: 0; flex-shrink: 0; overflow: hidden; background: var(--panel);
    border-left: 1px solid var(--border); transition: width 0.2s ease;
}
.settings-drawer.open { width: 300px; }
.settings-drawer-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 20px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.settings-drawer-header h3 { margin: 0; font-size: 15px; }
#settings-drawer-close {
    background: none; border: none; color: var(--text-muted); width: 28px; height: 28px;
    border-radius: 6px; display: flex; align-items: center; justify-content: center;
}
#settings-drawer-close:hover { background: var(--panel-2); color: var(--text); }
.settings-drawer-body { padding: 20px; width: 300px; }
.settings-section { margin-bottom: 22px; }

/* Generic accordion — reusable wherever a collapsible grouped section
   is needed, not specific to agent permissions. */
.accordion-item { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
.accordion-header {
    width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 12px 16px; background: var(--panel-2); border: none; color: var(--text); font-weight: 600; font-size: 13px;
}
.accordion-header:hover { background: var(--border); }
.accordion-header .accordion-chevron { transition: transform 0.15s ease; flex-shrink: 0; color: var(--text-muted); }
.accordion-item.open .accordion-header .accordion-chevron { transform: rotate(180deg); }
.accordion-header .accordion-count { margin-left: auto; margin-right: 8px; font-size: 11px; font-weight: 500; color: var(--text-faint); }
.accordion-body { padding: 16px; display: none; }
.accordion-item.open .accordion-body { display: block; }
.settings-section:last-child { margin-bottom: 0; }
.theme-options { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.theme-option {
    text-align: left; padding: 10px 12px; border-radius: var(--radius);
    background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
}
.theme-option:hover { border-color: var(--text-faint); }
.theme-option.active { border-color: var(--blue); color: var(--blue); background: var(--blue-bg); }

.notif-panel {
    display: none; position: absolute; top: 100%; right: 0; margin-top: 6px; z-index: 31;
    background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
    width: 340px; max-height: 420px; box-shadow: 0 8px 24px rgba(0,0,0,0.35);
    flex-direction: column; overflow: hidden;
}
.notif-panel.open { display: flex; }
.notif-panel-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 13px; font-weight: 600;
}
#notif-mark-all-btn { background: none; border: none; color: var(--blue); font-size: 12px; font-weight: 500; padding: 0; }
#notif-mark-all-btn:hover { text-decoration: underline; }
.notif-panel-body { overflow-y: auto; flex: 1; }
.notif-loader { display: flex; align-items: center; justify-content: center; padding: 30px 0; }
.notif-empty { padding: 30px 14px; text-align: center; color: var(--text-faint); font-size: 13px; }
.notif-load-more { width: 100%; padding: 10px; background: none; border: none; border-top: 1px solid var(--border); color: var(--text-muted); font-size: 12px; }
.notif-load-more:hover { background: var(--panel-2); color: var(--text); }

.notif-item { position: relative; border-bottom: 1px solid var(--border); }
.notif-item:last-child { border-bottom: none; }
.notif-item-link { display: flex; gap: 8px; padding: 12px 14px; align-items: flex-start; }
.notif-item-link:hover { background: var(--panel-2); text-decoration: none; }
.notif-item.unread .notif-item-link { padding-left: 8px; }
.notif-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--blue); flex-shrink: 0; margin-top: 6px; }
.notif-item-body { flex: 1; min-width: 0; }
.notif-item-title { font-size: 13px; color: var(--text); font-weight: 500; line-height: 1.4; }
.notif-item.unread .notif-item-title { font-weight: 700; }
.notif-item-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notif-item-time { font-size: 11px; color: var(--text-faint); margin-top: 4px; }
.notif-mark-read {
    position: absolute; top: 10px; right: 10px; display: none;
    width: 22px; height: 22px; border-radius: 50%; background: var(--panel-2); border: none;
    color: var(--text-muted); font-size: 12px; align-items: center; justify-content: center;
}
.notif-item:hover .notif-mark-read { display: flex; }
.notif-mark-read:hover { background: var(--blue); color: var(--blue-text); }

#chrome-avatar-btn {
    width: 30px; height: 30px; border-radius: 50%; border: none; color: var(--blue-text);
    font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center;
}
.chrome-avatar-menu {
    display: none; position: absolute; top: 100%; right: 0; margin-top: 6px; z-index: 31;
    background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
    min-width: 180px; box-shadow: 0 8px 24px rgba(0,0,0,0.35); overflow: hidden;
}
.chrome-avatar-menu.open { display: block; }
.chrome-avatar-menu-name { padding: 10px 12px 8px; font-size: 12px; font-weight: 600; color: var(--text-muted); border-bottom: 1px solid var(--border); }
.chrome-avatar-menu a { display: flex; align-items: center; gap: 8px; padding: 9px 12px; font-size: 13px; color: var(--text); }
.chrome-avatar-menu a:hover { background: var(--panel-2); text-decoration: none; }
.main .page-header { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.main .page-header h1 { font-size: 18px; }
.main .page-header .spacer { flex: 1; }

/* ---------- Filter bar ---------- */
.filter-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.filter-bar input[type=search] { max-width: 220px; }
.filter-bar select { width: auto; min-width: 130px; }
.filter-bar .spacer { flex: 1; }

/* Card/tabular view toggle */
.view-toggle-wrap { position: relative; }
.view-toggle-menu {
    display: none; position: absolute; right: 0; top: 100%; margin-top: 4px; z-index: 20;
    background: var(--panel); border: 1px solid var(--border); border-radius: 8px; min-width: 130px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.35); overflow: hidden;
}
.view-toggle-menu.open { display: block; }
.view-toggle-option { width: 100%; display: flex; align-items: center; gap: 8px; text-align: left; padding: 9px 12px; background: none; border: none; color: var(--text); font-size: 13px; }
.view-toggle-option:hover { background: var(--panel-2); }

/* Tabular ticket list */
.ticket-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ticket-table th { text-align: left; padding: 10px 12px; color: var(--text-muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; border-bottom: 1px solid var(--border); }
.ticket-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.ticket-table tr:hover td { background: var(--panel-2); }
.ticket-table a { display: inline-flex; align-items: center; gap: 6px; }

/* Pinned/important markers — same treatment in both card and table view */
.ticket-row-important, tr.ticket-row-important td { background: rgba(232, 163, 61, 0.06); }
.ticket-row a svg, .ticket-table a svg { width: 14px; height: 14px; vertical-align: -2px; }

/* ---------- Public / centered pages ---------- */
.public-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.35);
    padding: 28px;
    width: 100%;
    max-width: 420px;
}
.card.card-wide { max-width: 640px; }
.card.card-medium { max-width: 560px; }
.card.card-split { max-width: 1080px; padding: 0; display: grid; grid-template-columns: 1fr 1fr; overflow: hidden; }
.card-split-marketing { background: var(--panel-2); padding: 48px 40px; display: flex; flex-direction: column; justify-content: center; }
.card-split-marketing h1 { font-size: 32px; line-height: 1.2; margin: 0 0 14px; }
.card-split-marketing ul { list-style: none; padding: 0; margin: 20px 0 0; display: flex; flex-direction: column; gap: 10px; }
.card-split-marketing li { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.card-split-marketing li svg { width: 16px; height: 16px; color: var(--green); flex-shrink: 0; }
.card-split-form { padding: 40px; }
@media (max-width: 860px) {
    .card.card-split { grid-template-columns: 1fr; max-width: 480px; }
    .card-split-marketing { display: none; }
}
.card h1 { margin-bottom: 4px; }
.card p.subtitle { color: var(--text-muted); margin: 0 0 20px; font-size: 13px; }

/* Fullscreen editor overlay — creation form's Fullscreen button */
.editor-fullscreen-active {
    position: fixed; inset: 0; z-index: 1000; background: var(--bg);
    padding: 24px; overflow-y: auto; display: flex; flex-direction: column;
}
.editor-fullscreen-active .rich-editor { flex: 1; max-height: none; }

/* Preview pane */
.form-preview { border: 1px solid var(--border); border-radius: 12px; padding: 20px; margin-bottom: 16px; background: var(--panel); }
.form-preview .preview-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint); margin-bottom: 10px; }
.form-preview h2 { font-size: 16px; margin-bottom: 4px; }
.form-preview .preview-meta { font-size: 12px; color: var(--text-muted); margin-bottom: 14px; }

/* Preview modal */
.modal-overlay {
    position: fixed; inset: 0; z-index: 1100; background: rgba(0,0,0,0.6);
    display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal-dialog {
    background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
    width: 100%; max-width: 560px; max-height: 80vh; display: flex; flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-header h2 { font-size: 16px; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 22px; line-height: 1; padding: 0; width: 28px; height: 28px; }
.modal-close:hover { color: var(--text); background: var(--panel-2); border-radius: 6px; }
.modal-body { padding: 20px; overflow-y: auto; }

/* ---------- Badges ---------- */
.badge { display: inline-block; font-size: 12px; padding: 3px 10px; border-radius: 20px; font-weight: 600; white-space: nowrap; }
.badge-blue   { background: var(--blue-bg);  color: var(--blue); }
.badge-amber  { background: var(--amber-bg); color: var(--amber); }
.badge-red    { background: var(--red-bg);   color: var(--red); }
.badge-green  { background: var(--green-bg); color: var(--green); }
.badge-gray   { background: var(--gray-bg);  color: var(--gray); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot-blue  { background: var(--blue); }
.dot-amber { background: var(--amber); }
.dot-red   { background: var(--red); }
.dot-green { background: var(--green); }
.dot-gray  { background: var(--gray); }

/* ---------- Ticket list rows ---------- */
.ticket-list { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.ticket-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}
.ticket-row:last-child { border-bottom: none; }
.ticket-row:hover { background: var(--panel-2); }
.ticket-row .row-main { flex: 1; min-width: 0; }
.ticket-row .row-main a { color: var(--text); font-weight: 600; font-size: 14px; }
.ticket-row .row-meta { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.ticket-row .row-time { font-size: 12px; color: var(--text-faint); width: 70px; text-align: right; flex-shrink: 0; }
.row-rating { font-size: 12px; color: var(--amber); font-weight: 600; flex-shrink: 0; white-space: nowrap; }
.empty-state { text-align: center; color: var(--text-muted); padding: 40px 16px; }

/* ---------- Ticket detail (standalone card, no sidebar) ---------- */
.bare-page { padding: 24px; }
.ticket-card {
    max-width: 980px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}
.ticket-card-header { display: flex; align-items: flex-start; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.ticket-card-header .back-link { color: var(--text-muted); font-size: 18px; margin-top: 2px; }
.ticket-card-header .titles { flex: 1; min-width: 0; }
.ticket-card-header h1 { font-size: 16px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ticket-card-header .subtitle { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.title-icon-form { display: inline-flex; }
.title-icon-btn { background: none; border: none; padding: 3px; color: var(--text-faint); display: inline-flex; align-items: center; border-radius: 6px; }
.title-icon-btn:hover { background: var(--panel-2); color: var(--text); }
.title-icon-btn.active { color: var(--blue); }
.title-icon-btn.active-important { color: #E8A33D; }

.ticket-card-body { display: flex; align-items: stretch; }
.detail-main { flex: 1; min-width: 0; padding: 20px 22px; }
.detail-side {
    width: 220px;
    flex-shrink: 0;
    border-left: 1px solid var(--border);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.detail-side .field-label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.detail-side .field-value { font-size: 13px; }
.detail-side .divider { border: none; border-top: 1px solid var(--border); margin: 0; }
.detail-side .tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.detail-side .tag { font-size: 11px; background: var(--panel-2); border: 1px solid var(--border); color: var(--text-muted); padding: 3px 9px; border-radius: 20px; }

.avatar {
    width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700; color: #fff;
}
.avatar-sm { width: 20px; height: 20px; font-size: 10px; }

/* ---------- Thread — plain text replies, internal notes are the only boxed message by default ---------- */
.thread { display: flex; flex-direction: column; gap: 16px; margin-bottom: 18px; }
.msg { display: flex; gap: 10px; align-items: flex-start; }
.msg .msg-body { flex: 1; min-width: 0; }
.msg .msg-meta { display: flex; justify-content: space-between; align-items: flex-start; font-size: 12px; color: var(--text-muted); margin-bottom: 5px; gap: 10px; }
.msg .msg-meta strong { color: var(--text); }
.msg p { margin: 0; white-space: pre-wrap; color: var(--text); }
.msg.internal .msg-body { background: var(--amber-bg); border: 1px solid #4A3A1E; border-radius: var(--radius); padding: 10px 12px; }
.msg.internal .msg-meta strong { color: var(--amber); }
.msg.from-cc .msg-body { border-left: 3px solid var(--blue); padding-left: 10px; }

/* Role badge — Operator / Requester / CC */
.role-badge { font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 20px; white-space: nowrap; flex-shrink: 0; }
.role-badge-operator { background: var(--blue-bg); color: var(--blue); }
.role-badge-requester { background: var(--gray-bg); color: var(--gray); }
.role-badge-cc { background: var(--panel-2); color: var(--text-muted); border: 1px solid var(--border); }

/* Thread toolbar — toggles on the left, filters on the right */
.thread-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar-toggles { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.thread-filters { display: flex; gap: 8px; }
.thread-filters select { width: auto; min-width: 130px; padding: 6px 28px 6px 10px; font-size: 12px; }
.msg.filtered-out { display: none !important; }

/* Threaded (chat-style) alignment — operator replies flip to the right */
.thread[data-layout-mode="threaded"] .msg { max-width: 85%; }
.thread[data-layout-mode="threaded"] .msg[data-role="operator"] { flex-direction: row-reverse; margin-left: auto; }
.thread[data-layout-mode="threaded"] .msg[data-role="operator"] .msg-meta { flex-direction: row-reverse; }
.thread[data-layout-mode="threaded"] .msg[data-role="operator"] .msg-body { text-align: right; }
.thread[data-layout-mode="threaded"] .msg[data-role="operator"] .msg-actions { flex-direction: row-reverse; }
.thread[data-layout-mode="threaded"] .msg[data-role="operator"] .stars-wrap { margin-left: 0; margin-right: auto; }
.thread[data-layout-mode="threaded"] .msg[data-role="requester"],
.thread[data-layout-mode="threaded"] .msg[data-role="cc"] { margin-right: auto; }

/* Indented — everyone stays left-aligned (unlike Threaded), but operator
   and CC replies step inward, giving the back-and-forth a nested look
   without mirroring text direction. */
.thread[data-layout-mode="indented"] .msg[data-role="operator"] { margin-left: 48px; }
.thread[data-layout-mode="indented"] .msg[data-role="cc"] { margin-left: 24px; }

/* Numbered pagination */
.thread-pagination { display: flex; align-items: center; justify-content: center; gap: 6px; margin-bottom: 18px; flex-wrap: wrap; }
.page-link { display: inline-flex; align-items: center; justify-content: center; min-width: 30px; height: 30px; border-radius: var(--radius); font-size: 12px; color: var(--text-muted); border: 1px solid var(--border); }
.page-link:hover { background: var(--panel-2); text-decoration: none; }
.page-link.active { background: var(--blue); color: var(--blue-text); border-color: var(--blue); }
.page-nav-icon { padding: 0; width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center; }

/* Feedback-on-close section — full width, below both detail-main/detail-side columns */
.feedback-section { border-top: 1px solid var(--border); padding: 20px 22px; }
.feedback-stars { font-size: 20px; margin: 6px 0; }
.feedback-comment { font-size: 13px; color: var(--text); margin-top: 8px; white-space: pre-wrap; }
.feedback-section .csat-stars { justify-content: flex-start; margin: 10px 0; }
.feedback-section .csat-thanks { padding: 4px 0; text-align: left; }
.feedback-section .csat-thanks .big-check { font-size: 24px; display: inline-block; margin-right: 8px; }
.page-ellipsis { display: inline-flex; align-items: center; justify-content: center; min-width: 30px; height: 30px; color: var(--text-faint); font-size: 12px; }
.thread-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.thread-toggle button { background: var(--panel-2); color: var(--text-muted); border: none; border-radius: 0; padding: 6px 14px; font-size: 12px; font-weight: 500; }
.thread-toggle button:hover { background: var(--panel); }
.thread-toggle button.active { background: var(--blue); color: var(--blue-text); }

/* Boxed mode — every reply gets a bordered card and header divider, avatar
   stays visible next to the box like in plain mode. */
.thread.boxed .msg .msg-body {
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
}
.thread.boxed .msg.internal .msg-body { background: var(--amber-bg); border-color: #4A3A1E; }
.thread.boxed .msg .msg-meta { border-bottom: 1px solid var(--border); padding-bottom: 8px; margin-bottom: 10px; }

/* Message footer — quote on the left, bigger right-aligned stars on the right */
.msg-actions { margin-top: 10px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.msg-actions .stars-wrap { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.msg-actions .stars .star { font-size: 20px; }
.msg-actions .stars.disabled .star { cursor: default; opacity: 0.35; }

/* ---------- Reply area — flows in the same column, no separate boxed panel ---------- */
.reply-area { border-top: 1px solid var(--border); padding-top: 16px; }
.reply-actions { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.reply-actions .spacer { flex: 1; }
.internal-toggle { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.internal-toggle input { width: auto; }

/* Reply form's Reply / Personal note tabs — plain underline style */
.reply-tabs { display: flex; gap: 18px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.reply-tab {
    background: none; border: none; border-radius: 0; padding: 8px 2px; margin-bottom: -1px;
    font-size: 13px; font-weight: 500; color: var(--text-muted);
    border-bottom: 2px solid transparent;
}
.reply-tab:hover { background: none; color: var(--text); }
.reply-tab.active { background: none; color: var(--text); border-bottom-color: var(--blue); }
.reply-tab.active:hover { background: none; }
.reply-tab-panel { margin-bottom: 12px; }
.reply-tab-panel select { width: auto; }
.reply-blocked-notice { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: var(--red-bg); border: 1px solid #4A1E1E; border-radius: var(--radius); color: var(--red); font-size: 13px; }
.pending-review-banner { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--amber); background: var(--amber-bg); border: 1px solid #4A3A1E; border-radius: var(--radius); padding: 6px 10px; margin-bottom: 8px; }
.msg.pending-review .msg-body { opacity: 0.9; }
.review-actions { display: flex; gap: 8px; margin-top: 10px; }

/* Reply dot-menu */
.msg-dot-menu { position: relative; margin-left: auto; }
.dot-menu-btn { background: none; border: none; color: var(--text-faint); padding: 4px; border-radius: 6px; display: flex; }
.dot-menu-btn:hover { background: var(--panel-2); color: var(--text); }
.dot-menu-dropdown {
    display: none; position: absolute; right: 0; top: 100%; margin-top: 4px; z-index: 20;
    background: var(--panel); border: 1px solid var(--border); border-radius: 8px; min-width: 120px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.35); overflow: hidden;
}
.dot-menu-dropdown.open { display: block; }
.dot-menu-dropdown button { width: 100%; text-align: left; padding: 9px 12px; background: none; border: none; color: var(--text); font-size: 13px; }
.dot-menu-dropdown button:hover { background: var(--panel-2); }

/* Inline reply editing */
.msg-content.editing { outline: 2px solid var(--blue); outline-offset: 4px; border-radius: 6px; padding: 6px; }
.msg-edit-actions { display: flex; gap: 8px; }

/* Edit history */
.edit-history-toggle { background: none; border: none; color: var(--text-faint); text-decoration: underline; font-size: inherit; padding: 0; cursor: pointer; }
.edit-history-toggle:hover { color: var(--text); }
.edit-history-panel { margin-top: 10px; padding: 10px 12px; background: var(--panel-2); border-radius: 8px; border: 1px solid var(--border); }
.edit-history-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint); margin-bottom: 8px; }
.edit-history-entry { padding: 8px 0; border-top: 1px solid var(--border); }
.edit-history-entry:first-child { border-top: none; padding-top: 0; }
.edit-history-meta { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.edit-history-body { font-size: 13px; color: var(--text-faint); opacity: 0.85; }

/* Timeline accordion */
.timeline-accordion { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 16px; overflow: hidden; }
.timeline-accordion-toggle {
    width: 100%; display: flex; align-items: center; gap: 8px; padding: 12px 14px;
    background: var(--panel); border: none; color: var(--text); font-size: 13px; font-weight: 600;
}
.timeline-accordion-toggle:hover { background: var(--panel-2); }
.timeline-accordion-toggle .timeline-chevron { margin-left: auto; transition: transform 0.15s; }
.timeline-accordion-toggle.open .timeline-chevron { transform: rotate(180deg); }
.timeline-panel { padding: 12px 14px; border-top: 1px solid var(--border); }
.timeline-entry { display: flex; gap: 10px; padding: 8px 0; max-width: 100%; }
.timeline-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; }
.timeline-body { min-width: 0; }
.dot-timeline-admin { background: var(--purple, #B78CFF); }
.dot-timeline-agent { background: var(--blue); }
.dot-timeline-customer { background: var(--green); }
.dot-timeline-cc { background: var(--text-faint); }
.timeline-detail { font-size: 13px; color: var(--text); overflow-wrap: anywhere; }
.timeline-role-label { font-size: 11px; font-weight: 600; margin: 0 2px; }
.dot-timeline-admin-text { color: var(--purple, #B78CFF); }
.dot-timeline-agent-text { color: var(--blue); }
.dot-timeline-customer-text { color: var(--green); }
.dot-timeline-cc-text { color: var(--text-faint); }
.timeline-time { font-size: 11px; color: var(--text-faint); margin-top: 2px; }
.thread-loading { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 40px 0; color: var(--text-muted); font-size: 13px; }

/* Personal notes (sidebar accordion) */
.personal-note-entry { padding: 10px 0; border-top: 1px solid var(--border); max-width: 100%; }
.personal-note-entry:first-child { border-top: none; padding-top: 0; }
.personal-note-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; font-size: 12px; margin-bottom: 4px; }
.personal-note-meta strong { overflow-wrap: anywhere; min-width: 0; }
.personal-note-body { font-size: 13px; color: var(--text); overflow-wrap: anywhere; }
.personal-note-delete { background: none; border: none; color: var(--text-faint); margin-left: auto; padding: 2px; flex-shrink: 0; }
.personal-note-delete:hover { color: var(--red); }

/* Spinner — used on Load more buttons while a request is in flight */
.btn-spinner {
    display: inline-block; width: 14px; height: 14px; border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.35); border-top-color: #fff;
    animation: btn-spin 0.7s linear infinite; margin-right: 6px; vertical-align: -2px;
}
.btn-secondary .btn-spinner { border-color: rgba(232,233,235,0.3); border-top-color: var(--text); }
@keyframes btn-spin { to { transform: rotate(360deg); } }

/* ---------- Rich text editor ---------- */
.editor-toolbar {
    display: flex; flex-wrap: wrap; align-items: center; gap: 2px;
    background: var(--panel-2); border: 1px solid var(--border); border-bottom: none;
    border-radius: var(--radius) var(--radius) 0 0; padding: 6px;
}
.editor-toolbar button {
    background: none; border: none; color: var(--text-muted);
    width: 30px; height: 30px; padding: 0; border-radius: 6px;
    display: inline-flex; align-items: center; justify-content: center;
}
.editor-toolbar button:hover { background: var(--panel); color: var(--text); }
.editor-toolbar button.active { background: var(--blue-bg); color: var(--blue); }
.toolbar-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; flex-shrink: 0; }
.toolbar-color-wrap { position: relative; }
.color-menu {
    display: none; position: absolute; bottom: 36px; left: 0; z-index: 5;
    background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
    padding: 8px; gap: 6px; grid-template-columns: repeat(6, 20px); box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.color-menu.open { display: grid; }
.color-menu .swatch { width: 20px; height: 20px; border-radius: 5px; border: 1px solid var(--border); cursor: pointer; }

/* Paragraph-style dropdown (Normal/H1/H2/H3) — sits at the start of the toolbar */
.toolbar-heading-select {
    width: auto; flex-shrink: 0;
    background-color: var(--panel-2); color: var(--text); border: 1px solid var(--border);
    border-radius: 6px; padding: 4px 26px 4px 8px; font-size: 12px; height: 28px;
}

/* Emoji picker */
.toolbar-emoji-wrap { position: relative; }
.emoji-menu {
    display: none; position: absolute; bottom: 36px; left: 0; z-index: 5;
    background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
    padding: 8px; gap: 4px; grid-template-columns: repeat(6, 28px); box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    width: max-content; max-width: 220px;
}
.emoji-menu.open { display: grid; }
.emoji-menu .emoji-item { width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; font-size: 17px; border-radius: 5px; cursor: pointer; }
.emoji-menu .emoji-item:hover { background: var(--panel-2); }

/* Headings applied via the dropdown — inside both the live editor and
   rendered message content, since a heading typed while composing needs
   to look the same once the reply is actually posted and displayed. */
.rich-editor h1, .msg-content h1 { font-size: 22px; font-weight: 700; margin: 10px 0 6px; line-height: 1.3; }
.rich-editor h2, .msg-content h2 { font-size: 18px; font-weight: 700; margin: 8px 0 5px; line-height: 1.3; }
.rich-editor h3, .msg-content h3 { font-size: 15px; font-weight: 700; margin: 6px 0 4px; line-height: 1.3; }
.rich-editor h4, .msg-content h4 { font-size: 14px; font-weight: 700; margin: 5px 0 3px; line-height: 1.3; }
.rich-editor h5, .msg-content h5 { font-size: 13px; font-weight: 700; margin: 4px 0 3px; line-height: 1.3; text-transform: uppercase; letter-spacing: 0.02em; }
.rich-editor h6, .msg-content h6 { font-size: 12px; font-weight: 700; margin: 4px 0 3px; line-height: 1.3; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.02em; }

/* HTML source-view switch — sits at the far right of the toolbar */
.code-switch { display: flex; align-items: center; gap: 6px; margin-left: auto; padding: 0 6px; font-size: 11px; color: var(--text-muted); cursor: pointer; user-select: none; }
.code-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track { position: relative; width: 30px; height: 16px; background: var(--panel); border: 1px solid var(--border); border-radius: 20px; flex-shrink: 0; transition: background 0.15s, border-color 0.15s; }
.switch-thumb { position: absolute; top: 1px; left: 1px; width: 12px; height: 12px; border-radius: 50%; background: var(--text-faint); transition: transform 0.15s, background 0.15s; }
.code-switch input:checked + .switch-track { background: var(--blue-bg); border-color: var(--blue); }
.code-switch input:checked + .switch-track .switch-thumb { transform: translateX(14px); background: var(--blue); }

.html-source-view {
    width: 100%; min-height: 100px; max-height: 320px;
    border: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius);
    padding: 10px 12px; background: var(--panel); color: var(--text);
    font-family: 'JetBrains Mono', Consolas, monospace; font-size: 12px; line-height: 1.6; resize: vertical;
}
.html-source-view:focus { outline: none; border-color: var(--blue); }

.rich-editor {
    min-height: 100px; max-height: 320px; overflow-y: auto;
    border: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius);
    padding: 10px 12px; background: var(--panel-2); color: var(--text); font-size: 14px; line-height: 1.6;
}
.rich-editor:focus { outline: none; border-color: var(--blue); }
.rich-editor:empty:before { content: attr(data-placeholder); color: var(--text-faint); }
.rich-editor img { max-width: 100%; border-radius: 6px; margin: 4px 0; }
.rich-editor iframe { max-width: 100%; border-radius: 6px; margin: 4px 0; }

/* Shared rendering for rich content — both while composing and in past
   replies, since stored bodies are the same sanitized HTML either way. */
.msg-content, .rich-editor { }
.msg-content blockquote, .rich-editor blockquote {
    border-left: 3px solid var(--border); margin: 8px 0; padding: 4px 0 4px 12px; color: var(--text-muted);
}
.msg-content pre, .rich-editor pre { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; overflow-x: auto; }
.msg-content code, .rich-editor code {
    background: var(--panel); border: 1px solid var(--border); border-radius: 4px;
    padding: 1px 5px; font-family: 'JetBrains Mono', Consolas, monospace; font-size: 12px;
}
.msg-content ul, .rich-editor ul, .msg-content ol, .rich-editor ol { margin: 6px 0; padding-left: 22px; }
.msg-content a, .rich-editor a { color: var(--blue); text-decoration: underline; }
.msg-content img, .msg-content iframe { max-width: 100%; border-radius: 6px; margin: 4px 0; }
.msg-content p, .rich-editor p, .msg-content div, .rich-editor div { margin: 0 0 8px; }
.msg-content p:last-child, .rich-editor p:last-child { margin-bottom: 0; }

/* Attachments (Attach button — distinct from inline images) */
.msg-attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.attachment-chip {
    display: inline-flex; align-items: center; gap: 6px; font-size: 12px;
    background: var(--panel); border: 1px solid var(--border); border-radius: 20px;
    padding: 5px 12px; color: var(--text); text-decoration: none;
}
.attachment-chip:hover { background: var(--panel-2); text-decoration: none; }
.attachment-chip .attachment-size { color: var(--text-faint); }
.pending-attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.pending-attachments .attachment-chip { cursor: default; }
.pending-attachments .remove-x { cursor: pointer; font-weight: 700; color: var(--text-faint); }

/* Canned reply dropdown */
.canned-menu-wrap { position: relative; }
.canned-menu {
    display: none; position: absolute; bottom: 40px; left: 0; z-index: 5;
    width: 260px; max-height: 260px; overflow-y: auto;
    background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.canned-menu.open { display: block; }
.canned-item { padding: 9px 12px; font-size: 13px; cursor: pointer; border-bottom: 1px solid var(--border); }
.canned-item:hover { background: var(--panel-2); }
.canned-item.save-new { color: var(--blue); font-weight: 500; border-bottom: none; }
.canned-empty { padding: 12px; font-size: 12px; color: var(--text-faint); }

/* ---------- Chip inputs (CC / BCC) ---------- */
.chip-field {
    display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: 6px 8px; min-height: 38px; background: var(--panel-2);
}
.chip-field input[type=text] { border: none; flex: 1; min-width: 120px; padding: 4px; box-shadow: none; background: transparent; }
.chip-field input[type=text]:focus { box-shadow: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--blue-bg); color: var(--blue); font-size: 12px; padding: 3px 8px; border-radius: 20px; white-space: nowrap; }
.chip.chip-muted { background: var(--gray-bg); color: var(--gray); }
.chip .chip-remove { cursor: pointer; font-weight: 700; }

/* ---------- Social login ---------- */
.social-buttons { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border); }
.btn-social {
    display: flex; align-items: center; justify-content: center;
    padding: 9px 16px; border: 1px solid var(--border); border-radius: var(--radius);
    color: var(--text); background: var(--panel-2); font-weight: 500; font-size: 13px;
}
.btn-social:hover { background: #21242B; text-decoration: none; }

.helper-text { font-size: 12px; color: var(--text-muted); margin-top: 10px; }

/* Toggle switch — a genuinely reusable component (Chart of Accounts,
   Voucher Types, Journal Entry, the offline queue panel all use it),
   defined once globally rather than duplicated per-page. Previously
   only defined locally in two of those pages, leaving every use
   elsewhere — including 4 toggles on the journal entry form itself —
   silently unstyled. */
.toggle-switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; inset: 0; background: var(--border); border-radius: 22px; transition: background 0.15s ease; cursor: pointer; }
.toggle-slider::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: white; border-radius: 50%; transition: transform 0.15s ease; }
.toggle-switch input:checked + .toggle-slider { background: var(--blue); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(18px); }
.error-text { color: var(--red); font-size: 13px; margin-bottom: 14px; }
.captcha-wrap { margin: 4px 0 14px; }

/* ---------- Star ratings ---------- */
.stars { display: inline-flex; gap: 2px; }
.stars .star, .csat-stars .star { cursor: pointer; color: var(--border); font-size: 18px; line-height: 1; transition: color 0.1s, transform 0.1s; }
.stars .star:hover, .csat-stars .star:hover { color: var(--amber); transform: scale(1.15); }
.stars .star.filled, .csat-stars .star.filled { color: var(--amber); }
.stars.readonly .star { cursor: default; }
.stars.readonly .star:hover { color: var(--border); transform: none; }
.stars-lg .star { font-size: 30px; }
.rating-note { font-size: 11px; color: var(--text-faint); margin-top: 4px; }

/* ---------- Quote button on thread messages ---------- */
.msg-actions { margin-top: 6px; }
.quote-btn { background: none; border: none; padding: 0; color: var(--text-faint); font-size: 11px; cursor: pointer; font-weight: 500; }
.quote-btn:hover { color: var(--blue); background: none; }

/* ---------- CSAT survey page ---------- */
.csat-card h1 { margin-bottom: 6px; }
.csat-stars { display: flex; justify-content: center; gap: 8px; margin: 20px 0; }
.csat-stars .star { font-size: 36px; }
.csat-thanks { text-align: center; padding: 20px 0; }
.csat-thanks .big-check { font-size: 40px; color: var(--green); margin-bottom: 10px; }

/* ---------- Reports page ---------- */
.reports-grid { display: flex; gap: 16px; margin-bottom: 24px; }
.stat-card { flex: 1; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 18px; }
.stat-card .stat-label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.stat-card .stat-value { font-size: 26px; font-weight: 700; }
.stat-card .stat-meta { font-size: 12px; color: var(--text-faint); margin-top: 4px; }
.dist-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.dist-row .dist-label { width: 50px; font-size: 12px; color: var(--text-muted); flex-shrink: 0; }
.dist-bar-track { flex: 1; height: 8px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.dist-bar-fill { height: 100%; background: var(--amber); }
.dist-row .dist-count { width: 30px; text-align: right; font-size: 12px; color: var(--text-muted); flex-shrink: 0; }
.review-row { padding: 14px 0; border-bottom: 1px solid var(--border); }
.review-row:last-child { border-bottom: none; }
.review-row .review-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.review-row .review-comment { font-size: 13px; color: var(--text); }

/* ---------- select2 dark theme (global) ----------
   This stylesheet loads before the select2 CDN CSS in <head>, so
   these need !important to reliably win the cascade regardless of
   load order — otherwise select2's own default (light) theme can
   win ties and show a white dropdown on this dark theme. This is
   the single, authoritative copy; individual view files no longer
   need to (and shouldn't) duplicate it. */
.select2-container--default .select2-selection--single { background: var(--panel-2) !important; border: 1px solid var(--border) !important; height: 36px !important; }
.select2-container--default .select2-selection--single .select2-selection__rendered { color: var(--text) !important; line-height: 34px !important; padding-left: 10px !important; padding-right: 24px !important; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.select2-container--default .select2-selection--single .select2-selection__arrow { height: 34px !important; }
.select2-container--default .select2-selection--single .select2-selection__arrow b svg { width: 14px; height: 14px; color: var(--text-muted); }
.select2-dropdown { background: var(--panel) !important; border: 1px solid var(--border) !important; color: var(--text) !important; }
.select2-results__options { background: var(--panel) !important; }
.select2-container--default .select2-results__option { background: var(--panel) !important; color: var(--text) !important; padding: 8px 12px; }
.select2-container--default .select2-results__option[aria-selected="true"] { background: var(--panel-2) !important; color: var(--text-muted) !important; }
.select2-container--default .select2-results__option--highlighted[aria-selected] { background: var(--blue) !important; color: #fff !important; }
.select2-search--dropdown { background: var(--panel) !important; padding: 8px !important; }
.select2-search--dropdown .select2-search__field { background: var(--panel-2) !important; border: 1px solid var(--border) !important; color: var(--text) !important; }
