/* ═══════════════════════════════════════════════════════════════
   BornilaDNS — Support Tickets (user / reseller / admin)
   Uses the shared design tokens (--bg2, --text, --primary …) so it
   follows each panel and dark mode (theme.css) automatically.
   ═══════════════════════════════════════════════════════════════ */

/* Sidebar unread badge */
.nav-item .nav-badge {
    margin-left: -5px;          /* sit right after the label ("Support 2"), not at the far edge */
    flex-shrink: 0;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--danger, #ef4444);
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.25);
}
.nav-item .nav-badge[hidden] { display: none; }
/* Collapsed sidebar: keep the count visible as a bubble on the icon */
.sidebar.collapsed .nav-item .nav-badge {
    position: absolute;
    top: 2px;
    right: 4px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    font-size: 0.6rem;
    line-height: 16px;
}

#support-root { color: var(--text); }
#support-root .sp-pane[hidden] { display: none; }

/* ── Header ───────────────────────────────────── */
.sp-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}
.sp-title { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; color: var(--text); }
.sp-sub { font-size: 0.86rem; color: var(--text3); margin-top: 4px; }
.sp-new-btn { white-space: nowrap; }

/* ── Stat cards ───────────────────────────────── */
.sp-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.sp-stat {
    --c: var(--primary);
    --c-r: var(--primary-r);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    background: var(--bg2);
    box-shadow: var(--shadow);
    cursor: pointer;
    text-align: left;
    font: inherit;
    color: inherit;
    transition: transform .18s var(--ease), box-shadow .18s var(--ease), border-color .18s var(--ease);
}
.sp-stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.sp-stat.active { border-color: rgba(var(--c-r), 0.55); box-shadow: 0 0 0 3px rgba(var(--c-r), 0.12); }
.sp-stat-ok    { --c: #10b981; --c-r: 16, 185, 129; }
.sp-stat-warn  { --c: #f59e0b; --c-r: 245, 158, 11; }
.sp-stat-muted { --c: #64748b; --c-r: 100, 116, 139; }
.sp-stat-ico {
    width: 42px; height: 42px;
    flex: none;
    display: grid; place-items: center;
    border-radius: 12px;
    background: rgba(var(--c-r), 0.12);
    color: var(--c);
    font-size: 1.1rem;
}
.sp-ico { width: 1em; height: 1em; flex: none; vertical-align: -0.15em; }
.sp-stat-ico .sp-ico { width: 22px; height: 22px; }
.sp-del .sp-ico { margin-right: 4px; }
.sp-stat-body { display: flex; flex-direction: column; min-width: 0; }
.sp-stat-n { font-size: 1.4rem; font-weight: 800; line-height: 1.1; color: var(--text); }
.sp-stat-l { font-size: 0.78rem; color: var(--text3); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Card ─────────────────────────────────────── */
.sp-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.sp-card + .sp-card { margin-top: 16px; }
.sp-card-head { padding: 18px 22px; border-bottom: 1px solid var(--border); }
.sp-card-title { font-size: 1.05rem; font-weight: 700; }
.sp-card-body { padding: 20px 22px; }

/* ── Toolbar / tabs ───────────────────────────── */
.sp-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}
.sp-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.sp-tab {
    border: 0;
    background: transparent;
    color: var(--text2);
    font: inherit;
    font-size: 0.84rem;
    font-weight: 600;
    padding: 7px 12px;
    border-radius: 999px;
    cursor: pointer;
    transition: background .15s, color .15s;
}
.sp-tab:hover { background: var(--bg3); color: var(--text); }
.sp-tab.active { background: var(--primary-dim); color: var(--primary); }
.sp-tab-n:not(:empty) {
    display: inline-block;
    min-width: 18px;
    margin-left: 4px;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--bg3);
    color: var(--text2);
    font-size: 0.7rem;
    line-height: 18px;
    text-align: center;
}
.sp-tab.active .sp-tab-n { background: var(--primary); color: #fff; }
.sp-search { max-width: 280px; height: 38px; margin: 0; }

/* ── Ticket rows ──────────────────────────────── */
.sp-rows { display: flex; flex-direction: column; }
.sp-row {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 15px 18px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    position: relative;
    transition: background .15s;
}
.sp-row:last-child { border-bottom: 0; }
.sp-row:hover, .sp-row:focus-visible { background: var(--bg3); outline: none; }
.sp-row.unread::before {
    content: '';
    position: absolute;
    left: 0; top: 10px; bottom: 10px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--primary);
}
.sp-row-main { flex: 1; min-width: 0; }
.sp-row-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.sp-no { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.8rem; color: var(--text3); font-weight: 600; flex: none; }
.sp-subject { font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sp-row.unread .sp-subject { font-weight: 800; }
.sp-new-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); flex: none; box-shadow: 0 0 0 3px var(--primary-dim); }
.sp-row-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px 8px;
    margin-top: 5px;
    font-size: 0.78rem;
    color: var(--text3);
}
.sp-dot { opacity: .6; }
.sp-who { color: var(--text2); font-weight: 600; display: inline-flex; align-items: center; gap: 6px; margin-right: 4px; }
.sp-email { color: var(--text3); font-weight: 400; }
.sp-role {
    font-size: 0.66rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: 1px 6px;
    border-radius: 6px;
    background: rgba(253, 177, 57, 0.12);
    color: #FDB139;
}
.sp-row-side { display: flex; align-items: center; gap: 8px; flex: none; }

