/* ==========================================================================
   Kissly CRM — application stylesheet
   Plain CSS, custom properties, mobile-first responsive layout.
   ========================================================================== */

/* ---------- 1. Design tokens ---------------------------------------------- */
:root {
    --brand-50:  #eef2ff;
    --brand-100: #e0e7ff;
    --brand-200: #c7d2fe;
    --brand-400: #818cf8;
    --brand-500: #6366f1;
    --brand-600: #4f46e5;
    --brand-700: #4338ca;

    --ink-900: #0f172a;
    --ink-800: #1e293b;
    --ink-700: #334155;
    --ink-600: #475569;
    --ink-500: #64748b;
    --ink-400: #94a3b8;
    --ink-300: #cbd5e1;
    --ink-200: #e2e8f0;
    --ink-100: #f1f5f9;
    --ink-50:  #f8fafc;

    --green-50: #ecfdf5;  --green-600: #059669;  --green-700: #047857;
    --amber-50: #fffbeb;  --amber-600: #d97706;  --amber-700: #b45309;
    --red-50:   #fef2f2;  --red-600:   #dc2626;  --red-700:   #b91c1c;
    --blue-50:  #eff6ff;  --blue-600:  #2563eb;
    --slate-50: #f8fafc;

    --bg:            #f4f6fb;
    --surface:       #ffffff;
    --surface-alt:   var(--ink-50);
    --border:        var(--ink-200);
    --text:          var(--ink-800);
    --text-muted:    var(--ink-500);

    --sidebar-bg:    #111827;
    --sidebar-hover: #1f2937;
    --sidebar-text:  #cbd5e1;
    --sidebar-active:var(--brand-500);

    --radius-sm: 6px;
    --radius:    10px;
    --radius-lg: 16px;

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --shadow:    0 4px 12px rgba(15, 23, 42, .08);
    --shadow-lg: 0 20px 45px rgba(15, 23, 42, .18);

    --sidebar-w:    258px;
    --sidebar-rail: 74px;
    --header-h:     62px;

    /* Inter is loaded from Google Fonts; the stack degrades to the best
       available system UI face if the network is unavailable. */
    --font: "Inter", "Inter var", "Segoe UI Variable Text", "Segoe UI", system-ui,
            -apple-system, "Helvetica Neue", Arial, sans-serif;
    --mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Consolas,
            "Liberation Mono", monospace;

    --transition: 160ms cubic-bezier(.4, 0, .2, 1);
}

/* ---------- 2. Reset ------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 14.5px;
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    /* cv11 = single-storey "a"/"g", ss01 = friendlier punctuation */
    font-feature-settings: "cv11", "ss01";
    font-variant-ligatures: contextual;
}

/* Numbers that line up in columns — essential in a CRM full of counts,
   dates, phone numbers and IDs. */
.table, .stat__value, .mono, .pagination, .tab__count,
.detail-list__val, .badge, .json-box, .diff-table {
    font-variant-numeric: tabular-nums;
}

h1, h2, h3, .card__title, .stat__value, .modal__title,
.page-head h1, .auth__title, .sidebar__title {
    letter-spacing: -.011em;
}

