/* =============================================================
   JokoUI — RoC Desk Design System
   =============================================================
   Custom component classes built with Tailwind's @apply directive.
   This file defines the "JokoUI" design language: clean, modern,
   card-based, with a dark-mode aware color palette.
   ============================================================= */

/* ----- Root Variables ----- */
:root {
    --jk-primary: #2563eb;
    --jk-primary-hover: #1d4ed8;
    --jk-primary-light: #dbeafe;
    --jk-secondary: #16a34a;
    --jk-success: #10b981;
    --jk-warning: #f59e0b;
    --jk-danger: #ef4444;
    --jk-info: #06b6d4;
    --jk-surface: #ffffff;
    --jk-surface-alt: #f8fafc;
    --jk-border: #e2e8f0;
    --jk-text: #1e293b;
    --jk-text-muted: #64748b;
    --jk-sidebar-bg: #0c1b2e;
    --jk-sidebar-text: #cbd5e1;
    --jk-sidebar-active: #2563eb;
    --jk-radius: 12px;
    --jk-radius-sm: 8px;
    --jk-shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --jk-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --jk-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
    --jk-transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* =============================================================
   LAYOUT
   ============================================================= */

.jk-page {
    min-height: 100vh;
    min-height: 100dvh;
    background-color: var(--jk-surface-alt);
    color: var(--jk-text);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    overflow-x: hidden;
}

.jk-content {
    padding: 2rem;
}

/* Personal unread activity markers, shared by desk and portal. */
.jk-ticket-unread,
a.jk-table-link.jk-ticket-unread {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.125rem 0.5rem;
    border: 1px solid rgba(220, 38, 38, 0.55);
    border-radius: 0.5rem;
    background: rgba(239, 68, 68, 0.08);
    color: #b91c1c;
    font-weight: 600;
}
/* Unread count on the ticket-number pill's top-right corner (Task Management table) */
.jk-ticket-unread { position: relative; }
.jk-unread-count {
    position: absolute; top: -7px; right: -8px;
    min-width: 16px; height: 16px; padding: 0 4px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 9999px; background: #dc2626; color: #fff;
    font-size: 9px; font-weight: 700; line-height: 1;
    box-shadow: 0 0 0 2px #fff; pointer-events: none;
}
.jk-nav-unread-badge,
.jk-bell-count {
    border-radius: 999px;
    background: #dc2626;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 1.4;
    min-width: 1.25rem;
    padding: 0.125rem 0.375rem;
    text-align: center;
}
.jk-nav-unread-badge { margin-left: auto; }
.jk-saved-filter-active { background: #eef2ff !important; border-color: #a5b4fc !important; }
.jk-nav-unread-badge[hidden] { display: none !important; }
.jk-bell-count { position: absolute; top: 0; right: -0.125rem; }

/* Opaque toolbar covers cards scrolling underneath, including the content gutter. */
.jk-my-tickets { --jk-ticket-toolbar-height: 200px; }
.jk-my-tickets-toolbar {
    position: sticky;
    top: var(--jk-topbar-height, 64px);
    z-index: 20;
    background: var(--jk-surface-alt);
    isolation: isolate;
}
.jk-my-tickets-toolbar::before {
    content: '';
    position: absolute;
    inset: -2rem -2rem 0;
    background: var(--jk-surface-alt);
    z-index: -1;
}
.jk-my-tickets-table {
    overflow: auto;
    max-height: max(240px, calc(100dvh - var(--jk-topbar-height, 64px) - var(--jk-ticket-toolbar-height) - 3rem));
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
}
.jk-my-tickets-table table { border-collapse: separate; border-spacing: 0; }
.jk-my-tickets-table th { position: sticky; top: 0; z-index: 1; background: #f8fafc; border-bottom: 1px solid #e2e8f0; }
.jk-my-tickets-table td { overflow-wrap: anywhere; }

.jk-portal-chat-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    min-width: 0;
}
.jk-portal-chat-actions > label,
.jk-portal-chat-actions > button { min-height: 44px; padding: 0.375rem 0.625rem; }
.jk-portal-chat-connection { flex: 1 1 100px; white-space: nowrap; }
.jk-portal-chat-send { width: 44px; height: 44px; margin-left: auto; }
/* Staff reply attachments: one compact card per file (thumb · name/size · remove) */
.jk-chat-upload-previews { display: flex; flex-wrap: wrap; gap: 0.5rem; padding: 0 0.5rem 0.625rem; max-height: 168px; overflow-y: auto; }
.jk-chat-upload-preview { display: flex; align-items: center; gap: 0.625rem; width: 232px; max-width: 100%; padding: 0.4375rem 0.5rem 0.4375rem 0.4375rem; border: 1px solid #e2e8f0; border-radius: 0.75rem; background: #fff; box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05); transition: border-color 0.15s, box-shadow 0.15s; }
.jk-chat-upload-preview:hover { border-color: #c7d2fe; box-shadow: 0 2px 8px rgba(99, 102, 241, 0.12); }
.jk-chat-upload-preview__thumb { flex-shrink: 0; width: 40px; height: 40px; border-radius: 0.5rem; overflow: hidden; display: flex; align-items: center; justify-content: center; background: #f1f5f9; color: #475569; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.02em; }
.jk-chat-upload-preview__thumb img,
.jk-chat-upload-preview__thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.jk-chat-upload-preview__thumb.is-pdf { background: #fee2e2; color: #b91c1c; }
.jk-chat-upload-preview__thumb.is-sheet { background: #dcfce7; color: #15803d; }
.jk-chat-upload-preview__thumb.is-doc { background: #dbeafe; color: #1d4ed8; }
.jk-chat-upload-preview__thumb.is-slide { background: #ffedd5; color: #c2410c; }
.jk-chat-upload-preview__thumb.is-audio { background: #f3e8ff; color: #7e22ce; }
.jk-chat-upload-preview__thumb.is-archive { background: #fef9c3; color: #a16207; }
.jk-chat-upload-preview__meta { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.jk-chat-upload-preview__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; font-weight: 600; color: #1e293b; }
.jk-chat-upload-preview__size { font-size: 11px; color: #64748b; margin-top: 1px; }
.jk-chat-upload-preview__remove { flex-shrink: 0; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; border: none; border-radius: 9999px; background: transparent; color: #94a3b8; cursor: pointer; transition: background 0.15s, color 0.15s; }
.jk-chat-upload-preview__remove:hover { background: #fee2e2; color: #dc2626; }
@media (max-width: 480px) { .jk-chat-upload-preview { width: 100%; } }
@media (max-width: 768px) {
    .jk-my-tickets-toolbar::before { inset: -1rem -1rem 0; }
}
@media (max-width: 480px) {
    .jk-portal-chat-connection { flex-basis: calc(100% - 150px); text-align: right; }
    .jk-portal-chat-actions > button { flex-shrink: 1; white-space: normal; }
    .jk-portal-chat-actions > .jk-portal-chat-send { flex-shrink: 0; }
}

/* Auth pages (login, forgot password, etc.) — no padding, no max-width constraint */
.jk-main.full-width .jk-content {
    padding: 0;
    max-width: 100%;
}

.jk-main.full-width .jk-topbar {
    display: none;
}

/* ----- Sidebar ----- */
.jk-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 260px;
    height: 100vh;
    height: 100dvh;
    background: var(--jk-sidebar-bg);
    color: var(--jk-sidebar-text);
    display: flex;
    flex-direction: column;
    z-index: 40;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    overflow-x: hidden;
}

/* Custom Sleek Scrollbar for Sidebar */
.jk-sidebar::-webkit-scrollbar {
    width: 4px;
}
.jk-sidebar::-webkit-scrollbar-track {
    background: transparent;
}
.jk-sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}
.jk-sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

.jk-sidebar--collapsed {
    width: 72px;
}

/* Pre-hydration anti-FOUC state: set on <html> by an inline script in
   base.html's <head> from localStorage, before Alpine loads. Removed by
   Alpine's x-init the moment it hydrates, so it never fights the
   lg:ml-[72px]/lg:ml-[260px] classes Alpine binds afterwards. */
html.sidebar-collapsed .jk-sidebar {
    width: 72px;
}

.jk-sidebar-sticky-top {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--jk-sidebar-bg);
    flex-shrink: 0;
}

.jk-sidebar-brand {
    padding: 0.75rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.jk-sidebar-brand-icon {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--jk-primary), var(--jk-secondary));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.125rem;
    color: #fff;
    flex-shrink: 0;
}

.jk-sidebar-brand-text {
    font-family: 'Plus Jakarta Sans', 'Inter', system-ui, sans-serif;
    font-weight: 700;
    font-size: 1.125rem;
    color: #f1f5f9;
    letter-spacing: -0.025em;
}

.jk-sidebar-brand-text--lg {
    font-size: 1.375rem;
}

.jk-sidebar-brand-text--md {
    font-size: 1.125rem;
}

.jk-sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
/* Scrollbar handled by sidebar parent */

.jk-sidebar-search-wrap {
    padding: 0 0.75rem 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.jk-sidebar-search-icon {
    position: absolute;
    left: 0.6rem;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    color: rgba(255, 255, 255, 0.3);
    pointer-events: none;
}

.jk-sidebar-search-input {
    width: 100%;
    padding: 0.5rem 0.625rem 0.5rem 1.875rem;
    border-radius: var(--jk-radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.05);
    color: #f1f5f9;
    font-size: 0.8125rem;
    font-family: inherit;
    transition: var(--jk-transition);
}

.jk-sidebar-search-input::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

.jk-sidebar-search-input:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.08);
}

.jk-sidebar-search-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 40;
    max-height: 320px;
    overflow-y: auto;
    background: #101f33;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--jk-radius-sm);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
    padding: 0.375rem;
}

.jk-sidebar-search-dropdown-label {
    font-size: 0.625rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255, 255, 255, 0.3);
    padding: 0.375rem 0.5rem;
}

.jk-sidebar-search-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.5rem 0.625rem;
    border-radius: var(--jk-radius-sm);
    color: var(--jk-sidebar-text);
    text-decoration: none;
    font-size: 0.8125rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.jk-sidebar-search-item:hover,
.jk-sidebar-search-item.active {
    background: rgba(255, 255, 255, 0.1);
    color: #f1f5f9;
}

.jk-sidebar-search-item-icon {
    flex-shrink: 0;
    font-size: 0.9rem;
}

.jk-sidebar-search-empty {
    padding: 0.5rem 0.625rem;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.35);
}

.jk-sidebar-section {
    font-size: 0.625rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(255, 255, 255, 0.3);
    padding: 1.25rem 0.75rem 0.5rem;
    white-space: nowrap;
}

.jk-sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    border-radius: var(--jk-radius-sm);
    color: var(--jk-sidebar-text);
    text-decoration: none;
    font-size: 0.8125rem;
    font-weight: 500;
    transition: var(--jk-transition);
    white-space: nowrap;
}

.jk-sidebar--collapsed .jk-sidebar-link {
    justify-content: center;
    padding: 0.625rem 0;
}

.jk-sidebar-link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #f1f5f9;
}

.jk-sidebar-link.active {
    background: var(--jk-sidebar-active);
    color: #ffffff;
}

.jk-sidebar-link-icon {
    width: 20px;
    text-align: center;
    font-size: 1rem;
    flex-shrink: 0;
}

/* ----- Main Area ----- */
.jk-main {
    min-height: 100vh;
    min-height: 100dvh;
    transition: margin-left 0.3s ease;
    min-width: 0;
    max-width: 100%;
}

/* Default (expanded-sidebar) margin so the layout is already correct on
   first paint, before Alpine's lg:ml-[72px]/lg:ml-[260px] binding runs.
   Wrapped in :where() to keep this at zero specificity — otherwise, once
   Alpine's x-init removes html.sidebar-collapsed below and hands control
   back to its own lg:ml-[...] utility class, a plain .jk-main rule here
   (same 0,1,0 specificity, but declared later since jokoui.css loads
   after tailwind.css) would permanently win over it and pin the margin.
   Mobile still forces 0 via the max-width:1024px !important override. */
:where(.jk-main) {
    margin-left: 260px;
}

html.sidebar-collapsed .jk-main {
    margin-left: 72px;
}

.jk-main.full-width {
    margin-left: 0;
}

/* ----- Top Navbar ----- */
.jk-topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 2rem;
    background: #fff;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--jk-border);
}

.jk-topbar-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--jk-text);
    letter-spacing: -0.025em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.jk-topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

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

.jk-card {
    background: var(--jk-surface);
    border: 1px solid var(--jk-border);
    border-radius: var(--jk-radius);
    box-shadow: var(--jk-shadow);
    transition: var(--jk-transition);
    overflow: hidden;
}

.jk-card:hover {
    box-shadow: var(--jk-shadow-md);
}

.jk-card-clickable {
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    display: block;
}

.jk-card-clickable:hover {
    box-shadow: var(--jk-shadow-lg);
    transform: translateY(-2px);
    border-color: var(--jk-primary);
}

.jk-card-body {
    padding: 1.5rem;
}

.jk-card-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--jk-border);
    font-weight: 600;
    font-size: 0.9375rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.jk-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: var(--jk-radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: var(--jk-transition);
    text-decoration: none;
    line-height: 1.4;
    white-space: nowrap;
}

.jk-btn:focus-visible {
    outline: 2px solid var(--jk-primary);
    outline-offset: 2px;
}

.jk-btn-primary {
    background: var(--jk-primary);
    color: #ffffff;
    border-color: var(--jk-primary);
}

.jk-btn-primary:hover {
    background: var(--jk-primary-hover);
    border-color: var(--jk-primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}

.jk-btn-secondary {
    background: var(--jk-surface-alt);
    color: var(--jk-text);
    border-color: var(--jk-border);
}

.jk-btn-secondary:hover {
    background: #e2e8f0;
    border-color: #cbd5e1;
}

.jk-btn-outline {
    background: #f1f5f9;
    color: var(--jk-text);
    border-color: #cbd5e1;
}

.jk-btn-outline:hover {
    background: #e2e8f0;
    border-color: #94a3b8;
}

.jk-btn-success {
    background: var(--jk-success);
    color: #ffffff;
    border-color: var(--jk-success);
}

.jk-btn-success:hover {
    background: #059669;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.35);
}

.jk-btn-danger {
    background: var(--jk-danger);
    color: #ffffff;
    border-color: var(--jk-danger);
}

.jk-btn-danger:hover {
    background: #dc2626;
    transform: translateY(-1px);
}

.jk-btn-sm {
    padding: 0.375rem 0.875rem;
    font-size: 0.8125rem;
}

.jk-btn-lg {
    padding: 0.75rem 1.75rem;
    font-size: 1rem;
}

.jk-btn-block {
    width: 100%;
}

/* =============================================================
   FORM INPUTS
   ============================================================= */

.jk-input,
.jk-select,
.jk-textarea {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--jk-text);
    background: var(--jk-surface);
    border: 1px solid var(--jk-border);
    border-radius: var(--jk-radius-sm);
    transition: var(--jk-transition);
    font-family: inherit;
}

.jk-input:focus,
.jk-select:focus,
.jk-textarea:focus {
    outline: none;
    border-color: var(--jk-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.jk-input::placeholder,
.jk-textarea::placeholder {
    color: #94a3b8;
}

/* Padding overrides for jk-input combined with Tailwind utilities.
   Two-class specificity (0-2-0) beats the single-class base rule (0-1-0),
   so these win even though jokoui.css loads after tailwind.css. */
.jk-input.pl-7  { padding-left: 1.75rem; }
.jk-input.pl-8  { padding-left: 2rem; }
.jk-input.pl-9  { padding-left: 2.25rem; }
.jk-input.pl-10 { padding-left: 2.5rem; }
.jk-input.pl-12 { padding-left: 3rem; }
.jk-input.pr-8  { padding-right: 2rem; }
.jk-input.pr-10 { padding-right: 2.5rem; }
.jk-input.py-1\.5, .jk-select.py-1\.5 { padding-top: 0.375rem; padding-bottom: 0.375rem; }

/* TomSelect (.jk-select-search) — match the compact jk-input/jk-select scale
   instead of the library's own larger default control sizing. */
.ts-control {
    padding: 6px 8px !important;
    border-radius: var(--jk-radius-sm) !important;
    border-color: var(--jk-border) !important;
    font-size: 0.875rem;
    min-height: unset;
}
/* Centre the chosen value / tags vertically (flex items stretched to the control's
   min-height left the text at the top with empty space under it). */
.ts-wrapper .ts-control { align-items: center; }
.ts-wrapper.single .ts-control > .item { line-height: 1.25rem; }
/* Multi-select tags: the remove × sits as a small round badge on the tag's top-right corner. */
.ts-wrapper.multi.plugin-remove_button .ts-control > .item {
    position: relative; margin: 6px 10px 2px 0 !important; padding: 2px 8px !important;
    border-radius: 6px; background: #eef2ff; border: 1px solid #c7d2fe; color: #3730a3; font-size: 0.8rem; font-weight: 500;
}
.ts-wrapper.multi.plugin-remove_button .ts-control > .item .remove {
    position: absolute; top: -7px; right: -7px; display: flex; align-items: center; justify-content: center;
    width: 16px; height: 16px; padding: 0 !important; margin: 0 !important; border: 0 !important; border-radius: 9999px;
    background: #64748b; color: #fff !important; font-size: 12px; line-height: 1; text-decoration: none; z-index: 2;
}
.ts-wrapper.multi.plugin-remove_button .ts-control > .item .remove:hover { background: #e11d48 !important; }
.ts-dropdown {
    border-radius: var(--jk-radius-sm);
    font-size: 0.875rem;
    z-index: 9999;
}
.jk-input.py-2  { padding-top: 0.5rem;  padding-bottom: 0.5rem; }
.jk-input.py-3  { padding-top: 0.75rem; padding-bottom: 0.75rem; }
.jk-input.text-xs { font-size: 0.75rem; }

.jk-textarea {
    resize: vertical;
    min-height: 90px;
}

.jk-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.5rem;
}

.jk-file-input {
    width: 100%;
    padding: 0.5rem;
    font-size: 0.875rem;
    color: var(--jk-text-muted);
    border: 2px dashed var(--jk-border);
    border-radius: var(--jk-radius-sm);
    cursor: pointer;
    transition: var(--jk-transition);
}

.jk-file-input:hover {
    border-color: var(--jk-primary);
    background: var(--jk-primary-light);
}

.jk-label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--jk-text);
    margin-bottom: 0.375rem;
}

.jk-form-group {
    margin-bottom: 1.25rem;
}

.jk-form-error {
    font-size: 0.75rem;
    color: var(--jk-danger);
    margin-top: 0.25rem;
}

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

.jk-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.1875rem 0.625rem;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    border-radius: 0.25rem;
    white-space: nowrap;
}

/* Larger variant — e.g. the portal chat header, where the status badge is
   a primary piece of info rather than a dense table-row label. */
.jk-badge-lg {
    padding: 0.4375rem 1rem;
    font-size: 0.8125rem;
    border-radius: 0.375rem;
}

/* Status badges — solid fill (not a pale rounded pill), same hex colors as
   CaseRecord.STATUS_META in cases/models.py so this matches the Kanban column
   headers and the Status filter chips, which already use the solid color. */
.jk-badge-open {
    background: #1d4ed8;
    color: #fff;
}

.jk-badge-investigating {
    background: #d97706;
    color: #fff;
}

.jk-badge-pending {
    background: #0284c7;
    color: #fff;
}

.jk-badge-resolved {
    background: #059669;
    color: #fff;
}

.jk-badge-closed {
    background: #475569;
    color: #fff;
}

.jk-badge-new {
    background: #4f46e5;
    color: #fff;
}

.jk-badge-assigned {
    background: #9333ea;
    color: #fff;
}

.jk-badge-pending-external {
    background: #db2777;
    color: #fff;
}

.jk-badge-rejected {
    background: #dc2626;
    color: #fff;
}

.jk-badge-cancelled {
    background: #57534e;
    color: #fff;
}

.jk-badge-approval {
    background: #ccfbf1;
    color: #0f766e;
}

.jk-badge-revision {
    background: #ffedd5;
    color: #c2410c;
}

.jk-badge-wa {
    background: #dcfce7;
    color: #15803d;
}

.jk-badge-email {
    background: #e0e7ff;
    color: #4338ca;
}

.jk-badge-web {
    background: #f0f9ff;
    color: #0369a1;
}

.jk-badge-sla-ok {
    background: #d1fae5;
    color: #065f46;
}

.jk-badge-sla-warn {
    background: #fef3c7;
    color: #92400e;
}

.jk-badge-sla-breach {
    background: #fee2e2;
    color: #991b1b;
}

/* =============================================================
   CHAT PANEL — Full Chat App Layout
   ============================================================= */

/* --- Panel Container --- */
.jk-chat-panel {
    display: flex;
    flex-direction: column;
    background: var(--jk-surface);
    border: 1px solid var(--jk-border);
    border-radius: var(--jk-radius);
    box-shadow: var(--jk-shadow);
    overflow: hidden;
    max-height: calc(100vh - 220px);
    max-height: calc(100dvh - 220px);
    min-height: 500px;
}

/* --- Drag & drop attachment overlay (static/js/chat-dropzone.js) --- */
.jk-chat-dropzone {
    position: absolute;
    inset: 0;
    z-index: 60;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(238, 242, 255, 0.92);
    border: 2px dashed #6366f1;
    border-radius: inherit;
    pointer-events: none;
}
.jk-chat-dropzone.is-active { display: flex; }
.jk-chat-dropzone__inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.375rem;
    color: #4338ca;
    text-align: center;
}
.jk-chat-dropzone__title { font-size: 0.95rem; font-weight: 700; }
.jk-chat-dropzone__hint { font-size: 0.75rem; color: #6366f1; }

/* --- Panel Header --- */
.jk-chat-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1.25rem;
    background: linear-gradient(135deg, #1e293b, #334155);
    color: #f1f5f9;
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.jk-chat-panel__header-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
    flex: 1 1 0;
}

.jk-chat-panel__header-info > div {
    min-width: 0;
}

.jk-chat-panel__header-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9375rem;
    color: #fff;
    flex-shrink: 0;
}

