/* =====================================================================
   Agent Management System — Premium UI theme
   ===================================================================== */

:root {
    --sidebar-w: 264px;

    /* Brand */
    --brand: #6366f1;
    --brand-2: #8b5cf6;
    --brand-ink: #4f46e5;
    --brand-grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --brand-soft: rgba(99, 102, 241, .12);

    /* Surfaces */
    --bg: #f4f5fb;
    --card: #ffffff;
    --card-border: #eceef6;
    --ink: #1b2236;
    --ink-soft: #4a5169;
    --muted: #8990a6;

    /* Status */
    --ok: #10b981;
    --warn: #f59e0b;
    --bad: #ef4444;
    --info: #0ea5e9;

    /* Surface tokens (overridden in dark mode) */
    --surface-2: #f4f5fb;
    --row-border: #f1f2f8;
    --row-hover: #fafaff;
    --topbar-bg: rgba(255, 255, 255, .8);
    --input-bg: #ffffff;
    --input-border: #e3e6f0;
    --code-ink: #b4258a;

    --radius: 16px;
    --radius-sm: 11px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
    --shadow-md: 0 6px 20px rgba(16, 24, 40, .08);
    --shadow-lg: 0 18px 50px rgba(24, 20, 50, .18);

    /* Fluid type scale (min @360px → max @1200px viewport) */
    --fs-h1: clamp(1.25rem, 1.05rem + 1.0vw, 1.5rem);
    --fs-h2: clamp(1.1rem, 0.98rem + 0.6vw, 1.25rem);
    --content-pad: clamp(1rem, 0.4rem + 2.4vw, 1.75rem);
}

/* ---------------- Dark theme ---------------- */
[data-theme="dark"] {
    --bg: #14121f;
    --card: #1d1a2e;
    --card-border: rgba(255, 255, 255, .08);
    --ink: #e9eaf6;
    --ink-soft: #c2c6dc;
    --muted: #8e93ab;
    --brand-soft: rgba(139, 92, 246, .18);
    --surface-2: #262236;
    --row-border: rgba(255, 255, 255, .06);
    --row-hover: rgba(255, 255, 255, .035);
    --topbar-bg: rgba(29, 26, 46, .82);
    --input-bg: #262236;
    --input-border: rgba(255, 255, 255, .10);
    --code-ink: #f0a3d6;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, .4);
}
[data-theme="dark"] body,
body[data-theme="dark"] {
    background:
        radial-gradient(1200px 600px at 110% -10%, rgba(139, 92, 246, .16), transparent 60%),
        radial-gradient(900px 500px at -10% 10%, rgba(99, 102, 241, .12), transparent 55%),
        var(--bg);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background:
        radial-gradient(1200px 600px at 110% -10%, rgba(139, 92, 246, .10), transparent 60%),
        radial-gradient(900px 500px at -10% 10%, rgba(99, 102, 241, .08), transparent 55%),
        var(--bg);
    color: var(--ink);
    font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    letter-spacing: -.006em;
}

h1, h2, h3, h4, h5, h6 { letter-spacing: -.02em; }
a { color: var(--brand-ink); }
code { color: var(--code-ink); }
.text-muted { color: var(--muted) !important; }
body, .card-surface, .stat-card, .topbar, .form-control, .form-select, .app-footer, .table tbody tr {
    transition: background-color .25s ease, border-color .25s ease, color .25s ease;
}