h1, h2, h3, h4, h5, p, figure { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
img, svg { max-width: 100%; display: block; }
a { color: var(--brand-600); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; }
:focus-visible { outline: 2px solid var(--brand-500); outline-offset: 2px; }

/* ---------- 3. Utilities -------------------------------------------------- */
.hidden { display: none !important; }
.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--red-600); }
.text-success { color: var(--green-700); }
.text-warning { color: var(--amber-700); }
.text-sm    { font-size: 13px; }
.text-xs    { font-size: 12px; }
.text-right { text-align: right; }
.text-center{ text-align: center; }
.nowrap     { white-space: nowrap; }
.mono       { font-family: var(--mono); font-size: 12.5px; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.w-full { width: 100%; }

/* ---------- 4. App shell -------------------------------------------------- */
.app { min-height: 100vh; }

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform var(--transition);
}
.sidebar.is-open { transform: translateX(0); }

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: 10px;
    height: var(--header-h);
    padding: 0 18px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
    flex-shrink: 0;
}
.sidebar__logo {
    width: 34px; height: 34px;
    display: grid; place-items: center;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
    color: #fff; font-weight: 700; font-size: 15px;
    flex-shrink: 0;
}
.sidebar__title { color: #fff; font-weight: 650; font-size: 15.5px; letter-spacing: .2px; }
.sidebar__subtitle { font-size: 11.5px; color: var(--ink-400); }

.sidebar__nav { flex: 1; overflow-y: auto; padding: 14px 12px; }
.sidebar__section {
    font-size: 11px; text-transform: uppercase; letter-spacing: .09em;
    color: #64748b; padding: 14px 10px 6px;
}
.sidebar__link {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    font-weight: 500;
    transition: background var(--transition), color var(--transition);
    margin-bottom: 2px;
}
.sidebar__link:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.sidebar__link.is-active { background: var(--brand-600); color: #fff; box-shadow: var(--shadow-sm); }
.sidebar__link svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar__badge {
    margin-left: auto;
    background: rgba(255, 255, 255, .14);
    color: #fff;
    font-size: 11px; font-weight: 600;
    padding: 1px 7px; border-radius: 999px;
}
.sidebar__link.is-active .sidebar__badge { background: rgba(255, 255, 255, .25); }

.sidebar__footer {
    padding: 14px; border-top: 1px solid rgba(255, 255, 255, .08);
    font-size: 12px; color: var(--ink-400);
    flex-shrink: 0;
}

.sidebar-overlay {
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, .5);
    z-index: 55;
    opacity: 0; pointer-events: none;
    transition: opacity var(--transition);
}
.sidebar-overlay.is-visible { opacity: 1; pointer-events: auto; }

/* ---------- 4b. Collapsed sidebar (desktop icon rail) ---------------------
   Applied on <body>; only takes effect from 1024px up, where the sidebar is
   docked. Below that the sidebar is a drawer and this class is ignored.     */
@media (min-width: 1024px) {
    body.sidebar-collapsed .sidebar { width: var(--sidebar-rail); }
    body.sidebar-collapsed .main    { margin-left: var(--sidebar-rail); }

    body.sidebar-collapsed .sidebar__brand { justify-content: center; padding: 0 10px; }
    body.sidebar-collapsed .sidebar__brand > div,
    body.sidebar-collapsed .sidebar__section,
    body.sidebar-collapsed .sidebar__footer,
    body.sidebar-collapsed .sidebar__link > span:not(.sidebar__badge) { display: none; }

    body.sidebar-collapsed .sidebar__nav  { padding: 12px 10px; }
    body.sidebar-collapsed .sidebar__link {
        justify-content: center;
        padding: 11px 0;
        position: relative;
    }
    body.sidebar-collapsed .sidebar__link svg { width: 20px; height: 20px; }
    body.sidebar-collapsed .sidebar__badge {
        position: absolute; top: 5px; right: 9px;
        margin: 0; padding: 0 5px;
        font-size: 10px; line-height: 15px;
        background: var(--red-600);
    }
    /* The sidebar and content shift together rather than one sliding late. */
    .sidebar, .main { transition: width var(--transition), margin-left var(--transition), transform var(--transition); }
}

.main { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
    position: sticky; top: 0; z-index: 40;
    height: var(--header-h);
    display: flex; align-items: center; gap: 12px;
    padding: 0 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.topbar__toggle {
    display: inline-grid; place-items: center;
    width: 38px; height: 38px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--ink-700);
    cursor: pointer;
    position: relative;
}
.topbar__toggle:hover { background: var(--ink-100); }
.topbar__toggle-icon {
    position: absolute;
    transition: opacity var(--transition), transform var(--transition);
}
.topbar__toggle-icon--close {
    opacity: 0;
    transform: scale(.82) rotate(-45deg);
}
.topbar__toggle.is-open .topbar__toggle-icon--menu {
    opacity: 0;
    transform: scale(.82) rotate(45deg);
}
.topbar__toggle.is-open .topbar__toggle-icon--close {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}
body.sidebar-collapsed .topbar__toggle {
    background: var(--brand-50);
    border-color: var(--brand-200);
    color: var(--brand-700);
}
.topbar__heading { font-size: 16px; font-weight: 650; }
.topbar__crumb { font-size: 12px; color: var(--text-muted); }
.topbar__spacer { margin-left: auto; }

.user-chip {
    display: flex; align-items: center; gap: 9px;
    padding: 5px 9px 5px 5px;
    border: 1px solid var(--border); border-radius: 999px;
    background: var(--surface); cursor: pointer;
}
.user-chip:hover { background: var(--ink-50); }
.avatar {
    width: 30px; height: 30px; border-radius: 50%;
    display: grid; place-items: center;
    background: var(--brand-100); color: var(--brand-700);
    font-weight: 700; font-size: 12.5px;
    flex-shrink: 0;
}
.user-chip__meta { display: none; line-height: 1.2; text-align: left; }
.user-chip__name { font-size: 13px; font-weight: 600; }
.user-chip__role { font-size: 11px; color: var(--text-muted); }

.dropdown { position: relative; }
.dropdown__menu {
    position: absolute; right: 0; top: calc(100% + 8px);
    min-width: 210px;
    background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 6px;
    display: none;
    z-index: 50;
}
.dropdown__menu.is-open { display: block; }
.dropdown__header { padding: 8px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.dropdown__item {
    display: flex; align-items: center; gap: 9px;
    width: 100%; padding: 9px 10px;
    background: none; border: 0; border-radius: var(--radius-sm);
    color: var(--text); text-align: left; cursor: pointer;
}
.dropdown__item:hover { background: var(--ink-100); text-decoration: none; color: var(--text); }
.dropdown__item.is-danger { color: var(--red-600); }
.dropdown__item.is-danger:hover { background: var(--red-50); }

.content { flex: 1; padding: 18px 16px 40px; max-width: 1560px; width: 100%; margin: 0 auto; }

/* ---------- 5. Page header ------------------------------------------------ */
.page-head {
    display: flex; flex-wrap: wrap; align-items: flex-start;
    gap: 12px; margin-bottom: 18px;
}
.page-head__text { flex: 1 1 260px; min-width: 0; }
.page-head h1 { font-size: 21px; font-weight: 680; letter-spacing: -.01em; }
.page-head p { color: var(--text-muted); font-size: 13.5px; margin-top: 2px; }
.page-head__actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- 6. Cards ------------------------------------------------------ */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card__head {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.card__title { font-size: 14.5px; font-weight: 650; }
.card__body { padding: 16px; }
.card__body--flush { padding: 0; }
.card__foot { padding: 12px 16px; border-top: 1px solid var(--border); background: var(--surface-alt); }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}
.stat {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 15px 16px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: transform var(--transition), box-shadow var(--transition);
}
.stat:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.stat::after {
    content: ""; position: absolute; inset: 0 auto 0 0; width: 3px;
    background: var(--brand-500);
}
.stat--green::after { background: var(--green-600); }
.stat--amber::after { background: var(--amber-600); }
.stat--red::after   { background: var(--red-600); }
.stat--blue::after  { background: var(--blue-600); }
.stat--slate::after { background: var(--ink-400); }

.stat__label {
    font-size: 11.5px; font-weight: 600; letter-spacing: .05em;
    text-transform: uppercase; color: var(--text-muted);
}
.stat__value { font-size: 27px; font-weight: 700; line-height: 1.15; margin-top: 6px; letter-spacing: -.02em; }
.stat__hint { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.stat__icon {
    position: absolute; right: 14px; top: 14px;
    width: 34px; height: 34px; border-radius: 9px;
    display: grid; place-items: center;
    background: var(--brand-50); color: var(--brand-600);
}
.stat--green .stat__icon { background: var(--green-50); color: var(--green-700); }
.stat--amber .stat__icon { background: var(--amber-50); color: var(--amber-700); }
.stat--red   .stat__icon { background: var(--red-50);   color: var(--red-700); }
.stat--blue  .stat__icon { background: var(--blue-50);  color: var(--blue-600); }
.stat--slate .stat__icon { background: var(--ink-100);  color: var(--ink-600); }

.grid-2 { display: grid; grid-template-columns: 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr; gap: 16px; }

/* ---------- 7. Buttons ---------------------------------------------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    padding: 9px 15px;
    min-height: 40px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 13.5px; font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--transition), border-color var(--transition), color var(--transition), opacity var(--transition);
}
.btn:hover { text-decoration: none; }
.btn:disabled, .btn.is-loading { opacity: .6; cursor: not-allowed; pointer-events: none; }
.btn svg { width: 16px; height: 16px; }

.btn--primary { background: var(--brand-600); color: #fff; }
.btn--primary:hover { background: var(--brand-700); color: #fff; }
.btn--secondary { background: var(--surface); border-color: var(--border); color: var(--ink-700); }
.btn--secondary:hover { background: var(--ink-100); }
.btn--ghost { background: transparent; color: var(--ink-600); }
.btn--ghost:hover { background: var(--ink-100); }
.btn--danger { background: var(--red-600); color: #fff; }
.btn--danger:hover { background: var(--red-700); color: #fff; }
.btn--success { background: var(--green-600); color: #fff; }
.btn--success:hover { background: var(--green-700); color: #fff; }
.btn--sm { padding: 6px 11px; min-height: 32px; font-size: 12.5px; border-radius: var(--radius-sm); }
.btn--icon { padding: 0; width: 34px; min-height: 34px; flex-shrink: 0; }
.btn--icon.btn--sm { width: 32px; min-height: 32px; }
.btn--icon svg { width: 16px; height: 16px; }
.btn--icon {
    background: var(--surface);
    border-color: var(--border);
    color: var(--ink-600);
}
.btn--icon:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}
.btn--icon.btn--danger,
.btn--icon.btn--success,
.btn--icon.btn--primary {
    background: var(--surface);
    border-color: var(--border);
}
.btn--icon.btn--danger { color: var(--red-700); }
.btn--icon.btn--success { color: var(--green-700); }
.btn--icon.btn--primary { color: var(--brand-700); }
.btn--icon-view,
.btn--action-view,
.btn[data-action="view"] { color: var(--blue-600); background: var(--blue-50); border-color: #bfdbfe; }
.btn--icon-edit,
.btn--action-edit,
.btn[data-action="edit"],
.btn[data-act="edit-follow"],
.btn[data-problem-action="edit"] { color: var(--brand-700); background: var(--brand-50); border-color: var(--brand-200); }
.btn--icon-trash,
.btn--action-delete,
.btn[data-action="delete"] { color: var(--red-700); background: var(--red-50); border-color: #fecaca; }
.btn--icon-phone,
.btn--action-call,
.btn[data-action="call"] { color: var(--green-700); background: var(--green-50); border-color: #a7f3d0; }
.btn--icon-calendar,
.btn--action-follow,
.btn--action-reschedule,
.btn[data-action="follow"],
.btn[data-act="edit-follow"] { color: var(--amber-700); background: var(--amber-50); border-color: #fde68a; }
.btn--icon-check,
.btn--action-complete,
.btn[data-act="complete"] { color: var(--green-700); background: var(--green-50); border-color: #a7f3d0; }
.btn--icon-key,
.btn--action-password,
.btn--action-reset,
.btn[data-action="reset-password"] { color: var(--brand-700); background: var(--brand-50); border-color: var(--brand-200); }
.btn--icon-power,
.btn--action-toggle,
.btn[data-action="toggle-status"],
.btn[data-problem-action="toggle"] { color: var(--amber-700); background: var(--amber-50); border-color: #fde68a; }
.btn--icon-close,
.btn--action-cancel,
.btn[data-action="cancel"] { color: var(--red-700); background: var(--red-50); border-color: #fecaca; }
.btn--icon-user { color: var(--blue-600); background: var(--blue-50); border-color: #bfdbfe; }
.btn--icon-activity,
.btn--action-activity { color: var(--ink-700); background: var(--ink-100); border-color: var(--ink-200); }
.btn--icon-archive,
.btn--action-archive { color: var(--red-700); background: var(--red-50); border-color: #fecaca; }
.btn--block { width: 100%; }

.btn.is-loading::before {
    content: ""; width: 14px; height: 14px;
    border: 2px solid currentColor; border-right-color: transparent;
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

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

/* Action rows never wrap onto a second line — icons stay side by side. */
.btn-group { display: inline-flex; gap: 5px; flex-wrap: nowrap; align-items: center; }

/* ---------- 7b. Tooltips --------------------------------------------------
   Rendered into <body> with position:fixed so a scrollable .table-wrap can
   never clip them.                                                          */
.tooltip {
    position: fixed;
    z-index: 300;
    padding: 5px 9px;
    background: var(--ink-900);
    color: #fff;
    font-size: 12px;
    font-weight: 550;
    line-height: 1.35;
    border-radius: 6px;
    box-shadow: var(--shadow);
    pointer-events: none;
    white-space: nowrap;
    max-width: 260px;
    opacity: 0;
    transform: translateY(3px);
    transition: opacity .12s ease, transform .12s ease;
}
.tooltip.is-visible { opacity: 1; transform: none; }
.tooltip::after {
    content: "";
    position: absolute;
    left: 50%; margin-left: -4px;
    top: 100%;
    border: 4px solid transparent;
    border-top-color: var(--ink-900);
}
.tooltip--below::after {
    top: auto; bottom: 100%;
    border-top-color: transparent;
    border-bottom-color: var(--ink-900);
}
/* Touch devices get no hover — suppress rather than leave a stuck bubble. */
@media (hover: none) {
    .tooltip { display: none; }
}

/* ---------- 8. Forms ------------------------------------------------------ */
.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
}
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field--full { grid-column: 1 / -1; }
.label { font-size: 12.5px; font-weight: 600; color: var(--ink-700); }
.label .req { color: var(--red-600); }

.input, .select, .textarea {
    width: 100%;
    padding: 9px 11px;
    min-height: 40px;
    font: inherit;
    font-size: 14px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--ink-300);
    border-radius: var(--radius-sm);
    transition: border-color var(--transition), box-shadow var(--transition);
    -webkit-appearance: none;
    appearance: none;
}
.select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%2364748b'%3E%3Cpath d='M5.2 7.5 10 12.3l4.8-4.8'  stroke='%2364748b' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 9px center;
    background-size: 18px;
    padding-right: 32px;
}
.textarea { min-height: 92px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--brand-500);
    box-shadow: 0 0 0 3px var(--brand-100);
}
.input::placeholder, .textarea::placeholder { color: var(--ink-400); }
.input.is-invalid, .select.is-invalid, .textarea.is-invalid {
    border-color: var(--red-600);
    box-shadow: 0 0 0 3px var(--red-50);
}
.input:disabled, .select:disabled, .textarea:disabled { background: var(--ink-100); color: var(--ink-500); cursor: not-allowed; }