.jk-chat-panel__header-name {
    font-weight: 700;
    font-size: 0.9375rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.jk-chat-panel__header-meta {
    font-size: 0.75rem;
    opacity: 0.7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- Panel Body (scrollable messages area) --- */
.jk-chat-panel__body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
}

/* --- Message List --- */
.jk-chat-messages {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 1rem 0.75rem;
    background:
        radial-gradient(circle at 20% 80%, rgba(99, 102, 241, 0.03) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(14, 165, 233, 0.03) 0%, transparent 50%),
        #f0f2f5;
    min-height: 100%;
}

/* --- Single Message Row --- */
.jk-msg {
    display: flex;
    gap: 0.5rem;
    max-width: 85%;
    min-width: 0;
    animation: jk-msg-in 0.2s ease;
}

@keyframes jk-msg-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.jk-msg--in {
    align-self: flex-start;
}

.jk-msg--out {
    align-self: flex-end;
    flex-direction: row-reverse;
}

/* --- Avatar --- */
.jk-msg__avatar {
    flex-shrink: 0;
    padding-top: 1.25rem;
}

.jk-msg__avatar-circle {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
}

.jk-msg__avatar--client {
    background: #cbd5e1;
    color: #334155;
}

.jk-msg__avatar--staff {
    background: var(--jk-primary-light);
    color: var(--jk-primary-hover);
}

/* --- Message Content Wrapper --- */
.jk-msg__content {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* --- Sender Info Row --- */
.jk-msg__info {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0 0.25rem;
    margin-bottom: 0.125rem;
}

.jk-msg__name {
    font-size: 0.6875rem;
    font-weight: 700;
    color: var(--jk-text-muted);
}

.jk-msg--out .jk-msg__info {
    flex-direction: row-reverse;
}

.jk-msg__badge {
    display: inline-flex;
    align-items: center;
    gap: 0.1875rem;
    font-size: 0.5625rem;
    font-weight: 700;
    padding: 0.0625rem 0.3125rem;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.jk-msg__badge--wa {
    background: #dcfce7;
    color: #15803d;
}

.jk-msg__badge--email {
    background: #e0e7ff;
    color: #4338ca;
}

.jk-msg__time {
    font-size: 0.625rem;
    color: #94a3b8;
}

.jk-msg__bubble {
    padding: 0.625rem 0.875rem;
    border-radius: 12px;
    font-size: 0.875rem;
    line-height: 1.55;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: normal;
    position: relative;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
    min-width: 0;
}

.jk-msg__bubble--in {
    background: #ffffff;
    color: var(--jk-text);
    border-top-left-radius: 4px;
}

.jk-msg__bubble--out {
    background: #d9fdd3;
    color: #1a2e1a;
    border-top-right-radius: 4px;
}

.jk-msg__bubble--escalate {
    background: #bae6fd !important;
    /* Tailwind sky-200 */
    color: #0c4a6e !important;
    /* Tailwind sky-900 */
}

.jk-msg__text {
    white-space: pre-wrap;
    overflow-wrap: break-word;
    word-break: normal;
}

.jk-msg__text a {
    word-break: break-all;
}

/* bubble-content: renders Quill HTML inside chat bubbles (desk + portal) */
.bubble-content p { margin: 0 0 0.2rem; }
.bubble-content p:last-child { margin-bottom: 0; }
.bubble-content pre.ql-syntax { background: rgba(0,0,0,0.3); border-radius: 0.375rem; padding: 0.5rem 0.75rem; font-size: 0.72rem; font-family: monospace; white-space: pre-wrap; overflow-x: auto; margin: 0.25rem 0; }
.bubble-content code { background: rgba(0,0,0,0.12); border-radius: 0.2rem; padding: 0.05rem 0.3rem; font-size: 0.8em; font-family: monospace; }
.bubble-content ul { list-style: disc; padding-left: 1.25rem; margin: 0.2rem 0; }
.bubble-content ol { list-style: decimal; padding-left: 1.25rem; margin: 0.2rem 0; }
.bubble-content strong { font-weight: 700; }
.bubble-content em { font-style: italic; }
.bubble-content s { text-decoration: line-through; }
.bubble-content a { text-decoration: underline; opacity: 0.85; word-break: break-all; }

/* Formatted text (core.rich_text) shown outside chat bubbles: comments, RCA */
.rich-text p { margin: 0; }
.rich-text ul,
.rich-textarea .ql-editor ul { list-style: disc; padding-left: 1.25rem; margin: 0.15rem 0; }
.rich-text ol,
.rich-textarea .ql-editor ol { list-style: decimal; padding-left: 1.25rem; margin: 0.15rem 0; }
/* Sub-items are nested lists on display (core.rich_text.nest_lists), marked like the editor */
.rich-text ol ol { list-style-type: lower-alpha; margin: 0; }
.rich-text ol ol ol { list-style-type: lower-roman; }
.rich-text ul ul, .rich-text ol ul { margin: 0; }
.rich-text ul ul { list-style-type: circle; }
.rich-text strong { font-weight: 700; }
.rich-text em { font-style: italic; }
.rich-text s { text-decoration: line-through; }
.rich-text .ql-indent-1, .bubble-content .ql-indent-1, .rich-textarea .ql-indent-1 { margin-left: 1.5em; }
.rich-text .ql-indent-2, .bubble-content .ql-indent-2, .rich-textarea .ql-indent-2 { margin-left: 3em; }
.rich-text .ql-indent-3, .bubble-content .ql-indent-3, .rich-textarea .ql-indent-3 { margin-left: 4.5em; }
/* Quill 2 (submit-ticket page) draws its own list markers: keep the indent as with Quill 1 */
.rich-textarea .ql-editor ol:has(> li[data-list]) { padding-left: 0.25rem; }
.rich-textarea .ql-editor li[data-list] { padding-left: 1.5em; margin-left: 0; }
.rich-textarea .ql-editor li[data-list].ql-indent-1 { padding-left: 3em; }
.rich-textarea .ql-editor li[data-list].ql-indent-2 { padding-left: 4.5em; }
.rich-textarea .ql-editor li[data-list].ql-indent-3 { padding-left: 6em; }

/* Toolbar-less editor that replaces a textarea (static/js/rich-textarea.js).
   The box keeps the textarea's classes, so it looks the same. */
.rich-textarea { position: relative; height: auto; cursor: text; overflow-y: auto; }
/* Pages that load Quill's snow.css for other editors (submit ticket) would get its
   Helvetica 13px, editor padding and italic placeholder: the box already does that part. */
.rich-textarea.ql-container { font-family: inherit; height: auto; }
.rich-textarea.jk-textarea.ql-container { font-size: 0.875rem; }
.rich-textarea .ql-editor {
    position: relative;
    padding: 0;
    height: auto;
    overflow-y: visible;
    line-height: inherit;
    outline: none;
    white-space: pre-wrap;
    overflow-wrap: break-word;
    min-height: calc(var(--rich-rows, 2) * 1.5em);
    tab-size: 4;
}
.rich-textarea .ql-editor p { margin: 0; }
/* The box shows focus (:focus-within below); a contenteditable is always
   :focus-visible, so the global ring in base.html would draw a second box. */
.rich-textarea .ql-editor:focus-visible { outline: none !important; }
.rich-textarea .ql-editor.ql-blank::before {
    content: attr(data-placeholder);
    position: absolute;
    left: 0;
    right: 0;
    color: #94a3b8;
    font-style: normal;
    pointer-events: none;
}
.rich-textarea .ql-clipboard { position: absolute; left: -100000px; height: 1px; overflow-y: hidden; top: 50%; }
.rich-textarea.jk-textarea { max-height: 24rem; }
.rich-textarea.jk-textarea:focus-within,
.rich-textarea.jk-input:focus-within {
    outline: none;
    border-color: var(--jk-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}
.rich-textarea.jk-input:focus-within { background: #fff; }
.rich-textarea.jk-reply-bar__input:focus-within {
    background: #ffffff;
    border-color: var(--jk-primary);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.02), 0 0 0 3px rgba(99, 102, 241, 0.1);
}
.has-error .rich-textarea {
    border-color: #ef4444 !important;
    box-shadow: 0 0 0 2px #ef4444 !important;
    background-color: #fef2f2 !important;
}

/* --- Attachments inside bubble --- */
.jk-msg__file {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.625rem;
    background: rgba(0, 0, 0, 0.04);
    border-radius: 6px;
    font-size: 0.8125rem;
    text-decoration: none;
    color: inherit;
    transition: var(--jk-transition);
}

.jk-msg__file:hover {
    background: rgba(0, 0, 0, 0.08);
}

.jk-msg__file small {
    color: #94a3b8;
    font-size: 0.6875rem;
}

/* --- Audio Player in Chat --- */
.jk-msg__audio-player {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    max-width: 300px;
    padding: 0.5rem 0.625rem;
    background: rgba(0, 0, 0, 0.04);
    border-radius: 10px;
    margin-top: 0.25rem;
}

.jk-msg__audio-icon {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #6366f1;
    color: #fff;
    border-radius: 50%;
    margin-top: 2px;
}

.jk-msg__audio-body {
    flex: 1;
    min-width: 0;
}

.jk-msg__audio-control {
    width: 100%;
    height: 36px;
    border-radius: 6px;
}

.jk-msg__audio-control::-webkit-media-controls-panel {
    background: transparent;
}

.jk-msg__audio-meta {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-size: 0.6875rem;
    color: #94a3b8;
    margin-top: 0.125rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.jk-msg__audio-meta span {
    overflow: hidden;
    text-overflow: ellipsis;
}

.jk-msg__bubble--out .jk-msg__audio-player {
    background: rgba(255, 255, 255, 0.15);
}

.jk-msg__bubble--out .jk-msg__audio-meta {
    color: rgba(255, 255, 255, 0.6);
}

/* --- Image Thumbnails in Chat --- */
.jk-msg__files {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.jk-msg__img-thumb {
    width: 120px;
    height: 120px;
    object-fit: cover;
    border-radius: 8px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}

.jk-msg__img-thumb:hover {
    border-color: #6366f1;
    transform: scale(1.03);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* --- Lightbox Overlay --- */
.jk-lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
}

.jk-lightbox.active {
    opacity: 1;
    visibility: visible;
}

.jk-lightbox__img {
    max-width: 90vw;
    max-height: calc(100vh - 160px);
    max-height: calc(100dvh - 160px);
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.4);
    transition: transform 0.15s ease-out;
    transform-origin: center center;
}

.jk-lightbox__close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    transition: background 0.15s;
}

.jk-lightbox__close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.jk-lightbox__nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 2.75rem;
    height: 2.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 1.25rem;
    cursor: pointer;
    transition: background 0.15s;
}

.jk-lightbox__nav:hover {
    background: rgba(255, 255, 255, 0.3);
}

.jk-lightbox__nav--prev { left: 1rem; }
.jk-lightbox__nav--next { right: 1rem; }

.jk-lightbox__counter {
    position: absolute;
    bottom: 5.5rem;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.875rem;
    font-weight: 500;
}

.jk-lightbox__filename {
    position: absolute;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.8125rem;
    font-weight: 500;
    max-width: 60vw;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.jk-lightbox__main {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: calc(100% - 100px);
    padding: 3rem 4rem;
}

/* --- Thumbnail Strip --- */
.jk-lightbox__strip {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.3) transparent;
}

.jk-lightbox__strip::-webkit-scrollbar {
    height: 4px;
}

.jk-lightbox__strip::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.3);
    border-radius: 2px;
}

.jk-lightbox__strip-thumb {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: 6px;
    cursor: pointer;
    border: 2px solid transparent;
    opacity: 0.5;
    transition: opacity 0.15s, border-color 0.15s, transform 0.15s;
    flex-shrink: 0;
}

.jk-lightbox__strip-thumb:hover {
    opacity: 0.8;
    transform: scale(1.05);
}

.jk-lightbox__strip-thumb.active {
    opacity: 1;
    border-color: #6366f1;
    box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.5);
}

