:root {
    --syntax-orange: #f67d30;
    --syntax-orange-600: #f5631a;
    --syntax-orange-700: #e64910;
    --syntax-orange-50: #fff7f0;
    --syntax-orange-100: #feead6;
    --syntax-orange-200: #fcd1ac;

    --syntax-dark: #253439;
    --syntax-dark-700: #3d5a61;
    --syntax-dark-600: #466d74;
    --syntax-dark-500: #518389;
    --syntax-dark-200: #c5dbdc;
    --syntax-dark-100: #e0eced;
    --syntax-dark-50: #f3f8f8;

    --app-bg: #f9fbfb;
    --app-surface: #ffffff;
    --app-border: #e0eced;
    --app-text-muted: #466d74;

    --bs-primary: var(--syntax-orange);
    --bs-primary-rgb: 246, 125, 48;
}

html { font-size: 15px; min-height: 100%; position: relative; }
body {
    background: var(--app-bg);
    color: var(--syntax-dark);
    font-family: "Cairo", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    font-weight: 400;
}

a { color: var(--syntax-orange); text-decoration: none; }
a:hover { color: var(--syntax-orange-700); text-decoration: underline; }

h1, h2, h3, h4, h5, h6 { color: var(--syntax-dark); font-weight: 600; }

.app-navbar {
    background: var(--syntax-dark);
    border-bottom: 3px solid var(--syntax-orange);
}
.app-navbar .nav-link {
    color: rgba(255,255,255,0.78) !important;
    font-weight: 500;
}
.app-navbar .nav-link:hover,
.app-navbar .nav-link.active { color: #fff !important; }
.app-navbar .navbar-brand { color: #fff; font-weight: 700; letter-spacing: 0.2px; }
.app-navbar .navbar-brand img { height: 32px; }
.app-navbar .dropdown-menu .dropdown-item { color: var(--syntax-dark); }
.app-navbar .dropdown-menu .dropdown-item:hover { background: var(--syntax-orange-50); color: var(--syntax-orange-700); }
.app-navbar .navbar-toggler-icon {
    background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3E%3Cpath stroke='rgba(255,255,255,0.9)' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3E%3C/svg%3E");
}

.avatar {
    /* Base — every avatar uses these. Background color is set inline by the
       AvatarComponent based on a stable per-user hash so the same user always
       renders the same color across the app. */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--syntax-orange);
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
    line-height: 1;
    flex-shrink: 0;
    transition: transform 120ms ease, box-shadow 120ms ease;
}
a.avatar:hover, a.avatar:focus-visible {
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(37, 52, 57, 0.18);
    text-decoration: none;
}
.avatar-xs { width: 20px; height: 20px; font-size: 0.62rem; }
.avatar-sm { width: 28px; height: 28px; font-size: 0.72rem; }
.avatar-md { width: 36px; height: 36px; font-size: 0.88rem; }
.avatar-lg { width: 56px; height: 56px; font-size: 1.18rem; }
.avatar-stack > .avatar { margin-left: -8px; border: 2px solid #fff; }
.avatar-stack > .avatar:first-child { margin-left: 0; }

.card {
    border: 1px solid var(--app-border);
    border-radius: 12px;
    background: var(--app-surface);
    box-shadow: 0 1px 3px rgba(37, 52, 57, 0.06);
}
.card-header {
    background: transparent;
    border-bottom: 1px solid var(--app-border);
    font-weight: 600;
    color: var(--syntax-dark);
}

.stat-card {
    border-radius: 12px;
    padding: 1rem 1.25rem;
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(37, 52, 57, 0.08);
}
.stat-card .stat-value { font-size: 1.75rem; font-weight: 700; color: var(--syntax-dark); }
.stat-card .stat-label { color: var(--app-text-muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.stat-card .stat-icon {
    width: 44px; height: 44px; border-radius: 12px;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 1.25rem;
}

.badge-status {
    font-weight: 600;
    padding: 0.35em 0.7em;
    border-radius: 6px;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.05em;
}
.badge-priority {
    font-weight: 600;
    padding: 0.35em 0.7em;
    border-radius: 6px;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.priority-Low { background: #f3f8f8; color: var(--syntax-dark-700); }
.priority-Normal { background: var(--syntax-dark-100); color: var(--syntax-dark); }
.priority-High { background: #feead6; color: var(--syntax-orange-700); }
.priority-Urgent { background: #fcd1ac; color: #bf350f; }
.priority-Critical { background: #f5631a; color: #fff; }

.status-New { background: #e0eced; color: var(--syntax-dark); }
.status-Open { background: #fff7f0; color: var(--syntax-orange-700); border: 1px solid #feead6; }
.status-InProgress { background: #fcd1ac; color: #7a2614; }
.status-PendingCustomer { background: #feead6; color: var(--syntax-orange-700); }
.status-Resolved { background: #dcfae4; color: #066041; }
.status-Closed { background: var(--syntax-dark); color: #fff; }
.status-Reopened { background: #fee2e2; color: #991b1b; }

.notif-panel {
    width: 380px; max-width: 92vw; padding: 0;
    border: 1px solid var(--app-border);
    box-shadow: 0 12px 32px rgba(37, 52, 57, 0.16);
    border-radius: 12px;
    overflow: hidden;
}
.notif-list { max-height: 440px; overflow-y: auto; }
.notif-item {
    display: block;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--app-border);
    text-decoration: none;
    color: inherit;
    transition: background 0.15s;
}
.notif-item:last-child { border-bottom: 0; }
.notif-item:hover { background: var(--syntax-dark-50); text-decoration: none; }
.notif-item.unread { background: #fff7f0; border-left: 3px solid var(--syntax-orange); }
.notif-item .notif-title { font-weight: 600; font-size: 0.9rem; color: var(--syntax-dark); }
.notif-item .notif-msg { color: var(--app-text-muted); font-size: 0.83rem; }
.notif-item .notif-time { color: #9cc0c4; font-size: 0.72rem; margin-top: 2px; }

.comment {
    display: flex; gap: 12px;
    padding: 1rem 0;
    border-bottom: 1px solid var(--app-border);
    /* Flex containers default children to min-width:auto, which lets a wide <pre>
       inside the comment body push the whole row beyond the card. Constrain the
       flex container itself too so the column from the surrounding layout wins. */
    min-width: 0;
}
.comment:last-child { border-bottom: 0; }
/* Apply min-width:0 to every direct child too — that's what unblocks the
   <pre>'s own overflow-x:auto so long code lines scroll horizontally instead
   of stretching the conversation card. */
.comment > * { min-width: 0; }
.comment.internal {
    background: #fffaf5;
    border-left: 3px solid var(--syntax-orange);
    padding-left: 12px;
    border-radius: 6px;
    margin-bottom: 6px;
}
.comment-body { line-height: 1.6; }
.comment-meta { color: var(--app-text-muted); font-size: 0.82rem; }

/* Rich-text content rendered from TinyMCE output. Keep whitespace handling
   normal (HTML markup carries paragraphs/breaks) and style block elements
   so they look like the editor preview. */
.rich-text-display {
    line-height: 1.6;
    white-space: normal;
    word-wrap: break-word;
    /* Same flex-shrink reset — guarantees children like <pre> can't push our
       width beyond the parent column. */
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
}
.rich-text-display p { margin: 0 0 0.65rem 0; }
.rich-text-display p:last-child { margin-bottom: 0; }
.rich-text-display h1, .rich-text-display h2, .rich-text-display h3, .rich-text-display h4 {
    margin: 0.75rem 0 0.4rem;
    font-weight: 600;
    line-height: 1.3;
}
.rich-text-display h1 { font-size: 1.4rem; }
.rich-text-display h2 { font-size: 1.2rem; }
.rich-text-display h3 { font-size: 1.05rem; }
.rich-text-display h4 { font-size: 0.95rem; }
.rich-text-display ul, .rich-text-display ol { margin: 0 0 0.65rem 1.25rem; padding-left: 1rem; }
.rich-text-display blockquote {
    border-left: 3px solid #e5e7eb;
    padding: 0.1rem 0 0.1rem 0.85rem;
    color: #4b5563;
    margin: 0.5rem 0;
}
.rich-text-display code {
    background: #f3f4f6;
    color: #b45309;
    padding: 0.05rem 0.3rem;
    border-radius: 3px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.92em;
}
/* Base code-block styling. When a language is present (TinyMCE codesample saves
   class="language-xxx"), Prism.js's prism-tomorrow theme paints the foreground
   tokens — these rules then provide the surrounding box, padding, scrolling,
   and consistent typography so the block reads cleanly inside ticket replies. */
.rich-text-display pre {
    background: #1f2937;
    color: #f9fafb;
    padding: 0.85rem 1rem;
    border-radius: 8px;
    overflow-x: auto;             /* Long lines scroll horizontally inside the block */
    overflow-y: auto;
    max-height: 480px;
    /* Cap width to the parent column so we never stretch the conversation card.
       Without this, white-space:pre on long lines forces intrinsic min-width to
       the longest line's pixel length and breaks flex layouts. */
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
    margin: 0.6rem 0;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.86rem;
    line-height: 1.5;
    border: 1px solid #111827;
    box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset;
    tab-size: 4;
    text-shadow: none;            /* Override Prism's default glow */
    white-space: pre;             /* Real code formatting — no soft-wrap, scroll horizontally */
    word-break: normal;
    overflow-wrap: normal;
}
.rich-text-display pre[class*="language-"] {
    /* Prism's tomorrow theme injects its own background — we keep ours for
       visual consistency with non-highlighted blocks. */
    background: #1f2937;
}
.rich-text-display pre code {
    background: transparent;
    color: inherit;
    padding: 0;
    font-family: inherit;
    font-size: inherit;
    text-shadow: none;
    white-space: inherit;
}
.rich-text-display table {
    border-collapse: collapse;
    margin: 0.5rem 0;
    max-width: 100%;
}
.rich-text-display table td, .rich-text-display table th {
    border: 1px solid #d1d5db;
    padding: 0.35rem 0.55rem;
    vertical-align: top;
}
.rich-text-display table th {
    background: #f3f4f6;
    font-weight: 600;
    text-align: left;
}
.rich-text-display a { color: var(--syntax-orange-600); text-decoration: underline; }
.rich-text-display hr { border: 0; border-top: 1px solid #e5e7eb; margin: 0.75rem 0; }
.rich-text-display img { max-width: 100%; height: auto; }

/* CSAT rating stars — no underline, no focus outline jitter; the icon itself
   carries the highlight via JS. */
.rating-stars .rating-star {
    text-decoration: none;
    border: 0;
    line-height: 1;
    color: #d1d5db;
    transition: transform 0.06s ease;
}
.rating-stars .rating-star:hover { transform: scale(1.08); }
.rating-stars .rating-star:focus { box-shadow: none; outline: 2px solid #fde68a; outline-offset: 2px; border-radius: 4px; }

.btn-primary {
    background: var(--syntax-orange);
    border-color: var(--syntax-orange);
    color: #fff;
    font-weight: 600;
}
.btn-primary:hover, .btn-primary:focus {
    background: var(--syntax-orange-600);
    border-color: var(--syntax-orange-600);
    color: #fff;
}
.btn-primary:active, .btn-primary:disabled {
    background: var(--syntax-orange-700) !important;
    border-color: var(--syntax-orange-700) !important;
}
.btn-outline-primary {
    color: var(--syntax-orange);
    border-color: var(--syntax-orange);
    font-weight: 600;
}
.btn-outline-primary:hover {
    background: var(--syntax-orange);
    border-color: var(--syntax-orange);
    color: #fff;
}
.btn-dark, .btn-secondary { background: var(--syntax-dark); border-color: var(--syntax-dark); }
.btn-dark:hover, .btn-secondary:hover { background: var(--syntax-dark-700); border-color: var(--syntax-dark-700); }
.btn-light { background: #fff; border-color: var(--app-border); color: var(--syntax-dark); }
.text-primary { color: var(--syntax-orange) !important; }
.bg-primary { background-color: var(--syntax-orange) !important; }
.border-primary { border-color: var(--syntax-orange) !important; }

.form-control:focus, .form-select:focus {
    border-color: var(--syntax-orange-200);
    box-shadow: 0 0 0 0.2rem rgba(246, 125, 48, 0.2);
}
.form-label { font-weight: 600; color: var(--syntax-dark); font-size: 0.9rem; }
.form-text { color: var(--app-text-muted); }

.table { border-collapse: separate; border-spacing: 0; }
.table > :not(caption) > * > * { padding: 0.9rem 0.85rem; vertical-align: middle; }
.table th {
    font-size: 0.74rem; text-transform: uppercase;
    color: var(--app-text-muted); letter-spacing: 0.05em;
    font-weight: 700;
    background: var(--syntax-dark-50);
}
.table > tbody > tr:hover { background: #fff7f0; }
.table > tbody > tr > td { border-color: var(--app-border); }

.empty-state { padding: 3rem 1rem; text-align: center; color: var(--app-text-muted); }
.empty-state i { font-size: 3rem; opacity: 0.45; color: var(--syntax-dark-500); }

.timeline { border-left: 2px solid var(--app-border); padding-left: 16px; }
.timeline-item { position: relative; padding-bottom: 12px; }
.timeline-item::before {
    content: ""; position: absolute; left: -22px; top: 6px;
    width: 10px; height: 10px; border-radius: 50%;
    background: var(--syntax-orange);
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px var(--app-border);
}

.btn-icon { width: 36px; height: 36px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }

.hero {
    background: linear-gradient(135deg, var(--syntax-dark) 0%, var(--syntax-dark-700) 100%);
    color: #fff;
    border-radius: 16px;
    padding: 4rem 2rem;
    position: relative;
    overflow: hidden;
}
.hero::before {
    content: "";
    position: absolute;
    right: -120px; top: -120px;
    width: 360px; height: 360px;
    background: radial-gradient(circle, var(--syntax-orange) 0%, transparent 70%);
    opacity: 0.3;
}
.hero h1 { color: #fff; }
.hero .lead { color: rgba(255,255,255,0.86); }

.footer {
    background: var(--app-surface);
    border-top: 1px solid var(--app-border);
    color: var(--app-text-muted);
}

.auth-card {
    max-width: 460px; margin: 3rem auto;
    background: #fff;
    border: 1px solid var(--app-border);
    border-radius: 16px;
    padding: 2.5rem;
    box-shadow: 0 12px 32px rgba(37, 52, 57, 0.08);
}
.auth-brand { text-align: center; margin-bottom: 1.5rem; }
.auth-brand img { height: 56px; }

.pagination .page-link {
    color: var(--syntax-dark);
    border-color: var(--app-border);
}
.pagination .page-item.active .page-link {
    background: var(--syntax-orange);
    border-color: var(--syntax-orange);
    color: #fff;
}
.pagination .page-link:hover {
    background: var(--syntax-orange-50);
    color: var(--syntax-orange-700);
    border-color: var(--syntax-orange-200);
}

/* Kanban board */
.board {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(280px, 1fr);
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 8px;
}
.board-column {
    background: var(--syntax-dark-50);
    border: 1px solid var(--app-border);
    border-radius: 12px;
    padding: 10px;
    min-height: 240px;
    display: flex;
    flex-direction: column;
}
.board-column-header {
    font-size: 0.85rem;
    color: var(--syntax-dark);
    padding: 4px 6px 10px;
    border-bottom: 1px solid var(--app-border);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.board-cards { min-height: 80px; }
.board-card {
    display: block;
    background: #fff;
    border: 1px solid var(--app-border);
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 8px;
    box-shadow: 0 1px 2px rgba(37,52,57,0.04);
    cursor: grab;
    text-decoration: none;
    color: inherit;
    transition: box-shadow 0.15s, transform 0.05s;
}
.board-card:hover {
    box-shadow: 0 4px 10px rgba(37,52,57,0.08);
    text-decoration: none;
    color: inherit;
}
.board-card:active { cursor: grabbing; }
.board-card-type i { font-size: 1.05rem; }
.board-card-subject { font-weight: 600; font-size: 0.92rem; line-height: 1.3; }
.board-card-parent { margin-top: 2px; }
.card-ghost { opacity: 0.4; background: #fff7f0; }

/* Backlog */
.backlog-list { min-height: 60px; }
.backlog-item {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    border: 1px solid var(--app-border);
    border-radius: 8px;
    margin-bottom: 6px;
    background: #fff;
    transition: background 0.15s;
}
.backlog-item:hover { background: var(--syntax-dark-50); }
.backlog-item .bi-grip-vertical { cursor: grab; }

/* Mentions */
.mention {
    background: var(--syntax-orange-50);
    color: var(--syntax-orange-700);
    border: 1px solid var(--syntax-orange-200);
    border-radius: 4px;
    padding: 1px 6px;
    font-weight: 600;
    font-size: 0.92em;
    white-space: nowrap;
}
.mention-popover {
    position: absolute;
    z-index: 1090;
    background: #fff;
    border: 1px solid var(--app-border);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(37, 52, 57, 0.12);
    min-width: 240px;
    max-width: 320px;
    max-height: 260px;
    overflow-y: auto;
    padding: 4px;
}
.mention-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.1s;
}
.mention-item:hover, .mention-item.active { background: var(--syntax-orange-50); }
.mention-avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--syntax-orange);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.72rem;
    flex-shrink: 0;
}
.mention-name { font-weight: 600; font-size: 0.88rem; color: var(--syntax-dark); }
.mention-handle { font-size: 0.78rem; color: var(--app-text-muted); }

/* Sticky table header — keeps column titles visible when scrolling long tables. */
.table-sticky-head th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--app-surface, #fff);
    box-shadow: inset 0 -1px 0 var(--app-border, #e0eced);
}
.table-sortable th a:hover { color: var(--syntax-orange); text-decoration: underline; }

/* Density toggle — applied via data-density attribute on <body>. */
body[data-density="compact"] .table > :not(caption) > * > * { padding-top: .35rem; padding-bottom: .35rem; }
body[data-density="compact"] .card { border-radius: 8px; }
body[data-density="compact"] .stat-card .stat-value { font-size: 1.1rem; }

.attachment-preview {
    max-width: 320px;
}
.attachment-image img,
.attachment-video video {
    display: block;
    max-width: 100%;
    max-height: 240px;
    border-radius: 8px;
    border: 1px solid var(--app-border, #e0eced);
    background: #f9fbfb;
}
.attachment-video video {
    max-height: 280px;
    width: 100%;
}

@media (max-width: 768px) {
    .stat-card .stat-value { font-size: 1.35rem; }
    .hero { padding: 2.5rem 1.25rem; }
    .auth-card { margin: 1.5rem 1rem; padding: 1.75rem; }
    .attachment-preview { max-width: 100%; }
}
