/* =====================================================================
   VinkDesk AI — Design System
   Premium SaaS theme with light/dark mode driven by [data-bs-theme].
   ===================================================================== */

:root {
    --sd-primary: #4f46e5;
    --sd-primary-rgb: 79, 70, 229;
    --sd-primary-hover: #4338ca;
    --sd-accent: #0ea5e9;
    --sd-sidebar-w: 264px;
    --sd-radius: 14px;
    --sd-radius-sm: 10px;
    --bs-body-font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

/* ---- Light theme ------------------------------------------------- */
[data-bs-theme="light"] {
    --sd-bg: #f5f6fb;
    --sd-surface: #ffffff;
    --sd-surface-2: #f8fafc;
    --sd-border: #e9ecf3;
    --sd-text: #1e2235;
    --sd-muted: #6b7280;
    --sd-sidebar-bg: #ffffff;
    --sd-sidebar-text: #4b5563;
    --sd-shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
    --sd-shadow-lg: 0 12px 32px rgba(16, 24, 40, .10);
}

/* ---- Dark theme -------------------------------------------------- */
[data-bs-theme="dark"] {
    --sd-bg: #0b0e1a;
    --sd-surface: #151a2d;
    --sd-surface-2: #1b2138;
    --sd-border: #252c44;
    --sd-text: #e6e9f5;
    --sd-muted: #9aa3bd;
    --sd-sidebar-bg: #0f1322;
    --sd-sidebar-text: #aab2cd;
    --sd-shadow: 0 1px 3px rgba(0, 0, 0, .4);
    --sd-shadow-lg: 0 16px 40px rgba(0, 0, 0, .5);
    --bs-body-bg: var(--sd-bg);
    --bs-body-color: var(--sd-text);
}

body {
    background: var(--sd-bg);
    color: var(--sd-text);
    font-family: var(--bs-body-font-family);
    -webkit-font-smoothing: antialiased;
}

/* ---- Layout shell ------------------------------------------------ */
.sd-shell { display: flex; min-height: 100vh; }

.sd-sidebar {
    width: var(--sd-sidebar-w);
    background: var(--sd-sidebar-bg);
    border-right: 1px solid var(--sd-border);
    position: fixed; inset: 0 auto 0 0; z-index: 1040;
    display: flex; flex-direction: column;
    transition: transform .25s ease;
}
.sd-main {
    flex: 1; margin-left: var(--sd-sidebar-w);
    min-width: 0; display: flex; flex-direction: column;
}

.sd-brand {
    display: flex; align-items: center; gap: .65rem;
    padding: 1.15rem 1.25rem; font-weight: 700; font-size: 1.12rem;
    color: var(--sd-text); text-decoration: none;
    border-bottom: 1px solid var(--sd-border);
}
.sd-brand-mark {
    width: 34px; height: 34px; border-radius: 9px;
    background: linear-gradient(135deg, var(--sd-primary), var(--sd-accent));
    display: grid; place-items: center; color: #fff; font-size: 1.05rem;
    box-shadow: 0 4px 12px rgba(var(--sd-primary-rgb), .4);
}

.sd-nav { padding: .85rem .75rem; overflow-y: auto; flex: 1; }
.sd-nav-label {
    font-size: .68rem; text-transform: uppercase; letter-spacing: .08em;
    color: var(--sd-muted); font-weight: 600; padding: .9rem .75rem .35rem;
}
.sd-nav-link {
    display: flex; align-items: center; gap: .7rem;
    padding: .58rem .75rem; margin-bottom: 2px; border-radius: var(--sd-radius-sm);
    color: var(--sd-sidebar-text); text-decoration: none; font-size: .9rem;
    font-weight: 500; transition: all .15s ease;
}
.sd-nav-link i { font-size: 1.05rem; width: 20px; text-align: center; }
.sd-nav-link:hover { background: var(--sd-surface-2); color: var(--sd-text); }
.sd-nav-link.active {
    background: rgba(var(--sd-primary-rgb), .12); color: var(--sd-primary); font-weight: 600;
}
.sd-nav-link .badge { margin-left: auto; }

/* ---- Topbar ------------------------------------------------------ */
.sd-topbar {
    height: 64px; background: var(--sd-surface);
    border-bottom: 1px solid var(--sd-border);
    display: flex; align-items: center; gap: 1rem;
    padding: 0 1.25rem; position: sticky; top: 0; z-index: 1030;
}
.sd-search { position: relative; max-width: 440px; flex: 1; }
.sd-search input {
    width: 100%; border: 1px solid var(--sd-border); background: var(--sd-surface-2);
    border-radius: var(--sd-radius-sm); padding: .5rem .9rem .5rem 2.4rem; color: var(--sd-text);
}
.sd-search i { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); color: var(--sd-muted); }
.sd-search-results {
    position: absolute; top: 110%; left: 0; right: 0; background: var(--sd-surface);
    border: 1px solid var(--sd-border); border-radius: var(--sd-radius); box-shadow: var(--sd-shadow-lg);
    z-index: 1050; max-height: 420px; overflow-y: auto; display: none;
}
.sd-content { padding: 1.6rem 1.75rem; flex: 1; }