/* --- Zoom Controls --- */
.jk-lightbox__zoom-controls {
    position: absolute;
    top: 1rem;
    right: 3.5rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    border-radius: 8px;
    padding: 0.25rem 0.5rem;
    z-index: 10;
}

.jk-lightbox__zoom-controls button {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
}

.jk-lightbox__zoom-controls button:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

.jk-lightbox__zoom-controls span {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.75rem;
    font-weight: 500;
    min-width: 40px;
    text-align: center;
    user-select: none;
}

/* --- Empty State --- */
.jk-chat-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    color: #94a3b8;
    min-height: 300px;
}

.jk-chat-empty p {
    font-size: 0.9375rem;
    font-weight: 600;
    margin-top: 0.75rem;
}

.jk-chat-empty small {
    font-size: 0.8125rem;
    opacity: 0.7;
}

/* --- Panel Footer / Reply Bar --- */
.jk-chat-panel__footer {
    flex-shrink: 0;
    padding: 0.75rem 1rem;
    background: #ffffff;
    border-top: none;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.06);
    position: relative;
    z-index: 10;
}

.jk-reply-bar {
    display: flex;
    align-items: flex-end;
    gap: 0.625rem;
}

.jk-reply-bar__attach {
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: #64748b;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
    background: #f1f5f9;
    border: 1px solid transparent;
}

