/* ==========================================================================
   Meraki CRM — design system
   Premium SaaS look: glassmorphism, soft gradients, light/dark theme via
   [data-theme] on <html>, driven by assets/js/app.js + a server-read cookie
   so the first paint already has the right theme (no flash).
   ========================================================================== */

:root,
:root[data-theme="light"] {
    --bg-gradient: #f6f8f7;
    --surface: #ffffff;
    --surface-solid: #ffffff;
    --surface-border: rgba(16, 24, 40, 0.07);
    --text-primary: #101828;
    --text-secondary: #667085;
    --text-muted: #98a2b3;
    --brand: #3B6FF0;
    --brand-rgb: 59, 111, 240;
    --brand-2: #7C9FF7;
    --brand-gradient: var(--brand);
    --success: #5FA97D;
    --warning: #CB9B52;
    --danger: #CB7676;
    --info: #6E93C9;
    --shadow-soft: 0 4px 16px rgba(16, 24, 40, 0.08);
    --shadow-card: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 6px rgba(16, 24, 40, 0.04);
    --sidebar-bg: #ffffff;
    --topbar-bg: #ffffff;
    --input-bg: #ffffff;
    --scrollbar-thumb: rgba(var(--brand-rgb), 0.35);

    --tone-a-bg: #fbf0dd; --tone-a-fg: #C99A52;
    --tone-b-bg: #e2f0ec; --tone-b-fg: #5B9E96;
    --tone-c-bg: #ece8f7; --tone-c-fg: #9B8AC4;
    --tone-d-bg: #f9e9f0; --tone-d-fg: #C97DA0;
}

:root[data-theme="dark"] {
    --bg-gradient: #0c1512;
    --surface: #131c18;
    --surface-solid: #131c18;
    --surface-border: rgba(255, 255, 255, 0.08);
    --text-primary: #f1f5f4;
    --text-secondary: #a3ada7;
    --text-muted: #6b776f;
    --brand: #6C93F5;
    --brand-rgb: 108, 147, 245;
    --brand-2: #9FBBFA;
    --brand-gradient: var(--brand);
    --success: #8FC9A6;
    --warning: #E0B975;
    --danger: #E09999;
    --info: #93B4E0;
    --shadow-soft: 0 4px 16px rgba(0, 0, 0, 0.35);
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 6px rgba(0, 0, 0, 0.25);
    --sidebar-bg: #101915;
    --topbar-bg: #101915;
    --input-bg: rgba(255, 255, 255, 0.06);
    --scrollbar-thumb: rgba(var(--brand-rgb), 0.4);

    --tone-a-bg: rgba(224, 185, 117, 0.16); --tone-a-fg: #E0B975;
    --tone-b-bg: rgba(127, 203, 170, 0.16); --tone-b-fg: #7FC9BD;
    --tone-c-bg: rgba(184, 168, 222, 0.18); --tone-c-fg: #B8A8DE;
    --tone-d-bg: rgba(224, 146, 184, 0.16); --tone-d-fg: #E092B8;
}

* {
    box-sizing: border-box;
}

html {
    scrollbar-color: var(--scrollbar-thumb) transparent;
}

body {
    background: var(--bg-gradient);
    color: var(--text-primary);
    font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-weight: 300;
    font-size: 0.9rem;
    min-height: 100vh;
    transition: background 0.3s ease, color 0.3s ease;
}

h1, h2, h3, h4, h5, h6 { font-weight: 500; letter-spacing: -0.01em; }
.fw-bold { font-weight: 600 !important; }
.fw-semibold { font-weight: 500 !important; }

a {
    color: var(--brand);
    text-decoration: none;
}