.icon-btn {
    width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--sd-border);
    background: var(--sd-surface); color: var(--sd-text); display: grid; place-items: center;
    position: relative; cursor: pointer; transition: all .15s;
}
.icon-btn:hover { background: var(--sd-surface-2); }
.icon-btn .dot {
    position: absolute; top: 7px; right: 8px; min-width: 16px; height: 16px;
    background: #ef4444; color: #fff; border-radius: 9px; font-size: .6rem;
    display: grid; place-items: center; padding: 0 3px; font-weight: 700;
}

/* ---- Cards ------------------------------------------------------- */
.card {
    background: var(--sd-surface); border: 1px solid var(--sd-border);
    border-radius: var(--sd-radius); box-shadow: var(--sd-shadow);
}
.card-header { background: transparent; border-bottom: 1px solid var(--sd-border); font-weight: 600; }

.stat-card { padding: 1.25rem; display: flex; align-items: center; gap: 1rem; }
.stat-icon {
    width: 52px; height: 52px; border-radius: 13px; display: grid; place-items: center; font-size: 1.4rem;
}
.stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1; }
.stat-label { color: var(--sd-muted); font-size: .82rem; margin-top: .3rem; }

.text-muted, .sd-muted { color: var(--sd-muted) !important; }

/* ---- Tables ------------------------------------------------------ */
.table { color: var(--sd-text); margin: 0; }
.table > :not(caption) > * > * { border-bottom-color: var(--sd-border); padding: .8rem 1rem; }
.table thead th {
    font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
    color: var(--sd-muted); font-weight: 600; background: var(--sd-surface-2);
}
.table-hover tbody tr { transition: background .12s; }
.table-hover tbody tr:hover { background: var(--sd-surface-2); }
.ticket-row { cursor: pointer; }

/* ---- Badges / pills ---------------------------------------------- */
.badge { font-weight: 600; padding: .35em .65em; border-radius: 7px; }
.pill { display: inline-flex; align-items: center; gap: .35rem; font-size: .76rem; font-weight: 600;
    padding: .25rem .6rem; border-radius: 30px; }