.jk-reply-bar__attach:hover {
    background: #eef2ff;
    color: var(--jk-primary);
    border-color: rgba(99, 102, 241, 0.2);
    transform: scale(1.08);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.08);
}

.jk-reply-bar__attach:active {
    transform: scale(0.95);
}

.jk-reply-bar__input-wrap {
    flex: 1;
    min-width: 0;
}

.jk-reply-bar__input {
    width: 100%;
    padding: 0.6875rem 1.125rem;
    font-size: 0.875rem;
    line-height: 1.45;
    color: var(--jk-text);
    background: #f8fafc;
    border: 1.5px solid #e2e8f0;
    border-radius: 22px;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
    resize: none;
    overflow-y: auto;
    max-height: 120px;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.04);
}

.jk-reply-bar__input:focus {
    outline: none;
    background: #ffffff;
    border-color: var(--jk-primary);
    box-shadow:
        inset 0 1px 2px rgba(0, 0, 0, 0.02),
        0 0 0 3px rgba(99, 102, 241, 0.1);
}

.jk-reply-bar__input::placeholder {
    color: #94a3b8;
    font-weight: 400;
}

.jk-reply-bar__file-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    margin-top: 0.5rem;
    padding: 0.3125rem 0.75rem;
    background: linear-gradient(135deg, #eef2ff, #e0e7ff);
    color: #4338ca;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    max-width: 100%;
    border: 1px solid rgba(99, 102, 241, 0.15);
    animation: jk-file-tag-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes jk-file-tag-in {
    from {
        opacity: 0;
        transform: translateY(6px) scale(0.9);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.jk-reply-bar__file-tag svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.jk-reply-bar__file-tag span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.jk-reply-bar__file-remove {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.875rem;
    color: #6366f1;
    padding: 0 0 0 0.125rem;
    line-height: 1;
    opacity: 0.6;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
}

.jk-reply-bar__file-remove:hover {
    opacity: 1;
    background: rgba(99, 102, 241, 0.15);
    color: var(--jk-danger);
}

.jk-reply-bar__send {
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    color: #ffffff;
    border: none;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
    box-shadow: 0 3px 12px rgba(99, 102, 241, 0.3);
    padding: 0;
}

.jk-reply-bar__send:hover:not(:disabled) {
    background: linear-gradient(135deg, #4f46e5, #4338ca);
    transform: scale(1.1);
    box-shadow: 0 5px 20px rgba(99, 102, 241, 0.4);
}

.jk-reply-bar__send:active:not(:disabled) {
    transform: scale(0.95);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.jk-reply-bar__send:disabled {
    background: #e2e8f0;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
    opacity: 0.7;
}

/* --- Voice Recorder --- */
.jk-reply-bar__mic {
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: #ffffff;
    border: none;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
}

.jk-reply-bar__mic:hover:not(:disabled) {
    background: linear-gradient(135deg, #16a34a, #15803d);
    transform: scale(1.1);
    box-shadow: 0 5px 20px rgba(34, 197, 94, 0.4);
}

.jk-reply-bar__mic:disabled {
    background: #e2e8f0;
    cursor: not-allowed;
    opacity: 0.7;
}

.jk-reply-bar__recording {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    padding: 0.5rem 0.75rem;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 999px;
}

.jk-reply-bar__rec-dot {
    width: 10px;
    height: 10px;
    background: #ef4444;
    border-radius: 50%;
    flex-shrink: 0;
    animation: jk-pulse-rec 1s ease-in-out infinite;
}

@keyframes jk-pulse-rec {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.8); }
}

.jk-reply-bar__rec-send {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    color: #fff;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s;
}

.jk-reply-bar__rec-send:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

/* --- Message Actions (Delete, Edit, React) --- */
.jk-msg__bubble {
    position: relative;
}

.jk-msg__action-trigger {
    position: absolute;
    top: 2px;
    right: -28px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: rgba(0, 0, 0, 0.3);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s;
    z-index: 2;
}

.jk-msg__bubble:hover .jk-msg__action-trigger {
    opacity: 1;
}

.jk-msg__action-trigger:hover {
    background: rgba(0, 0, 0, 0.08);
    color: rgba(0, 0, 0, 0.6);
}

.jk-msg__bubble--out .jk-msg__action-trigger {
    color: rgba(0, 0, 0, 0.35);
    right: auto;
    left: -28px;
}

.jk-msg__bubble--out .jk-msg__action-trigger:hover {
    background: rgba(0, 0, 0, 0.08);
    color: rgba(0, 0, 0, 0.7);
}

.jk-msg__bubble--out .jk-msg__action-menu {
    right: auto;
    left: -28px;
}

.jk-msg__action-menu {
    position: absolute;
    top: 28px;
    right: 4px;
    min-width: 140px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    z-index: 20;
    overflow: hidden;
    padding: 0.25rem 0;
}

.jk-msg__quick-react {
    display: flex;
    align-items: center;
    gap: 0.125rem;
    padding: 0.375rem 0.5rem;
    border-bottom: 1px solid #f1f5f9;
}

.jk-msg__react-btn {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.15s, transform 0.15s;
}

.jk-msg__react-btn:hover {
    background: #f1f5f9;
    transform: scale(1.2);
}

.jk-msg__action-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: none;
    background: transparent;
    font-size: 0.8125rem;
    color: #475569;
    cursor: pointer;
    transition: background 0.15s;
    text-align: left;
}

.jk-msg__action-item:hover {
    background: #f8fafc;
}

.jk-msg__action-item--danger {
    color: #ef4444;
}

.jk-msg__action-item--danger:hover {
    background: #fef2f2;
}

/* Inline edit */
.jk-msg__edit-wrap {
    padding: 0.25rem 0;
}

.jk-msg__edit-input {
    width: 100%;
    padding: 0.375rem 0.5rem;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.8125rem;
    resize: vertical;
    outline: none;
    color: #1e293b;
}

.jk-msg__edit-input:focus {
    border-color: #6366f1;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
}

.jk-msg__edit-cancel {
    padding: 0.25rem 0.5rem;
    font-size: 0.6875rem;
    border: 1px solid #e2e8f0;
    background: #fff;
    border-radius: 4px;
    cursor: pointer;
    color: #64748b;
}

.jk-msg__edit-cancel:hover {
    background: #f8fafc;
}

.jk-msg__edit-save {
    padding: 0.25rem 0.5rem;
    font-size: 0.6875rem;
    border: none;
    background: #6366f1;
    color: #fff;
    border-radius: 4px;
    cursor: pointer;
}

.jk-msg__edit-save:hover {
    background: #4f46e5;
}

/* Edited tag */
.jk-msg__edited-tag {
    font-size: 0.625rem;
    font-style: italic;
    opacity: 0.5;
    margin-left: 0.375rem;
}

/* Reactions */
.jk-msg__reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-top: 0.375rem;
}

.jk-msg__reaction-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    background: rgba(0, 0, 0, 0.06);
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 0.125rem 0.375rem;
    cursor: pointer;
    transition: background 0.15s, transform 0.15s, border-color 0.15s;
}

.jk-msg__reaction-badge:hover {
    background: rgba(0, 0, 0, 0.12);
    transform: scale(1.15);
    border-color: rgba(0, 0, 0, 0.1);
}

.jk-msg__bubble--out .jk-msg__reaction-badge {
    background: rgba(255, 255, 255, 0.2);
}

/* --- Escalate Selection Mode --- */
.jk-escalate-select-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-basis: 100%;
    padding: 8px 16px;
    background: linear-gradient(135deg, #eef2ff, #e0e7ff);
    border-top: 1px solid #c7d2fe;
    margin: 8px -1.25rem -0.875rem;
    gap: 8px;
    min-height: 38px;
}

/* Checkbox hidden by default, shown when parent #chat-thread has .escalate-selecting */
.jk-msg__select-check {
    display: none;
    align-items: flex-start;
    padding-top: 10px;
    cursor: pointer;
    flex-shrink: 0;
    z-index: 5;
}

.escalate-selecting .jk-msg__select-check {
    display: flex;
}

.jk-msg__select-check input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #4f46e5;
}