/* ---- surfaces ---- */
.glass-card {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: 10px;
    box-shadow: var(--shadow-card);
    transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.glass-panel {
    background: var(--surface);
    border: 1px solid var(--surface-border);
}

/* ---- brand accents ---- */
.text-brand-gradient {
    background: var(--brand-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.btn-brand {
    background: var(--brand-gradient);
    border: none;
    color: #fff;
    font-weight: 500;
    font-size: 0.85rem;
    border-radius: 8px;
    padding: 0.5rem 1rem;
    box-shadow: 0 1px 2px rgba(var(--brand-rgb), 0.2);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.btn-brand:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(var(--brand-rgb), 0.3);
    color: #fff;
}
.btn-brand:active { transform: translateY(0); }

/* ---- floating gradient blobs (login/auth background decoration) ---- */
.bg-blobs {
    position: fixed;
    inset: 0;
    overflow: hidden;
    z-index: 0;
    pointer-events: none;
}
.bg-blobs span {
    position: absolute;
    border-radius: 50%;
    filter: blur(70px);
    opacity: 0.45;
    animation: floaty 16s ease-in-out infinite;
}
.bg-blobs span:nth-child(1) { width: 380px; height: 380px; background: #D98A54; top: -80px; left: -60px; }
.bg-blobs span:nth-child(2) { width: 320px; height: 320px; background: #F0B98A; bottom: -100px; right: -60px; animation-delay: -6s; }
.bg-blobs span:nth-child(3) { width: 260px; height: 260px; background: #E8A572; top: 40%; left: 60%; animation-delay: -11s; }

@keyframes floaty {
    0%, 100% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(30px, -20px) scale(1.08); }
}

/* ---- auth pages ---- */
.auth-shell {
    position: relative;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    z-index: 1;
}
.auth-card {
    width: 100%;
    max-width: 400px;
    padding: 1.75rem 1.6rem;
    animation: rise 0.5s ease;
}
@keyframes rise {
    from { opacity: 0; transform: translateY(14px); }
    to { opacity: 1; transform: translateY(0); }
}
.auth-logo {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: var(--brand-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 600;
    font-size: 1.15rem;
    box-shadow: 0 2px 6px rgba(var(--brand-rgb), 0.25);
}

.form-control, .form-select {
    background: var(--input-bg);
    border: 1px solid var(--surface-border);
    color: var(--text-primary);
    border-radius: 8px;
    padding: 0.45rem 0.7rem;
    font-size: 0.87rem;
}
.form-control:focus, .form-select:focus {
    background: var(--input-bg);
    color: var(--text-primary);
    border-color: var(--brand);
    box-shadow: 0 0 0 0.2rem rgba(var(--brand-rgb), 0.15);
}
.form-control::placeholder { color: var(--text-muted); }

.otp-input {
    letter-spacing: 10px;
    font-size: 1.4rem;
    font-weight: 600;
    text-align: center;
}

/* ---- app shell (authenticated area) ---- */
.app-shell {
    display: flex;
    min-height: 100vh;
}

/* Sidebar is always white, independent of the light/dark theme toggle —
   a fixed brand rail, same as the reference dashboards it's modeled on. */
.sidebar {
    width: 232px;
    flex-shrink: 0;
    background: #ffffff;
    border: 1px solid rgba(16, 24, 40, 0.07);
    border-radius: 15px;
    margin: 10px;
    position: sticky;
    top: 10px;
    height: calc(100vh - 20px);
    overflow-y: auto;
    z-index: 10;
    transition: width 0.2s ease;
}
.sidebar.collapsed { width: 68px; }
.sidebar.collapsed .nav-label,
.sidebar.collapsed .sidebar-brand-text,
.sidebar.collapsed .nav-section-title { display: none; }

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 1rem 1.1rem;
    font-weight: 500;
    font-size: 0.95rem;
    color: #101828;
    border-bottom: 1px solid rgba(16, 24, 40, 0.07);
}

.nav-section-title {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    font-weight: 600;
    color: rgba(16, 24, 40, 0.4);
    padding: 0.85rem 1.1rem 0.25rem;
}

.nav-link-item {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    margin: 0.05rem 0.6rem;
    padding: 0.45rem 0.75rem;
    color: rgba(16, 24, 40, 0.65);
    font-size: 0.85rem;
    font-weight: 400;
    border-radius: 6px;
    position: relative;
    transition: background 0.15s ease, color 0.15s ease;
}
.nav-link-item i { font-size: 1rem; width: 20px; text-align: center; }
.nav-link-item:hover { background: rgba(16, 24, 40, 0.05); color: #101828; }
.nav-link-item.active {
    color: #ffffff;
    background: var(--brand-gradient);
    font-weight: 500;
    box-shadow: none;
}
/* the sidebar is always white, so theme-dependent muted colors need a scoped override here */
.sidebar .text-muted-soft { color: rgba(16, 24, 40, 0.35) !important; }
.sidebar .badge-soft.muted { background: rgba(16, 24, 40, 0.06); color: rgba(16, 24, 40, 0.45); }

.main-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky;
    top: 10px;
    z-index: 9;
    background: var(--topbar-bg);
    border: 1px solid var(--surface-border);
    border-radius: 15px;
    margin: 10px;
    padding: 0.6rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

.icon-btn {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--surface-border);
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}
.icon-btn:hover { background: rgba(var(--brand-rgb), 0.1); color: var(--brand); }

.notif-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 600;
    line-height: 18px;
    text-align: center;
}
.notif-panel {
    width: 340px;
    max-height: 420px;
    overflow-y: auto;
    padding: 0.25rem 0;
}
.notif-item {
    white-space: normal;
    padding: 0.5rem 0.85rem;
    border-bottom: 1px solid var(--surface-border);
}
.notif-item:last-child { border-bottom: none; }
.notif-item.is-new { background: rgba(var(--brand-rgb), 0.08); }

.page-body {
    padding: 1.1rem 1.25rem;
    flex: 1;
}

.stat-card {
    padding: 0.95rem 1.1rem;
}
.stat-card:hover {
    box-shadow: var(--shadow-soft);
    transform: translateY(-1px);
}
.stat-icon {
    width: 38px; height: 38px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.05rem;
    color: #fff;
    background: var(--brand-gradient);
}
.tone-a { background: var(--tone-a-bg); color: var(--tone-a-fg); }
.tone-b { background: var(--tone-b-bg); color: var(--tone-b-fg); }
.tone-c { background: var(--tone-c-bg); color: var(--tone-c-fg); }
.tone-d { background: var(--tone-d-bg); color: var(--tone-d-fg); }

.avatar-circle {
    width: 34px; height: 34px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.badge-soft.purple { background: var(--tone-c-bg); color: var(--tone-c-fg); }

.icon-chip {
    width: 34px; height: 34px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.table-glass {
    background: transparent;
}
.table-glass thead th {
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--surface-border);
    font-weight: 500;
}
.table-glass td, .table-glass th {
    border-color: var(--surface-border);
    color: var(--text-primary);
    vertical-align: middle;
}

.badge-soft {
    padding: 0.2rem 0.55rem;
    border-radius: 5px;
    font-size: 0.7rem;
    font-weight: 500;
}
.badge-soft.success { background: rgba(95, 169, 125, 0.16); color: var(--success); }
.badge-soft.warning { background: rgba(203, 155, 82, 0.16); color: var(--warning); }
.badge-soft.danger  { background: rgba(203, 118, 118, 0.16); color: var(--danger); }
.badge-soft.info    { background: rgba(110, 147, 201, 0.16); color: var(--info); }
.badge-soft.muted   { background: rgba(100, 116, 139, 0.14); color: var(--text-secondary); }

/* ---- inline lead status dropdown (leads list) ---- */
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    display: inline-block;
}
.status-trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--input-bg);
    border: 1px solid var(--surface-border);
    border-radius: 6px;
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
    font-weight: 400;
    color: var(--text-primary);
    cursor: pointer;
}
.status-trigger:hover { border-color: var(--text-muted); }
.status-trigger i { font-size: 0.7rem; color: var(--text-muted); margin-left: 0.15rem; }
.status-dropdown-menu {
    min-width: 190px;
    background: var(--surface);
    border: 1px solid var(--surface-border);
    box-shadow: var(--shadow-soft);
    border-radius: 8px;
    overflow: hidden;
}
.status-search {
    font-size: 0.8rem;
}
.status-option {
    font-size: 0.85rem;
    padding: 0.4rem 0.75rem;
    color: var(--text-primary);
}
.status-option:hover, .status-option:focus { background: rgba(var(--brand-rgb), 0.08); color: var(--text-primary); }
.status-option.d-none { display: none !important; }

.text-secondary-soft { color: var(--text-secondary) !important; }
.text-muted-soft { color: var(--text-muted) !important; }

@media (max-width: 992px) {
    .sidebar { position: fixed; left: -280px; height: 100vh; }
    .sidebar.mobile-open { left: 0; }
}

/* ---- pipeline (kanban) ---- */
.pipeline-board {
    display: flex;
    gap: 1rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
}
.pipeline-col {
    flex: 0 0 280px;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 180px);
}
.pipeline-col-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-top: 2px solid var(--brand);
    border-radius: 8px 8px 0 0;
    font-weight: 500;
    font-size: 0.82rem;
}
.pipeline-col-body {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-top: none;
    border-radius: 0 0 8px 8px;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-height: 120px;
    transition: background 0.15s ease;
}
.pipeline-col-body.drag-over {
    background: rgba(var(--brand-rgb), 0.08);
}
.pipeline-card {
    display: block;
    background: var(--surface-solid);
    border: 1px solid var(--surface-border);
    border-radius: 8px;
    padding: 0.6rem 0.7rem;
    box-shadow: var(--shadow-card);
    cursor: grab;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.pipeline-card:hover {
    box-shadow: var(--shadow-soft);
    transform: translateY(-1px);
}
.pipeline-card.dragging {
    opacity: 0.4;
}
.pipeline-empty {
    text-align: center;
    padding: 1.5rem 0;
}

/* ---- reports: horizontal bars ---- */
.hbar-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.7rem;
}
.hbar-label {
    flex: 0 0 130px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.hbar-track {
    flex: 1;
    height: 10px;
    background: var(--surface-border);
    border-radius: 999px;
    overflow: hidden;
}
.hbar-fill {
    height: 100%;
    border-radius: 999px;
    transition: width 0.3s ease;
}
.hbar-value {
    flex: 0 0 36px;
    text-align: right;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-primary);
}

