/* ============================================================
   MAILROOM v2 — Professional Helpdesk UI
   Clean, functional, information-dense like Freshdesk
   ============================================================ */

:root {
    --bg: #f6f9f9;
    --bg-card: #ffffff;
    --bg-sidebar: #0f2027;
    --bg-sidebar-hover: #1a3540;
    --bg-sidebar-active: #10b8a6;

    --text: #0f2730;
    --text-secondary: #4a6572;
    --text-muted: #8b9aa3;
    --text-sidebar: #b8d4d8;
    --text-sidebar-active: #ffffff;

    --border: #e1e8ea;
    --border-light: #eef3f4;

    /* Mailroom brand: teal-green gradient (logo) */
    --accent: #10b8a6;
    --accent-soft: #e6faf6;
    --accent-dark: #0d9488;
    --accent-gradient: linear-gradient(135deg, #5cd685 0%, #10b8a6 50%, #1d809f 100%);

    --success: #3eb795;
    --success-soft: #ecfdf5;
    --warning: #f59e0b;
    --warning-soft: #fef9ec;
    --danger: #e11d48;
    --danger-soft: #fef1f3;
    --info: #0ea5e9;
    --info-soft: #f0f9ff;

    --purple: #8b5cf6;
    --purple-soft: #f5f0ff;

    --sans: 'DM Sans', -apple-system, system-ui, sans-serif;
    --serif: 'Source Serif 4', Georgia, serif;
    --mono: 'JetBrains Mono', monospace;

    --r: 8px;
    --r-lg: 12px;
    --shadow-sm: 0 1px 2px rgba(15, 39, 48, 0.04);
    --shadow: 0 1px 3px rgba(15, 39, 48, 0.06), 0 1px 2px rgba(15, 39, 48, 0.04);
    --shadow-lg: 0 4px 12px rgba(15, 39, 48, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    font-family: var(--sans);
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: inherit; }

/* ============================================================
   LAYOUT: sidebar + main
   ============================================================ */

body { display: flex; }

.sidebar {
    width: 240px;
    background: var(--bg-sidebar);
    height: 100vh;
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    color: var(--text-sidebar);
    font-size: 13px;
    flex-shrink: 0;
    transition: width 0.2s ease;
}
.sidebar.--collapsed { width: 60px; }
.sidebar.--collapsed .sb-brand-name,
.sidebar.--collapsed .sb-brand-sub,
.sidebar.--collapsed .sb-link-text,
.sidebar.--collapsed .sb-section-title,
.sidebar.--collapsed .sb-badge,
.sidebar.--collapsed .sb-footer-text { display: none; }
.sidebar.--collapsed .sb-brand { justify-content: center; padding: 16px 8px; }
.sidebar.--collapsed .sb-link { justify-content: center; padding: 10px 4px; }
.sidebar.--collapsed .sb-link:hover .sb-link-text {
    display: block; position: absolute; left: 60px; top: 50%;
    transform: translateY(-50%); background: #1f2937; color: white;
    padding: 6px 10px; border-radius: 4px; font-size: 12px;
    white-space: nowrap; z-index: 100;
}

.sb-toggle {
    position: absolute; top: 14px; right: -10px;
    width: 20px; height: 20px; border-radius: 50%;
    background: var(--bg-sidebar); border: 1px solid rgba(255,255,255,0.15);
    color: var(--text-sidebar); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; line-height: 1;
    z-index: 10; transition: all 0.15s;
}
.sb-toggle:hover { background: var(--accent); color: white; }

.main {
    flex: 1;
    padding: 24px 32px;
    min-width: 0;
    max-width: 100%;
    position: relative;
    transition: padding-right 0.25s ease-out;
}
/* When right-side filter drawer is open, push main content left so it doesn't
   get hidden underneath the drawer. */
body.--drawer-open .main {
    padding-right: 400px;  /* drawer is 380px + 20px gap */
}
.main::before {
    content: "";
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 320px; height: 320px;
    background-image: url('/static/logo-watermark.svg');
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    opacity: 0.05;
    pointer-events: none;
    z-index: 0;
}
.main > * { position: relative; z-index: 1; }

/* ============================================================
   SIDEBAR
   ============================================================ */

.sb-brand {
    padding: 20px 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    gap: 10px;
}

.sb-logo {
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
}
.sb-logo svg { width: 100%; height: 100%; display: block; }

.sb-brand-name { font-weight: 600; font-size: 15px; color: white; }
.sb-brand-sub { font-size: 11px; color: var(--text-muted); }

.sb-nav { flex: 1; padding: 12px 8px; overflow-y: auto; }

.sb-section {
    padding: 16px 12px 6px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
}

.sb-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 6px;
    color: var(--text-sidebar);
    font-weight: 500;
    transition: all 0.12s;
    text-decoration: none;
    position: relative;
}

.sb-link:hover { background: var(--bg-sidebar-hover); color: white; text-decoration: none; }
.sb-link.active { background: var(--accent-gradient); color: white; box-shadow: 0 1px 4px rgba(16, 184, 166, 0.3); }

.sb-icon { width: 18px; text-align: center; font-size: 15px; opacity: 0.7; }
.sb-link.active .sb-icon { opacity: 1; }

.sb-badge {
    margin-left: auto;
    background: var(--danger);
    color: white;
    font-size: 11px; font-weight: 600;
    padding: 1px 7px;
    border-radius: 10px;
    min-width: 20px; text-align: center;
}

.sb-link.active .sb-badge { background: rgba(255,255,255,0.25); }

.sb-footer {
    padding: 12px 12px;
    border-top: 1px solid rgba(255,255,255,0.08);
}

.sb-user {
    display: flex; align-items: center; gap: 10px;
    padding: 8px;
    border-radius: 6px;
}

.sb-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 13px; color: white;
}