/* --- Inline Delivery Status Indicators --- */
.jk-msg__status {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.625rem;
    font-weight: 600;
    margin-left: 0.375rem;
    vertical-align: middle;
}

.jk-msg__status--success {
    color: #22c55e;
}

.jk-msg__status--pending {
    color: #f59e0b;
}

.jk-msg__status--failed {
    color: #ef4444;
    cursor: pointer;
    position: relative;
}

.jk-msg__error-popup {
    position: absolute;
    bottom: calc(100% + 8px);
    right: -4px;
    background: #ffffff;
    border: 1px solid #fecaca;
    border-radius: 10px;
    font-size: 0.6875rem;
    font-weight: 400;
    width: 240px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
    z-index: 60;
    overflow: hidden;
}

.jk-msg__error-popup::after {
    content: '';
    position: absolute;
    top: 100%;
    right: 10px;
    border: 6px solid transparent;
    border-top-color: #fecaca;
}

.jk-msg__error-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.375rem 0.625rem;
    background: #fef2f2;
    border-bottom: 1px solid #fecaca;
    font-weight: 700;
    font-size: 0.8875rem;
    color: #dc2626;
}

.jk-msg__error-popup-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    color: #dc2626;
    opacity: 0.6;
    line-height: 1;
    padding: 0;
}

.jk-msg__error-popup-close:hover {
    opacity: 1;
}

.jk-msg__error-popup-body {
    padding: 0.5rem 0.625rem;
    color: #64748b;
    line-height: 1.4;
    word-break: break-word;
    font-family: ui-monospace, monospace;
    font-size: 0.6235rem;
}

@keyframes jk-status-spin {
    to {
        transform: rotate(360deg);
    }
}

.jk-msg__status--pending svg {
    animation: jk-status-spin 1s linear infinite;
}

/* --- Tablet/Desktop Responsive Chat Header (in split panel) --- */
@media (min-width: 769px) and (max-width: 1280px) {
    .jk-chat-panel__header {
        padding: 0.625rem 0.875rem;
        gap: 0.375rem;
    }

    .jk-chat-panel__header-avatar {
        width: 32px;
        height: 32px;
        font-size: 0.8125rem;
    }

    .jk-chat-panel__header-info {
        gap: 0.5rem;
    }

    .jk-chat-panel__header-name {
        font-size: 0.8125rem;
    }

    .jk-chat-panel__header-meta {
        font-size: 0.6875rem;
    }
}

/* --- Mobile Responsive Chat --- */
@media (max-width: 1024px) {
    .jk-chat-panel {
        max-height: none;
        min-height: auto;
    }

    .jk-chat-panel__body {
        max-height: 60vh;
        min-height: 300px;
    }
}

@media (max-width: 768px) {
    .jk-chat-panel {
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    .jk-chat-panel__header {
        padding: 0.5rem 0.75rem;
        gap: 0.375rem;
    }

    .jk-chat-panel__header-avatar {
        width: 30px;
        height: 30px;
        font-size: 0.75rem;
    }

    .jk-chat-panel__header-info {
        gap: 0.5rem;
    }

    .jk-chat-panel__header-name {
        font-size: 0.8125rem;
    }

    .jk-chat-panel__header-meta {
        font-size: 0.625rem;
    }

    .jk-msg {
        max-width: 92%;
    }

    .jk-chat-messages {
        padding: 0.75rem 0.5rem;
    }

    .jk-chat-panel__body {
        max-height: 55vh;
        min-height: 250px;
    }

    .jk-msg__avatar {
        display: none;
    }

    .jk-reply-bar__input {
        font-size: 1rem;
    }
}

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

.jk-table-wrapper {
    overflow-x: auto;
    border-radius: var(--jk-radius);
    border: 1px solid var(--jk-border);
    background: var(--jk-surface);
    -webkit-overflow-scrolling: touch;
    position: relative;
}

.jk-table {
    width: 100%;
    min-width: 600px;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.jk-table thead {
    background: var(--jk-surface-alt);
}

.jk-table th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--jk-text-muted);
    border-bottom: 1px solid var(--jk-border);
    white-space: nowrap;
}