/* ---- reports: trend sparkbar ---- */
.trend-chart {
    display: flex;
    align-items: flex-end;
    gap: 0.35rem;
    height: 140px;
    overflow-x: auto;
    padding-top: 0.5rem;
}
.trend-bar-wrap {
    flex: 1 0 18px;
    min-width: 18px;
    height: 100%;
    display: flex;
    align-items: flex-end;
}
.trend-bar {
    width: 100%;
    max-width: 22px;
    margin: 0 auto;
    background: var(--brand-gradient);
    border-radius: 4px 4px 0 0;
    min-height: 4px;
}

/* ---- dashboard module tiles ---- */
.module-group-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin: 1rem 0 0.5rem;
}
.module-group-title:first-of-type {
    margin-top: 0;
}
.module-tiles {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-bottom: 0.25rem;
}
.module-tile {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.75rem;
    border-radius: 8px;
    background: var(--surface-solid);
    border: 1px solid var(--surface-border);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 400;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.module-tile i {
    color: var(--brand);
    font-size: 1rem;
}
.module-tile:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-card);
    color: var(--text-primary);
}
.module-tile-soon {
    background: transparent;
    border-style: dashed;
    color: var(--text-muted);
    cursor: default;
}
.module-tile-soon i {
    color: var(--text-muted);
}
.module-tile-soon:hover {
    transform: none;
    box-shadow: none;
}