.field-error { font-size: 12px; color: var(--red-600); min-height: 0; }
.field-hint  { font-size: 12px; color: var(--text-muted); }

.checkbox, .radio {
    display: flex; align-items: flex-start; gap: 9px;
    padding: 9px 11px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    cursor: pointer;
    background: var(--surface);
    transition: border-color var(--transition), background var(--transition);
}
.checkbox:hover, .radio:hover { background: var(--ink-50); }
.checkbox input, .radio input { margin: 3px 0 0; width: 16px; height: 16px; accent-color: var(--brand-600); flex-shrink: 0; }
.checkbox.is-checked { border-color: var(--brand-400); background: var(--brand-50); }
.checkbox__text { font-size: 13.5px; font-weight: 550; }
.checkbox__hint { font-size: 11.5px; color: var(--text-muted); display: block; }
.checkbox.is-disabled { opacity: .55; cursor: not-allowed; }

.permission-grid { display: grid; grid-template-columns: 1fr; gap: 8px; }

.filters {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-alt);
    border-radius: var(--radius) var(--radius) 0 0;
}
.filters__actions { display: flex; gap: 8px; align-items: flex-end; }

.search-box { position: relative; }
.search-box .input { padding-left: 34px; }
.search-box svg {
    position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
    width: 16px; height: 16px; color: var(--ink-400); pointer-events: none;
}