.sb-user-name { font-weight: 500; font-size: 13px; color: white; }
.sb-user-role { font-size: 11px; color: var(--text-muted); }

.sb-logout {
    display: block; width: 100%;
    padding: 7px; margin-top: 8px;
    text-align: center;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 6px;
    color: var(--text-sidebar);
    font-size: 12px;
    background: transparent;
    transition: all 0.12s;
}

.sb-logout:hover { background: var(--bg-sidebar-hover); color: white; text-decoration: none; }

/* ============================================================
   PAGE HEADER
   ============================================================ */

.page-header {
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    /* Sticky — luôn hiển thị khi scroll */
    position: sticky;
    top: 0;
    z-index: 30;
    background: var(--bg);
    padding: 14px 0 12px;
    margin-top: -14px;  /* compensate parent padding */
    border-bottom: 1px solid var(--border-light);
}

.page-title {
    font-family: var(--serif);
    font-size: 24px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.page-subtitle { color: var(--text-secondary); font-size: 13px; margin-top: 2px; }

/* ============================================================
   STATS GRID
   ============================================================ */

.stats { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }

.stat-card {
    flex: 1;
    min-width: 140px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 16px 18px;
    position: relative;
}

.stat-card::before {
    content: '';
    position: absolute; top: 0; left: 0;
    width: 3px; height: 100%;
    border-radius: 3px 0 0 3px;
}

.stat-card.--accent::before { background: var(--accent); }
.stat-card.--success::before { background: var(--success); }
.stat-card.--warning::before { background: var(--warning); }
.stat-card.--danger::before { background: var(--danger); }
.stat-card.--purple::before { background: var(--purple); }

.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; }
.stat-value { font-size: 28px; font-weight: 700; line-height: 1.2; margin-top: 4px; }
.stat-meta { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }

/* ============================================================
   CARDS
   ============================================================ */

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    overflow: hidden;
    margin-bottom: 16px;
}

.card-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-title { font-weight: 600; font-size: 15px; }
.card-body { padding: 18px; }

/* ============================================================
   BUTTONS
   ============================================================ */

.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px; font-weight: 500;
    background: white; color: var(--text);
    transition: all 0.12s;
    line-height: 1.3;
    white-space: nowrap;
}

.btn:hover { background: var(--bg); border-color: var(--text-muted); text-decoration: none; }