/* ---------------- Auth ---------------- */
.auth-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    padding: 1rem; position: relative; overflow: hidden;
    background: radial-gradient(1000px 700px at 80% -10%, #7c3aed, transparent 60%),
                radial-gradient(900px 600px at 0% 110%, #4f46e5, transparent 55%),
                linear-gradient(135deg, #4338ca 0%, #6d28d9 100%);
}
.auth-page::before {
    content: ""; position: absolute; inset: 0;
    background-image: radial-gradient(rgba(255,255,255,.06) 1px, transparent 1px);
    background-size: 22px 22px; opacity: .5;
}
.auth-card {
    position: relative; width: 100%; max-width: 410px;
    background: rgba(255, 255, 255, .98);
    border: 1px solid rgba(255, 255, 255, .6);
    border-radius: 20px; padding: 2.5rem 2.25rem;
    box-shadow: var(--shadow-lg);
}
/* The auth card is always a white surface (on the purple gradient), so pin its
   text to dark inks regardless of the active theme — otherwise dark mode's light
   --ink/--ink-soft/--muted render light-on-white and become unreadable. */
.auth-card {
    --ink: #1b2236;
    --ink-soft: #4a5169;
    --muted: #8990a6;
    color: var(--ink);
}
.auth-card h1 { font-size: 1.45rem; font-weight: 800; color: var(--ink); }
.auth-card .form-label { color: var(--ink-soft); }
.auth-card .text-muted { color: var(--muted) !important; }
/* Inputs inside the card: keep them light to match the white surface. */
.auth-card .form-control {
    --input-bg: #ffffff;
    --input-border: #e3e6f0;
    background: #fff; color: var(--ink); border-color: #e3e6f0;
}
.auth-card .form-control::placeholder { color: #9aa0b4; }
.auth-brand-tile {
    width: 60px; height: 60px; border-radius: 16px; margin: 0 auto;
    display: grid; place-items: center; color: #fff; font-size: 1.7rem;
    background: var(--brand-grad); box-shadow: 0 10px 24px rgba(99, 102, 241, .45);
}
.auth-flash {
    position: fixed; top: 1.25rem; left: 50%; transform: translateX(-50%);
    z-index: 10; min-width: 320px; text-align: center; box-shadow: var(--shadow-md);
}

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

.sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-w);
    background: linear-gradient(185deg, #211c3c 0%, #181430 100%);
    color: #b9bfd4; display: flex; flex-direction: column; z-index: 1030;
    border-right: 1px solid rgba(255, 255, 255, .05);
}
.sidebar-brand {
    display: flex; align-items: center; gap: .7rem;
    padding: 1.25rem 1.25rem; font-size: 1.2rem; font-weight: 800; color: #fff;
    letter-spacing: -.02em;
}
.sidebar-brand .brand-tile {
    width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
    background: var(--brand-grad); color: #fff; font-size: 1.15rem;
    box-shadow: 0 8px 18px rgba(99, 102, 241, .5);
}
.sidebar-brand strong { color: #c4b5fd; font-weight: 800; }

.sidebar-nav { padding: .5rem .75rem 1rem; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.sidebar-section {
    font-size: .66rem; font-weight: 700; text-transform: uppercase; letter-spacing: .12em;
    color: #6b7090; padding: .9rem .85rem .35rem;
}
.sidebar-nav .nav-link {
    position: relative; color: #aeb4cc; border-radius: 10px; padding: .58rem .8rem;
    display: flex; align-items: center; gap: .7rem; font-size: .92rem; font-weight: 500;
    transition: background .15s ease, color .15s ease;
}
.sidebar-nav .nav-link i { font-size: 1.05rem; width: 22px; text-align: center; opacity: .9; }
.sidebar-nav .nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.sidebar-nav .nav-link.active {
    background: linear-gradient(90deg, rgba(124, 58, 237, .9), rgba(99, 102, 241, .85));
    color: #fff; box-shadow: 0 8px 18px rgba(79, 70, 229, .35);
}
.sidebar-nav .nav-link.active::before {
    content: ""; position: absolute; left: -.75rem; top: 50%; transform: translateY(-50%);
    width: 3px; height: 22px; border-radius: 0 4px 4px 0; background: #c4b5fd;
}

.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
    background: var(--topbar-bg); backdrop-filter: blur(10px);
    height: 64px; display: flex; align-items: center; padding: 0 1.5rem;
    border-bottom: 1px solid var(--card-border); position: sticky; top: 0; z-index: 1020;
}
.topbar .user-chip {
    display: flex; align-items: center; gap: .55rem; font-size: .9rem; color: var(--ink-soft);
    font-weight: 600;
}
.topbar .user-chip .avatar {
    width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
    background: var(--brand-grad); color: #fff; font-size: .85rem; font-weight: 700;
}
.content { padding: var(--content-pad); flex: 1; min-width: 0; }

/* Global search */
.global-search { position: relative; width: min(420px, 42vw); }
.global-search > .bi-search {
    position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: .95rem;
}
.global-search input {
    width: 100%; height: 40px; border: 1px solid var(--input-border); background: var(--input-bg);
    border-radius: 11px; padding: 0 2.2rem 0 2.4rem; color: var(--ink); font-size: .9rem;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.global-search input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.global-search input::placeholder { color: var(--muted); }
.gs-kbd {
    position: absolute; right: .6rem; top: 50%; transform: translateY(-50%);
    background: var(--surface-2); color: var(--muted); border: 1px solid var(--card-border);
    border-radius: 6px; padding: 0 .4rem; font-size: .75rem; line-height: 1.4;
}
.search-results {
    position: absolute; top: calc(100% + .5rem); left: 0; right: 0; z-index: 1040;
    background: var(--card); border: 1px solid var(--card-border); border-radius: 14px;
    box-shadow: var(--shadow-lg); padding: .4rem; display: none; max-height: 70vh; overflow-y: auto;
}
.search-results.open { display: block; animation: fadeUp .15s ease both; }
.search-item {
    display: flex; align-items: center; gap: .7rem; padding: .55rem .65rem; border-radius: 10px;
    text-decoration: none; color: var(--ink);
}
.search-item:hover, .search-item.active { background: var(--surface-2); }
.search-item.active { box-shadow: inset 0 0 0 1.5px var(--brand); }
.search-item .si-icon {
    width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; flex: none;
    background: var(--brand-soft); color: var(--brand-ink);
}
.search-item .si-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.search-item .si-label { font-weight: 600; font-size: .9rem; }
.search-item .si-sub { color: var(--muted); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-item .si-type {
    font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
    color: var(--muted); background: var(--surface-2); border-radius: 6px; padding: .1rem .45rem; flex: none;
}
.search-empty { padding: 1rem; text-align: center; color: var(--muted); font-size: .88rem; }
/* Topbar search toggle (mobile) — hidden on desktop where search is always shown */
.search-toggle { display: none; }

.app-footer {
    padding: 1.1rem 1.75rem; border-top: 1px solid var(--card-border); background: var(--card);
    color: var(--muted); font-size: .85rem;
}
.app-footer a { color: var(--brand-ink); text-decoration: none; font-weight: 600; }
.app-footer a:hover { text-decoration: underline; }

/* Form action rows (desktop default; stacks full-width on phones) */
.form-actions { display: flex; align-items: center; gap: .6rem; }

/* ---------------- Page head ---------------- */
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; gap: 1rem; flex-wrap: wrap; }
.page-head h1 { font-size: var(--fs-h1); font-weight: 800; margin: 0; }

/* ---------------- Cards ---------------- */
.card-surface {
    background: var(--card); border: 1px solid var(--card-border); border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.stat-card {
    background: var(--card); border: 1px solid var(--card-border); border-radius: var(--radius);
    padding: 1.35rem; display: flex; align-items: center; gap: 1rem;
    box-shadow: var(--shadow-sm); transition: transform .18s ease, box-shadow .18s ease;
    position: relative; overflow: hidden;
}
.stat-card::after {
    content: ""; position: absolute; right: -28px; top: -28px; width: 96px; height: 96px;
    border-radius: 50%; background: var(--brand-soft); opacity: .6;
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.stat-card .icon {
    width: 54px; height: 54px; border-radius: 15px; display: grid; place-items: center;
    font-size: 1.5rem; color: #fff; flex: none; box-shadow: 0 8px 18px rgba(16, 24, 40, .18);
}
.stat-card .value { font-size: 1.8rem; font-weight: 800; line-height: 1; letter-spacing: -.03em; }
.stat-card .label { color: var(--muted); font-size: .82rem; font-weight: 600; margin-top: .25rem; }

/* gradient icon tiles */
.ic-violet { background: linear-gradient(135deg, #6366f1, #8b5cf6); }
.ic-sky    { background: linear-gradient(135deg, #0ea5e9, #38bdf8); }
.ic-green  { background: linear-gradient(135deg, #10b981, #34d399); }
.ic-amber  { background: linear-gradient(135deg, #f59e0b, #fbbf24); }
.ic-rose   { background: linear-gradient(135deg, #f43f5e, #fb7185); }

/* ---------------- Tables ---------------- */
.table { --bs-table-bg: transparent; --bs-table-color: var(--ink); color: var(--ink); }
.table thead th {
    font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
    font-weight: 700; border-bottom: 1px solid var(--card-border); padding-top: .5rem; padding-bottom: .65rem;
}
.table tbody td { border-bottom: 1px solid var(--row-border); padding-top: .8rem; padding-bottom: .8rem; vertical-align: middle; }
.table tbody tr:hover { background: var(--row-hover); }
.table tbody tr:last-child td { border-bottom: 0; }

.api-key { font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem; }
.site-link {
    color: var(--brand-ink); text-decoration: none; font-size: .8rem; font-weight: 500;
    display: inline-flex; align-items: center; gap: .25rem; max-width: 240px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.site-link:hover { text-decoration: underline; }
.copy-key {
    border: 1px solid transparent; background: transparent; color: var(--muted);
    padding: .12rem .4rem; border-radius: 7px; line-height: 1;
}
.copy-key:hover { background: var(--surface-2); color: var(--brand-ink); }
.avatar-sm {
    width: 40px; height: 40px; border-radius: 12px; object-fit: cover;
    background: var(--brand-soft); color: var(--brand-ink); display: grid; place-items: center;
}
.serial-badge {
    display: inline-grid; place-items: center; min-width: 28px; height: 28px; padding: 0 .4rem;
    border-radius: 8px; background: var(--brand-soft); color: var(--brand-ink);
    font-weight: 700; font-size: .82rem; font-variant-numeric: tabular-nums;
}

/* ---- Bulk "select all matching" ---- */
.bulk-allmatch {
    font-size: .82rem; font-weight: 600; color: var(--brand-ink); text-decoration: none;
    padding: .2rem .6rem; border-radius: 7px; background: var(--brand-soft);
}
.bulk-allmatch:hover { text-decoration: underline; }

/* ---- Confirmation modal ---- */
.confirm-modal {
    background: var(--card); border: 1px solid var(--card-border); border-radius: 18px;
    color: var(--ink); box-shadow: var(--shadow-lg);
}
.confirm-ic {
    width: 66px; height: 66px; margin: 0 auto; border-radius: 18px; display: grid; place-items: center;
    font-size: 1.7rem; background: rgba(239, 68, 68, .14); color: var(--bad);
}

/* ---- Stats strip ---- */
.stat-strip { display: flex; gap: .75rem; flex-wrap: wrap; }
.stat-strip .ss-item {
    flex: 1; min-width: 170px; display: flex; align-items: center; gap: .8rem;
    background: var(--card); border: 1px solid var(--card-border); border-radius: 13px;
    padding: .8rem 1rem; box-shadow: var(--shadow-sm);
}
.stat-strip .ss-ic { width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center;
    color: #fff; font-size: 1.15rem; flex: none; }
.stat-strip .ss-num { display: block; font-size: 1.35rem; font-weight: 800; line-height: 1; letter-spacing: -.02em; }
.stat-strip .ss-lbl { display: block; color: var(--muted); font-size: .8rem; font-weight: 600; margin-top: .2rem; text-transform: capitalize; }
a.ss-item { text-decoration: none; color: inherit; cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease; }
a.ss-item:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
a.ss-item.ss-active { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }

/* ---- Agent identity cell ---- */
.identity { display: flex; align-items: center; gap: .7rem; }
.identity .avatar-init, .identity .avatar-img {
    width: 42px; height: 42px; border-radius: 13px; flex: none; object-fit: cover;
}
.identity .avatar-init {
    display: grid; place-items: center; color: #fff; font-weight: 700; font-size: .92rem;
    box-shadow: 0 5px 12px rgba(16, 24, 40, .14);
}
.identity .meta { min-width: 0; }
.identity .name { font-weight: 600; line-height: 1.25; color: var(--ink); }
.identity .uname { color: var(--muted); font-size: .8rem; }

/* ---- Contact chips ---- */
.contact-list { display: flex; flex-direction: column; gap: .3rem; }
.contact-chip { display: inline-flex; align-items: center; gap: .45rem; font-size: .82rem; color: var(--ink-soft); }
.contact-chip i { width: 23px; height: 23px; border-radius: 7px; display: grid; place-items: center; font-size: .78rem; }
.contact-chip.phone i { background: var(--brand-soft); color: var(--brand-ink); }
.contact-chip.wa i { background: rgba(16, 185, 129, .14); color: #059669; }

/* ---- Location breadcrumb ---- */
.loc { display: inline-flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.loc-chip { font-size: .76rem; font-weight: 600; padding: .22rem .55rem; border-radius: 7px;
    background: var(--surface-2); color: var(--ink-soft); border: 1px solid var(--card-border); }
.loc-sep { color: var(--muted); font-size: .7rem; }

/* ---- Status pill ---- */
.status-pill { display: inline-flex; align-items: center; gap: .45rem; font-size: .78rem; font-weight: 600;
    padding: .28rem .65rem; border-radius: 999px; }
.status-pill .dot { width: 7px; height: 7px; border-radius: 50%; }
.status-pill.on { background: rgba(16, 185, 129, .12); color: #047857; }
.status-pill.on .dot { background: #10b981; box-shadow: 0 0 0 3px rgba(16,185,129,.18); }
.status-pill.off { background: var(--surface-2); color: var(--muted); }
.status-pill.off .dot { background: #9aa0b8; }

/* ---- Ghost row actions ---- */
.row-actions .btn { border: 1px solid transparent; background: transparent; color: var(--muted); padding: .3rem .5rem; }
.row-actions .btn:hover { background: var(--surface-2); }
.row-actions .btn.edit:hover { color: var(--brand-ink); background: var(--brand-soft); }
.row-actions .btn.del:hover { color: var(--bad); background: rgba(239, 68, 68, .1); }

/* ---------------- Buttons ---------------- */
.btn { border-radius: 10px; font-weight: 600; transition: transform .12s ease, box-shadow .12s ease, filter .12s ease; }
.btn:active { transform: translateY(1px); }
.btn-sm { border-radius: 9px; }
.btn-primary {
    background: var(--brand-grad); border: none; box-shadow: 0 6px 16px rgba(99, 102, 241, .35);
}
.btn-primary:hover, .btn-primary:focus { filter: brightness(1.05); box-shadow: 0 8px 22px rgba(99, 102, 241, .45); }
.btn-success { background: linear-gradient(135deg, #10b981, #059669); border: none; }
.btn-danger  { background: linear-gradient(135deg, #ef4444, #dc2626); border: none; }
.btn-outline-secondary { border-color: var(--card-border); color: var(--ink-soft); background: var(--card); }
.btn-outline-secondary:hover { background: var(--surface-2); color: var(--ink); border-color: var(--card-border); }
.btn-outline-primary { border-color: #d7d9f7; color: var(--brand-ink); background: var(--card); }
.btn-outline-primary:hover { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-outline-danger:hover { background: var(--bad); border-color: var(--bad); }

/* ---------------- Badges ---------------- */
.badge { font-weight: 600; border-radius: 999px; padding: .4em .7em; letter-spacing: .01em; }
.badge.bg-success { background: rgba(16, 185, 129, .14) !important; color: #047857; }
.badge.bg-secondary { background: #eef0f6 !important; color: #5b6377; }
.badge.bg-warning { background: rgba(245, 158, 11, .16) !important; color: #b45309; }
.badge.bg-danger { background: rgba(239, 68, 68, .14) !important; color: #b91c1c; }
.badge.bg-info { background: rgba(14, 165, 233, .14) !important; color: #0369a1; }
.badge.bg-dark { background: #2b2548 !important; color: #fff; }
.badge.bg-primary { background: var(--brand-grad) !important; color: #fff; }
.badge.bg-light { background: var(--surface-2) !important; color: var(--ink-soft); border: 1px solid var(--card-border); }

/* ---------------- Forms ---------------- */
.form-label { font-weight: 600; font-size: .86rem; color: var(--ink-soft); margin-bottom: .35rem; }
.form-control, .form-select {
    border-radius: 10px; border: 1px solid var(--input-border); padding: .55rem .8rem; color: var(--ink);
    background-color: var(--input-bg);
}
.form-select { background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%238990a6' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e"); }
.form-control:focus, .form-select:focus {
    border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft);
}
.form-control::placeholder { color: #aab0c4; }
.input-group .btn { border-radius: 0 10px 10px 0; }
.form-text { color: var(--muted); }

/* ---------------- Pills / tabs ---------------- */
.nav-pills .nav-link { color: var(--ink-soft); border-radius: 10px; font-weight: 600; }
.nav-pills .nav-link.active { background: var(--brand-grad); box-shadow: 0 6px 16px rgba(99,102,241,.3); }

/* ---------------- Pagination ---------------- */
.pagination { gap: .25rem; }
.page-link { border: 1px solid var(--card-border); border-radius: 9px !important; color: var(--ink-soft); font-weight: 600; }
.page-item.active .page-link { background: var(--brand-grad); border-color: transparent; }
.page-link { background: var(--card); }
.page-link:hover { background: var(--surface-2); color: var(--brand-ink); }

/* ---------------- Alerts ---------------- */
.alert { border: 1px solid transparent; border-radius: 12px; }
.alert-success { background: rgba(16,185,129,.1); color: #065f46; border-color: rgba(16,185,129,.2); }
.alert-danger  { background: rgba(239,68,68,.08); color: #991b1b; border-color: rgba(239,68,68,.18); }
.alert-info    { background: rgba(14,165,233,.08); color: #075985; border-color: rgba(14,165,233,.18); }
.alert-warning { background: rgba(245,158,11,.1); color: #92400e; border-color: rgba(245,158,11,.2); }

/* ---------------- API docs ---------------- */
.api-mono { font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .84rem; }
.code-block {
    background: #1a1633; color: #e7e9f5; border-radius: 12px; padding: 1.1rem 1.2rem;
    overflow-x: auto; font-size: .82rem; line-height: 1.6;
    border: 1px solid rgba(255,255,255,.06);
}
.code-block code { color: inherit; white-space: pre; font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace; }
.endpoint { background: var(--surface-2); border: 1px solid var(--card-border); border-radius: 12px; padding: .9rem 1.1rem; }
.pre, pre.bg-light { background: var(--surface-2) !important; color: var(--ink); border-color: var(--card-border) !important; }

/* ---------------- Empty states ---------------- */
.empty-state { text-align: center; padding: 3rem 1rem; }
.empty-state .empty-icon {
    width: 76px; height: 76px; border-radius: 22px; margin: 0 auto 1rem;
    display: grid; place-items: center; font-size: 2rem; color: var(--brand-ink);
    background: var(--brand-soft);
}
.empty-state h3 { font-size: 1.05rem; font-weight: 700; margin-bottom: .25rem; }
.empty-state p { color: var(--muted); margin-bottom: 1rem; max-width: 360px; margin-left: auto; margin-right: auto; }

/* ---------------- Theme toggle ---------------- */
.theme-toggle {
    width: 38px; height: 38px; border-radius: 11px; border: 1px solid var(--card-border);
    background: var(--card); color: var(--ink-soft); display: grid; place-items: center;
    font-size: 1.05rem; cursor: pointer; transition: background .15s ease, color .15s ease, transform .12s ease;
}
.theme-toggle:hover { background: var(--surface-2); color: var(--brand-ink); }
.theme-toggle:active { transform: scale(.92); }

/* ---------------- Micro-interactions ---------------- */
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.content > * { animation: fadeUp .35s ease both; }
.content > *:nth-child(2) { animation-delay: .04s; }
.content > *:nth-child(3) { animation-delay: .08s; }
.stat-card .icon { transition: transform .2s ease; }
.stat-card:hover .icon { transform: scale(1.06) rotate(-3deg); }
.btn i, .nav-link i { transition: transform .15s ease; }
.btn:hover i { transform: translateX(1px); }
@media (prefers-reduced-motion: reduce) {
    .content > *, .stat-card, .btn, .nav-link i, .stat-card .icon { animation: none !important; transition: none !important; }
}

/* =====================================================================
   Responsive system
   Breakpoints: sm 576 · md 768 · lg 992 (sidebar rail) · xl 1200 · xxl 1400
   ===================================================================== */

/* Prevent horizontal overflow + let flex children shrink everywhere */
html, body { max-width: 100%; overflow-x: hidden; }
.main, .topbar, .content, .page-head, .card-surface { min-width: 0; }
/* Long, unbreakable strings (API keys, slugs, URLs) never blow out a row */
.text-break-all, code, .api-key, .mono { overflow-wrap: anywhere; word-break: break-word; }
/* Code blocks scroll horizontally instead of stretching the layout */
pre { max-width: 100%; overflow-x: auto; }
/* Images never exceed their container */
img { max-width: 100%; height: auto; }

/* Sidebar backdrop (mobile drawer) */
.sidebar-backdrop {
    position: fixed; inset: 0; z-index: 1029; background: rgba(15, 12, 28, .55);
    backdrop-filter: blur(2px); opacity: 0; visibility: hidden;
    transition: opacity .22s ease, visibility .22s ease;
}
body.sidebar-open .sidebar-backdrop { opacity: 1; visibility: visible; }

/* ---- ≤ 992px: sidebar becomes an off-canvas drawer ---- */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%); transition: transform .24s ease;
        box-shadow: var(--shadow-lg); width: min(280px, 84vw);
    }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-open { overflow: hidden; }     /* scroll-lock behind the drawer */
    .main { margin-left: 0; }
}
@media (min-width: 992px) {
    .sidebar-backdrop { display: none; }
}

/* ---- ≤ 768px: topbar + collapsible search ---- */
@media (max-width: 767.98px) {
    .topbar { padding: 0 1rem; gap: .5rem; }
    .search-toggle {
        display: grid; place-items: center; width: 40px; height: 40px; flex: none;
        border-radius: 11px; border: 1px solid var(--input-border);
        background: var(--input-bg); color: var(--ink-soft);
    }
    /* Search drops down as a floating input inset from the screen edges.
       No container padding → the icon nests inside the input exactly like desktop. */
    .global-search {
        position: absolute; top: calc(100% + .4rem); left: .6rem; right: .6rem; width: auto;
        display: none; z-index: 1025;
    }
    .topbar.search-open .global-search { display: block; animation: fadeUp .15s ease both; }
    .global-search input { box-shadow: var(--shadow-lg); }
    .global-search .gs-kbd { display: none; }
    /* Results sit directly under the floating input, capped to the viewport */
    .global-search .search-results {
        left: 0; right: 0; top: calc(100% + .4rem);
        max-height: calc(100vh - 130px);
    }
    .topbar .ms-auto { gap: .6rem !important; }
}

/* ---- Page head / toolbars stack on small screens ---- */
@media (max-width: 575.98px) {
    .page-head { align-items: stretch; }
    .page-head .page-actions, .page-head .btn-group, .page-head form { width: 100%; }
    .page-head .page-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
    .page-head .page-actions .btn { flex: 1 1 auto; }
    /* Forms: full-width primary actions, comfortable controls */
    .form-actions { display: flex; flex-direction: column-reverse; gap: .6rem; }
    .form-actions .btn { width: 100%; }
    .stat-card { padding: 1rem; }
}

/* =====================================================================
   Responsive data tables → stacked cards on phones
   Add class "table-cards" to a <table>; JS fills td[data-label] from <thead>.
   ===================================================================== */
@media (max-width: 767.98px) {
    .table-cards { border: 0; background: transparent; }
    .table-cards thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    .table-cards tbody { display: block; }

    /* Each row → a self-contained card */
    .table-cards tbody tr {
        display: block; position: relative;
        background: var(--card); border: 1px solid var(--card-border);
        border-radius: 16px; padding: 1rem 1.05rem .85rem; margin-bottom: .85rem;
        box-shadow: var(--shadow-sm); transition: border-color .15s ease, box-shadow .15s ease;
    }
    .table-cards tbody tr:hover { background: var(--card); border-color: var(--brand-soft); box-shadow: var(--shadow-md); }
    .table-cards tbody tr:last-child td { border-bottom: 0; }

    /* Default cell = a "label … value" line */
    .table-cards tbody td {
        display: flex; align-items: center; justify-content: space-between; gap: 1rem;
        padding: .6rem 0 !important; border: 0 !important;
        border-top: 1px solid var(--row-border) !important;
        text-align: right; min-height: 40px;
    }
    .table-cards tbody td::before {
        content: attr(data-label); text-align: left; font-weight: 600; font-size: .72rem;
        text-transform: uppercase; letter-spacing: .04em; color: var(--muted); flex: none;
    }

    /* Full-width, label-less cells */
    .table-cards tbody td.cell-block { justify-content: flex-start; text-align: left; border-top: 0 !important; padding: 0 !important; min-height: 0; }
    .table-cards tbody td.cell-block::before { display: none; }

    /* Identity / name → prominent card header (with breathing room for the corner checkbox) */
    .table-cards tbody td.cell-primary {
        padding-bottom: .85rem !important; padding-right: 2rem !important;
        font-size: 1.02rem; font-weight: 700; color: var(--ink);
    }
    .table-cards tbody td.cell-primary + td { border-top: 0 !important; }
    .table-cards td.cell-primary .identity { gap: .8rem; }
    .table-cards td.cell-primary .avatar-init,
    .table-cards td.cell-primary .avatar-img { width: 46px; height: 46px; border-radius: 14px; }
    .table-cards td.cell-primary .name { font-size: 1.02rem; font-weight: 700; }

    /* Row-select checkbox → pinned to the card's top-right corner */
    .table-cards tbody td.cell-check { position: absolute; top: .85rem; right: .9rem; padding: 0 !important; }
    .table-cards tbody td.cell-check .form-check-input { width: 1.15rem; height: 1.15rem; }
    /* Drag handle → top-left accent, frees the header */
    .table-cards tbody td.cell-drag { position: absolute; top: .9rem; left: .9rem; color: var(--muted); }

    /* Value side: let multi-chip content (contacts, location) align right and wrap nicely */
    .table-cards tbody td .contact-list { align-items: flex-end; }
    .table-cards tbody td .loc { justify-content: flex-end; }

    /* Actions → a right-aligned row of tappable icon buttons (label hidden) */
    .table-cards tbody td.cell-actions { justify-content: flex-end; gap: .5rem; padding-top: .75rem !important; }
    .table-cards tbody td.cell-actions::before { display: none; }
    .table-cards tbody td.cell-actions .btn {
        width: 42px; height: 42px; display: inline-grid; place-items: center; font-size: 1rem;
        border: 1px solid var(--card-border) !important; border-radius: 11px; color: var(--ink-soft);
        background: var(--surface-2);
    }
    .table-cards tbody td.cell-actions .btn:hover { color: var(--brand-ink); border-color: var(--brand) !important; }
    .table-cards tbody td.cell-actions .btn.del:hover,
    .table-cards tbody td.cell-actions .btn.btn-outline-danger:hover { color: var(--bad); border-color: var(--bad) !important; }

    /* Empty-state row keeps its full-width centered layout */
    .table-cards tbody tr.is-empty-row { background: transparent; border: 0; box-shadow: none; padding: 0; }
    .table-cards tbody tr.is-empty-row td { display: block; text-align: center; border: 0 !important; }
    .table-cards tbody tr.is-empty-row td::before { display: none; }

    /* Pagination: center + wrap */
    .pagination { flex-wrap: wrap; justify-content: center; }
}

/* Filter bars: collapse multi-column filter forms to a single column */
@media (max-width: 767.98px) {
    .filter-bar { flex-direction: column; align-items: stretch; }
    .filter-bar > * { width: 100%; }
}

/* Bulk action bar: wrap + scroll on small screens instead of overflowing */
@media (max-width: 767.98px) {
    .bulk-bar { flex-wrap: wrap; gap: .5rem; }
    .bulk-bar .bulk-actions { width: 100%; display: flex; flex-wrap: wrap; gap: .4rem; }
    .bulk-bar .bulk-actions .btn { flex: 1 1 auto; }
}

/* Charts stay inside their cards on every width */
.chart-wrap { position: relative; width: 100%; }
.chart-wrap canvas { max-width: 100% !important; }

/* Scrollbar polish */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #d7dae6; border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #c2c6d8; background-clip: content-box; }