/* ---------- 9. Tables ----------------------------------------------------- */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

.table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 720px; }
.table th, .table td { padding: 11px 14px; text-align: left; vertical-align: middle; }
.table thead th {
    background: var(--surface-alt);
    font-size: 11.5px; font-weight: 650; letter-spacing: .05em; text-transform: uppercase;
    color: var(--ink-600);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    position: sticky; top: 0; z-index: 1;
}
.table thead th.is-sortable { cursor: pointer; user-select: none; }
.table thead th.is-sortable:hover { color: var(--brand-600); }
.table thead th .sort-arrow { opacity: .45; font-size: 10px; margin-left: 3px; }
.table thead th.is-sorted .sort-arrow { opacity: 1; color: var(--brand-600); }
.table tbody tr { border-bottom: 1px solid var(--ink-100); }
.table tbody tr:last-child { border-bottom: 0; }
.table tbody tr:hover { background: var(--brand-50); }
.table td .cell-title { font-weight: 600; }
.table td .cell-sub { font-size: 12px; color: var(--text-muted); }
.table .col-actions { width: 1%; white-space: nowrap; text-align: right; }

/* Mobile: turn each row into a stacked card. */
@media (max-width: 767px) {
    .table, .table thead, .table tbody, .table tr, .table th, .table td { display: block; }
    .table { min-width: 0; }
    .table thead { display: none; }
    .table tbody tr {
        border: 1px solid var(--border);
        border-radius: var(--radius);
        margin-bottom: 10px;
        padding: 6px 4px;
        background: var(--surface);
        box-shadow: var(--shadow-sm);
    }
    .table tbody tr:hover { background: var(--surface); }
    .table td {
        display: flex; align-items: flex-start; justify-content: space-between; gap: 14px;
        padding: 7px 12px;
        border: 0;
        text-align: right;
    }
    .table td::before {
        content: attr(data-label);
        font-size: 11.5px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase;
        color: var(--text-muted);
        text-align: left;
        flex-shrink: 0;
    }
    .table td:empty { display: none; }
    .table .col-actions { width: auto; text-align: right; }
    .table .col-actions .btn-group { justify-content: flex-end; flex-wrap: nowrap; }
    /* Give the icon row a little more room to breathe on a phone. */
    .table .col-actions .btn--icon { width: 34px; min-height: 34px; }
}