/* ---- WhatsApp inbox ---- */
.wa-shell {
    display: flex;
    height: calc(100vh - 200px);
    min-height: 420px;
    overflow: hidden;
    padding: 0;
}
.wa-conv-list {
    width: 280px;
    flex-shrink: 0;
    border-right: 1px solid var(--surface-border);
    overflow-y: auto;
}
.wa-conv-item {
    display: block;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--surface-border);
    color: var(--text-primary);
    transition: background 0.12s ease;
}
.wa-conv-item:hover {
    background: rgba(var(--brand-rgb), 0.06);
    color: var(--text-primary);
}
.wa-conv-item.active {
    background: rgba(var(--brand-rgb), 0.12);
    border-left: 3px solid var(--brand);
}
.wa-thread {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.wa-thread-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}
.wa-thread-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.85rem 1.25rem;
    border-bottom: 1px solid var(--surface-border);
}
.wa-thread-body {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.wa-bubble-row {
    display: flex;
}
.wa-bubble-row.out {
    justify-content: flex-end;
}
.wa-bubble {
    max-width: 65%;
    padding: 0.5rem 0.75rem;
    border-radius: 10px;
    background: var(--surface-solid);
    border: 1px solid var(--surface-border);
    font-size: 0.88rem;
}
.wa-bubble-row.out .wa-bubble {
    background: var(--brand-gradient);
    color: #fff;
    border: none;
}
.wa-bubble-meta {
    font-size: 0.68rem;
    opacity: 0.7;
    margin-top: 0.25rem;
    text-align: right;
}
.wa-send-form {
    display: flex;
    gap: 0.6rem;
    padding: 0.85rem 1.25rem;
    border-top: 1px solid var(--surface-border);
}

/* ---- brand color picker (bottom-right, dashboard only) ---- */
.theme-picker {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
}
.theme-picker-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--brand-gradient);
    border: 3px solid var(--surface);
    box-shadow: var(--shadow-soft);
    cursor: pointer;
    padding: 0;
}
.theme-picker-panel {
    position: absolute;
    bottom: 54px;
    right: 0;
    width: 200px;
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: 10px;
    box-shadow: var(--shadow-soft);
    padding: 0.85rem;
    display: none;
}
.theme-picker-panel.open { display: block; }
.theme-picker-panel label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    color: var(--text-muted);
    display: block;
    margin-bottom: 0.4rem;
}
.theme-picker-panel input[type="color"] {
    width: 100%;
    height: 36px;
    border: 1px solid var(--surface-border);
    border-radius: 6px;
    padding: 2px;
    background: var(--input-bg);
    cursor: pointer;
}
.theme-picker-reset {
    width: 100%;
    margin-top: 0.6rem;
    padding: 0.35rem 0.6rem;
    font-size: 0.78rem;
    font-weight: 500;
    background: transparent;
    border: 1px solid var(--surface-border);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
}
.theme-picker-reset:hover { color: var(--text-primary); border-color: var(--text-muted); }

/* ---- table-responsive + dropdown-menu clipping fix ----
   .table-responsive sets overflow-x: auto for horizontal scrolling on narrow screens, but per
   the CSS spec that also forces overflow-y to compute as auto (never stays visible) once any
   axis is non-visible — so an open Bootstrap dropdown on the last row or two gets clipped by
   the table's own bottom edge instead of floating over whatever's below it, exactly the
   "menu item cut off / stuck behind the next card" look. Only lift the clip while a dropdown
   inside is actually open, so normal horizontal scrolling on narrow screens is unaffected. */
.table-responsive:has(.dropdown-menu.show) {
    overflow: visible;
}