/* ── Pills ────────────────────────────────────── */
.sp-pill {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    white-space: nowrap;
}
.st-open     { background: rgba(245, 158, 11, 0.14); color: #d97706; }
.st-customer { background: rgba(244, 63, 94, 0.12);  color: #e11d48; }
.st-answered { background: rgba(16, 185, 129, 0.14); color: #059669; }
.st-closed   { background: rgba(100, 116, 139, 0.14); color: #64748b; }
html[data-theme="dark"] .st-open     { color: #fbbf24; }
html[data-theme="dark"] .st-customer { color: #fb7185; }
html[data-theme="dark"] .st-answered { color: #34d399; }
html[data-theme="dark"] .st-closed   { color: #94a3b8; }

.sp-prio { display: inline-flex; align-items: center; gap: 5px; font-size: 0.74rem; font-weight: 600; color: var(--text2); white-space: nowrap; }
.sp-prio i { width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; }
.pr-medium i { background: #E56F32; }
.pr-high i   { background: #f59e0b; }
.pr-urgent i { background: #f43f5e; box-shadow: 0 0 0 3px rgba(244, 63, 94, 0.18); }
.pr-urgent   { color: #e11d48; }

.sp-chip {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--bg3);
    color: var(--text2);
    font-size: 0.72rem;
    font-weight: 600;
}

/* ── Empty / loading / pager ──────────────────── */
.sp-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 48px 20px;
    color: var(--text3);
    text-align: center;
    font-size: 0.9rem;
}
.sp-not-found { font-size: 0.95rem; font-weight: 600; }
.sp-loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 40px; color: var(--text3); font-size: 0.88rem; }
.sp-spin {
    width: 18px; height: 18px;
    border-radius: 50%;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    animation: sp-spin .7s linear infinite;
}
@keyframes sp-spin { to { transform: rotate(360deg); } }
.sp-pager { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 0 16px; }
.sp-pager:not(:empty) { padding: 12px 16px; border-top: 1px solid var(--border); }
.sp-pager-info { font-size: 0.8rem; color: var(--text3); }

/* ── New ticket form ──────────────────────────── */
.sp-form-card { max-width: 820px; }
.sp-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.sp-textarea { resize: vertical; min-height: 110px; line-height: 1.55; font-family: inherit; }
.sp-counter { text-align: right; font-size: 0.72rem; color: var(--text3); margin-top: 4px; }
.sp-form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
#support-root .form-group { margin-bottom: 16px; }
#support-root .field-error:empty { display: none; }
#support-root .field-invalid { border-color: var(--danger) !important; }

/* ── Back link ────────────────────────────────── */
.sp-back {
    border: 0;
    background: none;
    color: var(--text2);
    font: inherit;
    font-size: 0.86rem;
    font-weight: 600;
    padding: 6px 0;
    margin-bottom: 12px;
    cursor: pointer;
}
.sp-back:hover { color: var(--primary); }

/* ── Ticket detail ────────────────────────────── */
.sp-detail { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; align-items: start; }
.sp-detail.with-side { grid-template-columns: minmax(0, 1fr) 300px; }
.sp-conv { display: flex; flex-direction: column; }
.sp-detail-head { padding: 18px 22px; border-bottom: 1px solid var(--border); }
.sp-detail-title { font-size: 1.15rem; font-weight: 800; line-height: 1.35; word-break: break-word; }
.sp-detail-title .sp-no { font-size: 0.9rem; margin-right: 4px; }
.sp-detail-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }

.sp-thread {
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 22px;
    max-height: 560px;
    overflow-y: auto;
    background: var(--bg);
}
.sp-msg { display: flex; gap: 10px; align-items: flex-start; max-width: 86%; }
.sp-msg.mine { margin-left: auto; }
.sp-avatar {
    width: 34px; height: 34px;
    flex: none;
    display: grid; place-items: center;
    border-radius: 50%;
    background: var(--bg3);
    color: var(--text2);
    font-weight: 700;
    font-size: 0.85rem;
}
.sp-avatar.lg { width: 44px; height: 44px; font-size: 1.05rem; background: var(--gradient); color: #fff; }
.sp-msg.staff .sp-avatar { background: var(--gradient); color: #fff; }
/* Support Team: headset emoji (CSS content, so icons.js leaves it in colour) */
.sp-msg .sp-avatar.sp-avatar-support {
    background: var(--bg3);
    border: 1px solid var(--border);
    font-size: 1.1rem;
    line-height: 1;
}
.sp-avatar-support::before { content: '\1F3A7'; }
/* Customer's own replies: same look as the header profile logo */
.sp-avatar.sp-avatar-me {
    background: var(--gradient);
    color: #fff;
    border-radius: 10px;
    line-height: 1;
}
.sp-bubble-wrap { min-width: 0; }
.sp-msg-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 5px; font-size: 0.76rem; }
.sp-msg.mine .sp-msg-head { justify-content: flex-end; }
.sp-msg-name { font-weight: 700; color: var(--text); }
.sp-msg-time { color: var(--text3); }
.sp-staff-tag {
    font-size: 0.62rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .05em;
    padding: 1px 6px;
    border-radius: 5px;
    background: var(--primary-dim);
    color: var(--primary);
}
.sp-bubble {
    padding: 12px 15px;
    border-radius: 4px 16px 16px 16px;
    background: var(--bg2);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    font-size: 0.9rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}
.sp-msg.mine .sp-bubble {
    border-radius: 16px 4px 16px 16px;
    background: linear-gradient(135deg, rgba(var(--primary-r), 0.12), rgba(var(--purple-r), 0.10));
    border-color: rgba(var(--primary-r), 0.25);
}
.sp-bubble a { color: var(--primary); text-decoration: underline; }

.sp-composer { padding: 16px 22px 20px; border-top: 1px solid var(--border); }
.sp-composer .sp-textarea { width: 100%; box-sizing: border-box; margin: 0; }
.sp-composer-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 10px; }
.sp-composer-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.sp-hint { font-size: 0.74rem; color: var(--text3); }
.sp-closed-note {
    padding: 10px 14px;
    margin-bottom: 12px;
    border-radius: 10px;
    background: var(--bg3);
    color: var(--text2);
    font-size: 0.84rem;
}
.sp-quick { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.sp-quick-btn {
    border: 1px dashed rgba(var(--primary-r), 0.35);
    background: var(--primary-dim);
    color: var(--primary);
    font: inherit;
    font-size: 0.74rem;
    font-weight: 600;
    padding: 5px 10px;
    border-radius: 999px;
    cursor: pointer;
}
.sp-quick-btn:hover { background: rgba(var(--primary-r), 0.16); }

/* ── Admin side panel ─────────────────────────── */
.sp-side .sp-card { padding: 16px 18px; }
.sp-side .sp-card + .sp-card { margin-top: 14px; }
.sp-side-title { font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--text3); margin-bottom: 12px; }
.sp-cust { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.sp-cust-name { font-weight: 700; word-break: break-word; }
.sp-cust-role { font-size: 0.78rem; color: var(--text3); }
.sp-dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 12px; margin: 0; font-size: 0.82rem; }
.sp-dl dt { color: var(--text3); }
.sp-dl dd { margin: 0; text-align: right; color: var(--text); font-weight: 600; word-break: break-all; }
.sp-side .form-group { margin-bottom: 12px !important; }
.sp-del { width: 100%; margin-top: 16px; }
.sp-other {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 8px 0;
    border: 0;
    border-top: 1px solid var(--border);
    background: none;
    color: var(--text);
    font: inherit;
    font-size: 0.8rem;
    text-align: left;
    cursor: pointer;
}
.sp-other:first-of-type { border-top: 0; }
.sp-other:hover .sp-other-sub { color: var(--primary); }
.sp-other-sub { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Confirm dialog ───────────────────────────── */
.sp-confirm-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: grid;
    place-items: center;
    padding: 16px;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(3px);
    animation: sp-fade .15s ease;
}
.sp-confirm {
    width: 100%;
    max-width: 380px;
    padding: 24px;
    border-radius: var(--radius-lg);
    background: var(--bg2);
    color: var(--text);
    box-shadow: var(--shadow-lg);
    text-align: center;
}
.sp-confirm-msg { font-size: 0.95rem; line-height: 1.5; margin-bottom: 20px; }
.sp-confirm-actions { display: flex; justify-content: center; gap: 10px; }
@keyframes sp-fade { from { opacity: 0; } }

/* ── Responsive ───────────────────────────────── */
@media (max-width: 1100px) {
    .sp-detail.with-side { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
    .sp-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
    .sp-title { font-size: 1.25rem; }
    .sp-head { flex-direction: column; align-items: flex-start; gap: 12px; }
    .sp-new-btn {
        width: auto;
        align-self: flex-start;
        padding: 7px 14px;
        font-size: 0.82rem;
        min-height: 0;
        height: auto;
        border-radius: 10px;
    }
    .sp-stat { padding: 12px; gap: 10px; }
    .sp-stat-ico { width: 36px; height: 36px; font-size: 1rem; }
    .sp-stat-ico .sp-ico { width: 19px; height: 19px; }
    .sp-row { flex-direction: column; align-items: stretch; gap: 10px; padding: 14px; }
    .sp-row-side { justify-content: flex-start; }
    .sp-subject { white-space: normal; }
    .sp-search { max-width: none; width: 100%; }
    .sp-grid-2 { grid-template-columns: 1fr; }
    .sp-thread { padding: 16px 12px; max-height: none; }
    .sp-msg { max-width: 100%; }
    .sp-detail-head, .sp-composer { padding-left: 14px; padding-right: 14px; }
    .sp-composer-btns, .sp-composer-btns .btn { width: 100%; }
    .sp-form-actions .btn { flex: 1; }
}