/* ---------- 10. Badges ---------------------------------------------------- */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 9px;
    font-size: 11.5px; font-weight: 650; letter-spacing: .02em;
    border-radius: 999px;
    background: var(--ink-100); color: var(--ink-700);
    white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge--new            { background: var(--blue-50);  color: var(--blue-600); }
.badge--interested     { background: var(--green-50); color: var(--green-700); }
.badge--not_interested { background: var(--red-50);   color: var(--red-700); }
.badge--call_back      { background: var(--amber-50); color: var(--amber-700); }
.badge--no_answer      { background: var(--ink-100);  color: var(--ink-600); }
.badge--completed      { background: var(--brand-50); color: var(--brand-700); }
.badge--answered       { background: var(--green-50); color: var(--green-700); }
.badge--busy           { background: var(--amber-50); color: var(--amber-700); }
.badge--pending        { background: var(--blue-50);  color: var(--blue-600); }
.badge--cancelled      { background: var(--ink-100);  color: var(--ink-600); }
.badge--missed         { background: var(--red-50);   color: var(--red-700); }
.badge--admin          { background: var(--brand-50); color: var(--brand-700); }
.badge--staff          { background: var(--ink-100);  color: var(--ink-700); }
.badge--active         { background: var(--green-50); color: var(--green-700); }
.badge--inactive       { background: var(--red-50);   color: var(--red-700); }
.badge--overdue        { background: var(--red-50);   color: var(--red-700); }
.badge--today          { background: var(--amber-50); color: var(--amber-700); }
.badge--upcoming       { background: var(--blue-50);  color: var(--blue-600); }
.badge--plain::before  { display: none; }