.btn.--primary { background: var(--accent-gradient); color: white; border-color: transparent; box-shadow: 0 1px 2px rgba(16, 184, 166, 0.25); }
.btn.--primary:hover { filter: brightness(1.05); box-shadow: 0 2px 6px rgba(16, 184, 166, 0.35); }
.btn.--success { background: var(--success); color: white; border-color: var(--success); }
.btn.--danger { background: white; color: var(--danger); border-color: var(--danger); }
.btn.--danger:hover { background: var(--danger); color: white; }
.btn.--ghost { background: transparent; border-color: transparent; color: var(--text-secondary); }
.btn.--ghost:hover { background: var(--bg); }
.btn.--sm { padding: 4px 10px; font-size: 12px; }
.btn.--xs { padding: 2px 8px; font-size: 11px; }

/* ============================================================
   FORMS
   ============================================================ */

.form-group { margin-bottom: 14px; }
.form-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 4px; color: var(--text); }
.label-hint { font-size: 11px; color: var(--text-muted); font-weight: 400; }

.input, .textarea, .select {
    width: 100%; padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: white; color: var(--text);
    transition: border-color 0.15s;
}
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--accent); }
.textarea { min-height: 80px; resize: vertical; font-family: var(--mono); font-size: 13px; line-height: 1.5; }

/* ============================================================
   TABLE
   ============================================================ */

.table { width: 100%; border-collapse: collapse; }
.table th {
    text-align: left; padding: 10px 14px;
    font-size: 11px; font-weight: 600;
    color: var(--text-muted); text-transform: uppercase;
    letter-spacing: 0.06em;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border-light); }
.table tr:hover { background: var(--bg); }

/* ============================================================
   TAGS / BADGES
   ============================================================ */

.tag {
    display: inline-flex; align-items: center;
    padding: 2px 8px; border-radius: 4px;
    font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.03em;
}