.jk-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #f1f5f9;
    color: var(--jk-text);
    vertical-align: middle;
}

.jk-table tbody tr {
    transition: var(--jk-transition);
}

.jk-table tbody tr:hover {
    background: #f8fafc;
}

.jk-table tbody tr:last-child td {
    border-bottom: none;
}

.jk-table-link {
    color: var(--jk-primary);
    text-decoration: none;
    font-weight: 600;
}

.jk-table-link:hover {
    text-decoration: underline;
}

/* =============================================================
   SPLIT PANEL
   ============================================================= */

.jk-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    align-items: start;
}

@media (max-width: 1024px) {
    .jk-split {
        grid-template-columns: 1fr;
    }
}

/* =============================================================
   ALERTS / TOASTS
   ============================================================= */

.jk-alert {
    padding: 0.75rem 1rem;
    border-radius: var(--jk-radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.jk-alert-success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.jk-alert-error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.jk-alert-info {
    background: #e0f2fe;
    color: #075985;
    border: 1px solid #bae6fd;
}

/* =============================================================
   CATEGORY GRID
   ============================================================= */

.jk-category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
}

.jk-category-card {
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    transition: var(--jk-transition);
    cursor: pointer;
}

.jk-category-card:hover {
    box-shadow: var(--jk-shadow-lg);
    transform: translateY(-3px);
    border-color: var(--jk-primary);
}

/* Disable conflicting hover on inner <a> to prevent overflow:hidden clipping */
.jk-category-card .jk-card-clickable {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.jk-category-card .jk-card-clickable:hover {
    box-shadow: none;
    transform: none;
    border-color: transparent;
}

.jk-category-card .jk-card-body {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.jk-category-action {
    margin-top: auto;
    padding-top: 0.875rem;
    border-top: 1px solid var(--jk-border);
}

.jk-category-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.375rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-bottom: 0.875rem;
    background: var(--jk-primary-light);
    color: var(--jk-primary);
    transition: var(--jk-transition);
    flex-shrink: 0;
}

.jk-card-clickable:hover .jk-category-icon {
    background: var(--jk-primary);
    color: #fff;
    transform: scale(1.04);
}

.jk-category-copy {
    min-width: 0;
    flex: 1;
}

.jk-category-name {
    font-weight: 700;
    font-size: 0.9375rem;
    margin-bottom: 0.3rem;
    color: var(--jk-text);
    letter-spacing: -0.015em;
    line-height: 1.35;
}

.jk-category-desc {
    font-size: 0.8rem;
    color: var(--jk-text-muted);
    line-height: 1.55;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.jk-marquee {
    overflow: hidden;
    max-width: 100%;
    min-width: 0;
}

.jk-marquee-track {
    display: inline-flex;
    width: max-content;
}

.jk-marquee-track span {
    flex-shrink: 0;
    white-space: nowrap;
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--jk-text-muted);
    padding-right: 2.5rem;
}

.jk-marquee:not(.is-overflow) .jk-marquee-track {
    display: block;
    width: 100%;
}

.jk-marquee:not(.is-overflow) .jk-marquee-track span:first-child {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 0;
}

.jk-marquee:not(.is-overflow) .jk-marquee-track span:last-child {
    display: none;
}

.jk-marquee.is-overflow {
    -webkit-mask-image: linear-gradient(to right, #000 88%, transparent);
    mask-image: linear-gradient(to right, #000 88%, transparent);
}

.jk-marquee.is-overflow .jk-marquee-track {
    animation: jk-marquee-scroll var(--jk-marquee-duration, 18s) linear infinite;
}

.jk-marquee.is-overflow:hover .jk-marquee-track,
.jk-marquee.is-overflow:focus-within .jk-marquee-track,
.jk-category-card:hover .jk-marquee.is-overflow .jk-marquee-track {
    animation-play-state: paused;
}

@keyframes jk-marquee-scroll {
    from { transform: translateX(0); }
    to { transform: translateX(-50%); }
}

@media (prefers-reduced-motion: reduce) {
    .jk-marquee.is-overflow .jk-marquee-track {
        animation: none;
    }
    .jk-marquee.is-overflow .jk-marquee-track span:first-child {
        display: block;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        padding-right: 0;
    }
    .jk-marquee.is-overflow .jk-marquee-track span:last-child {
        display: none;
    }
}

.jk-category-card .jk-card-body {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.jk-category-card .jk-card-body .jk-category-action {
    margin-top: auto;
    padding-top: 0.875rem;
    border-top: 1px solid var(--jk-border);
}

/* =============================================================
   UTILITIES
   ============================================================= */

.jk-divider {
    border: none;
    border-top: 1px solid var(--jk-border);
    margin: 1.5rem 0;
}

.jk-empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--jk-text-muted);
}

.jk-empty-state-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    opacity: 0.5;
}

.jk-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Running-text ("marquee") truncation — on hover, the inner span slides
   left by exactly its own overflow (computed in JS, see jk-marquee-init
   in base.html) so the full text scrolls into view, then eases back on
   mouse-leave. Falls back to a plain ellipsis-truncated label until
   hovered. */
.jk-marquee {
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    white-space: nowrap;
    vertical-align: bottom;
}

.jk-marquee-inner {
    display: inline-block;
    white-space: nowrap;
    transform: translateX(0);
}

/* Auto-running variant — no hover needed. JS (marquee-truncate.js) measures
   overflow and, only when the text actually overflows, sets
   --jk-marquee-shift/--jk-marquee-duration and adds .jk-marquee-animate to
   start the loop: pause at the start, scroll to reveal the tail, pause,
   scroll back, repeat. */
.jk-marquee-auto .jk-marquee-inner {
    transform: translateX(0);
}

.jk-marquee-auto.jk-marquee-animate .jk-marquee-inner {
    animation: jk-marquee-auto-scroll var(--jk-marquee-duration, 6s) ease-in-out infinite;
}

@keyframes jk-marquee-auto-scroll {
    0%, 15% { transform: translateX(0); }
    50%, 65% { transform: translateX(var(--jk-marquee-shift, 0px)); }
    100% { transform: translateX(0); }
}

/* HTMX loading indicator */
.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator {
    display: inline-block;
}

.htmx-request.htmx-indicator {
    display: inline-block;
}

.jk-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(99, 102, 241, 0.2);
    border-top-color: var(--jk-primary);
    border-radius: 50%;
    animation: jk-spin 0.6s linear infinite;
}

@keyframes jk-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Fade-in for HTMX swaps */
.htmx-added {
    animation: jk-fade-in 0.3s ease;
}

/* ...but not for the chat thread: it refreshes in place every few seconds,
   and fading the whole thread in each time looks like flicker. */
#chat-thread .htmx-added {
    animation: none;
}

@keyframes jk-fade-in {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* =============================================================
   DOCS PAGE — Grid helpers (responsive via media queries below)
   ============================================================= */

.docs-grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); }
.docs-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); }

/* =============================================================
   RESPONSIVE — Sidebar overlay (tablet & mobile)
   ============================================================= */

/* Tablet + Mobile: sidebar overlays content (≤1024px) */
@media (max-width: 1024px) {
    .jk-sidebar {
        transform: translateX(-100%);
    }

    .jk-sidebar.open {
        transform: translateX(0);
    }

    .jk-main {
        margin-left: 0 !important;
    }
}

/* Mobile-specific adjustments (≤768px) */
@media (max-width: 768px) {
    .jk-content {
        padding: 1rem;
    }

    .jk-topbar {
        padding: 0.75rem 1rem;
    }

    .jk-split {
        grid-template-columns: 1fr;
    }

    .jk-category-grid {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    }

    .jk-table-wrapper {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .jk-table th,
    .jk-table td {
        padding: 0.5rem 0.625rem;
        font-size: 0.8125rem;
    }

    .jk-table th {
        font-size: 0.6875rem;
    }

    .jk-topbar-title {
        font-size: 1rem;
        max-width: 180px;
    }

    .jk-topbar-actions {
        gap: 0.375rem;
    }

    .jk-card-body {
        padding: 1rem;
    }

    .jk-card-header {
        padding: 1rem;
        font-size: 0.8125rem;
    }

    .jk-btn {
        padding: 0.4375rem 0.75rem;
        font-size: 0.8125rem;
    }

    .jk-btn-sm {
        padding: 0.3125rem 0.625rem;
        font-size: 0.75rem;
    }

    .jk-category-grid {
        grid-template-columns: 1fr;
    }

    /* ── Docs pages: collapse main 2-col layout to single column ── */
    #docs-pdf-root {
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0 !important;
    }
    /* All direct children stretch to full width */
    #docs-pdf-root > * {
        width: 100% !important;
        box-sizing: border-box !important;
        min-width: 0 !important;
    }
    #docs-toc-sidebar {
        position: static !important;
        top: auto !important;
        margin-bottom: 1rem;
        order: -1;
    }
    /* Hide desktop TOC card-header — mobile button replaces it */
    #docs-toc-sidebar > .jk-card-header {
        display: none !important;
    }
    /* TOC nav body: hidden when collapsed, scrollable when open */
    #docs-toc-sidebar > .jk-card-body {
        max-height: 55vh;
        overflow-y: auto;
    }
    #docs-toc-sidebar.toc-collapsed > .jk-card-body {
        display: none !important;
    }
    /* Inner grids collapse to 1 column */
    .docs-hero {
        padding: 1.25rem !important;
    }
    .docs-grid-2,
    .docs-grid-3 {
        grid-template-columns: 1fr !important;
    }
}