/* ticket statuses */
.badge--open        { background: var(--blue-50);  color: var(--blue-600); }
.badge--in_progress { background: var(--amber-50); color: var(--amber-700); }
.badge--on_hold     { background: var(--ink-100);  color: var(--ink-600); }
.badge--resolved    { background: var(--green-50); color: var(--green-700); }
.badge--closed      { background: var(--ink-100);  color: var(--ink-700); }

/* ticket priorities */
.badge--low     { background: var(--ink-100);  color: var(--ink-600); }
.badge--normal  { background: var(--blue-50);  color: var(--blue-600); }
.badge--high    { background: var(--amber-50); color: var(--amber-700); }
.badge--urgent  { background: var(--red-50);   color: var(--red-700); }

/* ---------- 11. Tabs ------------------------------------------------------ */
.tabs {
    display: flex; gap: 4px;
    overflow-x: auto;
    border-bottom: 1px solid var(--border);
    padding: 0 6px;
    background: var(--surface);
    border-radius: var(--radius) var(--radius) 0 0;
    -webkit-overflow-scrolling: touch;
}
.tab {
    position: relative;
    padding: 12px 14px;
    border: 0; background: none;
    color: var(--ink-600); font-size: 13.5px; font-weight: 600;
    cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--brand-600); }
.tab.is-active { color: var(--brand-700); }
.tab.is-active::after {
    content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px;
    height: 2px; background: var(--brand-600); border-radius: 2px 2px 0 0;
}
.tab__count {
    display: inline-block; margin-left: 6px;
    background: var(--ink-100); color: var(--ink-600);
    font-size: 11px; font-weight: 700;
    padding: 1px 7px; border-radius: 999px;
}
.tab.is-active .tab__count { background: var(--brand-100); color: var(--brand-700); }

/* ---------- 12. Pagination ------------------------------------------------ */
.pagination {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
    gap: 10px; padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: var(--surface-alt);
    border-radius: 0 0 var(--radius) var(--radius);
}
.pagination__info { font-size: 12.5px; color: var(--text-muted); }
.pagination__pages { display: flex; gap: 4px; flex-wrap: wrap; }
.pagination__btn {
    min-width: 34px; height: 34px; padding: 0 9px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--ink-700);
    font-size: 13px; font-weight: 600; cursor: pointer;
}
.pagination__btn:hover:not(:disabled) { background: var(--ink-100); }
.pagination__btn.is-active { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }
.pagination__btn:disabled { opacity: .45; cursor: not-allowed; }
.pagination__gap { display: grid; place-items: center; min-width: 22px; color: var(--ink-400); }

/* ---------- 13. Empty / loading states ------------------------------------ */
.empty-state { padding: 46px 20px; text-align: center; }
.empty-state__icon {
    width: 52px; height: 52px; margin: 0 auto 12px;
    display: grid; place-items: center;
    border-radius: 50%; background: var(--ink-100); color: var(--ink-400);
}
.empty-state__title { font-weight: 650; font-size: 15px; margin-bottom: 4px; }
.empty-state__text { color: var(--text-muted); font-size: 13.5px; max-width: 380px; margin: 0 auto 14px; }

.skeleton {
    background: linear-gradient(90deg, var(--ink-100) 25%, var(--ink-200) 37%, var(--ink-100) 63%);
    background-size: 400% 100%;
    animation: shimmer 1.3s ease infinite;
    border-radius: var(--radius-sm);
    height: 14px;
}
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.skeleton-row { padding: 13px 14px; border-bottom: 1px solid var(--ink-100); display: flex; gap: 14px; align-items: center; }
.skeleton-row .skeleton:nth-child(1) { width: 22%; }
.skeleton-row .skeleton:nth-child(2) { width: 30%; }
.skeleton-row .skeleton:nth-child(3) { width: 16%; }
.skeleton-row .skeleton:nth-child(4) { width: 24%; }

.loading-bar {
    position: fixed; top: 0; left: 0; right: 0; height: 3px;
    background: transparent; z-index: 200;
    pointer-events: none; overflow: hidden;
}
.loading-bar.is-active::after {
    content: ""; position: absolute; inset: 0;
    background: linear-gradient(90deg, transparent, var(--brand-500), var(--brand-400), transparent);
    animation: slide 1.1s ease-in-out infinite;
}
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }

.inline-spinner {
    display: inline-block; width: 15px; height: 15px;
    border: 2px solid var(--ink-300); border-right-color: var(--brand-600);
    border-radius: 50%; animation: spin .7s linear infinite;
    vertical-align: -2px;
}

/* ---------- 14. Modals ---------------------------------------------------- */
.modal-root {
    position: fixed; inset: 0; z-index: 120;
    display: none;
    align-items: flex-end; justify-content: center;
    padding: 0;
    background: rgba(15, 23, 42, .55);
    overflow-y: auto;
}
.modal-root.is-open { display: flex; }

.modal {
    position: relative;
    width: 100%;
    max-width: 620px;
    background: var(--surface);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: var(--shadow-lg);
    animation: modal-up .22s cubic-bezier(.2, .8, .3, 1);
    max-height: 94vh;
    display: flex; flex-direction: column;
}
.modal--wide { max-width: 900px; }
.modal--sm   { max-width: 440px; }
@keyframes modal-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