.tag.--new { background: var(--info-soft); color: var(--info); }
.tag.--open { background: var(--accent-soft); color: var(--accent); }
.tag.--pending { background: var(--warning-soft); color: var(--warning); }
.tag.--on_hold { background: #f3f4f6; color: #6b7280; }
.tag.--resolved { background: var(--success-soft); color: var(--success); }
.tag.--closed { background: #f3f4f6; color: var(--text-muted); }

.tag.--urgent { background: var(--danger-soft); color: var(--danger); }
.tag.--high { background: #fff1f2; color: #e11d48; }
.tag.--medium { background: var(--warning-soft); color: var(--warning); }
.tag.--low { background: #f0f9ff; color: #0284c7; }

.tag.--cs { background: var(--success-soft); color: var(--success); }
.tag.--partner { background: var(--warning-soft); color: var(--warning); }

/* ============================================================
   TICKET LIST
   ============================================================ */

.ticket-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--border-light); transition: background 0.1s; }
.ticket-row:hover { background: var(--bg); }
.ticket-row a { color: var(--text); text-decoration: none; flex: 1; min-width: 0; }
.ticket-row a:hover { color: var(--accent); }
.ticket-num { font-family: var(--mono); font-size: 12px; color: var(--text-muted); min-width: 75px; }
.ticket-subj { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ticket-from { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.ticket-meta { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.ticket-time { font-size: 11px; color: var(--text-muted); min-width: 60px; text-align: right; }

/* ============================================================
   TICKET DETAIL — 2 column layout
   ============================================================ */

.ticket-layout { display: grid; grid-template-columns: 1fr 340px; gap: 20px; align-items: start; }

@media (max-width: 1100px) { .ticket-layout { grid-template-columns: 1fr; } }

.ticket-conv { min-width: 0; }

.ticket-panel {
    position: sticky; top: 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    overflow: hidden;
    max-height: calc(100vh - 48px);
    overflow-y: auto;
}

/* Messages */
.msg {
    padding: 18px 20px;
    border-bottom: 2px solid var(--border);  /* thicker so messages clearly separate */
}
.msg:last-child { border-bottom: none; }

.msg.--outbound { background: var(--accent-soft); border-left: 3px solid var(--accent); }
.msg.--note { background: #fffbeb; border-left: 3px solid var(--warning); }

/* Message header — Gorgias/Shopify-style with avatar + verb + To line */
.msg-header {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-light);
}
.msg-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px;
    flex-shrink: 0;
    color: white;
    text-transform: uppercase;
}
.msg-avatar.--inbound  { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.msg-avatar.--outbound { background: linear-gradient(135deg, #10b8a6, #0d9488); }
.msg-avatar.--note     { background: linear-gradient(135deg, #f59e0b, #d97706); }

.msg-header-info { flex: 1; min-width: 0; }
.msg-header-line1 {
    display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap;
    margin-bottom: 2px;
}
.msg-header-line2 {
    font-size: 11px; color: var(--text-muted);
    display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
}
.msg-sender { font-weight: 600; font-size: 14px; color: #0000FF; }
.msg-sender-email {
    font-family: var(--mono); font-size: 11px; color: var(--text-muted);
}
.msg-action {
    font-size: 11px; color: var(--text-muted); font-style: italic;
}
.msg-action.--in  { color: #2563eb; }
.msg-action.--out { color: var(--accent-dark); }
.msg-action.--note{ color: #92400e; }

.msg-to-label { color: var(--text-secondary); font-weight: 600; }
.msg-to-addr  { font-family: var(--mono); color: var(--text-secondary); }
.msg-time-sep { color: #d1d5db; }
.msg-time { font-size: 11px; color: var(--text-muted); }
.msg-dir { font-size: 10px; padding: 1px 6px; border-radius: 3px; font-weight: 600; }
.msg-dir.--in { background: var(--bg); color: var(--text-secondary); }
.msg-dir.--out { background: var(--accent-soft); color: var(--accent); }
.msg-dir.--note { background: var(--warning-soft); color: var(--warning); }
.msg-body {
    font-size: 14px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;       /* break even at non-space chars */
    overflow: hidden;              /* clip — don't let content escape card */
    color: #1f2937;
    font-family: -apple-system, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    max-width: 100%;
}
/* Force any inline media to fit. Some marketing emails set explicit
   width="800" on <img> / <table> which would otherwise blow out the
   conversation card width. */
.msg-body img,
.msg-body iframe,
.msg-body video,
.msg-body embed,
.msg-body object {
    max-width: 100% !important;
    height: auto;
}
.msg-body table {
    max-width: 100% !important;
    table-layout: auto;
}
.msg-body td,
.msg-body th {
    word-break: break-word;
    overflow-wrap: anywhere;
    max-width: 100%;
}
/* For inputs/textarea in HTML emails (rare but Shopify form previews use them) */
.msg-body input,
.msg-body textarea,
.msg-body select {
    max-width: 100%;
    box-sizing: border-box;
}
/* When the body is HTML (rendered inside .email-html-content), the outer
   pre-wrap must NOT apply — otherwise the indentation Jinja inserts between
   template tags shows up as a big leading blank block above the content. */
.msg-body:has(> .email-html-content) { white-space: normal; }

/* HTML email content — give it proper Gmail-style typography defaults.
   Preserves email's own inline styles (Shopify/Stripe table layouts) but
   adds sensible browser defaults for bare HTML emails. */
.msg-body .email-html-content {
    white-space: normal;
    line-height: 1.7;
    color: #1f2937;
    max-width: 100%;
    overflow-x: auto;              /* internal scroll if a wide table really needs it */
    overflow-y: hidden;
}
.msg-body .email-html-content p {
    margin: 0 0 12px 0;
}
.msg-body .email-html-content p:last-child { margin-bottom: 0; }
.msg-body .email-html-content b,
.msg-body .email-html-content strong { font-weight: 600; color: #111827; }
.msg-body .email-html-content h1,
.msg-body .email-html-content h2,
.msg-body .email-html-content h3,
.msg-body .email-html-content h4 {
    margin: 16px 0 8px 0;
    font-weight: 600;
    line-height: 1.3;
    color: #111827;
}
.msg-body .email-html-content h1 { font-size: 20px; }
.msg-body .email-html-content h2 { font-size: 17px; }
.msg-body .email-html-content h3 { font-size: 15px; }
.msg-body .email-html-content h4 { font-size: 14px; }
.msg-body .email-html-content ul,
.msg-body .email-html-content ol {
    margin: 8px 0 12px 0;
    padding-left: 24px;
}
.msg-body .email-html-content li { margin: 2px 0; }
.msg-body .email-html-content img { max-width: 100%; height: auto; border-radius: 4px; }
.msg-body .email-html-content a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.msg-body .email-html-content a:hover { text-decoration: underline; opacity: 0.85; }
.msg-body .email-html-content blockquote {
    border-left: 3px solid var(--border);
    margin: 12px 0; padding: 4px 0 4px 14px;
    color: var(--text-muted);
}
.msg-body .email-html-content code {
    background: #f3f4f6; padding: 1px 6px; border-radius: 4px;
    font-family: var(--mono); font-size: 12.5px;
}
.msg-body .email-html-content pre {
    background: #f9fafb; border: 1px solid var(--border);
    padding: 10px 12px; border-radius: 6px;
    font-family: var(--mono); font-size: 12.5px;
    overflow-x: auto; margin: 8px 0;
    white-space: pre-wrap;          /* prefer wrap over scroll */
    word-break: break-word;
    overflow-wrap: anywhere;
}
.msg-body .email-html-content pre code { background: none; padding: 0; }
.msg-body .email-html-content table { max-width: 100%; border-collapse: collapse; margin: 8px 0; }
.msg-body .email-html-content table td,
.msg-body .email-html-content table th { padding: 6px 10px; vertical-align: top; }
.msg-body .email-html-content > * { max-width: 100%; }
.msg-body .email-html-content hr {
    border: none; border-top: 1px solid var(--border);
    margin: 16px 0;
}
/* Block scripts/iframes from email HTML for safety */
.msg-body .email-html-content script,
.msg-body .email-html-content iframe,
.msg-body .email-html-content object,
.msg-body .email-html-content embed { display: none !important; }

/* Linkify ticket refs inside plain-text bodies */
.msg-body a.ticket-ref-link:hover { opacity: 0.85; }

/* Reply box */
.reply-box {
    padding: 16px 18px;
    border-top: 2px solid var(--accent);
    background: white;
}

.reply-tabs { display: flex; gap: 0; margin-bottom: 12px; }
.reply-tab {
    padding: 6px 14px; font-size: 12px; font-weight: 600;
    border: 1px solid var(--border);
    background: white; color: var(--text-secondary);
    cursor: pointer;
}
.reply-tab:first-child { border-radius: 6px 0 0 6px; }
.reply-tab:last-child { border-radius: 0 6px 6px 0; }
.reply-tab.active { background: var(--accent); color: white; border-color: var(--accent); }

/* Panel sections */
.panel-sec { padding: 14px 16px; border-bottom: 1px solid var(--border-light); }
.panel-sec:last-child { border-bottom: none; }
.panel-sec-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); margin-bottom: 10px; }
.panel-sec.collapsible .caret { transition: transform 0.15s; font-size: 10px; }
.panel-sec.collapsible.collapsed .caret { transform: rotate(-90deg); }
.panel-sec.collapsible.collapsed .panel-sec-title { margin-bottom: 0; }
.panel-sec.collapsible.collapsed .panel-sec-body { display: none; }

.panel-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; }
.panel-row-label { color: var(--text-secondary); }
.panel-row-value { font-weight: 500; text-align: right; max-width: 180px; word-break: break-all; }

/* ============================================================
   LOGIN PAGE
   ============================================================ */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-sidebar);
}

.login-card {
    background: white;
    border-radius: var(--r-lg);
    padding: 40px 36px;
    width: 380px;
    max-width: 90vw;
    box-shadow: var(--shadow-lg);
}

.login-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 32px; }
.login-logo-mark {
    width: 48px; height: 48px;
    display: flex; align-items: center; justify-content: center;
}
.login-logo-mark svg { width: 100%; height: 100%; }
.login-logo-text { font-weight: 700; font-size: 22px; color: var(--text); letter-spacing: -0.5px; }

.login-title { font-size: 18px; font-weight: 600; margin-bottom: 4px; }
.login-sub { color: var(--text-secondary); font-size: 13px; margin-bottom: 24px; }

.login-card .btn { width: 100%; justify-content: center; padding: 10px; font-size: 14px; }

.login-hint { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-muted); }

.alert { padding: 10px 14px; border-radius: 6px; font-size: 13px; margin-bottom: 14px; }
.alert.--error { background: var(--danger-soft); color: var(--danger); border: 1px solid #fecaca; }
.alert.--success { background: var(--success-soft); color: var(--success); border: 1px solid #bbf7d0; }

/* ============================================================
   TOAST
   ============================================================ */

#toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 6px; }
.toast { background: var(--text); color: white; padding: 10px 16px; border-radius: 6px; font-size: 13px; box-shadow: var(--shadow-lg); animation: slideUp 0.2s ease; }
.toast.--success { background: var(--success); }
.toast.--error { background: var(--danger); }
@keyframes slideUp { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ============================================================
   EMPTY STATE
   ============================================================ */

.empty { text-align: center; padding: 60px 20px; }
.empty-icon { font-size: 48px; color: var(--border); margin-bottom: 12px; }
.empty-title { font-weight: 600; font-size: 16px; margin-bottom: 4px; }
.empty-text { color: var(--text-muted); font-size: 13px; }

/* ============================================================
   FILTER BAR
   ============================================================ */

.filter-bar {
    display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
    padding: 10px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    margin-bottom: 16px;
}

.filter-bar .select, .filter-bar .input {
    width: auto; min-width: 120px; padding: 6px 10px; font-size: 12px;
}

/* ============================================================
   SEARCHABLE COMBOBOX
   ------------------------------------------------------------
   Click-to-open dropdown that also accepts type-to-filter.
   Hidden <input> carries the actual form value; visible input
   shows the selected option's label. See cb* helpers in app.js.
   ============================================================ */
.combobox {
    position: relative;
}
.combobox .combobox-input {
    width: 100%;
    cursor: pointer;
    background-image: linear-gradient(45deg, transparent 50%, #6b7280 50%),
                      linear-gradient(135deg, #6b7280 50%, transparent 50%);
    background-position: calc(100% - 14px) center, calc(100% - 9px) center;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    padding-right: 24px;
}
.combobox .combobox-input:focus { cursor: text; }
.combobox-dropdown {
    position: absolute;
    top: calc(100% + 2px);
    left: 0; right: 0;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    max-height: 240px;
    overflow-y: auto;
    z-index: 50;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.combobox-opt {
    padding: 6px 10px;
    font-size: 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.combobox-opt:last-child { border-bottom: none; }
.combobox-opt:hover, .combobox-opt.--active { background: #eef2ff; }
.combobox-opt.--selected { background: #f3f4f6; font-weight: 600; }
.combobox-opt[hidden] { display: none; }
.combobox-empty {
    padding: 8px 10px;
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
}

/* ============================================================
   SECTION HEADER (CS GROUP / Partner)
   ============================================================ */

.section-header {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 16px;
    border-radius: var(--r) var(--r) 0 0;
    margin-bottom: 0;
}
.section-header.--cs { background: var(--success-soft); border-left: 3px solid var(--success); }
.section-header.--partner { background: var(--warning-soft); border-left: 3px solid var(--warning); }
.section-title { font-weight: 700; font-size: 15px; }

/* Helpers */
.row { display: flex; align-items: center; gap: 10px; }
.row.--between { justify-content: space-between; }
.row.--end { justify-content: flex-end; }
.spacer { flex: 1; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-mono { font-family: var(--mono); }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }

@media (max-width: 800px) {
    body { flex-direction: column; }
    .sidebar { width: 100%; height: auto; position: static; }
    .main { padding: 16px; }
}

/* ============================================================
   ATTACHMENTS
   ============================================================ */
.attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    font-size: 12px;
    color: var(--text);
    text-decoration: none;
    max-width: 250px;
    transition: all 0.15s;
}
.attachment-chip:hover {
    background: white;
    border-color: var(--accent);
    color: var(--accent);
    text-decoration: none;
}
.attachment-chip .att-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 160px;
}
.attachment-chip .att-size {
    color: var(--text-muted);
    font-size: 11px;
}
.attachment-chip .att-icon {
    font-size: 14px;
}

/* ============================================================
   MODAL OVERLAY (popup with backdrop)
   Shared by ticket_detail, email_accounts, etc.
   Hidden by default; add .show to display.
   ============================================================ */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal-overlay.show { display: flex; }
.modal-card {
    background: white;
    border-radius: 12px;
    width: 540px;
    max-width: 100%;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    max-height: 90vh;
    overflow-y: auto;
}