.pill .dot-sm { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ---- Buttons ----------------------------------------------------- */
.btn-primary {
    --bs-btn-bg: var(--sd-primary); --bs-btn-border-color: var(--sd-primary);
    --bs-btn-hover-bg: var(--sd-primary-hover); --bs-btn-hover-border-color: var(--sd-primary-hover);
    --bs-btn-active-bg: var(--sd-primary-hover);
}
.btn { border-radius: var(--sd-radius-sm); font-weight: 500; }
.btn-soft { background: rgba(var(--sd-primary-rgb), .1); color: var(--sd-primary); border: none; }
.btn-soft:hover { background: rgba(var(--sd-primary-rgb), .18); color: var(--sd-primary); }

.form-control, .form-select {
    background: var(--sd-surface); border-color: var(--sd-border); color: var(--sd-text);
    border-radius: var(--sd-radius-sm);
}
.form-control:focus, .form-select:focus {
    background: var(--sd-surface); color: var(--sd-text); border-color: var(--sd-primary);
    box-shadow: 0 0 0 .2rem rgba(var(--sd-primary-rgb), .15);
}
.form-control::placeholder { color: var(--sd-muted); }
.dropdown-menu {
    background: var(--sd-surface); border-color: var(--sd-border); box-shadow: var(--sd-shadow-lg);
    border-radius: var(--sd-radius);
}
.dropdown-item { color: var(--sd-text); }
.dropdown-item:hover { background: var(--sd-surface-2); color: var(--sd-text); }

/* ---- Auth pages -------------------------------------------------- */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth-side {
    background: linear-gradient(150deg, var(--sd-primary), var(--sd-accent));
    color: #fff; padding: 3.5rem; display: flex; flex-direction: column; justify-content: center;
}
.auth-form { display: grid; place-items: center; padding: 2rem; }
.auth-card { width: 100%; max-width: 410px; }
@media (max-width: 860px) { .auth-wrap { grid-template-columns: 1fr; } .auth-side { display: none; } }

/* ---- Ticket conversation ----------------------------------------- */
/* The customer sits on the left, anyone from the support side on the right,
   the way a chat reads. Alignment alone is not enough for accessibility, so
   each side also carries its own bubble tint and avatar colour. */
.conv-item { display: flex; gap: .9rem; margin-bottom: 1.4rem; align-items: flex-start; }
.conv-bubble {
    background: var(--sd-surface); border: 1px solid var(--sd-border);
    border-radius: var(--sd-radius); padding: 1rem 1.15rem;
    /* Sized to its content instead of flex:1, otherwise every bubble spans the
       full row and the left/right split is invisible. */
    flex: 0 1 auto; max-width: 78%; min-width: 0; overflow-wrap: anywhere;
}
.conv-bubble > .d-flex { gap: 1rem; }

/* Customer — left, neutral */
.conv-item.customer .conv-bubble { background: var(--sd-surface-2); }
.conv-item.customer .avatar { background: linear-gradient(135deg, #94a3b8, #64748b); }

/* Support side — right, brand tint */
.conv-item.staff { flex-direction: row-reverse; }
.conv-item.staff .conv-bubble {
    background: rgba(var(--sd-primary-rgb), .07);
    border-color: rgba(var(--sd-primary-rgb), .22);
}
[data-bs-theme="dark"] .conv-item.staff .conv-bubble {
    background: rgba(var(--sd-primary-rgb), .16);
    border-color: rgba(var(--sd-primary-rgb), .34);
}

/* Internal / private notes — right as well (staff wrote them), but amber so
   they never get mistaken for something the customer can see. */
.conv-item.note { flex-direction: row-reverse; }
.conv-item.note .conv-bubble { background: #fff9e6; border-color: #f5e6a8; color: #6b5900; }
[data-bs-theme="dark"] .conv-item.note .conv-bubble { background: #2a2410; border-color: #4a3f18; color: #f0deb0; }

@media (max-width: 640px) { .conv-bubble { max-width: 92%; } }

.avatar {
    width: 40px; height: 40px; border-radius: 50%; object-fit: cover;
    display: grid; place-items: center; font-weight: 600; color: #fff; flex-shrink: 0;
    background: linear-gradient(135deg, var(--sd-primary), var(--sd-accent)); font-size: .85rem;
}
.avatar-sm { width: 30px; height: 30px; font-size: .72rem; }

/* ---- Timeline ---------------------------------------------------- */
.timeline { position: relative; padding-left: 1.5rem; }
.timeline::before { content: ''; position: absolute; left: 6px; top: 4px; bottom: 4px; width: 2px; background: var(--sd-border); }
.timeline-item { position: relative; padding-bottom: 1.1rem; }
.timeline-item::before {
    content: ''; position: absolute; left: -1.5rem; top: 4px; width: 12px; height: 12px;
    border-radius: 50%; background: var(--sd-primary); border: 2px solid var(--sd-surface);
}

/* ---- Misc -------------------------------------------------------- */
.score-ring { font-size: 2.4rem; font-weight: 800; }
.ai-panel { background: linear-gradient(135deg, rgba(var(--sd-primary-rgb), .08), rgba(14,165,233,.06));
    border: 1px solid rgba(var(--sd-primary-rgb), .2); border-radius: var(--sd-radius); }
.cursor-pointer { cursor: pointer; }
.sd-backdrop { display: none; }

@media (max-width: 991.98px) {
    .sd-sidebar { transform: translateX(-100%); }
    .sd-sidebar.show { transform: translateX(0); }
    .sd-main { margin-left: 0; }
    .sd-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1039; }
}