/* --- Extra small screens (very small phones) --- */
@media (max-width: 480px) {
    .jk-content {
        padding: 0.75rem;
    }

    .jk-topbar {
        padding: 0.625rem 0.75rem;
    }

    .jk-topbar-title {
        font-size: 0.875rem;
        max-width: 140px;
    }

    /* Docs: hide PDF button text label — keep only icon */
    #pdf-btn .lang-id,
    #pdf-btn .lang-en {
        display: none !important;
    }

    /* Docs: reduce hero padding further */
    .docs-hero {
        padding: 1rem !important;
    }

    .jk-table th,
    .jk-table td {
        padding: 0.375rem 0.5rem;
        font-size: 0.75rem;
    }

    .jk-table th {
        font-size: 0.625rem;
        letter-spacing: 0.02em;
    }

    .jk-table-link {
        font-size: 0.6875rem;
    }

    /* --- Ultra-compact chat header --- */
    .jk-chat-panel__header {
        padding: 0.375rem 0.5rem;
        gap: 0.25rem;
    }

    .jk-escalate-select-bar {
        margin: 4px -0.5rem -0.375rem;
        padding: 6px 8px;
        gap: 4px;
        flex-wrap: wrap;
        min-height: unset;
    }

    .jk-escalate-select-bar span[style*="font-size:13px"] {
        font-size: 11px !important;
    }

    .jk-chat-panel__header-avatar {
        width: 24px;
        height: 24px;
        font-size: 0.6875rem;
    }

    .jk-chat-panel__header-name {
        font-size: 0.75rem;
    }

    .jk-chat-panel__header-meta {
        font-size: 0.5625rem;
    }

    /* --- Ultra-compact bubbles --- */
    .jk-msg__bubble {
        padding: 0.375rem 0.5rem;
        font-size: 0.75rem;
        line-height: 1.4;
        border-radius: 8px;
    }

    .jk-msg__name {
        font-size: 0.5625rem;
    }

    .jk-msg__time {
        font-size: 0.5rem;
    }

    .jk-msg__badge {
        font-size: 0.4375rem;
        padding: 0 0.1875rem;
    }

    .jk-msg__file {
        font-size: 0.6875rem;
        padding: 0.1875rem 0.375rem;
    }

    .jk-msg__file small {
        font-size: 0.5625rem;
    }

    .jk-msg__audio-player {
        max-width: 240px;
    }

    .jk-msg__audio-icon {
        width: 26px;
        height: 26px;
    }

    .jk-msg__audio-icon svg {
        width: 14px;
        height: 14px;
    }

    .jk-msg__audio-control {
        height: 30px;
    }

    .jk-msg__img-thumb {
        width: 80px;
        height: 80px;
    }

    .jk-chat-panel__body {
        max-height: 50vh;
        min-height: 200px;
    }

    /* --- Ultra-compact reply bar --- */
    .jk-chat-panel__footer {
        padding: 0.5rem 0.625rem;
    }

    .jk-reply-bar__input {
        font-size: 0.8125rem;
        padding: 0.5rem 0.75rem;
        border-radius: 18px;
    }

    .jk-reply-bar__send {
        width: 36px;
        height: 36px;
    }

    .jk-reply-bar__mic {
        width: 36px;
        height: 36px;
    }

    .jk-reply-bar__attach {
        width: 36px;
        height: 36px;
    }

    .jk-card-body {
        padding: 0.75rem;
    }

    .jk-card-header {
        padding: 0.75rem;
        font-size: 0.75rem;
    }
}

/* =============================================================
   CASE DETAIL — MOBILE RESPONSIVE
   ============================================================= */

@media (max-width: 768px) {
    /* --- Ticket Header Card --- */
    .jk-detail-header .jk-card-body {
        padding: 0.75rem !important;
    }

    /* Compact status & source badges */
    .jk-detail-badges > div {
        padding: 0.25rem 0.625rem !important;
        font-size: 0.6875rem !important;
        gap: 0.25rem !important;
    }

    .jk-detail-badges > div svg {
        width: 0.875rem;
        height: 0.875rem;
    }

    /* Meta row: stack vertically on mobile */
    .jk-detail-meta {
        flex-direction: column;
        gap: 0.25rem !important;
    }

    .jk-detail-meta > div {
        display: flex;
        justify-content: space-between;
        width: 100%;
        padding: 0.125rem 0;
        border-bottom: 1px solid #f1f5f9;
    }

    .jk-detail-meta > div:last-child {
        border-bottom: none;
    }

    /* Subject title smaller */
    .jk-detail-subject {
        font-size: 1rem !important;
    }

    /* Requester info line */
    .jk-detail-requester {
        font-size: 0.75rem !important;
    }

    /* Chat panel header buttons compact */
    .jk-chat-panel__header .jk-btn-sm {
        padding: 0.1875rem 0.375rem;
        font-size: 0.625rem;
    }

    .jk-chat-panel__header .jk-btn-sm svg {
        width: 0.75rem;
        height: 0.75rem;
        margin-right: 0.125rem;
    }

    /* Split panel gap reduction */
    .jk-split {
        gap: 0.75rem;
    }

    /* RCA form compact */
    .jk-rca-section .jk-form-group {
        margin-bottom: 0.75rem;
    }

    .jk-rca-section .jk-label {
        font-size: 0.75rem;
    }

    .jk-rca-section .jk-textarea {
        font-size: 0.8125rem;
    }
}

@media (max-width: 480px) {
    /* Even tighter on very small screens */
    .jk-detail-header .jk-card-body {
        padding: 0.5rem !important;
    }

    .jk-detail-subject {
        font-size: 0.875rem !important;
        line-height: 1.3;
    }

    .jk-detail-requester {
        font-size: 0.6875rem !important;
    }

    .jk-detail-badges .jk-badge-pill {
        padding: 0.1875rem 0.5rem;
        font-size: 0.625rem;
    }

    .jk-detail-meta {
        font-size: 0.625rem !important;
    }

    /* Chat header even more compact */
    .jk-chat-panel__header .jk-btn-sm {
        padding: 0.125rem 0.25rem;
        font-size: 0.5625rem;
    }
}

/* ===================================================================
   Case List — Mobile Card Layout
   On screens ≤ 768px the table rows become stacked cards.
   =================================================================== */