.modal__head {
    display: flex; align-items: flex-start; gap: 12px;
    padding: 16px 18px; border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.modal__title { font-size: 16px; font-weight: 680; }
.modal__subtitle { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.modal__close {
    margin-left: auto;
    width: 32px; height: 32px;
    display: grid; place-items: center;
    border: 0; border-radius: var(--radius-sm);
    background: transparent; color: var(--ink-500); cursor: pointer;
    flex-shrink: 0;
}
.modal__close:hover { background: var(--ink-100); color: var(--ink-800); }
.modal__body { padding: 18px; overflow-y: auto; flex: 1; }
.modal__foot {
    display: flex; justify-content: flex-end; gap: 8px;
    padding: 14px 18px; border-top: 1px solid var(--border);
    background: var(--surface-alt);
    flex-shrink: 0;
    flex-wrap: wrap;
}
.modal__foot .btn { flex: 1 1 auto; }

.confirm-icon {
    width: 44px; height: 44px; border-radius: 50%;
    display: grid; place-items: center;
    background: var(--red-50); color: var(--red-600);
    flex-shrink: 0;
}
.confirm-icon--warn { background: var(--amber-50); color: var(--amber-700); }
.confirm-icon--info { background: var(--blue-50); color: var(--blue-600); }

/* ---------- 15. Toasts ---------------------------------------------------- */
.toast-root {
    position: fixed; z-index: 200;
    left: 12px; right: 12px; bottom: 12px;
    display: flex; flex-direction: column-reverse; gap: 8px;
    pointer-events: none;
}
.toast {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--brand-500);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    pointer-events: auto;
    animation: toast-in .22s ease;
}
.toast.is-leaving { animation: toast-out .2s ease forwards; }
@keyframes toast-in  { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toast-out { to { transform: translateY(10px); opacity: 0; } }
.toast--success { border-left-color: var(--green-600); }
.toast--error   { border-left-color: var(--red-600); }
.toast--warning { border-left-color: var(--amber-600); }
.toast--info    { border-left-color: var(--blue-600); }
.toast__icon { flex-shrink: 0; margin-top: 1px; }
.toast--success .toast__icon { color: var(--green-600); }
.toast--error   .toast__icon { color: var(--red-600); }
.toast--warning .toast__icon { color: var(--amber-600); }
.toast--info    .toast__icon { color: var(--blue-600); }
.toast__body { flex: 1; min-width: 0; }
.toast__title { font-weight: 650; font-size: 13.5px; }
.toast__text { font-size: 13px; color: var(--text-muted); word-break: break-word; }
.toast__close {
    border: 0; background: none; color: var(--ink-400); cursor: pointer;
    padding: 0; width: 20px; height: 20px; display: grid; place-items: center;
    flex-shrink: 0;
}
.toast__close:hover { color: var(--ink-700); }

/* ---------- 16. Timeline (notes / calls / follow-ups) --------------------- */
.timeline { position: relative; padding-left: 26px; }
.timeline::before {
    content: ""; position: absolute; left: 8px; top: 6px; bottom: 6px;
    width: 2px; background: var(--ink-200);
}
.timeline__item { position: relative; padding-bottom: 18px; }
.timeline__item:last-child { padding-bottom: 0; }
.timeline__dot {
    position: absolute; left: -22px; top: 4px;
    width: 12px; height: 12px; border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--brand-500);
}
.timeline__dot--green { border-color: var(--green-600); }
.timeline__dot--red   { border-color: var(--red-600); }
.timeline__dot--amber { border-color: var(--amber-600); }
.timeline__dot--slate { border-color: var(--ink-400); }
.timeline__head {
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
    margin-bottom: 3px;
}
.timeline__time { font-size: 12px; color: var(--text-muted); }
.timeline__body {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    font-size: 13.5px;
    white-space: pre-wrap;
    word-break: break-word;
}
.timeline__meta { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ---------- 17. Definition list ------------------------------------------ */
.detail-list { display: grid; grid-template-columns: 1fr; gap: 0; }
.detail-list__row {
    display: flex; justify-content: space-between; gap: 16px;
    padding: 9px 0;
    border-bottom: 1px dashed var(--ink-200);
    font-size: 13.5px;
}
.detail-list__row:last-child { border-bottom: 0; }
.detail-list__key { color: var(--text-muted); flex-shrink: 0; }
.detail-list__val { text-align: right; font-weight: 550; word-break: break-word; }

/* ---------- 18. JSON viewer ----------------------------------------------- */
.json-box {
    background: var(--ink-900);
    color: #e2e8f0;
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    font-family: var(--mono);
    font-size: 12.5px;
    line-height: 1.6;
    overflow-x: auto;
    white-space: pre;
    max-height: 320px;
    overflow-y: auto;
}
.json-box .k { color: #93c5fd; }
.json-box .s { color: #86efac; }
.json-box .n { color: #fca5a5; }
.json-box .b { color: #fcd34d; }
.json-box--empty { background: var(--ink-100); color: var(--ink-500); font-style: italic; white-space: normal; }

.diff-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.diff-table th, .diff-table td { padding: 8px 10px; border: 1px solid var(--border); text-align: left; vertical-align: top; }
.diff-table th { background: var(--surface-alt); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-600); }
.diff-old { background: var(--red-50); color: var(--red-700); font-family: var(--mono); font-size: 12.5px; word-break: break-word; }
.diff-new { background: var(--green-50); color: var(--green-700); font-family: var(--mono); font-size: 12.5px; word-break: break-word; }

/* ---------- 19. Login page ------------------------------------------------ */
/* A single centred card — nothing else on the page. */
.auth {
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 24px 16px;
    background:
        radial-gradient(1100px 520px at 50% -12%, var(--brand-50) 0%, transparent 62%),
        var(--bg);
}

.auth__card {
    width: 100%;
    max-width: 390px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 12px 34px rgba(15, 23, 42, .07);
    padding: 34px 30px 30px;
}

.auth__brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-bottom: 26px;
}
.auth__brand .sidebar__logo {
    width: 46px; height: 46px;
    font-size: 19px;
    border-radius: 13px;
    box-shadow: 0 6px 16px rgba(79, 70, 229, .28);
}
.auth__title {
    font-size: 18.5px;
    font-weight: 680;
    letter-spacing: -.01em;
    text-align: center;
}

.auth__form { display: grid; gap: 16px; }
.auth__form .btn { margin-top: 2px; }
.auth__form--shake { animation: auth-shake .2s ease; }
@keyframes auth-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

.alert {
    display: flex; gap: 10px; align-items: flex-start;
    padding: 11px 13px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    border: 1px solid transparent;
}
.alert svg { flex-shrink: 0; margin-top: 2px; }
.alert--error   { background: var(--red-50);   color: var(--red-700);   border-color: #fecaca; }
.alert--success { background: var(--green-50); color: var(--green-700); border-color: #a7f3d0; }
.alert--info    { background: var(--blue-50);  color: var(--blue-600);  border-color: #bfdbfe; }
.alert--warning { background: var(--amber-50); color: var(--amber-700); border-color: #fde68a; }

.password-field { position: relative; }
.password-field .input { padding-right: 44px; }
.password-toggle {
    position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
    width: 34px; height: 34px;
    display: grid; place-items: center;
    border: 0; background: none; color: var(--ink-500); cursor: pointer;
    border-radius: var(--radius-sm);
}
.password-toggle:hover,
.password-toggle.is-showing { background: var(--ink-100); color: var(--brand-700); }
.password-toggle__icon--hide { display: none; }
.password-toggle.is-showing .password-toggle__icon--show { display: none; }
.password-toggle.is-showing .password-toggle__icon--hide { display: block; }
.auth .field-error:not(:empty) {
    display: block;
    margin-top: 6px;
    font-weight: 600;
}
.auth .input.is-invalid {
    background: #fff7f7;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, .08);
}

/* ---------- 20. Error pages ---------------------------------------------- */
.state-page { display: grid; place-items: center; min-height: 60vh; padding: 24px; text-align: center; }
.state-page__code { font-size: 58px; font-weight: 800; color: var(--brand-600); line-height: 1; }
.state-page__title { font-size: 20px; font-weight: 680; margin-top: 8px; }
.state-page__text { color: var(--text-muted); max-width: 420px; margin: 8px auto 18px; }

/* ---------- 21. Responsive breakpoints ------------------------------------ */
@media (min-width: 576px) {
    .toast-root { left: auto; right: 18px; bottom: 18px; width: 370px; }
    .modal-root { align-items: center; padding: 20px; }
    .modal { border-radius: var(--radius-lg); }
    .modal__foot .btn { flex: 0 0 auto; }
    .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .permission-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .user-chip__meta { display: block; }
}

@media (min-width: 768px) {
    .content { padding: 22px 22px 48px; }
    .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .detail-list { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 28px; }
}

@media (min-width: 992px) {
    .filters { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .grid-3 { grid-template-columns: 2fr 1fr; }
}

@media (min-width: 1024px) {
    .sidebar { transform: translateX(0); }
    .main { margin-left: var(--sidebar-w); }
    .topbar { padding: 0 22px; }
    .sidebar-overlay { display: none; }
    .filters { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (min-width: 1280px) {
    .grid-3 { grid-template-columns: 2.2fr 1fr; }
    .permission-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* Reduce motion for users who ask for it. */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}

/* Print: keep the report readable. */
@media print {
    .sidebar, .topbar, .page-head__actions, .pagination, .filters, .toast-root { display: none !important; }
    .main { margin-left: 0; }
    .card { box-shadow: none; border-color: #999; }
}