@media (max-width: 768px) {
    /* Table wrapper — remove border so cards float freely */
    .jk-case-list-wrapper {
        border: none;
        border-radius: 0;
        background: transparent;
        box-shadow: none;
        overflow: visible;
    }

    /* Remove min-width so table doesn't force horizontal scroll */
    .jk-case-list-table {
        min-width: 0 !important;
        display: block;
    }

    .jk-case-list-table thead {
        display: none;
    }

    .jk-case-list-table tbody {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.5rem;
    }

    .jk-case-list-table tbody tr {
        display: grid;
        grid-template-columns: auto 1fr auto;
        grid-template-rows: auto auto auto auto auto;
        gap: 0.125rem 0.5rem;
        padding: 0.625rem 0.75rem;
        border-radius: 0.75rem;
        border: 1px solid #e2e8f0;
        background: #fff;
        position: relative;
    }

    .jk-case-list-table tbody tr.bg-rose-50 {
        box-shadow: inset 0 0 0 1px rgba(244,63,94,0.15), 0 2px 8px rgba(244,63,94,0.10);
    }

    /* Hide all cells by default, then show the ones we want */
    .jk-case-list-table tbody td {
        display: none;
        padding: 0;
        border: none;
    }

    /* Row 1: checkbox + ticket# + status badge */
    .jk-case-list-table tbody td.jk-col-checkbox {
        display: flex;
        align-items: center;
        grid-row: 1;
        grid-column: 1;
    }

    .jk-case-list-table tbody td.jk-col-ticket {
        display: flex;
        align-items: center;
        grid-row: 1;
        grid-column: 2;
        font-weight: 600;
    }

    .jk-case-list-table tbody td.jk-col-status {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        grid-row: 1;
        grid-column: 3;
    }

    /* Row 2: subject spanning full width */
    .jk-case-list-table tbody td.jk-col-subject {
        display: block;
        grid-row: 2;
        grid-column: 1 / -1;
        padding-top: 0.25rem;
    }

    .jk-case-list-table tbody td.jk-col-subject a {
        max-width: 100% !important;
        font-size: 0.8125rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Row 3: requester info (name + phone/email) */
    .jk-case-list-table tbody td.jk-col-requester {
        display: flex !important;
        align-items: center;
        gap: 0.375rem;
        grid-row: 3;
        grid-column: 1 / -1;
        padding-top: 0.25rem;
        font-size: 0.75rem;
        color: #475569;
        overflow: hidden;
        min-width: 0;
    }

    .jk-col-requester__name {
        font-weight: 600;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 45%;
        flex-shrink: 1;
        min-width: 0;
    }

    .jk-col-requester__contact {
        color: #64748b;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 45%;
        flex-shrink: 1;
        min-width: 0;
    }

    .jk-col-requester__contact::before {
        content: "•";
        margin-right: 0.375rem;
        color: #cbd5e1;
    }

    /* Row 4: unit/company */
    .jk-col-requester__unit {
        display: none;
    }

    .jk-case-list-table tbody td.jk-col-requester .jk-col-requester__unit {
        display: block;
        grid-row: 4;
        grid-column: 1 / -1;
        font-size: 0.6875rem;
        font-weight: 500;
        color: #4f46e5;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* When unit exists, requester cell becomes a 2-line block */
    .jk-case-list-table tbody td.jk-col-requester:has(.jk-col-requester__unit) {
        flex-wrap: wrap;
    }

    .jk-case-list-table tbody td.jk-col-requester .jk-col-requester__unit {
        width: 100%;
        flex-basis: 100%;
        padding-top: 0.0625rem;
    }

    /* Row 5: source + date */
    .jk-case-list-table tbody td.jk-col-source {
        display: inline-flex !important;
        grid-row: 5;
        grid-column: 1 / 2;
        padding-top: 0.375rem;
    }

    .jk-case-list-table tbody td.jk-col-source .jk-badge {
        font-size: 0.625rem;
        padding: 0.125rem 0.375rem;
    }

    .jk-case-list-table tbody td.jk-col-created {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        grid-row: 5;
        grid-column: 2 / -1;
        padding-top: 0.375rem;
        font-size: 0.6875rem;
        color: #94a3b8;
    }

    .jk-case-list-table tbody td.jk-col-created br {
        display: none;
    }

    .jk-case-list-table tbody td.jk-col-created span {
        margin-left: 0.25rem;
    }

    /* Badges inside cards */
    .jk-case-list-table .jk-badge {
        font-size: 0.6875rem;
        padding: 0.125rem 0.5rem;
    }

    /* Status filter bar — smaller pills on mobile */
    .jk-status-filter-bar {
        gap: 0.375rem !important;
    }

    .jk-status-filter-bar button {
        padding: 0.25rem 0.625rem;
        font-size: 0.6875rem;
    }

    /* Pagination compact */
    .jk-case-list-table + .px-6 {
        padding: 0.75rem;
    }

    /* Live indicator — smaller on mobile */
    #live-indicator {
        bottom: 10px !important;
        right: 10px !important;
        padding: 4px 10px !important;
        font-size: 10px !important;
        border-radius: 8px !important;
    }

    /* Bulk action bar — compact on mobile */
    .jk-bulk-bar {
        left: 0.5rem !important;
        right: 0.5rem !important;
        transform: none !important;
        width: auto !important;
        border-radius: 1rem;
        font-size: 0.75rem;
    }

    .jk-bulk-bar .px-5 {
        padding: 0.5rem 0.75rem;
    }

    .jk-bulk-bar .px-4 {
        padding: 0.5rem 0.625rem;
    }
}

/* =============================================================
   CONFIDENTIAL TICKET STYLES
   ============================================================= */

/* Masked confidential row in table */
.jk-confidential-masked {
    background: repeating-linear-gradient(
        -45deg,
        transparent,
        transparent 8px,
        rgba(245, 158, 11, 0.03) 8px,
        rgba(245, 158, 11, 0.03) 16px
    );
}

.jk-confidential-masked td {
    user-select: none;
}

/* Confidential management panel in case detail */
.jk-confidential-panel {
    background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
    border: 1px solid #fcd34d;
    border-radius: var(--jk-radius);
    padding: 1rem 1.25rem;
}

.jk-confidential-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.jk-confidential-panel__title {
    font-weight: 600;
    font-size: 0.875rem;
    color: #92400e;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.jk-confidential-panel__users {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin-bottom: 0.75rem;
}

.jk-confidential-panel__chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.625rem;
    background: #ffffff;
    border: 1px solid #fbbf24;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    color: #78350f;
}

.jk-confidential-panel__chip button {
    color: #dc2626;
    font-size: 0.625rem;
    line-height: 1;
    padding: 0.125rem;
    border-radius: 9999px;
    transition: var(--jk-transition);
}

.jk-confidential-panel__chip button:hover {
    background: #fecaca;
}

/* Confidential badge */
.jk-badge-confidential {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.5rem;
    background: #fffbeb;
    color: #92400e;
    border: 1px solid #fbbf24;
    border-radius: 9999px;
    font-size: 0.6875rem;
    font-weight: 600;
}

/* =============================================================
   Rebrand color utility shims (indigo/purple -> blue/green)
   =============================================================
   static/css/tailwind.css is a pre-compiled bundle with no build
   tooling in this repo (no package.json/tailwind.config) — it only
   contains whatever utility classes existed in templates at the time
   it was generated. The blue/green shades used in
   templates/client/dashboard.html's rebrand weren't all present in
   that build, so these hand-written rules fill the specific gaps
   (verified missing via grep against tailwind.css) rather than being
   a full Tailwind reimplementation. */
.bg-blue-500\/5 { background-color: rgb(59 130 246 / 0.05); }
.bg-blue-50\/80 { background-color: rgb(239 246 255 / 0.8); }
.border-blue-100\/50 { border-color: rgb(219 234 254 / 0.5); }
.text-blue-400 { color: #60a5fa; }
.ring-blue-400 { box-shadow: 0 0 0 1px #60a5fa; }
.hover\:border-blue-100:hover { border-color: #dbeafe; }
.hover\:border-blue-200:hover { border-color: #bfdbfe; }
.hover\:text-blue-700:hover { color: #1d4ed8; }
.focus\:ring-blue-500:focus { box-shadow: 0 0 0 3px rgb(59 130 246 / 0.5); }
.group:focus-within .group-focus-within\:bg-blue-500\/10 { background-color: rgb(59 130 246 / 0.1); }
.group:focus-within .group-focus-within\:border-blue-300 { border-color: #93c5fd; }
.group:focus-within .group-focus-within\:text-blue-500 { color: #3b82f6; }
.group:hover .group-hover\:text-blue-700 { color: #1d4ed8; }
.text-blue-200 { color: #bfdbfe; }

.bg-green-50\/80 { background-color: rgb(240 253 244 / 0.8); }
.border-green-100\/50 { border-color: rgb(220 252 231 / 0.5); }
.hover\:border-green-200:hover { border-color: #bbf7d0; }
.group:hover .group-hover\:text-green-700 { color: #15803d; }

.hover\:text-blue-800:hover { color: #1e40af; }
.border-blue-200\/50 { border-color: rgb(191 219 254 / 0.5); }
.shadow-blue-500\/20 { box-shadow: 0 10px 15px -3px rgb(59 130 246 / 0.2), 0 4px 6px -4px rgb(59 130 246 / 0.2); }
.shadow-blue-500\/25 { box-shadow: 0 10px 15px -3px rgb(59 130 246 / 0.25), 0 4px 6px -4px rgb(59 130 246 / 0.25); }
.hover\:shadow-blue-500\/30:hover { box-shadow: 0 20px 25px -5px rgb(59 130 246 / 0.3), 0 8px 10px -6px rgb(59 130 246 / 0.3); }

/* Chat widget rebrand gaps (bg-blue-* was never used pre-rebrand, only
   text-blue-*, so these background/border variants weren't compiled). */
.bg-blue-600 { background-color: #2563eb; }
.hover\:bg-blue-700:hover { background-color: #1d4ed8; }
.bg-blue-400 { background-color: #60a5fa; }
.text-blue-300 { color: #93c5fd; }
.border-blue-600 { border-color: #2563eb; }
.group:hover .group-hover\:text-blue-400 { color: #60a5fa; }

/* ===================================================================
   Task Management toolbar — mobile
   Status chips, saved filters and Export are hidden until "Status & saved filters" is tapped
   (.jk-extra-open on .jk-task-toolbar); the advanced filters have their own Filters button
   (.jk-filters-open).
   =================================================================== */
.jk-task-more { display: none; }
@media (max-width: 639px) {
    .jk-task-toolbar { display: flex; flex-direction: column; }
    .jk-task-toolbar > * { order: 1; }
    .jk-task-toolbar > .jk-task-more { order: 2; }
    .jk-task-toolbar > .jk-task-extra { order: 3; display: none !important; }
    .jk-task-toolbar > .jk-task-search { order: 4; margin-bottom: 0.625rem; }
    /* the status chips / saved filters have their own toggle ("Status & saved filters"), separate from Filters */
    .jk-task-toolbar.jk-extra-open > .jk-task-extra { display: flex !important; }
    .jk-task-more { display: inline-flex; align-items: center; gap: .4rem; align-self: flex-start; margin: 0 0 .5rem; padding: .3rem .7rem;
                    border: 1px solid #c7d2fe; border-radius: .6rem; background: #eef2ff; color: #3730a3; font-size: .75rem; font-weight: 700; cursor: pointer; }
    .jk-task-more:active { background: #e0e7ff; }
    .jk-task-more-caret { transition: transform .15s; }
    .jk-task-toolbar.jk-extra-open .jk-task-more-caret { transform: rotate(180deg); }
    .jk-task-more-badge { padding: 0 .4rem; border-radius: 9999px; background: #4f46e5; color: #fff; font-size: .65rem; line-height: 1.1rem; }
    .jk-task-toolbar .jk-export-desk { display: none !important; }
    /* Open filters can be taller than the screen — scroll with the page instead of pinning */
    .jk-task-toolbar.jk-filters-open, .jk-task-toolbar.jk-extra-open { position: relative !important; top: auto !important; }
}

/* Table rows become cards at ≤768px — the whole card opens the ticket */
@media (max-width: 768px) {
    .jk-case-list-table tbody tr[data-href] { cursor: pointer; transition: transform .1s; }
    .jk-case-list-table tbody tr[data-href]:active { transform: scale(0.99); }
}
