/* ============================================================
   PROSPECT DIGITAL CRM — Design System
   Premium SaaS: dark navy sidebar, blue accent, soft shadows
   ============================================================ */

:root {
    --primary: #1d4e8f;
    --primary-dark: #16376e;
    --primary-light: #dce6f5;
    --primary-50: #eef3fa;
    --navy-900: #0b1220;
    --navy-800: #0f172a;
    --navy-700: #1e293b;
    --navy-600: #334155;
    --ink: #0f172a;
    --text: #1e293b;
    --text-soft: #64748b;
    --text-mute: #94a3b8;
    --bg: #f1f5f9;
    --card: #ffffff;
    --border: #e2e8f0;
    --border-soft: #eef2f7;
    --green: #16a34a;
    --green-bg: #dcfce7;
    --red: #dc2626;
    --red-bg: #fee2e2;
    --amber: #d97706;
    --amber-bg: #fef3c7;
    --orange: #ea580c;
    --orange-bg: #ffedd5;
    --violet: #7c3aed;
    --violet-bg: #ede9fe;
    --teal: #0d9488;
    --teal-bg: #ccfbf1;
    --blue-bg: #dbeafe;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 14px rgba(15, 23, 42, .06);
    --shadow-lg: 0 10px 34px rgba(15, 23, 42, .16);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --sidebar-w: 252px;
    --topbar-h: 62px;
    --font: 'Inter', 'Segoe UI', system-ui, -apple-system, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font);
    color: var(--text);
    background: var(--bg);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: none; color: var(--primary-dark); }
h1, h2, h3, h4 { color: var(--ink); margin: 0 0 8px; line-height: 1.25; }
.muted { color: var(--text-soft); }
.small { font-size: 12.5px; }
.text-right { text-align: right; }
.m-0 { margin: 0; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
code { background: #f1f5f9; padding: 1px 6px; border-radius: 6px; font-size: 12.5px; }

/* ============================ Buttons ============================ */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 9px 16px; border-radius: 10px; border: 1px solid transparent;
    font-size: 13.5px; font-weight: 600; font-family: inherit; cursor: pointer;
    transition: all .16s ease; white-space: nowrap; line-height: 1.2;
    text-decoration: none;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff; box-shadow: 0 1px 2px rgba(37, 99, 235, .4);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); color: #fff; transform: translateY(-1px); }
.btn-ghost { background: var(--card); border-color: var(--border); color: var(--text); }
.btn-ghost:hover:not(:disabled) { border-color: #cbd5e1; background: #f8fafc; }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; color: #fff; }
.btn-soft { background: var(--primary-50); color: var(--primary-dark); }
.btn-soft:hover:not(:disabled) { background: var(--primary-light); color: var(--primary-dark); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn-lg { padding: 12px 22px; font-size: 15px; border-radius: 12px; }
.btn-block { width: 100%; }
.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; border-radius: 10px; border: none; background: transparent;
    color: var(--text-soft); cursor: pointer; transition: background .15s;
    font-size: 20px;
}
.icon-btn:hover { background: var(--border-soft); color: var(--text); }
.linklike {
    background: none; border: none; color: var(--primary); cursor: pointer;
    font-size: 13px; font-family: inherit; font-weight: 500; padding: 0;
}
.linklike:hover { text-decoration: underline; }

/* row action buttons */
.row-actions { display: inline-flex; gap: 4px; }
.act-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border);
    background: #fff; color: var(--text-soft); cursor: pointer; transition: all .14s;
}
.act-btn:hover { color: var(--primary); border-color: var(--primary); background: var(--primary-50); }
.act-btn.danger:hover { color: var(--red); border-color: var(--red); background: var(--red-bg); }

/* ============================ Spinner ============================ */
.spinner {
    width: 16px; height: 16px; border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, .35); border-top-color: #fff;
    animation: spin .7s linear infinite; display: inline-block;
}
.spinner.dark { border-color: rgba(29, 78, 143, .25); border-top-color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================ Alerts ============================ */
.alert {
    display: flex; gap: 10px; align-items: flex-start;
    padding: 12px 14px; border-radius: var(--radius-sm); font-size: 13.5px;
    margin-bottom: 14px; border: 1px solid transparent;
}
.alert svg { flex-shrink: 0; margin-top: 1px; }
.alert-error { background: var(--red-bg); color: #991b1b; border-color: #fecaca; }
.alert-success { background: var(--green-bg); color: #166534; border-color: #bbf7d0; }
.alert-warning { background: var(--amber-bg); color: #92400e; border-color: #fde68a; }
.alert-info { background: var(--blue-bg); color: #1e40af; border-color: #bfdbfe; }

/* ============================ Badges ============================ */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
    letter-spacing: .2px; white-space: nowrap;
}
/* Auto-generated record number chip (Customer ID / Document No.) */
.cid-badge {
    display: inline-block; padding: 2px 8px; border-radius: 6px;
    background: #e8eef9; color: #16376e;
    border: 1px solid rgba(22, 55, 110, .25);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 11.5px; font-weight: 700; letter-spacing: .4px; white-space: nowrap;
    vertical-align: middle;
}
h2 .cid-badge { font-size: 13px; margin-left: 8px; position: relative; top: -2px; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge-new { background: var(--blue-bg); color: #1e40af; }
.badge-company { background: #e8eef9; color: #16376e; }
.badge-store { background: var(--teal-bg); color: #0f766e; }
.badge-contacted { background: var(--teal-bg); color: #0f766e; }
.badge-qualified { background: var(--violet-bg); color: #6d28d9; }
.badge-proposal { background: var(--amber-bg); color: #b45309; }
.badge-negotiation { background: var(--orange-bg); color: #c2410c; }
.badge-won, .badge-completed { background: var(--green-bg); color: #15803d; }
.badge-lost { background: var(--red-bg); color: #b91c1c; }
.badge-pending { background: #f1f5f9; color: #475569; }
.badge-p-low { background: #f1f5f9; color: #64748b; }
.badge-p-medium { background: var(--blue-bg); color: #1d4ed8; }
.badge-p-high { background: var(--orange-bg); color: #c2410c; }
.badge-p-urgent { background: var(--red-bg); color: #b91c1c; }
.badge-role-admin { background: var(--violet-bg); color: #6d28d9; }
.badge-role-manager { background: var(--blue-bg); color: #1d4ed8; }
.badge-role-employee { background: var(--teal-bg); color: #0f766e; }
.badge-role-viewer { background: #f1f5f9; color: #64748b; }
.badge-status-active { background: var(--green-bg); color: #15803d; }
.badge-status-disabled { background: var(--red-bg); color: #b91c1c; }

/* ============================ Forms ============================ */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text); margin-bottom: 5px; }
.form-group label .req { color: var(--red); }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="tel"], input[type="date"], input[type="datetime-local"], input[type="search"],
input[type="url"], select, textarea {
    width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px;
    font-size: 13.5px; font-family: inherit; color: var(--text); background: #fff;
    transition: border-color .15s, box-shadow .15s; outline: none;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--primary); box-shadow: 0 0 0 3px rgba(29, 78, 143, .16);
}
input::placeholder, textarea::placeholder { color: var(--text-mute); }
textarea { resize: vertical; min-height: 84px; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24'%3E%3Cpath fill='%2364748b' d='m12 15-5-5h10l-5 5z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
.hint { display: block; color: var(--text-mute); font-size: 11.5px; margin-top: 4px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.checkbox { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; color: var(--text-soft); }
.checkbox input { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }

/* ============================ Layout ============================ */
.layout { display: flex; min-height: 100vh; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.content { flex: 1; padding: 22px 26px 30px; max-width: 1560px; width: 100%; margin: 0 auto; }
.app-footer { padding: 14px 26px; color: var(--text-mute); font-size: 12px; text-align: center; }

/* ============================ Sidebar ============================ */
.sidebar {
    width: var(--sidebar-w); flex-shrink: 0;
    background: linear-gradient(180deg, var(--navy-800) 0%, var(--navy-900) 100%);
    color: #cbd5e1; display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh; z-index: 60;
}
.sidebar-brand {
    display: flex; align-items: center; gap: 10px;
    padding: 16px 18px; border-bottom: 1px solid rgba(255, 255, 255, .07);
    min-height: var(--topbar-h);
}
.brand-logo { display: inline-flex; flex-shrink: 0; }
.brand-text {
    font-weight: 800; font-size: 13.5px; letter-spacing: .6px; color: #fff;
    display: flex; flex-direction: column; line-height: 1.15;
}
.brand-sub { font-size: 10px; letter-spacing: 4px; color: #60a5fa; font-weight: 700; }
.sidebar-close { display: none; color: #94a3b8; margin-left: auto; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 10px; }
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 4px; }
.nav-item {
    display: flex; align-items: center; gap: 11px;
    padding: 9.5px 12px; border-radius: 10px; color: #94a3b8;
    font-size: 13.5px; font-weight: 500; margin-bottom: 2px;
    transition: all .15s ease; position: relative;
}
.nav-item svg { flex-shrink: 0; opacity: .8; }
.nav-item:hover { background: rgba(255, 255, 255, .06); color: #e2e8f0; }
.nav-item.active {
    background: linear-gradient(90deg, rgba(29, 78, 143, .28), rgba(29, 78, 143, .08));
    color: #fff; font-weight: 600;
}
.nav-item.active::before {
    content: ''; position: absolute; left: -10px; top: 7px; bottom: 7px;
    width: 3.5px; border-radius: 0 4px 4px 0; background: var(--primary);
}
.nav-item.active svg { opacity: 1; color: #60a5fa; }
.sidebar-bottom { padding: 12px; border-top: 1px solid rgba(255, 255, 255, .07); }
.side-profile { display: flex; align-items: center; gap: 10px; padding: 6px 8px; margin-bottom: 6px; }
.side-profile-meta { display: flex; flex-direction: column; min-width: 0; }
.side-profile-name { color: #f1f5f9; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-profile-role { color: #64748b; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; }
.side-logout {
    display: flex; align-items: center; gap: 10px; padding: 9px 12px;
    border-radius: 10px; color: #f87171; font-size: 13px; font-weight: 600;
    transition: background .15s;
}
.side-logout:hover { background: rgba(248, 113, 113, .12); color: #fca5a5; }
.sidebar-backdrop { display: none; }

.avatar {
    width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
    background: linear-gradient(135deg, #16376e 0%, #e8262d 130%);
    color: #fff; font-weight: 700; font-size: 13px;
    display: inline-flex; align-items: center; justify-content: center;
}
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }

/* ============================ Topbar ============================ */
.topbar {
    height: var(--topbar-h); background: rgba(255, 255, 255, .9);
    backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 14px; padding: 0 22px;
    position: sticky; top: 0; z-index: 50;
}
.hamburger { display: none; }
.page-title { font-size: 17px; font-weight: 700; margin: 0; white-space: nowrap; }
.topbar-search { position: relative; flex: 1; max-width: 460px; margin-left: auto; }
.topbar-search > svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-mute); pointer-events: none; }
.topbar-search input {
    padding: 8px 14px 8px 38px; border-radius: 999px;
    background: var(--bg); border-color: transparent; font-size: 13px;
}
.topbar-search input:focus { background: #fff; border-color: var(--primary); }
.search-results {
    position: absolute; top: calc(100% + 8px); left: 0; right: 0;
    background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); max-height: 420px; overflow-y: auto; z-index: 100;
    padding: 6px;
}
.sr-group { padding: 6px 10px 3px; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .8px; color: var(--text-mute); }
.sr-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text); }
.sr-item:hover { background: var(--primary-50); }
.sr-item .sr-title { font-weight: 600; font-size: 13px; }
.sr-item .sr-sub { font-size: 11.5px; color: var(--text-soft); }
.sr-empty { padding: 16px; text-align: center; color: var(--text-mute); font-size: 13px; }

.topbar-right { display: flex; align-items: center; gap: 6px; }
.notif-wrap, .profile-wrap { position: relative; }
.notif-badge {
    position: absolute; top: 2px; right: 0; min-width: 17px; height: 17px;
    background: var(--red); color: #fff; font-size: 10px; font-weight: 700;
    border-radius: 999px; display: flex; align-items: center; justify-content: center;
    padding: 0 4px; border: 2px solid #fff;
}
.notif-panel {
    position: absolute; right: 0; top: calc(100% + 10px); width: 340px;
    background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); z-index: 110; overflow: hidden;
}
.notif-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border-soft); font-size: 13.5px; }
.notif-list { max-height: 360px; overflow-y: auto; }
.notif-item { display: flex; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--border-soft); font-size: 13px; }
.notif-item:hover { background: #f8fafc; }
.notif-item .ni-ico { width: 32px; height: 32px; border-radius: 9px; display: flex; align-items: center; justify-content: center; font-size: 15px; flex-shrink: 0; }
.ni-red { background: var(--red-bg); } .ni-orange { background: var(--orange-bg); }
.ni-blue { background: var(--blue-bg); } .ni-green { background: var(--green-bg); }
.notif-item .ni-title { font-weight: 600; color: var(--ink); }
.notif-item .ni-sub { color: var(--text-soft); font-size: 11.5px; }
.notif-empty { padding: 26px 14px; text-align: center; color: var(--text-mute); font-size: 13px; }

.profile-btn {
    display: flex; align-items: center; gap: 9px; padding: 5px 10px;
    background: none; border: 1px solid transparent; border-radius: 999px; cursor: pointer;
    font-family: inherit;
}
.profile-btn:hover { background: var(--border-soft); }
.profile-meta { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.2; }
.profile-name { font-size: 13px; font-weight: 600; color: var(--ink); }
.profile-role { font-size: 10.5px; color: var(--text-soft); }
.profile-menu {
    position: absolute; right: 0; top: calc(100% + 10px); width: 200px;
    background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); padding: 6px; z-index: 110;
}
.profile-menu a { display: block; padding: 9px 12px; border-radius: 8px; color: var(--text); font-size: 13.5px; font-weight: 500; }
.profile-menu a:hover { background: var(--border-soft); }
.profile-menu .menu-danger { color: var(--red); }
.profile-menu .menu-danger:hover { background: var(--red-bg); }
.menu-sep { height: 1px; background: var(--border-soft); margin: 5px 8px; }

/* ============================ Cards & KPI ============================ */
.card {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-sm);
    padding: 18px; margin-bottom: 18px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h3 { margin: 0; font-size: 15px; font-weight: 700; }
.card-head .sub { color: var(--text-soft); font-size: 12.5px; margin-top: 2px; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.kpi {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px 18px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
    transition: transform .15s ease, box-shadow .15s ease;
}
.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.kpi::after { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--kpi-color, var(--primary)); }
.kpi-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.kpi-label { font-size: 12px; font-weight: 600; color: var(--text-soft); text-transform: uppercase; letter-spacing: .5px; }
.kpi-ico { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 17px; background: color-mix(in srgb, var(--kpi-color, var(--primary)) 12%, #fff); }
.kpi-value { font-size: 24px; font-weight: 800; color: var(--ink); letter-spacing: -.3px; }
.kpi-sub { font-size: 11.5px; color: var(--text-mute); margin-top: 3px; }
.kpi-sub .up { color: var(--green); font-weight: 600; }
.kpi-sub .down { color: var(--red); font-weight: 600; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 18px; }
.grid-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; }
.grid-1-2 { display: grid; grid-template-columns: 1fr 2fr; gap: 18px; }
.grid-2 .card, .grid-3 .card, .grid-2-1 .card, .grid-1-2 .card { margin-bottom: 18px; }

/* ============================ Tables ============================ */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th {
    text-align: left; padding: 11px 14px; background: #f8fafc;
    font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px;
    color: var(--text-soft); border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data td { padding: 11px 14px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: #f8fafc; }
table.data .t-main { font-weight: 600; color: var(--ink); }
table.data .t-sub { font-size: 11.5px; color: var(--text-soft); }
table.data th a { color: inherit; }
table.data th.sorted a { color: var(--primary); }

/* task row visual indicators */
tr.task-overdue td:first-child { box-shadow: inset 3px 0 0 var(--red); }
tr.task-today td:first-child { box-shadow: inset 3px 0 0 var(--orange); }
tr.task-upcoming td:first-child { box-shadow: inset 3px 0 0 #eab308; }
tr.task-completed td:first-child { box-shadow: inset 3px 0 0 var(--green); }
tr.task-completed .t-main { text-decoration: line-through; color: var(--text-soft); }

/* ============================ Toolbar / filters ============================ */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .spacer { flex: 1; }
.toolbar input[type="search"], .toolbar input[type="text"], .toolbar select {
    width: auto; min-width: 150px; padding: 8px 12px; font-size: 13px;
}
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 20px; }
.page-head .sub { color: var(--text-soft); font-size: 13px; }

/* pagination */
.pagination { display: flex; gap: 6px; align-items: center; justify-content: center; padding: 16px 0 4px; flex-wrap: wrap; }
.pagination a, .pagination span.pg-cur {
    min-width: 34px; height: 34px; padding: 0 10px; display: inline-flex; align-items: center; justify-content: center;
    border-radius: 9px; border: 1px solid var(--border); background: #fff; color: var(--text);
    font-size: 13px; font-weight: 600;
}
.pagination a:hover { border-color: var(--primary); color: var(--primary); }
.pagination span.pg-cur { background: var(--primary); border-color: var(--primary); color: #fff; }
.pagination .pg-dots { border: none; background: none; color: var(--text-mute); }

/* ============================ Empty state ============================ */
.empty-state { text-align: center; padding: 52px 20px; }
.empty-state .es-ico {
    width: 64px; height: 64px; border-radius: 18px; margin: 0 auto 14px;
    background: var(--primary-50); color: var(--primary);
    display: flex; align-items: center; justify-content: center; font-size: 28px;
}
.empty-state h3 { font-size: 16px; margin-bottom: 6px; }
.empty-state p { color: var(--text-soft); font-size: 13.5px; max-width: 380px; margin: 0 auto 18px; }

/* ============================ Modals ============================ */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(11, 18, 32, .55);
    backdrop-filter: blur(3px); z-index: 200;
    display: flex; align-items: center; justify-content: center; padding: 18px;
    animation: fadeIn .16s ease;
}
.modal-overlay[hidden] { display: none; }
.modal {
    background: #fff; border-radius: var(--radius-lg); width: 100%; max-width: 560px;
    box-shadow: var(--shadow-lg); animation: popIn .18s ease;
    max-height: calc(100vh - 36px); display: flex; flex-direction: column;
}
.modal.modal-sm { max-width: 420px; }
.modal.modal-lg { max-width: 720px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border-soft); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-x { background: none; border: none; font-size: 24px; line-height: 1; color: var(--text-mute); cursor: pointer; padding: 2px 6px; border-radius: 8px; }
.modal-x:hover { background: var(--border-soft); color: var(--text); }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border-soft); display: flex; justify-content: flex-end; gap: 10px; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn { from { opacity: 0; transform: translateY(10px) scale(.98); } }

/* confirm dialog */
.confirm-ico { width: 52px; height: 52px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 24px; margin-bottom: 12px; background: var(--red-bg); }
.confirm-ico.warn { background: var(--amber-bg); }

/* ============================ Toasts ============================ */
.toast-container { position: fixed; top: 16px; right: 16px; z-index: 500; display: flex; flex-direction: column; gap: 10px; max-width: 360px; }
.toast {
    display: flex; align-items: flex-start; gap: 10px;
    background: #fff; border-radius: var(--radius); box-shadow: var(--shadow-lg);
    padding: 13px 15px; font-size: 13.5px; border-left: 4px solid var(--primary);
    animation: slideIn .25s ease; min-width: 260px;
}
.toast .t-ico { font-size: 16px; line-height: 1.3; }
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
.toast.warning { border-left-color: var(--amber); }
.toast.info { border-left-color: var(--primary); }
.toast.out { animation: slideOut .25s ease forwards; }
@keyframes slideIn { from { opacity: 0; transform: translateX(30px); } }
@keyframes slideOut { to { opacity: 0; transform: translateX(30px); } }

/* ============================ Tabs ============================ */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tab {
    padding: 10px 16px; font-size: 13.5px; font-weight: 600; color: var(--text-soft);
    border-bottom: 2.5px solid transparent; cursor: pointer; white-space: nowrap;
    background: none; border-top: none; border-left: none; border-right: none; font-family: inherit;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-pane { display: none; }
.tab-pane.active { display: block; animation: fadeIn .2s ease; }

/* ============================ Kanban / Pipeline ============================ */
.kanban { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 14px; align-items: flex-start; }
.kanban-col {
    background: #eef2f7; border-radius: var(--radius); min-width: 250px; width: 250px;
    flex-shrink: 0; display: flex; flex-direction: column; max-height: calc(100vh - 210px);
    border: 1px solid var(--border);
}
.kanban-col-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 14px; font-size: 12.5px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .5px; color: var(--text-soft); border-bottom: 1px solid var(--border);
}
.kanban-col-head .kc-count {
    background: #fff; border: 1px solid var(--border); border-radius: 999px;
    font-size: 11px; padding: 1px 8px; color: var(--text-soft);
}
.kanban-col-head .kc-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 7px; }
.kanban-col-body { padding: 10px; overflow-y: auto; flex: 1; min-height: 120px; }
.kanban-col.drag-over .kanban-col-body { background: var(--primary-50); border-radius: 0 0 var(--radius) var(--radius); outline: 2px dashed var(--primary); outline-offset: -4px; }
.kanban-col-total { padding: 8px 14px; font-size: 12px; font-weight: 700; color: var(--text-soft); border-top: 1px solid var(--border); }
.kcard {
    background: #fff; border: 1px solid var(--border); border-radius: 10px;
    padding: 12px; margin-bottom: 10px; cursor: grab; box-shadow: var(--shadow-sm);
    transition: box-shadow .15s, transform .15s;
}
.kcard:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.kcard.dragging { opacity: .45; transform: rotate(2deg); }
.kcard .kc-title { font-weight: 700; font-size: 13.5px; color: var(--ink); margin-bottom: 3px; }
.kcard .kc-company { font-size: 12px; color: var(--text-soft); margin-bottom: 8px; }
.kcard .kc-value { font-weight: 800; color: var(--primary-dark); font-size: 13.5px; }
.kcard .kc-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.kcard .kc-owner { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text-soft); }
.kcard .kc-follow { font-size: 11px; color: var(--text-mute); }
.kcard .kc-follow.due { color: var(--orange); font-weight: 600; }

/* ============================ Calendar ============================ */
.cal-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.cal-title { font-size: 16px; font-weight: 800; color: var(--ink); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: #fff; }
.cal-dow { padding: 9px 10px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--text-soft); background: #f8fafc; border-bottom: 1px solid var(--border); }
.cal-day {
    min-height: 104px; border-right: 1px solid var(--border-soft); border-bottom: 1px solid var(--border-soft);
    padding: 7px 8px; cursor: pointer; transition: background .12s; position: relative; background: #fff;
}
.cal-day:nth-child(7n) { border-right: none; }
.cal-day:hover { background: var(--primary-50); }
.cal-day.other { background: #fafbfc; color: var(--text-mute); }
.cal-day.today .cal-num { background: var(--primary); color: #fff; }
.cal-num {
    display: inline-flex; align-items: center; justify-content: center;
    width: 24px; height: 24px; border-radius: 50%; font-size: 12.5px; font-weight: 600; margin-bottom: 4px;
}
.cal-event {
    display: block; font-size: 11px; padding: 2.5px 7px; border-radius: 6px;
    margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    border-left: 3px solid;
}
.cal-event.ev-task { background: var(--blue-bg); border-color: var(--primary); color: #1e40af; }
.cal-event.ev-followup { background: var(--amber-bg); border-color: var(--amber); color: #92400e; }
.cal-event.ev-deal { background: var(--violet-bg); border-color: var(--violet); color: #6d28d9; }
.cal-event.ev-overdue { background: var(--red-bg); border-color: var(--red); color: #b91c1c; }
.cal-more { font-size: 10.5px; color: var(--primary); font-weight: 600; padding-left: 4px; }

.cal-week { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cal-week-row { display: flex; border-bottom: 1px solid var(--border-soft); }
.cal-week-row:last-child { border-bottom: none; }
.cal-week-date { width: 150px; flex-shrink: 0; padding: 12px 14px; font-weight: 600; font-size: 13px; border-right: 1px solid var(--border-soft); background: #f8fafc; }
.cal-week-date.today { background: var(--primary-50); color: var(--primary-dark); }
.cal-week-events { flex: 1; padding: 10px 12px; display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; }
.cal-week-empty { color: var(--text-mute); font-size: 12.5px; padding: 4px; }

/* ============================ Timeline ============================ */
.timeline { position: relative; padding-left: 26px; }
.timeline::before { content: ''; position: absolute; left: 8px; top: 4px; bottom: 4px; width: 2px; background: var(--border); }
.tl-item { position: relative; padding-bottom: 18px; }
.tl-item:last-child { padding-bottom: 0; }
.tl-dot {
    position: absolute; left: -26px; top: 2px; width: 18px; height: 18px; border-radius: 50%;
    background: #fff; border: 2px solid var(--primary); display: flex; align-items: center; justify-content: center;
    font-size: 9px; color: var(--primary);
}
.tl-dot.green { border-color: var(--green); color: var(--green); }
.tl-dot.red { border-color: var(--red); color: var(--red); }
.tl-dot.amber { border-color: var(--amber); color: var(--amber); }
.tl-title { font-weight: 600; font-size: 13.5px; color: var(--ink); }
.tl-meta { font-size: 11.5px; color: var(--text-mute); margin-top: 1px; }
.tl-details { font-size: 13px; color: var(--text-soft); margin-top: 4px; background: #f8fafc; border-radius: 8px; padding: 8px 11px; }

/* ============================ Detail pages ============================ */
.detail-head {
    background: linear-gradient(120deg, var(--navy-800), var(--navy-700));
    border-radius: var(--radius-lg); color: #fff; padding: 22px 24px; margin-bottom: 20px;
    display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
}
.detail-head h2 { color: #fff; font-size: 21px; margin: 0 0 4px; }
.detail-head .dh-sub { color: #94a3b8; font-size: 13px; display: flex; gap: 14px; flex-wrap: wrap; }
.detail-head .dh-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.detail-head .btn-ghost { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.18); color: #e2e8f0; }
.detail-head .btn-ghost:hover { background: rgba(255,255,255,.16); }
.detail-head .btn-danger { background: #dc2626; border-color: transparent; }

.info-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.info-item .ii-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--text-mute); margin-bottom: 3px; }
.info-item .ii-value { font-size: 14px; font-weight: 600; color: var(--ink); word-break: break-word; }

/* ============================ Charts ============================ */
.chart-box { position: relative; width: 100%; }
.chart-box canvas { width: 100%; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 10px; }
.legend .lg-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-soft); }
.legend .lg-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }

/* list rows (recent leads etc.) */
.list-row { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--border-soft); }
.list-row:last-child { border-bottom: none; }
.list-row .lr-main { flex: 1; min-width: 0; }
.list-row .lr-title { font-weight: 600; font-size: 13.5px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row .lr-sub { font-size: 11.5px; color: var(--text-soft); }
.list-row .lr-right { text-align: right; flex-shrink: 0; }

/* progress bar */
.progress { height: 7px; border-radius: 99px; background: var(--border-soft); overflow: hidden; }
.progress .bar { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--primary), #60a5fa); }

/* ============================ LOGIN PAGE ============================ */
.login-body {
    background: radial-gradient(1200px 700px at 80% -10%, rgba(37, 99, 235, .18), transparent 60%),
                linear-gradient(135deg, var(--navy-900) 0%, var(--navy-800) 55%, #16223c 100%);
    min-height: 100vh; color: var(--text);
}
.login-shell { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-brand { display: flex; flex-direction: column; justify-content: space-between; padding: 46px 54px; color: #cbd5e1; }
.login-brand .brand-text { font-size: 15px; }
.brand-lg { display: inline-flex; align-items: center; gap: 12px; }
.login-headline { color: #fff; font-size: 36px; font-weight: 800; letter-spacing: -.5px; line-height: 1.18; margin: 64px 0 14px; }
.login-sub { color: #94a3b8; font-size: 15.5px; max-width: 430px; }
.login-points { list-style: none; padding: 0; margin: 34px 0 0; display: grid; gap: 13px; }
.login-points li { display: flex; align-items: center; gap: 12px; font-size: 14px; color: #cbd5e1; }
.lp-ico {
    width: 36px; height: 36px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center;
    background: rgba(37, 99, 235, .18); border: 1px solid rgba(96, 165, 250, .25); font-size: 16px;
}
.login-brand-footer { color: #475569; font-size: 12.5px; }

.login-main { display: flex; align-items: center; justify-content: center; padding: 30px; }
.login-card {
    width: 100%; max-width: 430px; background: rgba(255, 255, 255, .97);
    border: 1px solid rgba(255, 255, 255, .5); border-radius: 20px;
    box-shadow: 0 24px 70px rgba(2, 6, 23, .55); padding: 34px 32px 26px;
    backdrop-filter: blur(12px);
}
.login-card.shake { animation: shake .4s ease; }
@keyframes shake {
    10%, 90% { transform: translateX(-2px); }
    20%, 80% { transform: translateX(4px); }
    30%, 50%, 70% { transform: translateX(-6px); }
    40%, 60% { transform: translateX(6px); }
}
.login-card-head { margin-bottom: 20px; }
.login-card-head h2 { font-size: 23px; margin-bottom: 4px; }
.login-card-head p { color: var(--text-soft); font-size: 13.5px; margin: 0; }
.input-icon { position: relative; }
.input-icon > svg:first-child { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-mute); pointer-events: none; }
.input-icon input { padding-left: 40px; padding-right: 42px; }
.pw-toggle {
    position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
    background: none; border: none; color: var(--text-mute); cursor: pointer; padding: 6px; border-radius: 8px;
    display: inline-flex;
}
.pw-toggle:hover { color: var(--primary); background: var(--primary-50); }
.pw-toggle .ico-eye-off { display: none; }
.pw-toggle.on .ico-eye { display: none; }
.pw-toggle.on .ico-eye-off { display: block; }
.caps-warning {
    display: flex; align-items: center; gap: 6px; color: var(--amber);
    font-size: 12px; font-weight: 600; margin-top: 6px;
}
.caps-warning[hidden] { display: none; }
.login-row { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 18px; }
.login-foot { text-align: center; color: var(--text-mute); font-size: 11.5px; margin: 18px 0 0; }

/* ============================ SETUP PAGE ============================ */
.setup-body {
    background: linear-gradient(135deg, var(--navy-900), var(--navy-700));
    min-height: 100vh; padding: 34px 16px;
}
.setup-wrap { max-width: 760px; margin: 0 auto; }
.setup-card {
    background: #fff; border-radius: 20px; box-shadow: 0 24px 70px rgba(2, 6, 23, .5);
    padding: 34px;
}
.setup-head { text-align: center; margin-bottom: 22px; }
.setup-head h1 { font-size: 21px; letter-spacing: .4px; margin: 12px 0 4px; }
.setup-head h1 span { color: var(--primary); }
.setup-head p { color: var(--text-soft); margin: 0; font-size: 13.5px; }
.setup-section { font-size: 14px; margin: 24px 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border-soft); }
.check-list { list-style: none; padding: 0; margin: 0 0 8px; display: grid; gap: 8px; }
.check-list li { display: flex; align-items: center; gap: 10px; font-size: 13.5px; padding: 9px 12px; border-radius: 10px; background: #f8fafc; border: 1px solid var(--border-soft); }
.check-list .ck { width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: #fff; flex-shrink: 0; }
.check-list li.ok .ck { background: var(--green); }
.check-list li.bad .ck { background: var(--red); }
.check-list .ck-info { margin-left: auto; color: var(--text-mute); font-size: 11.5px; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.setup-steps { padding-left: 20px; font-size: 13.5px; line-height: 2; }
.setup-note { text-align: center; color: var(--text-mute); font-size: 11.5px; margin-top: 14px; }

/* ============================ Error pages ============================ */
.error-body { background: linear-gradient(135deg, var(--navy-900), var(--navy-700)); min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.error-wrap { width: 100%; max-width: 480px; }
.error-card { background: #fff; border-radius: 20px; padding: 42px 34px; text-align: center; box-shadow: 0 24px 70px rgba(2, 6, 23, .5); }
.error-code { font-size: 56px; font-weight: 800; color: var(--primary); letter-spacing: -2px; }
.error-card h1 { font-size: 20px; }
.error-card p { color: var(--text-soft); font-size: 13.5px; }
.error-actions { display: flex; gap: 10px; justify-content: center; margin-top: 20px; }

/* ============================ Utilities ============================ */
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; }
.w-100 { width: 100%; }
.money { font-weight: 700; font-variant-numeric: tabular-nums; }

/* tooltips */
[data-tip] { position: relative; }
[data-tip]:hover::after {
    content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
    background: var(--navy-800); color: #fff; font-size: 11px; padding: 5px 9px; border-radius: 7px;
    white-space: nowrap; z-index: 300; pointer-events: none;
}

/* skeleton loading */
.skeleton { background: linear-gradient(90deg, #eef2f7 25%, #e2e8f0 50%, #eef2f7 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: 8px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ============================ Responsive ============================ */
@media (max-width: 1200px) {
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: 1fr 1fr; }
    .grid-2-1, .grid-1-2 { grid-template-columns: 1fr; }
}
@media (max-width: 1024px) {
    .sidebar {
        position: fixed; left: 0; top: 0; bottom: 0; height: 100vh;
        transform: translateX(-105%); transition: transform .25s ease;
        box-shadow: none;
    }
    body.sidebar-open .sidebar { transform: translateX(0); box-shadow: var(--shadow-lg); }
    body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(11,18,32,.5); z-index: 55; }
    .sidebar-close { display: inline-flex; }
    .hamburger { display: inline-flex; }
    .login-shell { grid-template-columns: 1fr; }
    .login-brand { display: none; }
    .grid-3 { grid-template-columns: 1fr 1fr; }
    .profile-meta { display: none; }
}
@media (max-width: 720px) {
    .content { padding: 14px 12px 24px; }
    .topbar { padding: 0 12px; gap: 8px; }
    .page-title { font-size: 15px; max-width: 32vw; overflow: hidden; text-overflow: ellipsis; }
    .topbar-search { max-width: none; }
    .topbar-search input { padding: 7px 12px 7px 34px; }
    .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .kpi { padding: 13px 14px; }
    .kpi-value { font-size: 19px; }
    .grid-2, .grid-3, .grid-2-1, .grid-1-2 { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .detail-head { padding: 18px; }
    .toolbar input[type="search"], .toolbar input[type="text"], .toolbar select { min-width: 0; width: 100%; }
    .toolbar { display: grid; grid-template-columns: 1fr 1fr; }
    .toolbar .spacer { display: none; }
    .toolbar > .btn { grid-column: 1 / -1; }
    .cal-day { min-height: 74px; padding: 4px 5px; }
    .cal-event { font-size: 9.5px; padding: 1.5px 4px; }
    .cal-week-row { flex-direction: column; }
    .cal-week-date { width: 100%; border-right: none; border-bottom: 1px solid var(--border-soft); }
    .notif-panel { width: calc(100vw - 30px); right: -60px; }
    table.data { font-size: 12.5px; }
    table.data th, table.data td { padding: 9px 10px; }
    .modal { max-width: 100%; }
    .login-card { padding: 26px 20px; }
}

/* ============================ Print ============================ */
@media print {
    .sidebar, .topbar, .toolbar, .app-footer, .toast-container, .btn, .pagination, .no-print { display: none !important; }
    body { background: #fff; }
    .content { padding: 0; max-width: none; }
    .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
    .table-wrap { overflow: visible; border: none; }
    table.data th { background: #eee; }
}


/* ============================================================
   GLOBAL PAGE COVERAGE — shared visual polish for every module
   Version 1.0.7: standardizes newer modules and standalone pages
   ============================================================ */

:root {
    --focus-ring: 0 0 0 3px rgba(29, 78, 143, .16);
}

/* Predictable rendering across old and new module markup. */
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, summary:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Buttons used by newer modules and account/security screens. */
.btn-secondary {
    background: #fff;
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.btn-secondary:hover:not(:disabled) {
    color: var(--primary-dark);
    border-color: #b8c8df;
    background: var(--primary-50);
}
.btn:not(.btn-primary):not(.btn-ghost):not(.btn-danger):not(.btn-soft):not(.btn-secondary) {
    background: #fff;
    color: var(--text);
    border-color: var(--border);
}
.btn:not(.btn-primary):not(.btn-ghost):not(.btn-danger):not(.btn-soft):not(.btn-secondary):hover:not(:disabled) {
    background: #f8fafc;
    border-color: #cbd5e1;
}

/* Keep error alerts consistent across legacy `alert-danger` and `alert-error` markup. */
.alert-danger {
    background: var(--red-bg);
    color: #991b1b;
    border: 1px solid #fecaca;
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    font-size: 13.5px;
    margin: 0 0 14px;
}
.alert-success, .alert-warning, .alert-info { border-width: 1px; border-style: solid; }

/* Card/panel convention used by Payments, Commissions and Tickets. */
.panel {
    min-width: 0;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    margin: 0 0 18px;
}
.panel-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    padding-bottom: 16px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border-soft);
}
.panel-head > div { min-width: 0; flex: 1 1 280px; }
.panel-head h2 { font-size: 17px; margin: 0 0 5px; }
.panel-head p { color: var(--text-soft); font-size: 13px; margin: 0; line-height: 1.55; }
.panel .card { box-shadow: none; background: #f8fafc; }

/* Apply the table system to older/newer modules that use bare <table>. */
.table-wrap > table,
table.audit-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
    color: var(--text);
}
.table-wrap > table th,
.table-wrap > table td {
    padding: 11px 13px;
    border-bottom: 1px solid var(--border-soft);
    text-align: left;
    vertical-align: top;
}
.table-wrap > table th {
    background: #f8fafc;
    color: #475569;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .045em;
    text-transform: uppercase;
    white-space: nowrap;
}
.table-wrap > table tbody tr:last-child td { border-bottom: 0; }
.table-wrap > table tbody tr:hover { background: #f8fbff; }
.table-wrap > table td small { color: var(--text-soft); font-size: 11.5px; }
.table-wrap > table form { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.table-wrap > table form select { min-width: 110px; width: auto; }
.table-wrap > table form .btn { min-height: 32px; }
.table-wrap > table td[colspan] { color: var(--text-soft); padding: 25px 14px; text-align: center; }

/* Forms nested in labels are used in ticket creation/update screens. */
.panel label, .sec-card label { color: var(--text); font-size: 12.5px; font-weight: 600; }
.panel label input:not([type="checkbox"]):not([type="radio"]),
.panel label select, .panel label textarea,
.sec-card label input:not([type="checkbox"]):not([type="radio"]),
.sec-card label select, .sec-card label textarea {
    display: block;
    margin-top: 6px;
}
input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); }
input[type="checkbox"] + label, input[type="radio"] + label { display: inline; }
form textarea { max-width: 100%; }
form button { touch-action: manipulation; }

/* Details/summary accordions used in tickets and audit-style flows. */
details { min-width: 0; }
details > summary {
    cursor: pointer;
    color: var(--primary-dark);
    font-size: 13px;
    font-weight: 600;
    padding: 7px 0;
}
details > summary::marker { color: var(--primary); }
details[open] > summary { margin-bottom: 8px; }
.table-wrap details { min-width: 110px; max-width: 360px; }
.table-wrap details form { display: grid !important; grid-template-columns: 1fr; align-items: stretch !important; }
.table-wrap details textarea { min-width: 180px; }

/* Role chips: add color coverage for all seven current roles. */
.badge-role-super_admin { background: #dbeafe; color: #1e40af; }
.badge-role-team_lead { background: #ede9fe; color: #6d28d9; }
.badge-role-agent { background: #dcfce7; color: #166534; }
.badge-role-accounts { background: #ccfbf1; color: #0f766e; }
.badge-role-customer { background: #f1f5f9; color: #475569; }
.badge-role-manager { background: var(--blue-bg); color: #1d4ed8; }
.badge-role-viewer { background: #f1f5f9; color: #64748b; }
.badge-status-pending { background: var(--amber-bg); color: #92400e; }
.badge-status-verified, .badge-status-paid { background: var(--green-bg); color: #166534; }
.badge-status-rejected, .badge-status-cancelled { background: var(--red-bg); color: #991b1b; }

/* Security Center / audit pages that share the same design system. */
.sec-wrap, .audit-wrap { width: min(1200px, 100%); margin: 28px auto; padding: 0 18px; }
.sec-wrap h1, .audit-wrap h1 { font-size: clamp(21px, 2.3vw, 28px); letter-spacing: -.025em; }
.sec-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.sec-row > div:first-child { flex: 1 1 280px; min-width: 0; }
.sec-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: clamp(16px, 2.5vw, 24px);
    margin: 18px 0;
    box-shadow: var(--shadow-sm);
}
.sec-card h2 { font-size: 16px; margin-bottom: 8px; }
.sec-card p { color: var(--text-soft); line-height: 1.65; }
.sec-hint, .audit-muted { color: var(--text-soft); font-size: 12px; overflow-wrap: anywhere; }
.sec-secret {
    display: block;
    max-width: 100%;
    overflow-wrap: anywhere;
    background: #f8fafc;
    border: 1px dashed #cbd5e1;
    border-radius: 10px;
    padding: 12px 14px;
    color: var(--ink);
    font: 700 16px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    letter-spacing: .04em;
}
.sec-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.audit-table-wrap { width: 100%; overflow: auto; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.audit-table th, .audit-table td { padding: 10px 12px; border-bottom: 1px solid var(--border-soft); text-align: left; vertical-align: top; overflow-wrap: anywhere; }
.audit-table th { position: sticky; top: 0; z-index: 1; background: #f8fafc; color: #475569; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.audit-table tr:last-child td { border-bottom: 0; }
.sev-critical { color: #b91c1c; font-weight: 700; }
.sev-warning { color: #b45309; font-weight: 700; }
.sev-info { color: #1d4ed8; font-weight: 700; }

/* Lead-capture form uses its own compact layout plus shared tokens. */
.cf-card { box-shadow: var(--shadow); }
.cf-f input:focus, .cf-f textarea:focus, .cf-f select:focus { border-color: var(--primary); box-shadow: var(--focus-ring); outline: 0; }
.cf-btn:focus-visible { outline: 3px solid rgba(96, 165, 250, .65); outline-offset: 3px; }

/* More robust mobile layout for every module and standalone utility page. */
@media (max-width: 720px) {
    .panel { padding: 14px; }
    .panel-head { gap: 10px; padding-bottom: 12px; margin-bottom: 12px; }
    .sec-wrap, .audit-wrap { margin: 18px auto; padding: 0 12px; }
    .sec-card { padding: 15px; }
    .sec-row { align-items: flex-start; }
    .sec-row .btn { flex: 1 1 auto; }
    .table-wrap > table { min-width: 640px; }
    .table-wrap > table td, .table-wrap > table th { padding: 9px 10px; }
    .table-wrap details { max-width: 250px; }
    .sec-secret { font-size: 13px; }
}
@media (max-width: 420px) {
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .login-main { padding: 18px 12px; }
    .login-card { border-radius: 15px; }
    .setup-card { padding: 22px 16px; }
    .sec-actions > .btn { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}


/* ============================================================
   GLOBAL FORM NORMALIZATION + THEME SWITCH
   - Handles legacy inputs without an explicit type attribute.
   - Light/Dark mode applies to all authenticated CRM modules.
   ============================================================ */
:root {
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --surface-hover: #f4f7fb;
    --surface-input: #ffffff;
    --topbar-surface: rgba(255, 255, 255, .94);
}

/* Some legacy forms omit type="text". Normalize those fields as real CRM inputs. */
input:not([type]),
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="tel"], input[type="date"],
input[type="datetime-local"], input[type="search"], input[type="url"],
select, textarea {
    display: block;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    min-height: 40px;
    box-sizing: border-box;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 9px;
    color: var(--text);
    background: var(--surface-input);
    font-family: var(--font);
    font-size: 13.5px;
    line-height: 1.35;
}
input[type="checkbox"], input[type="radio"], input[type="file"],
input[type="submit"], input[type="button"], input[type="reset"], input[type="hidden"] {
    width: auto;
    min-height: 0;
}
.panel label, .sec-card label, .payment-form > label, .form-grid > label {
    display: block;
    min-width: 0;
    line-height: 1.45;
}
.panel label input:not([type="checkbox"]):not([type="radio"]),
.panel label select, .panel label textarea,
.sec-card label input:not([type="checkbox"]):not([type="radio"]),
.sec-card label select, .sec-card label textarea,
.payment-form > label input, .payment-form > label select,
.payment-form > label textarea, .form-grid > label input,
.form-grid > label select, .form-grid > label textarea {
    display: block;
    width: 100%;
    margin-top: 6px;
}
.form-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.form-grid > * { min-width: 0; }
.payment-form { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 14px; align-items: start; }
.payment-form > label { margin: 0 0 14px; }
.payment-form .payment-submit { grid-column: 1; justify-self: stretch; width: 100%; min-width: 0; margin-top: 0; }
.payment-form input:focus, .payment-form select:focus { background: var(--surface-input); }
.panel .card { background: var(--surface-muted); border: 1px solid var(--border); }

/* Theme button stays visually consistent with notification/profile actions. */
.theme-toggle { flex: 0 0 38px; }
.theme-toggle[aria-pressed="true"] { color: var(--primary); background: var(--primary-50); }
.theme-icon[hidden] { display: none !important; }

/* Dark palette. A saved preference is applied early in the page head to avoid flashing. */
html[data-theme="dark"] {
    color-scheme: dark;
    --primary: #78aefa;
    --primary-dark: #a6cbff;
    --primary-light: #213a5d;
    --primary-50: #172b45;
    --ink: #f0f5fc;
    --text: #dce6f3;
    --text-soft: #a8b7ca;
    --text-mute: #8193ab;
    --bg: #0b1220;
    --card: #111c2d;
    --border: #2a3a50;
    --border-soft: #223147;
    --green-bg: #123b2f;
    --red-bg: #40212a;
    --amber-bg: #3f321a;
    --orange-bg: #422a1e;
    --violet-bg: #30234b;
    --teal-bg: #123936;
    --blue-bg: #1b3150;
    --surface: #111c2d;
    --surface-muted: #172337;
    --surface-hover: #1b2a40;
    --surface-input: #0d1726;
    --topbar-surface: rgba(17, 28, 45, .96);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .22);
    --shadow: 0 1px 3px rgba(0, 0, 0, .25), 0 4px 14px rgba(0, 0, 0, .18);
    --shadow-lg: 0 14px 36px rgba(0, 0, 0, .42);
}
html[data-theme="dark"] body { background: var(--bg); color: var(--text); }
html[data-theme="dark"] h1,
html[data-theme="dark"] h2,
html[data-theme="dark"] h3,
html[data-theme="dark"] h4,
html[data-theme="dark"] .page-title,
html[data-theme="dark"] .profile-name,
html[data-theme="dark"] .notif-item .ni-title,
html[data-theme="dark"] table.data .t-main { color: var(--ink); }
html[data-theme="dark"] code { background: var(--surface-muted); color: var(--text); }
html[data-theme="dark"] .topbar { background: var(--topbar-surface); border-bottom-color: var(--border); }
html[data-theme="dark"] .content,
html[data-theme="dark"] .main { background: var(--bg); }
html[data-theme="dark"] .panel,
html[data-theme="dark"] .card,
html[data-theme="dark"] .sec-card,
html[data-theme="dark"] .modal,
html[data-theme="dark"] .error-card,
html[data-theme="dark"] .table-wrap,
html[data-theme="dark"] .audit-table-wrap,
html[data-theme="dark"] .audit-table-wrap,
html[data-theme="dark"] .cal-grid,
html[data-theme="dark"] .cal-week,
html[data-theme="dark"] .search-results,
html[data-theme="dark"] .notif-panel,
html[data-theme="dark"] .profile-menu,
html[data-theme="dark"] .toast,
html[data-theme="dark"] .pagination a,
html[data-theme="dark"] .pagination span.pg-cur,
html[data-theme="dark"] .cal-event,
html[data-theme="dark"] .cal-day,
html[data-theme="dark"] .cal-cell,
html[data-theme="dark"] .kpi,
html[data-theme="dark"] .kcard,
html[data-theme="dark"] .kanban-col,
html[data-theme="dark"] .pipeline-col,
html[data-theme="dark"] .task-card,
html[data-theme="dark"] .lead-card { background: var(--surface); color: var(--text); border-color: var(--border); }
html[data-theme="dark"] .panel .card,
html[data-theme="dark"] .cal-dow,
html[data-theme="dark"] .cal-week-date,
html[data-theme="dark"] .cal-dow,
html[data-theme="dark"] .tl-details,
html[data-theme="dark"] .table-wrap > table th,
html[data-theme="dark"] table.data th,
html[data-theme="dark"] .audit-table th,
html[data-theme="dark"] .check-list li { background: var(--surface-muted); color: var(--text-soft); border-color: var(--border); }
html[data-theme="dark"] .table-wrap > table,
html[data-theme="dark"] table.data,
html[data-theme="dark"] table.audit-table,
html[data-theme="dark"] .table-wrap > table tbody,
html[data-theme="dark"] .table-wrap > table tr,
html[data-theme="dark"] table.data tbody tr,
html[data-theme="dark"] .audit-table tr { background: var(--surface); color: var(--text); }
html[data-theme="dark"] .table-wrap > table td,
html[data-theme="dark"] .table-wrap > table th,
html[data-theme="dark"] table.data td,
html[data-theme="dark"] table.data th,
html[data-theme="dark"] .audit-table td,
html[data-theme="dark"] .audit-table th { border-color: var(--border-soft); }
html[data-theme="dark"] .table-wrap > table tbody tr:hover,
html[data-theme="dark"] table.data tbody tr:hover,
html[data-theme="dark"] .notif-item:hover,
html[data-theme="dark"] .sr-item:hover,
html[data-theme="dark"] .profile-btn:hover { background: var(--surface-hover); }
html[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="file"]),
html[data-theme="dark"] select,
html[data-theme="dark"] textarea { background-color: var(--surface-input); color: var(--text); border-color: var(--border); }
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder { color: var(--text-mute); }
html[data-theme="dark"] .btn-ghost,
html[data-theme="dark"] .btn-secondary,
html[data-theme="dark"] .btn:not(.btn-primary):not(.btn-ghost):not(.btn-danger):not(.btn-soft):not(.btn-secondary),
html[data-theme="dark"] .act-btn,
html[data-theme="dark"] .pagination a { background: var(--surface); color: var(--text); border-color: var(--border); }
html[data-theme="dark"] .btn-ghost:hover:not(:disabled),
html[data-theme="dark"] .btn-secondary:hover:not(:disabled),
html[data-theme="dark"] .btn:not(.btn-primary):not(.btn-ghost):not(.btn-danger):not(.btn-soft):not(.btn-secondary):hover:not(:disabled),
html[data-theme="dark"] .act-btn:hover { background: var(--surface-hover); border-color: #446182; color: var(--ink); }
html[data-theme="dark"] .btn-primary { background: linear-gradient(135deg, #285fa8 0%, #1a417c 100%); color: #fff; border-color: #2b5f9d; }
html[data-theme="dark"] .topbar-search input:focus { background: var(--surface-input); }
html[data-theme="dark"] .profile-menu a { color: var(--text); }
html[data-theme="dark"] .profile-menu a:hover { background: var(--surface-hover); }
html[data-theme="dark"] .modal-foot,
html[data-theme="dark"] .modal-head,
html[data-theme="dark"] .panel-head { border-color: var(--border-soft); }
html[data-theme="dark"] .sec-secret { background: var(--surface-muted); color: var(--ink); border-color: var(--border); }
html[data-theme="dark"] .badge-pending,
html[data-theme="dark"] .badge-p-low,
html[data-theme="dark"] .badge-role-customer,
html[data-theme="dark"] .badge-role-viewer { background: #27364b; color: #d5dfeb; }
html[data-theme="dark"] .badge-new,
html[data-theme="dark"] .badge-company,
html[data-theme="dark"] .badge-role-admin,
html[data-theme="dark"] .badge-role-manager,
html[data-theme="dark"] .badge-role-super_admin { background: #1c3557; color: #b9d5ff; }
html[data-theme="dark"] .badge-won,
html[data-theme="dark"] .badge-completed,
html[data-theme="dark"] .badge-status-active,
html[data-theme="dark"] .badge-status-verified,
html[data-theme="dark"] .badge-status-paid,
html[data-theme="dark"] .badge-role-agent { background: #164134; color: #9de6c6; }
html[data-theme="dark"] .badge-lost,
html[data-theme="dark"] .badge-status-disabled,
html[data-theme="dark"] .badge-status-rejected,
html[data-theme="dark"] .badge-status-cancelled { background: #48242c; color: #ffb7c2; }
html[data-theme="dark"] .badge-qualified,
html[data-theme="dark"] .badge-role-team_lead { background: #332651; color: #d4bdff; }
html[data-theme="dark"] .badge-proposal,
html[data-theme="dark"] .badge-p-high,
html[data-theme="dark"] .badge-status-pending { background: #493719; color: #ffd58a; }
html[data-theme="dark"] .badge-negotiation,
html[data-theme="dark"] .badge-p-urgent { background: #4b2a1c; color: #ffc09b; }
html[data-theme="dark"] .badge-contacted,
html[data-theme="dark"] .badge-store,
html[data-theme="dark"] .badge-role-employee,
html[data-theme="dark"] .badge-role-accounts { background: #163d3b; color: #9fe8df; }
html[data-theme="dark"] .cid-badge { background: #1e3451; color: #c3d9fb; border-color: #37577c; }
html[data-theme="dark"] .app-footer { color: var(--text-mute); }
html[data-theme="dark"] .theme-toggle[aria-pressed="true"] { color: #ffd166; background: #263247; }

@media (max-width: 720px) {
    .payment-form { grid-template-columns: minmax(0, 1fr); }
    .payment-form .payment-submit { grid-column: 1; width: 100%; min-width: 0; }
}


/* ============================================================
   PAYMENT FORM HOTFIX + RELIABLE THEME SWITCH (themefix4)
   Strong scoped selectors fix legacy fields that arrive without
   a usable type attribute. Keep this at the end of the stylesheet.
   ============================================================ */
#paymentForm.payment-form {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    align-items: start;
    gap: 0 16px;
    width: 100%;
}
#paymentForm.payment-form > label {
    display: block !important;
    width: 100%;
    min-width: 0;
    margin: 0 0 14px;
    color: var(--text);
    font-size: 12.5px;
    font-weight: 600;
    line-height: 1.45;
}
#paymentForm.payment-form .payment-control,
#paymentForm.payment-form input:not([type]),
#paymentForm.payment-form input[type=""],
#paymentForm.payment-form input[type="text"],
#paymentForm.payment-form input[type="number"],
#paymentForm.payment-form input[type="date"],
#paymentForm.payment-form select,
#paymentForm.payment-form textarea {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    min-height: 42px !important;
    height: 42px;
    margin: 6px 0 0 !important;
    padding: 9px 12px !important;
    border: 1px solid var(--border) !important;
    border-radius: 9px !important;
    box-sizing: border-box !important;
    background-color: var(--surface-input) !important;
    color: var(--text) !important;
    font: 400 13.5px/1.35 var(--font) !important;
    box-shadow: none;
}
#paymentForm.payment-form .payment-control:focus,
#paymentForm.payment-form input:focus,
#paymentForm.payment-form select:focus,
#paymentForm.payment-form textarea:focus {
    outline: none;
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
}
#paymentForm.payment-form .payment-submit {
    grid-column: 1 / -1;
    justify-self: start;
    width: min(100%, 420px) !important;
    min-width: 0;
    min-height: 42px;
    margin-top: 0;
}
#paymentForm.payment-form input[type="hidden"] {
    display: none !important;
}
.theme-toggle {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto !important;
    gap: 7px;
    width: auto !important;
    min-width: 74px;
    height: 36px !important;
    padding: 0 10px !important;
    border: 1px solid var(--border) !important;
    border-radius: 10px !important;
    background: var(--surface-muted) !important;
    color: var(--text) !important;
    white-space: nowrap;
    font: 600 12px/1 var(--font) !important;
    cursor: pointer;
}
.theme-toggle:hover { background: var(--surface-hover) !important; border-color: var(--primary) !important; }
.theme-toggle:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 28%, transparent); outline-offset: 2px; }
.theme-toggle .theme-icon { display: block; flex: 0 0 18px; }
.theme-toggle .theme-label { display: inline-block; }
.theme-toggle[aria-pressed="true"] { border-color: var(--primary) !important; }
html[data-theme="dark"] .theme-toggle { background: var(--surface-muted) !important; color: var(--text) !important; border-color: var(--border) !important; }
html[data-theme="dark"] .theme-toggle[aria-pressed="true"] { color: #ffd166 !important; background: #263247 !important; }

/* Consistent dark surfaces for common and legacy CRM widgets. */
html[data-theme="dark"] .panel,
html[data-theme="dark"] .table-wrap,
html[data-theme="dark"] .audit-table-wrap,
html[data-theme="dark"] .sec-card,
html[data-theme="dark"] .modal,
html[data-theme="dark"] .error-card,
html[data-theme="dark"] .card:not(.kpi):not(.kcard),
html[data-theme="dark"] details.card {
    background-color: var(--surface) !important;
    color: var(--text) !important;
    border-color: var(--border) !important;
}
html[data-theme="dark"] .panel .card,
html[data-theme="dark"] .panel details,
html[data-theme="dark"] .tl-details,
html[data-theme="dark"] .info-item,
html[data-theme="dark"] .search-results,
html[data-theme="dark"] .notif-panel,
html[data-theme="dark"] .profile-menu,
html[data-theme="dark"] .modal-head,
html[data-theme="dark"] .modal-foot,
html[data-theme="dark"] .table-wrap > table th,
html[data-theme="dark"] table.audit-table th {
    background-color: var(--surface-muted) !important;
    color: var(--text) !important;
    border-color: var(--border) !important;
}
html[data-theme="dark"] .panel p,
html[data-theme="dark"] .panel label,
html[data-theme="dark"] .sec-card label,
html[data-theme="dark"] .panel small,
html[data-theme="dark"] .empty-state,
html[data-theme="dark"] .muted,
html[data-theme="dark"] .hint {
    color: var(--text-soft);
}
html[data-theme="dark"] .panel input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
html[data-theme="dark"] .panel select,
html[data-theme="dark"] .panel textarea,
html[data-theme="dark"] .sec-card input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
html[data-theme="dark"] .sec-card select,
html[data-theme="dark"] .sec-card textarea {
    background-color: var(--surface-input) !important;
    color: var(--text) !important;
    border-color: var(--border) !important;
}
html[data-theme="dark"] .table-wrap > table td,
html[data-theme="dark"] .table-wrap > table th,
html[data-theme="dark"] table.audit-table td,
html[data-theme="dark"] table.audit-table th { border-color: var(--border-soft) !important; }
html[data-theme="dark"] .topbar-search input { background: var(--surface-muted) !important; color: var(--text) !important; }
html[data-theme="dark"] .notif-badge { border-color: var(--surface); }

@media (max-width: 720px) {
    #paymentForm.payment-form { grid-template-columns: minmax(0, 1fr) !important; gap: 0; }
    #paymentForm.payment-form .payment-submit { grid-column: 1 / -1; width: 100% !important; }
    .theme-toggle { min-width: 36px; width: 36px !important; padding: 0 !important; }
    .theme-toggle .theme-label { display: none; }
    .topbar-right { gap: 4px; flex-shrink: 0; }
    .topbar-search { min-width: 0; }
}

/* ============================================================
   FULL CRM UI REFRESH — shared across every authenticated page
   Includes globally consistent form sizing, responsive tables,
   theme surfaces, and profile-photo rendering.
   ============================================================ */
:root {
    --ui-radius: 14px;
    --ui-radius-sm: 10px;
    --ui-line: var(--border);
    --ui-elevated: var(--card);
    --ui-soft: var(--surface-muted, #f8fafc);
    --ui-focus: 0 0 0 3px color-mix(in srgb, var(--primary) 19%, transparent);
}
html { min-height: 100%; scroll-behavior: smooth; }
body { min-height: 100vh; background: var(--bg); color: var(--text); }
.layout, .main, .content, main, section, article { min-width: 0; }
.content { width: 100%; max-width: 1720px; }
.page-head { align-items: flex-end; }
.page-head h2 { letter-spacing: -.025em; }
.page-head .sub { margin-top: 5px; line-height: 1.5; }

/* Standard card, panel, and page surfaces across older and newer modules. */
.card, .panel, .sec-card, .audit-card, .error-card, .profile-card,
.table-wrap, .audit-table-wrap, .modal, .settings-card {
    border-color: var(--border);
    border-radius: var(--ui-radius);
}
.card, .panel, .sec-card { box-shadow: var(--shadow-sm); }
.card-head, .panel-head { border-color: var(--border-soft); }
.card-head h3, .panel-head h2 { letter-spacing: -.012em; }
.page-head .btn, .toolbar .btn, .panel-head .btn { flex-shrink: 0; }
.toolbar { gap: 10px; }
.toolbar input, .toolbar select { min-height: 40px; }

/* Form controls: also style inputs that appear directly inside labels. */
form label, .form-group label, .panel label, .sec-card label,
.form-grid > label, .payment-form > label {
    color: var(--text);
    font-weight: 600;
    line-height: 1.45;
}
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="file"]),
select, textarea {
    min-width: 0;
    max-width: 100%;
    min-height: 42px;
    border: 1px solid var(--border);
    border-radius: var(--ui-radius-sm);
    background-color: var(--surface-input, #fff);
    color: var(--text);
    font-family: var(--font);
    font-size: 13.5px;
    line-height: 1.4;
    transition: border-color .16s ease, box-shadow .16s ease, background-color .16s ease;
}
textarea { min-height: 92px; }
input[type="file"] {
    display: block;
    max-width: 100%;
    min-height: 42px;
    padding: 7px;
    color: var(--text);
    background: var(--surface-input, #fff);
    border: 1px dashed var(--border);
    border-radius: var(--ui-radius-sm);
}
input[type="file"]::file-selector-button {
    margin-right: 10px;
    padding: 7px 11px;
    border: 0;
    border-radius: 7px;
    background: var(--primary-50);
    color: var(--primary-dark);
    font: 600 12px/1.2 var(--font);
    cursor: pointer;
}
input:focus, select:focus, textarea:focus,
input:focus-visible, select:focus-visible, textarea:focus-visible {
    border-color: var(--primary);
    box-shadow: var(--ui-focus);
}
input:disabled, select:disabled, textarea:disabled { opacity: .72; cursor: not-allowed; }
.form-group { min-width: 0; margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; }
.form-grid { align-items: start; }
.form-grid > *, .grid-2 > *, .grid-3 > *, .grid-2-1 > *, .grid-1-2 > * { min-width: 0; }
.form-actions, .form-footer, .form-buttons { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; }

/* Buttons have consistent height and keyboard focus on every page. */
.btn { min-height: 38px; border-radius: 10px; letter-spacing: -.005em; }
.btn-primary { background: linear-gradient(135deg, #2458a1, #173d78); }
.btn-ghost, .btn-secondary { background: var(--ui-soft); color: var(--text); border-color: var(--border); }
.icon-btn { flex-shrink: 0; }
button:focus-visible, a:focus-visible, summary:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--primary) 55%, transparent);
    outline-offset: 2px;
}

/* Tables across Leads, Contacts, Companies, Reports, Team, Payments, etc. */
.table-wrap, .audit-table-wrap { max-width: 100%; overflow: auto; background: var(--card); }
.table-wrap > table, table.data, table.audit-table { min-width: 700px; }
.table-wrap > table th, table.data th, table.audit-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 12px 14px;
    background: var(--surface-muted, #f8fafc);
    color: var(--text-soft);
    font-size: 10.5px;
    letter-spacing: .065em;
}
.table-wrap > table td, table.data td, table.audit-table td { padding: 12px 14px; }
.table-wrap > table tbody tr:nth-child(even), table.data tbody tr:nth-child(even) { background: color-mix(in srgb, var(--surface-muted, #f8fafc) 42%, transparent); }
.table-wrap > table tbody tr:hover, table.data tbody tr:hover { background: var(--surface-hover, #f4f7fb); }
.table-wrap > table td[colspan], table.data td[colspan] { padding: 32px 16px; text-align: center; color: var(--text-soft); }

/* Header, menus, user chips and photos. */
.topbar { background: var(--topbar-surface, rgba(255,255,255,.94)); border-color: var(--border); }
.topbar-right { min-width: 0; }
.profile-btn { max-width: 240px; }
.profile-name, .profile-role { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { position: relative; overflow: hidden; object-fit: cover; }
.avatar img, .profile-photo-preview img {
    display: block;
    width: 100%; height: 100%;
    object-fit: cover;
    border-radius: inherit;
}
.avatar img { position: absolute; inset: 0; }
.avatar.sm { position: relative; overflow: hidden; }
.profile-photo-editor {
    display: flex; align-items: center; gap: 18px;
    margin: 2px 0 22px; padding: 16px;
    border: 1px solid var(--border); border-radius: var(--ui-radius);
    background: var(--surface-muted, #f8fafc);
}
.profile-photo-preview {
    display: grid; place-items: center;
    width: 104px; height: 104px; flex: 0 0 104px;
    overflow: hidden; border-radius: 50%;
    border: 4px solid var(--card); background: var(--primary-50);
    box-shadow: 0 0 0 1px var(--border), var(--shadow);
}
.profile-avatar-large { width: 96px; height: 96px; font-size: 26px; }
.profile-photo-fields { display: grid; align-content: start; justify-items: start; gap: 8px; min-width: 0; flex: 1; }
.profile-photo-fields .field-label { font-size: 12.5px; font-weight: 700; color: var(--text); }
.profile-photo-fields input[type="file"] { width: 100%; }
.profile-fields-grid { margin-bottom: 4px; }
.profile-menu, .notif-panel, .search-results { background: var(--card); color: var(--text); border-color: var(--border); }
.theme-toggle { border-radius: 11px; }

/* Calendar, Kanban, tasks, reports and security modules share the same tokens. */
.cal-grid, .cal-week, .cal-day, .cal-cell, .kanban-col, .pipeline-col, .task-card,
.info-item, .sec-row, .sec-secret, .tl-details, .audit-filter, .report-filter {
    border-color: var(--border);
}
.kanban-col, .pipeline-col, .task-card { background: var(--card); border-radius: var(--ui-radius); }
.cal-day, .cal-cell { background: var(--card); color: var(--text); }
.cal-event { border-radius: 6px; }
.kpi, .kcard { border-color: var(--border); border-radius: var(--ui-radius); }

/* Light/dark mode: use semantic tokens rather than scattered white backgrounds. */
html[data-theme="light"] {
    color-scheme: light;
    --surface: #ffffff;
    --surface-muted: #f7f9fc;
    --surface-hover: #edf3fa;
    --surface-input: #ffffff;
    --topbar-surface: rgba(255,255,255,.94);
}
html[data-theme="dark"] body,
html[data-theme="dark"] .main,
html[data-theme="dark"] .content { background: var(--bg) !important; color: var(--text) !important; }
html[data-theme="dark"] .panel,
html[data-theme="dark"] .card,
html[data-theme="dark"] .sec-card,
html[data-theme="dark"] .table-wrap,
html[data-theme="dark"] .audit-table-wrap,
html[data-theme="dark"] .modal,
html[data-theme="dark"] .profile-photo-editor,
html[data-theme="dark"] .kanban-col,
html[data-theme="dark"] .pipeline-col,
html[data-theme="dark"] .task-card,
html[data-theme="dark"] .cal-grid,
html[data-theme="dark"] .cal-week,
html[data-theme="dark"] .cal-day,
html[data-theme="dark"] .cal-cell,
html[data-theme="dark"] .info-item,
html[data-theme="dark"] .kpi,
html[data-theme="dark"] .kcard {
    background-color: var(--surface) !important; color: var(--text) !important; border-color: var(--border) !important;
}
html[data-theme="dark"] .panel .card,
html[data-theme="dark"] .card-head,
html[data-theme="dark"] .panel-head,
html[data-theme="dark"] .table-wrap > table th,
html[data-theme="dark"] table.data th,
html[data-theme="dark"] table.audit-table th,
html[data-theme="dark"] .sec-row,
html[data-theme="dark"] .tl-details {
    background-color: var(--surface-muted) !important; color: var(--text) !important; border-color: var(--border) !important;
}
html[data-theme="dark"] p, html[data-theme="dark"] small, html[data-theme="dark"] label,
html[data-theme="dark"] .sub, html[data-theme="dark"] .hint,
html[data-theme="dark"] .muted, html[data-theme="dark"] .t-sub { color: var(--text-soft); }
html[data-theme="dark"] h1, html[data-theme="dark"] h2, html[data-theme="dark"] h3,
html[data-theme="dark"] h4, html[data-theme="dark"] .t-main,
html[data-theme="dark"] .page-title, html[data-theme="dark"] .profile-name { color: var(--ink); }
html[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="file"]),
html[data-theme="dark"] select, html[data-theme="dark"] textarea,
html[data-theme="dark"] input[type="file"] {
    background-color: var(--surface-input) !important; color: var(--text) !important; border-color: var(--border) !important;
}
html[data-theme="dark"] input[type="file"]::file-selector-button { background: #223754; color: #d8e7ff; }
html[data-theme="dark"] .table-wrap > table, html[data-theme="dark"] table.data,
html[data-theme="dark"] table.audit-table,
html[data-theme="dark"] .table-wrap > table tbody,
html[data-theme="dark"] table.data tbody,
html[data-theme="dark"] .table-wrap > table tr,
html[data-theme="dark"] table.data tr { color: var(--text); background: transparent; }
html[data-theme="dark"] .table-wrap > table td, html[data-theme="dark"] table.data td,
html[data-theme="dark"] table.audit-table td, html[data-theme="dark"] .table-wrap > table th,
html[data-theme="dark"] table.data th, html[data-theme="dark"] table.audit-table th { border-color: var(--border-soft) !important; }
html[data-theme="dark"] .table-wrap > table tbody tr:nth-child(even),
html[data-theme="dark"] table.data tbody tr:nth-child(even) { background: rgba(255,255,255,.018); }
html[data-theme="dark"] .table-wrap > table tbody tr:hover,
html[data-theme="dark"] table.data tbody tr:hover { background: var(--surface-hover) !important; }
html[data-theme="dark"] .btn-ghost, html[data-theme="dark"] .btn-secondary,
html[data-theme="dark"] .act-btn, html[data-theme="dark"] .pagination a,
html[data-theme="dark"] .pagination span { background: var(--surface-muted); color: var(--text); border-color: var(--border); }
html[data-theme="dark"] .theme-toggle { background: var(--surface-muted) !important; color: var(--text) !important; border-color: var(--border) !important; }
html[data-theme="dark"] .profile-menu a { color: var(--text); }
html[data-theme="dark"] .profile-menu a:hover, html[data-theme="dark"] .notif-item:hover,
html[data-theme="dark"] .sr-item:hover { background: var(--surface-hover); }
html[data-theme="dark"] .profile-photo-preview { border-color: var(--surface); }

/* Responsive CRM layout and all form-heavy views. */
@media (max-width: 1024px) {
    .content { padding: 18px 18px 26px; }
    .topbar { padding-inline: 16px; }
    .page-title { max-width: 30vw; overflow: hidden; text-overflow: ellipsis; }
}
@media (max-width: 720px) {
    .content { padding: 14px 12px 22px; }
    .topbar { min-height: 58px; height: auto; padding: 9px 10px; flex-wrap: wrap; }
    .page-title { max-width: 45vw; }
    .topbar-search { order: 3; flex: 1 0 100%; max-width: none; margin: 0; }
    .topbar-search input { width: 100%; }
    .topbar-right { margin-left: auto; }
    .profile-meta { display: none; }
    .page-head { align-items: flex-start; }
    .page-head > .btn, .page-head > .btn-primary { width: 100%; }
    .form-grid, .payment-form, .grid-2, .grid-3, .grid-2-1, .grid-1-2 { grid-template-columns: minmax(0,1fr) !important; }
    .form-grid .span-2, .payment-form .payment-submit { grid-column: 1 / -1 !important; }
    .payment-form .payment-submit { width: 100% !important; }
    .profile-photo-editor { align-items: flex-start; gap: 12px; padding: 12px; }
    .profile-photo-preview { width: 76px; height: 76px; flex-basis: 76px; }
    .profile-avatar-large { width: 68px; height: 68px; font-size: 20px; }
    .table-wrap > table, table.data, table.audit-table { min-width: 700px; }
    .toolbar { display: grid; grid-template-columns: minmax(0,1fr); }
    .toolbar input, .toolbar select, .toolbar .btn { width: 100%; }
    .theme-toggle { min-width: 36px; width: 36px !important; padding: 0 !important; }
    .theme-toggle .theme-label { display: none; }
}
@media (max-width: 420px) {
    .profile-photo-editor { flex-direction: column; }
    .profile-photo-fields { width: 100%; }
    .profile-photo-fields .btn { width: 100%; }
    .topbar-right { gap: 2px; }
    .icon-btn { width: 34px; height: 34px; }
}

/* ============================================================
   Release 12 — full CRM controls, payment form and theme polish
   Explicit sizing for legacy markup that places inputs directly
   inside labels. This is intentionally the final override layer.
   ============================================================ */
html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

form label > input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]),
form label > select,
form label > textarea,
.form-group > input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]),
.form-group > select,
.form-group > textarea,
.panel label > input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]),
.panel label > select,
.panel label > textarea,
.sec-card label > input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]),
.sec-card label > select,
.sec-card label > textarea {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    margin-top: 6px;
}

#paymentForm.payment-form {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    align-items: start;
    gap: 0 14px !important;
    padding: clamp(14px, 2vw, 22px) !important;
}
#paymentForm.payment-form > label {
    display: block !important;
    min-width: 0 !important;
    width: 100% !important;
    margin: 0 0 14px !important;
    color: var(--text) !important;
    font-size: 12.5px !important;
    font-weight: 600 !important;
    line-height: 1.45 !important;
}
#paymentForm.payment-form > label > input,
#paymentForm.payment-form > label > select,
#paymentForm.payment-form > label > textarea,
#paymentForm.payment-form .payment-control {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    height: auto;
    min-height: 42px !important;
    padding: 9px 12px !important;
    margin: 6px 0 0 !important;
    box-sizing: border-box !important;
    border: 1px solid var(--border) !important;
    border-radius: 9px !important;
    background: var(--surface-input, #fff) !important;
    color: var(--text) !important;
    font: 400 13.5px/1.4 var(--font) !important;
}
#paymentForm.payment-form .payment-submit {
    grid-column: 1 / -1 !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    justify-self: stretch !important;
    margin: 0 0 2px !important;
}
#paymentForm.payment-form > label:focus-within { color: var(--primary); }

/* Consistent app-level tables for all modules, including legacy unwrapped tables. */
.content table:not(.calendar-table) { max-width: 100%; }
.content table:not(.calendar-table) th { font-weight: 700; }
.content table:not(.calendar-table) td { overflow-wrap: anywhere; }
.content .table-wrap { width: 100%; min-width: 0; }
.content .page-head { gap: 14px; flex-wrap: wrap; }
.content .page-head .sub { max-width: 800px; }
.content .empty-state, .content td[colspan] { color: var(--text-soft); }

/* Theme control is deliberately labelled on desktop and icon-only on mobile. */
.topbar .theme-toggle {
    display: inline-flex !important;
    flex: 0 0 auto !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 7px !important;
    min-width: 74px !important;
    width: auto !important;
    height: 36px !important;
    padding: 0 10px !important;
    border: 1px solid var(--border) !important;
    border-radius: 10px !important;
    background: var(--surface, #fff) !important;
    color: var(--text) !important;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
}
.topbar .theme-toggle .theme-label { display: inline-block !important; font-size: 12px; font-weight: 700; }
.topbar .theme-toggle .theme-icon { flex: 0 0 18px; }
.topbar .theme-toggle:hover { border-color: var(--primary) !important; background: var(--surface-hover, #edf3fa) !important; }
.topbar .theme-toggle[aria-pressed="true"] { border-color: var(--primary) !important; }

/* Uniform interactive controls on dark surfaces. */
html[data-theme="dark"] .alert-danger { background: var(--red-bg) !important; color: #fecaca !important; border-color: #71333d !important; }
html[data-theme="dark"] .alert-success { background: var(--green-bg) !important; color: #bbf7d0 !important; border-color: #1f634d !important; }
html[data-theme="dark"] .alert-warning { background: var(--amber-bg) !important; color: #fde68a !important; border-color: #6b5425 !important; }
html[data-theme="dark"] .alert-info { background: var(--blue-bg) !important; color: #bfdbfe !important; border-color: #315783 !important; }
html[data-theme="dark"] code { background: var(--surface-muted) !important; color: var(--text) !important; }
html[data-theme="dark"] .sec-secret { background: var(--surface-muted) !important; color: var(--ink) !important; }
html[data-theme="dark"] .login-card,
html[data-theme="dark"] .setup-card { background: var(--card) !important; color: var(--text) !important; border-color: var(--border) !important; }
html[data-theme="dark"] .login-card h1,
html[data-theme="dark"] .login-card h2,
html[data-theme="dark"] .setup-card h1,
html[data-theme="dark"] .setup-card h2 { color: var(--ink) !important; }
html[data-theme="dark"] .login-body,
html[data-theme="dark"] .setup-body { background: var(--bg) !important; color: var(--text) !important; }

@media (max-width: 720px) {
    #paymentForm.payment-form { grid-template-columns: minmax(0, 1fr) !important; gap: 0 !important; }
    #paymentForm.payment-form > label { grid-column: 1 / -1 !important; }
    #paymentForm.payment-form .payment-submit { grid-column: 1 / -1 !important; }
    .topbar .theme-toggle { min-width: 36px !important; width: 36px !important; padding: 0 !important; }
    .topbar .theme-toggle .theme-label { display: none !important; }
}

/* Floating theme switch for standalone auth/security views without the CRM topbar. */
.standalone-theme-toggle {
    position: fixed;
    top: 14px;
    right: 16px;
    z-index: 9999;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 38px;
    padding: 0 13px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--surface, #fff);
    color: var(--text);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    font: 700 12px/1 var(--font);
}
.standalone-theme-toggle:hover { background: var(--surface-hover, #edf3fa); border-color: var(--primary); }
.standalone-theme-glyph { font-size: 17px; line-height: 1; }
html[data-theme="dark"] .standalone-theme-toggle { background: var(--surface-muted) !important; color: var(--text) !important; border-color: var(--border) !important; }
@media (max-width: 480px) {
    .standalone-theme-toggle { top: 10px; right: 10px; min-height: 36px; padding: 0 10px; }
    .standalone-theme-label { font-size: 11px; }
}


/* ============================================================
   Prospect CRM — Pro navigation / small-screen drawer
   Shared across all authenticated CRM pages.
   ============================================================ */
.sidebar {
    width: 260px;
    background:
        radial-gradient(circle at 0% 0%, rgba(37, 99, 235, .13), transparent 31%),
        linear-gradient(180deg, #0e1729 0%, #0a1220 100%);
    border-right: 1px solid rgba(148, 163, 184, .12);
    overflow: hidden;
    isolation: isolate;
}
.sidebar-brand {
    min-height: 72px;
    padding: 14px 14px 13px;
    gap: 8px;
    border-bottom-color: rgba(148, 163, 184, .13);
}
.sidebar-brand-link {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1 1 auto;
    min-width: 0;
    color: inherit;
    border-radius: 10px;
}
.sidebar-brand-link:focus-visible,
.nav-item:focus-visible,
.side-profile:focus-visible,
.side-logout:focus-visible,
.sidebar-close:focus-visible {
    outline: 2px solid #7db5ff;
    outline-offset: 2px;
}
.brand-logo { align-items: center; justify-content: center; }
.brand-logo svg { width: 32px; height: 32px; filter: drop-shadow(0 3px 7px rgba(29, 78, 216, .25)); }
.brand-text { font-size: 12px; letter-spacing: .65px; line-height: 1.2; min-width: 0; }
.brand-sub { margin-top: 4px; font-size: 9px; letter-spacing: 2.5px; color: #86b7ff; }
.sidebar-search-wrap {
    height: 40px;
    margin: 12px 12px 4px;
    padding: 0 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
    color: #91a4bf;
    background: rgba(148, 163, 184, .08);
    border: 1px solid rgba(148, 163, 184, .16);
    border-radius: 11px;
    transition: border-color .18s ease, background .18s ease, box-shadow .18s ease;
}
.sidebar-search-wrap:focus-within {
    border-color: rgba(96, 165, 250, .8);
    background: rgba(30, 58, 95, .5);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, .12);
}
.sidebar-search-wrap > svg { flex: 0 0 16px; color: #8fa5c3; }
.sidebar-search-wrap input {
    width: 100%; min-width: 0; height: 36px; margin: 0; padding: 0;
    border: 0 !important; outline: 0; box-shadow: none !important;
    border-radius: 0; background: transparent !important; color: #e5edf8 !important;
    font: 500 12px/1.4 var(--font);
}
.sidebar-search-wrap input::placeholder { color: #91a4bf; opacity: 1; }
.sidebar-search-wrap kbd {
    flex: 0 0 auto; padding: 2px 5px; border-radius: 5px;
    color: #91a4bf; background: rgba(15, 23, 42, .75);
    border: 1px solid rgba(148, 163, 184, .19); font: 10px/1.4 var(--font);
}
.sidebar-nav {
    flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden;
    padding: 11px 10px 18px;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 163, 184, .26) transparent;
}
.sidebar-section-label {
    display: block;
    padding: 15px 11px 7px;
    color: #7185a2;
    font-size: 9px;
    font-weight: 800;
    line-height: 1.25;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    user-select: none;
}
.sidebar-section-label:first-child { padding-top: 5px; }
.sidebar-nav [hidden], .sidebar-search-empty[hidden] { display: none !important; }
.nav-item {
    min-height: 43px;
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 2px 0;
    padding: 5px 10px;
    border: 1px solid transparent;
    border-radius: 11px;
    color: #a7b5ca;
    font-size: 12.7px;
    font-weight: 550;
    line-height: 1.3;
    transition: background .16s ease, border-color .16s ease, color .16s ease, transform .16s ease;
    -webkit-tap-highlight-color: transparent;
}
.nav-icon {
    width: 31px; height: 31px; flex: 0 0 31px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 9px;
    color: #8fa3bf;
    background: rgba(148, 163, 184, .07);
    transition: color .16s ease, background .16s ease;
}
.nav-icon svg { width: 18px; height: 18px; display: block; }
.nav-label { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.nav-current-dot { width: 6px; height: 6px; flex: 0 0 6px; border-radius: 50%; background: #79b5ff; box-shadow: 0 0 0 3px rgba(96, 165, 250, .12); }
.nav-item:hover {
    background: rgba(148, 163, 184, .085);
    border-color: rgba(148, 163, 184, .08);
    color: #f0f6ff;
}
.nav-item:hover .nav-icon { color: #c4d9f7; background: rgba(148, 163, 184, .12); }
.nav-item:active { transform: scale(.992); }
.nav-item.active {
    color: #fff;
    font-weight: 700;
    border-color: rgba(96, 165, 250, .22);
    background: linear-gradient(100deg, rgba(37, 99, 235, .27), rgba(37, 99, 235, .12));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .035);
}
.nav-item.active::before {
    content: ''; position: absolute; left: -1px; top: 9px; bottom: 9px;
    width: 3px; border-radius: 0 4px 4px 0; background: #72adff;
}
.nav-item.active .nav-icon { color: #a8ceff; background: rgba(59, 130, 246, .2); }
.sidebar-search-empty { padding: 16px 10px; color: #8fa3bf; font-size: 12px; text-align: center; }
.sidebar-bottom {
    flex: 0 0 auto;
    padding: 10px 10px max(10px, env(safe-area-inset-bottom));
    border-top: 1px solid rgba(148, 163, 184, .14);
    background: rgba(6, 12, 22, .28);
}
.side-profile {
    min-width: 0; min-height: 54px;
    display: flex; align-items: center; gap: 10px;
    padding: 8px 9px; margin: 0 0 5px;
    border: 1px solid transparent; border-radius: 12px;
    color: inherit; text-decoration: none;
    transition: background .16s ease, border-color .16s ease;
}
.side-profile:hover { background: rgba(148, 163, 184, .08); border-color: rgba(148, 163, 184, .1); color: #fff; }
.side-profile-avatar { width: 36px; height: 36px; flex: 0 0 36px; border: 2px solid rgba(255,255,255,.15); }
.side-profile-avatar img { display: block; width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.side-profile-meta { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.side-profile-name { color: #f1f5f9; font-size: 12px; font-weight: 750; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-profile-role { color: #91a4bf; font-size: 9px; font-weight: 700; text-transform: uppercase; letter-spacing: .9px; }
.side-profile-chevron { color: #7185a2; flex: 0 0 16px; }
.side-logout {
    min-height: 42px; padding: 8px 12px; gap: 11px;
    border-radius: 10px; color: #fda4af; font-size: 12.5px;
}
.side-logout svg { flex: 0 0 18px; }
.side-logout:hover { background: rgba(244, 63, 94, .11); color: #fecdd3; }
.sidebar-close { width: 38px; height: 38px; border-radius: 11px; border: 1px solid rgba(148, 163, 184, .17); background: rgba(148,163,184,.08); color: #c5d2e4; }
.sidebar-close:hover { background: rgba(148, 163, 184, .16); color: #fff; }

@media (max-width: 1024px) {
    body.sidebar-open { overflow: hidden; }
    .sidebar {
        position: fixed;
        z-index: 1001;
        inset: 0 auto 0 0;
        width: min(86vw, 340px);
        max-width: calc(100vw - 22px);
        height: 100vh;
        height: 100dvh;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        transform: translate3d(-105%, 0, 0);
        visibility: hidden;
        transition: transform .28s cubic-bezier(.22, .72, .18, 1), visibility .28s;
        box-shadow: none;
        will-change: transform;
    }
    body.sidebar-open .sidebar {
        visibility: visible;
        transform: translate3d(0, 0, 0);
        box-shadow: 20px 0 55px rgba(2, 6, 23, .32);
    }
    .sidebar-backdrop {
        display: block !important;
        position: fixed; inset: 0; z-index: 1000;
        margin: 0; padding: 0; border: 0; border-radius: 0;
        background: rgba(3, 8, 20, .58);
        backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
        opacity: 0; visibility: hidden; pointer-events: none;
        transition: opacity .22s ease, visibility .22s ease;
    }
    body.sidebar-open .sidebar-backdrop { opacity: 1; visibility: visible; pointer-events: auto; }
    .sidebar-brand { min-height: 72px; }
    .sidebar-close { display: inline-flex; align-items: center; justify-content: center; }
    .sidebar-nav { padding-bottom: 20px; }
    .nav-item { min-height: 46px; font-size: 13px; border-radius: 12px; }
    .nav-icon { width: 34px; height: 34px; flex-basis: 34px; }
    .sidebar-section-label { padding-top: 17px; }
}
@media (max-width: 480px) {
    .sidebar { width: min(88vw, 330px); max-width: calc(100vw - 18px); }
    .sidebar-brand { padding-inline: 13px; }
    .sidebar-search-wrap { margin-inline: 11px; height: 42px; }
    .sidebar-search-wrap input { height: 38px; font-size: 13px; }
    .sidebar-nav { padding: 8px 9px 18px; }
    .nav-item { min-height: 47px; margin-block: 2px; padding-inline: 9px; }
    .sidebar-bottom { padding-inline: 9px; }
}
@media (prefers-reduced-motion: reduce) {
    .sidebar, .sidebar-backdrop, .nav-item, .nav-icon, .side-profile { transition: none !important; }
}


/*
 * Prospect CRM — reference UI refresh.
 * This file intentionally complements style.css with a final, predictable
 * styling layer for every authenticated CRM module and both theme modes.
 */
:root {
    --reference-page: #f1f5fb;
    --reference-card: #ffffff;
    --reference-border: #e2eaf4;
    --reference-heading: #12213a;
    --reference-muted: #657791;
    --reference-accent: #2563eb;
    --reference-accent-soft: #eaf2ff;
}
html[data-theme="dark"] {
    --reference-page: #0b1220;
    --reference-card: #111c2d;
    --reference-border: #2a3a50;
    --reference-heading: #f0f5fc;
    --reference-muted: #a8b7ca;
    --reference-accent: #78aefa;
    --reference-accent-soft: #172b45;
}
html, body { min-width: 320px; }
body { background: var(--reference-page); color: var(--text); overflow-x: hidden; }
.layout { min-height: 100vh; min-height: 100dvh; }
.main { min-width: 0; background: var(--reference-page); }
.content {
    width: 100%; max-width: 1680px; min-width: 0;
    padding: clamp(14px, 1.7vw, 26px) clamp(12px, 2vw, 30px) 34px;
}
.app-footer { padding: 13px 18px max(14px, env(safe-area-inset-bottom)); }

/* Application bar */
.topbar {
    min-height: 62px; height: auto; padding: 10px clamp(12px, 1.7vw, 26px);
    gap: clamp(8px, 1vw, 15px); background: var(--topbar-surface, rgba(255,255,255,.95));
    border-bottom: 1px solid var(--reference-border); box-shadow: 0 1px 0 rgba(15,23,42,.02);
}
.page-title { color: var(--reference-heading); letter-spacing: -.025em; }
.topbar-search { min-width: 120px; max-width: 480px; }
.topbar-search input {
    min-height: 38px; border-radius: 999px; border-color: transparent;
    background: var(--surface-muted, #f8fafc); box-shadow: none;
}
.topbar-search input:focus { border-color: var(--reference-accent); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.topbar-right { gap: 5px; }
.topbar .icon-btn { border-radius: 10px; }
.profile-btn { border-color: transparent; }
.profile-btn .avatar, .side-profile-avatar { overflow: hidden; }
.profile-btn .avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; display: block; }

/* Consistent title blocks and page actions */
.page-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 14px; margin-bottom: 18px; min-width: 0;
}
.page-head h2 { color: var(--reference-heading); font-size: clamp(18px, 1.35vw, 22px); letter-spacing: -.025em; }
.page-head .sub, .page-head p { color: var(--reference-muted); line-height: 1.5; font-size: 13px; }
.page-head > div:first-child { min-width: 0; }
.page-head .btn, .page-head .btn-primary { flex: 0 0 auto; }

/* Panels, cards and charts share the visual language from the reference. */
.panel, .card, .sec-card, .profile-card, .settings-card, .audit-card {
    border: 1px solid var(--reference-border); border-radius: 14px;
    box-shadow: var(--shadow-sm); min-width: 0;
}
.panel { background: var(--reference-card); padding: clamp(14px, 1.5vw, 22px); }
.card, .sec-card { background: var(--reference-card); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding-bottom: 14px; margin-bottom: 14px; border-bottom: 1px solid var(--border-soft); }
.panel-head h2 { font-size: 16px; color: var(--reference-heading); }
.panel-head p { color: var(--reference-muted); max-width: 780px; }
.card-head { gap: 12px; }
.card-head h3 { color: var(--reference-heading); }
.kpi-grid { gap: 14px; }
.kpi { border-radius: 13px; background: var(--reference-card); }
.kpi-value { letter-spacing: -.04em; }
.grid-2, .grid-3, .grid-2-1, .grid-1-2 { gap: 16px; }

/* Form controls are normalized across both modern and legacy PHP markup. */
form label > input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="file"]),
form label > select, form label > textarea,
.form-group > input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="file"]),
.form-group > select, .form-group > textarea,
.panel input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="file"]),
.panel select, .panel textarea,
.sec-card input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="file"]),
.sec-card select, .sec-card textarea,
.form-grid input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="file"]),
.form-grid select, .form-grid textarea {
    display: block; width: 100%; max-width: 100%; min-width: 0;
    min-height: 40px; margin-top: 6px; padding: 9px 12px;
    box-sizing: border-box; border: 1px solid var(--reference-border);
    border-radius: 9px; background: var(--surface-input, #fff); color: var(--text);
    font: 400 13.5px/1.4 var(--font); box-shadow: none;
}
form label, .form-grid > label, .form-group > label { min-width: 0; color: var(--text); font-size: 12.5px; font-weight: 600; }
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--reference-accent) !important;
    box-shadow: 0 0 0 3px rgba(37,99,235,.13) !important;
}
input[type="checkbox"], input[type="radio"] { accent-color: var(--reference-accent); }
textarea { min-height: 92px; resize: vertical; }
input[type="file"] { max-width: 100%; color: var(--text-soft); }
.form-grid, .payment-form { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-grid > *, .payment-form > * { min-width: 0; }
.form-grid .span-2 { grid-column: 1 / -1; }
.toolbar {
    display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
    min-width: 0; margin-bottom: 16px;
}
.toolbar > * { min-width: 0; }
.toolbar input[type="search"], .toolbar input[type="text"], .toolbar select { min-height: 40px; }

/* Buttons: clear hierarchy, friendly radius and consistent touch area. */
.btn { min-height: 38px; border-radius: 9px; font-weight: 650; }
.btn-primary { background: linear-gradient(135deg, #2463d8, #174b9f); border-color: #1d55b5; box-shadow: 0 2px 4px rgba(37,99,235,.15); }
.btn-primary:hover:not(:disabled) { box-shadow: 0 4px 12px rgba(37,99,235,.2); }
.btn-ghost { background: var(--reference-card); }
.act-btn { width: 32px; height: 32px; border-radius: 8px; }

/* Tables: dense but readable, horizontal scroll on compact screens. */
.table-wrap, .audit-table-wrap {
    width: 100%; min-width: 0; overflow-x: auto; overscroll-behavior-x: contain;
    border: 1px solid var(--reference-border); border-radius: 12px; background: var(--reference-card);
}
.table-wrap > table, table.data, table.audit-table { width: 100%; min-width: 700px; border-collapse: separate; border-spacing: 0; }
.table-wrap > table th, table.data th, table.audit-table th {
    padding: 12px 14px; background: var(--surface-muted, #f8fafc);
    border-bottom: 1px solid var(--reference-border); color: var(--text-soft);
    text-align: left; font-size: 10.5px; font-weight: 800; letter-spacing: .055em;
    text-transform: uppercase; white-space: nowrap;
}
.table-wrap > table td, table.data td, table.audit-table td {
    padding: 12px 14px; border-bottom: 1px solid var(--border-soft);
    vertical-align: middle; color: var(--text); line-height: 1.45;
}
.table-wrap > table tbody tr:last-child td, table.data tbody tr:last-child td { border-bottom: 0; }
.table-wrap > table tbody tr:nth-child(even), table.data tbody tr:nth-child(even) { background: color-mix(in srgb, var(--surface-muted, #f8fafc) 46%, transparent); }
.table-wrap > table tbody tr:hover, table.data tbody tr:hover { background: var(--surface-hover, #eff6ff); }
.table-wrap td small, table.data td small { color: var(--text-soft); }
.table-wrap form { gap: 7px; }
.empty-state { border-radius: 12px; color: var(--text-soft); }

/* Theme-aware labels and misc controls. */
.theme-toggle { border: 1px solid var(--reference-border); border-radius: 10px; }
.topbar .theme-toggle:hover { border-color: var(--reference-accent); }
.search-results, .notif-panel, .profile-menu { background: var(--reference-card); border-color: var(--reference-border); }
.profile-menu a { color: var(--text); }

html[data-theme="dark"] .panel,
html[data-theme="dark"] .card,
html[data-theme="dark"] .sec-card,
html[data-theme="dark"] .profile-card,
html[data-theme="dark"] .settings-card,
html[data-theme="dark"] .audit-card,
html[data-theme="dark"] .table-wrap,
html[data-theme="dark"] .audit-table-wrap { background: var(--reference-card); border-color: var(--reference-border); }
html[data-theme="dark"] .panel-head,
html[data-theme="dark"] .card-head { border-color: var(--border-soft); }
html[data-theme="dark"] .table-wrap > table th,
html[data-theme="dark"] table.data th,
html[data-theme="dark"] table.audit-table th { background: var(--surface-muted); color: var(--text-soft); }
html[data-theme="dark"] .table-wrap > table tbody tr:nth-child(even),
html[data-theme="dark"] table.data tbody tr:nth-child(even) { background: rgba(255,255,255,.018); }
html[data-theme="dark"] .table-wrap > table tbody tr:hover,
html[data-theme="dark"] table.data tbody tr:hover { background: var(--surface-hover); }
html[data-theme="dark"] .btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
html[data-theme="dark"] .btn-ghost:hover:not(:disabled) { background: var(--surface-hover); }
html[data-theme="dark"] .table-wrap > table td, html[data-theme="dark"] table.data td { border-color: var(--border-soft); }

/* Responsive behaviours: preserve the reference desktop layout and make forms usable on phones. */
@media (max-width: 1024px) {
    .content { padding: 18px 18px 26px; }
    .topbar { padding-inline: 14px; }
}
@media (max-width: 720px) {
    .content { padding: 13px 11px 22px; }
    .topbar { padding: 9px 10px; gap: 8px; }
    .page-title { max-width: 42vw; overflow: hidden; text-overflow: ellipsis; }
    .topbar-search { order: 3; flex: 1 0 100%; max-width: none; margin: 0; }
    .topbar-search input { width: 100%; }
    .topbar-right { margin-left: auto; }
    .profile-meta { display: none; }
    .page-head { align-items: flex-start; }
    .page-head .btn, .page-head .btn-primary { width: 100%; }
    .form-grid, .payment-form, .grid-2, .grid-3, .grid-2-1, .grid-1-2 { grid-template-columns: minmax(0, 1fr) !important; }
    .form-grid .span-2, .payment-form > *, .payment-form .payment-submit { grid-column: 1 / -1 !important; }
    .toolbar { display: grid; grid-template-columns: minmax(0, 1fr); }
    .toolbar > *, .toolbar input, .toolbar select, .toolbar .btn { width: 100%; }
    .panel { padding: 14px; }
    .panel-head { align-items: flex-start; flex-direction: column; }
    .card { padding: 14px; }
    .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .kpi { padding: 13px; }
    .kpi-value { font-size: 21px; }
    .table-wrap > table, table.data, table.audit-table { min-width: 680px; }
}
@media (max-width: 420px) {
    .kpi-grid { grid-template-columns: minmax(0, 1fr); }
    .topbar-right { gap: 2px; }
    .icon-btn { width: 34px; height: 34px; }
    .topbar .theme-toggle { min-width: 36px !important; width: 36px !important; padding: 0 !important; }
    .topbar .theme-toggle .theme-label { display: none !important; }
}

/* ============================================================
   LOGIN FIELD ICON/PADDING HOTFIX (2026-10-21)
   The global input normalization later in this stylesheet resets
   padding on login inputs. Restore icon-safe spacing with a more
   specific selector so icons never cover typed values/placeholders.
   ============================================================ */
.login-body .input-icon {
    position: relative;
    display: block;
    width: 100%;
    min-width: 0;
}
.login-body .input-icon > svg:first-child {
    position: absolute;
    left: 14px;
    top: 50%;
    width: 18px;
    height: 18px;
    transform: translateY(-50%);
    z-index: 2;
    color: var(--text-mute);
    pointer-events: none;
}
.login-body .input-icon input#email {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    padding-left: 44px !important;
    padding-right: 14px !important;
    text-indent: 0;
}
.login-body .input-icon input#password {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    padding-left: 44px !important;
    padding-right: 48px !important;
    text-indent: 0;
}
.login-body .input-icon input#email:focus,
.login-body .input-icon input#password:focus {
    border-color: var(--primary);
    outline: 0;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, .16);
}
.login-body .input-icon .pw-toggle {
    z-index: 3;
    right: 7px;
    min-width: 34px;
    min-height: 34px;
    align-items: center;
    justify-content: center;
}
.login-body .input-icon input:-webkit-autofill,
.login-body .input-icon input:-webkit-autofill:hover,
.login-body .input-icon input:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--text);
    caret-color: var(--text);
    box-shadow: inset 0 0 0 1000px var(--surface-input);
}
html[data-theme="dark"] .login-body .input-icon > svg:first-child {
    color: #91a4bd;
}
.login-body #loginBtn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 46px;
    line-height: 1.25;
}
.login-body #loginBtn .spinner[hidden] { display: none !important; }
@media (max-width: 520px) {
    .login-body .login-main { padding: 20px 14px; }
    .login-body .login-card { padding: 28px 20px 24px; }
    .login-body .login-card-head { margin-bottom: 22px; }
    .login-body .form-group { margin-bottom: 18px; }
    .login-body .login-foot { line-height: 1.5; }
}



/* =====================================================================
   MOBILE UI REFRESH — scoped responsive layer (2026-10-21)
   Keeps desktop UI unchanged; improves only tablet/phone layouts.
   ===================================================================== */
@media (max-width: 1024px) {
    .layout { min-height: 100vh; min-height: 100dvh; }
    .sidebar { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
    .content { min-width: 0; }
    .table-wrap, .audit-table-wrap, .table-responsive, .data-table-wrap {
        max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 720px) {
    :root { --mobile-page-gutter: 12px; --mobile-touch-size: 44px; }
    html, body { width: 100%; min-width: 320px; }
    body { overflow-x: hidden; -webkit-tap-highlight-color: transparent; }
    .layout, .main, .content, .panel, .card, .page-head, .toolbar,
    .form-grid, .payment-form, .grid-2, .grid-3, .grid-2-1, .grid-1-2 {
        min-width: 0;
        max-width: 100%;
    }
    .content { padding: 12px var(--mobile-page-gutter) max(24px, env(safe-area-inset-bottom)); }
    .topbar {
        display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
        min-height: 56px; padding: 9px var(--mobile-page-gutter);
    }
    .hamburger { flex: 0 0 var(--mobile-touch-size); width: var(--mobile-touch-size); height: var(--mobile-touch-size); }
    .page-title { flex: 1 1 100px; min-width: 0; max-width: calc(100% - 60px); font-size: 15px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .topbar-right { display: flex; align-items: center; gap: 4px; margin-left: auto; min-width: 0; }
    .topbar .icon-btn { width: var(--mobile-touch-size); min-width: var(--mobile-touch-size); height: var(--mobile-touch-size); }
    .topbar .theme-toggle { min-width: var(--mobile-touch-size); width: var(--mobile-touch-size); padding: 0; justify-content: center; }
    .topbar .theme-toggle .theme-label { display: none; }
    .topbar-search { order: 5; display: block; flex: 1 0 100%; width: 100%; max-width: none; min-width: 0; margin: 0; }
    .topbar-search input { width: 100%; min-height: 42px; box-sizing: border-box; }
    .profile-btn { min-width: 0; padding: 3px; }
    .profile-btn > svg { display: none; }
    .profile-meta { display: none !important; }
    .notif-panel, .profile-menu, .search-results { max-width: calc(100vw - 20px); }
    .notif-panel { position: fixed; top: 64px; right: 10px; left: auto; width: min(360px, calc(100vw - 20px)); max-height: min(70dvh, 520px); overflow: auto; }
    .profile-menu { right: 8px; max-width: calc(100vw - 16px); }

    .page-head { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 10px; margin-bottom: 14px; }
    .page-head > div:first-child { flex: 1 1 100%; width: 100%; }
    .page-head h2 { font-size: 19px; line-height: 1.25; }
    .page-head .sub, .page-head p { font-size: 12.5px; }
    .page-head > .btn, .page-head > .btn-primary { flex: 1 1 100%; width: 100%; min-height: 44px; }
    .panel, .sec-card, .profile-card, .settings-card, .audit-card { border-radius: 12px; }
    .panel { padding: 13px; }
    .panel-head { gap: 8px; flex-wrap: wrap; }
    .panel-head > * { min-width: 0; max-width: 100%; }
    .card { padding: 13px; }
    .card-head { flex-wrap: wrap; align-items: flex-start; }
    .kpi-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
    .kpi { min-width: 0; padding: 12px; }
    .kpi-label { overflow-wrap: anywhere; font-size: 11px; }
    .kpi-value { font-size: clamp(17px, 5vw, 22px); overflow-wrap: anywhere; }
    .grid-2, .grid-3, .grid-2-1, .grid-1-2 { grid-template-columns: minmax(0, 1fr) !important; gap: 12px; }
    .form-grid, .payment-form { grid-template-columns: minmax(0, 1fr) !important; gap: 0; }
    .form-grid > *, .payment-form > *, .form-grid .span-2 { grid-column: 1 / -1; min-width: 0; }
    form label, .form-group label { display: block; min-width: 0; }
    form input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]),
    form select, form textarea, .form-group input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]),
    .form-group select, .form-group textarea, .panel label > input, .panel label > select, .panel label > textarea {
        width: 100%; max-width: 100%; min-width: 0; box-sizing: border-box; min-height: 44px;
    }
    textarea { min-height: 96px; }
    input[type="checkbox"], input[type="radio"] { min-width: 18px; min-height: 18px; }
    .toolbar { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
    .toolbar > *, .toolbar input, .toolbar select, .toolbar .btn { width: 100%; min-width: 0; max-width: 100%; }
    .toolbar .spacer { display: none; }
    .form-actions, .form-footer, .form-buttons, .sec-actions, .row-actions { display: flex; flex-wrap: wrap; gap: 8px; }
    .form-actions > .btn, .form-footer > .btn, .form-buttons > .btn { flex: 1 1 140px; min-height: 44px; }
    .btn, button, .act-btn { touch-action: manipulation; }
    .btn { min-height: 42px; }

    /* Keep wide data tables usable without making the entire page overflow. */
    .table-wrap, .audit-table-wrap, .table-responsive, .data-table-wrap {
        display: block; width: 100%; max-width: 100%; min-width: 0;
        overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch;
        border-radius: 10px; overscroll-behavior-x: contain;
    }
    .table-wrap > table, .table-wrap table, .audit-table-wrap table,
    .table-responsive table, .data-table-wrap table, table.data, table.audit-table {
        min-width: 640px; width: 100%; max-width: none; font-size: 12px;
    }
    .table-wrap th, .table-wrap td, table.data th, table.data td, table.audit-table th, table.audit-table td { padding: 10px 11px; }
    .table-wrap td form { display: flex; flex-wrap: wrap; gap: 6px; }
    .table-wrap td form select { min-width: 130px; max-width: 180px; }
    .empty-state { padding: 22px 14px; text-align: center; }

    .modal-overlay { padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom)); overflow-y: auto; }
    .modal { width: 100%; max-width: 100%; max-height: calc(100vh - 20px); max-height: calc(100dvh - 20px); min-height: 0; margin: auto; }
    .modal-body { min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
    .toast-container { position: fixed; top: 66px; right: 10px; left: 10px; width: auto; max-width: none; }
    .toast { min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
    .app-footer { padding: 12px var(--mobile-page-gutter) max(18px, env(safe-area-inset-bottom)); text-align: center; font-size: 11px; line-height: 1.5; }
    .profile-photo-editor { align-items: flex-start; flex-wrap: wrap; gap: 12px; }
    .profile-photo-fields { min-width: 0; flex: 1 1 100%; }
    .profile-photo-fields .btn { min-height: 44px; }
    .calendar-wrap, .calendar-grid, .chart-wrap { max-width: 100%; min-width: 0; overflow-x: auto; }
    canvas, svg { max-width: 100%; }
}

@media (max-width: 480px) {
    .content { padding-inline: 10px; }
    .topbar { padding-inline: 9px; gap: 6px; }
    .page-title { font-size: 14px; max-width: 40vw; }
    .topbar-right { gap: 2px; }
    .topbar .icon-btn, .hamburger { width: 40px; min-width: 40px; height: 40px; }
    .topbar .theme-toggle { width: 40px; min-width: 40px; }
    .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    .kpi { padding: 10px; }
    .kpi-value { font-size: 17px; }
    .panel, .card { padding: 11px; }
    .page-head h2 { font-size: 18px; }
    .sidebar { width: min(86vw, 320px); max-width: calc(100vw - 24px); }
    .login-card { width: 100%; }
}

@media (max-width: 360px) {
    .topbar { gap: 4px; }
    .page-title { max-width: 35vw; font-size: 13px; }
    .topbar .icon-btn, .hamburger { width: 36px; min-width: 36px; height: 36px; }
    .topbar .theme-toggle { width: 36px; min-width: 36px; }
    .kpi-grid { grid-template-columns: minmax(0, 1fr); }
    .table-wrap > table, .table-wrap table, .audit-table-wrap table,
    .table-responsive table, .data-table-wrap table, table.data, table.audit-table { min-width: 600px; }
}

@media (prefers-reduced-motion: reduce) {
    .sidebar, .sidebar-backdrop, .modal, .toast { transition: none !important; animation: none !important; }
}


/* ============================================================
   REFERENCE UI RELEASE — mobile CRM polish
   Existing PHP workflows and desktop layout are preserved.
   ============================================================ */
.mobile-bottom-nav { display: none; }

@media (max-width: 720px) {
    :root {
        --mobile-page-gutter: 12px;
        --mobile-touch-size: 44px;
    }
    html { -webkit-text-size-adjust: 100%; }
    body { overflow-x: clip; }
    .layout, .main, .content, .page-head, .panel, .card { min-width: 0; }
    .content { padding-bottom: calc(86px + env(safe-area-inset-bottom)); }
    .app-footer { padding-bottom: calc(82px + env(safe-area-inset-bottom)); }

    /* Compact app header, matching the mobile reference */
    .topbar {
        min-height: 58px;
        padding-top: max(7px, env(safe-area-inset-top));
        padding-right: 10px;
        padding-left: 10px;
        gap: 7px;
        flex-wrap: wrap;
        align-content: center;
    }
    .topbar .page-title { flex: 1 1 auto; min-width: 0; }
    .topbar-right { gap: 3px; }
    .topbar-search { order: 10; flex: 1 0 100%; margin: 0 0 2px; }
    .topbar-search input { min-height: 42px; border-radius: 12px; background: var(--card); }

    /* Page title and primary action share a row when space allows. */
    .page-head { align-items: center; gap: 10px; }
    .page-head > div:first-child { flex: 1 1 55%; width: auto; }
    .page-head h2 { margin-bottom: 3px; }
    .page-head > .btn, .page-head > .btn-primary {
        flex: 0 1 auto; width: auto; max-width: 100%;
        min-height: 42px; padding: 10px 13px; white-space: normal;
    }
    .page-head > .btn:only-child { width: 100%; }
    .panel, .card, .sec-card, .settings-card, .profile-card { border-radius: 14px; }
    .panel { border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
    .card { border: 1px solid var(--border-soft); box-shadow: 0 2px 8px rgba(15,23,42,.035); }

    /* Mobile cards and metrics use a calm, compact rhythm. */
    .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
    .kpi { border-radius: 13px; min-height: 92px; }
    .kpi-value { line-height: 1.15; }
    .grid-2, .grid-3, .grid-2-1, .grid-1-2 { gap: 12px; }
    .panel-head { align-items: center; }
    .panel-head h3, .card-head h3 { font-size: 14px; }

    /* Fixed bottom navigation is only shown on small screens. */
    .mobile-bottom-nav {
        position: fixed;
        z-index: 1100;
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        left: 0;
        right: 0;
        bottom: 0;
        min-height: 62px;
        padding: 6px 7px calc(6px + env(safe-area-inset-bottom));
        border-top: 1px solid var(--border);
        background: var(--card);\n        background: color-mix(in srgb, var(--card) 94%, transparent);
        backdrop-filter: blur(18px);
        -webkit-backdrop-filter: blur(18px);
        box-shadow: 0 -5px 20px rgba(15,23,42,.07);
    }
    .mobile-bottom-link {
        display: flex;
        align-items: center;
        justify-content: center;
        flex-direction: column;
        gap: 3px;
        min-width: 0;
        min-height: 48px;
        padding: 3px 2px;
        border: 0;
        border-radius: 10px;
        background: transparent;
        color: var(--text-soft);
        font: inherit;
        font-size: 10px;
        font-weight: 600;
        line-height: 1.1;
        text-decoration: none;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    .mobile-bottom-link svg { width: 21px; height: 21px; flex: 0 0 auto; }
    .mobile-bottom-link span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .mobile-bottom-link.is-active { color: var(--primary); background: var(--primary-50); }
    .mobile-bottom-link:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
    [data-theme="dark"] .mobile-bottom-nav {
        background: rgba(15,23,42,.96);
        border-color: #263449;
        box-shadow: 0 -6px 24px rgba(0,0,0,.24);
    }
    [data-theme="dark"] .mobile-bottom-link.is-active { background: rgba(59,130,246,.17); color: #93c5fd; }

    /* Keep dense CRM data within its own scroll container. */
    .table-wrap, .table-responsive, .data-table-wrap, .audit-table-wrap {
        border: 1px solid var(--border);
        background: var(--card);
        border-radius: 12px;
    }
    .table-wrap table, .table-responsive table, .data-table-wrap table { margin: 0; }
    .table-wrap th, .table-responsive th, .data-table-wrap th {
        position: sticky; top: 0; z-index: 1;
        background: var(--bg);
    }
    .search-box, .toolbar input[type="search"], .topbar-search input { border-radius: 12px; }
    .form-grid input, .form-grid select, .form-grid textarea,
    .payment-form input, .payment-form select, .payment-form textarea {
        border-radius: 10px;
    }
    .btn, button, input, select, textarea { scroll-margin-bottom: 90px; }
}

@media (max-width: 480px) {
    .content { padding-inline: 11px; }
    .page-head { align-items: stretch; }
    .page-head > div:first-child { flex: 1 1 100%; }
    .page-head > .btn, .page-head > .btn-primary { flex: 1 1 auto; }
    .page-head > div:first-child + .btn,
    .page-head > div:first-child + .btn-primary { width: auto; }
    .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .kpi { padding: 11px; }
    .kpi-label { font-size: 10.5px; }
    .panel, .card { padding: 12px; }
    .mobile-bottom-nav { grid-template-columns: repeat(5, minmax(0, 1fr)); }
    .mobile-bottom-link { font-size: 9.5px; }
    .mobile-bottom-link svg { width: 20px; height: 20px; }
    .profile-menu { max-height: calc(100dvh - 88px); overflow-y: auto; }
}

@media (max-width: 359px) {
    .topbar .page-title { max-width: 31vw; font-size: 12px; }
    .topbar .icon-btn, .hamburger, .topbar .theme-toggle { min-width: 36px; width: 36px; height: 36px; }
    .kpi-grid { grid-template-columns: minmax(0, 1fr); }
    .mobile-bottom-link { font-size: 9px; }
}

/* ============================================================
   PROSPECT CRM — Reference UI release (desktop + mobile)
   Dark navy surfaces, bright blue actions, tighter hierarchy.
   Appended intentionally to normalize older page-level styles.
   ============================================================ */
html[data-theme="dark"] {
    --primary: #1677ff;
    --primary-dark: #0757d8;
    --primary-light: #183d73;
    --primary-50: #10294b;
    --bg: #07111f;
    --card: #0d1a2b;
    --surface: #0c1a2c;
    --surface-muted: #102239;
    --surface-hover: #142a43;
    --surface-input: #091626;
    --border: #203853;
    --border-soft: #172c43;
    --ink: #f4f8ff;
    --text: #dce8f7;
    --text-soft: #9bb0ca;
    --text-mute: #7189a7;
    --topbar-surface: rgba(7, 17, 31, .94);
    --shadow-sm: 0 2px 8px rgba(0,0,0,.18);
    --shadow: 0 6px 18px rgba(0,0,0,.2);
    --shadow-lg: 0 18px 42px rgba(0,0,0,.45);
}
html[data-theme="dark"] body,
html[data-theme="dark"] .main,
html[data-theme="dark"] .content { background: var(--bg); }
html[data-theme="dark"] .topbar {
    min-height: 64px;
    border-bottom: 1px solid rgba(96,165,250,.14);
    backdrop-filter: blur(18px);
}
html[data-theme="dark"] .sidebar {
    background: linear-gradient(180deg, #071323 0%, #08111e 100%);
    border-right-color: #1a2b40;
}
html[data-theme="dark"] .nav-item { border-radius: 10px; margin-inline: 8px; width: calc(100% - 16px); }
html[data-theme="dark"] .nav-item.active {
    color: #fff;
    background: linear-gradient(100deg, #075bd8 0%, #123d78 100%);
    box-shadow: inset 3px 0 0 #54a1ff, 0 5px 14px rgba(0,82,204,.18);
}
html[data-theme="dark"] .nav-item:hover:not(.active) { background: rgba(96,165,250,.09); }
html[data-theme="dark"] .content { padding-top: 24px; }
html[data-theme="dark"] .page-head { margin-bottom: 20px; }
html[data-theme="dark"] .page-head h2 { font-size: clamp(21px, 2vw, 28px); letter-spacing: -.5px; }
html[data-theme="dark"] .card,
html[data-theme="dark"] .panel,
html[data-theme="dark"] .sec-card,
html[data-theme="dark"] .settings-card,
html[data-theme="dark"] .profile-card,
html[data-theme="dark"] .kpi {
    background: linear-gradient(145deg, rgba(15,32,53,.98), rgba(10,24,41,.98));
    border: 1px solid #203853;
    box-shadow: 0 8px 22px rgba(0,0,0,.13), inset 0 1px 0 rgba(255,255,255,.018);
}
html[data-theme="dark"] .card-head { border-bottom-color: rgba(80,119,158,.2); }
html[data-theme="dark"] .card-head h3 { font-size: 15px; letter-spacing: -.15px; }
html[data-theme="dark"] .sub,
html[data-theme="dark"] .kpi-sub { color: #8fa8c5; }
html[data-theme="dark"] .btn-primary,
html[data-theme="dark"] .btn.btn-primary {
    background: linear-gradient(135deg, #1677ff, #0757d8);
    border-color: #267fff;
    color: #fff;
    box-shadow: 0 5px 14px rgba(0,95,255,.22);
}
html[data-theme="dark"] .btn-soft { background: #102b4b; color: #91c2ff; border: 1px solid #214d7d; }
html[data-theme="dark"] .btn-ghost,
html[data-theme="dark"] .icon-btn { color: #c4d5e9; background: rgba(17,38,61,.5); border-color: #29425e; }
html[data-theme="dark"] .btn-ghost:hover,
html[data-theme="dark"] .icon-btn:hover { background: #173351; }
html[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]),
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
    background-color: #091626;
    color: #eaf3ff;
    border-color: #2a4564;
}
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder { color: #7891af; }
html[data-theme="dark"] .kpi-grid.dashboard-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
html[data-theme="dark"] .dashboard-kpis .kpi { position: relative; overflow: hidden; padding: 18px; min-height: 132px; }
html[data-theme="dark"] .dashboard-kpis .kpi::after { content: ""; position: absolute; width: 100px; height: 100px; right: -38px; bottom: -52px; border-radius: 50%; background: var(--kpi-color, #2878ff); opacity: .10; }
html[data-theme="dark"] .dashboard-kpis .kpi-ico { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 11px; background: color-mix(in srgb, var(--kpi-color, #2878ff) 20%, transparent); color: var(--kpi-color, #72adff); font-size: 19px; font-weight: 800; }
html[data-theme="dark"] .dashboard-kpis .kpi-value { font-size: clamp(23px, 2vw, 30px); letter-spacing: -.7px; }
html[data-theme="dark"] .dashboard-quick-actions { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; margin: 14px 0 22px; }
html[data-theme="dark"] .quick-action { display: flex; align-items: center; gap: 11px; min-width: 0; padding: 13px; border-radius: 13px; border: 1px solid #203853; background: #0c1a2c; color: #eaf3ff; transition: transform .15s ease, border-color .15s ease, background .15s ease; }
html[data-theme="dark"] .quick-action:hover { transform: translateY(-2px); border-color: #3677bd; background: #10243b; }
html[data-theme="dark"] .quick-action strong, html[data-theme="dark"] .quick-action small { display: block; }
html[data-theme="dark"] .quick-action strong { font-size: 12px; }
html[data-theme="dark"] .quick-action small { margin-top: 2px; color: #829bb8; font-size: 10.5px; }
html[data-theme="dark"] .quick-action-icon { width: 36px; height: 36px; flex: 0 0 36px; display: grid; place-items: center; border-radius: 10px; font-size: 20px; font-weight: 800; }
html[data-theme="dark"] .qa-blue { color: #8ec3ff; background: #123d70; }
html[data-theme="dark"] .qa-green { color: #5ee5bb; background: #104638; }
html[data-theme="dark"] .qa-orange { color: #ffc56c; background: #543519; }
html[data-theme="dark"] .qa-purple { color: #d6a5ff; background: #42265f; }
html[data-theme="dark"] .table-wrap,
html[data-theme="dark"] .table-responsive,
html[data-theme="dark"] .data-table-wrap,
html[data-theme="dark"] .audit-table-wrap { border-color: #203853; background: #0b192a; }
html[data-theme="dark"] table.data th,
html[data-theme="dark"] .table-wrap th,
html[data-theme="dark"] .table-responsive th,
html[data-theme="dark"] .data-table-wrap th { background: #102239; color: #9db4ce; }
html[data-theme="dark"] table.data td,
html[data-theme="dark"] .table-wrap td,
html[data-theme="dark"] .table-responsive td,
html[data-theme="dark"] .data-table-wrap td { border-color: #1b3048; }
html[data-theme="dark"] .list-row { border-bottom-color: #1b3048; }
html[data-theme="dark"] .list-row:hover { background: rgba(59,130,246,.06); }
html[data-theme="dark"] .avatar { border: 1px solid rgba(130,180,240,.24); }
html[data-theme="dark"] .mobile-bottom-nav { background: rgba(6,15,27,.96); border-top-color: #203853; backdrop-filter: blur(18px); }
html[data-theme="dark"] .mobile-bottom-link.is-active { color: #66b0ff; background: #102b4b; }
html[data-theme="dark"] .profile-menu,
html[data-theme="dark"] .notif-panel,
html[data-theme="dark"] .search-results { background: #0d1c2f; border-color: #29425e; box-shadow: 0 18px 48px rgba(0,0,0,.42); }
html[data-theme="dark"] .theme-toggle[aria-pressed="true"] { color: #ffce67; background: #142943; }

/* The layout stays dense on desktop, then becomes thumb-friendly on phones. */
@media (min-width: 1200px) {
    html[data-theme="dark"] .content { padding: 26px 28px 32px; }
    html[data-theme="dark"] .grid-2 { gap: 18px; }
    html[data-theme="dark"] .grid-3 { gap: 16px; }
}
@media (max-width: 1100px) {
    html[data-theme="dark"] .kpi-grid.dashboard-kpis { grid-template-columns: repeat(2, minmax(0,1fr)); }
    html[data-theme="dark"] .dashboard-quick-actions { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 767px) {
    html[data-theme="dark"] .content { padding: 14px 12px calc(94px + env(safe-area-inset-bottom)); }
    html[data-theme="dark"] .topbar { min-height: 58px; gap: 7px; padding: 8px 10px; }
    html[data-theme="dark"] .topbar .page-title { font-size: 14px; }
    html[data-theme="dark"] .topbar-search { order: 10; flex: 1 0 100%; width: 100%; max-width: none; margin: 0; }
    html[data-theme="dark"] .topbar-search input { min-height: 42px; border-radius: 12px; }
    html[data-theme="dark"] .page-head { align-items: flex-start; gap: 12px; }
    html[data-theme="dark"] .page-head h2 { font-size: 22px; }
    html[data-theme="dark"] .page-head .btn { min-height: 42px; }
    html[data-theme="dark"] .dashboard-kpis .kpi { min-height: 112px; padding: 13px; }
    html[data-theme="dark"] .dashboard-kpis .kpi-value { font-size: clamp(20px, 6vw, 27px); }
    html[data-theme="dark"] .dashboard-quick-actions { gap: 8px; margin: 12px 0 16px; }
    html[data-theme="dark"] .quick-action { padding: 10px; gap: 8px; }
    html[data-theme="dark"] .quick-action-icon { width: 32px; height: 32px; flex-basis: 32px; }
    html[data-theme="dark"] .quick-action small { font-size: 10px; }
    html[data-theme="dark"] .grid-2, html[data-theme="dark"] .grid-2-1, html[data-theme="dark"] .grid-3 { grid-template-columns: minmax(0,1fr) !important; }
    html[data-theme="dark"] .card { border-radius: 15px; }
    html[data-theme="dark"] .card-head { gap: 8px; }
    html[data-theme="dark"] .table-wrap, html[data-theme="dark"] .table-responsive, html[data-theme="dark"] .data-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    html[data-theme="dark"] .table-wrap table, html[data-theme="dark"] .table-responsive table, html[data-theme="dark"] .data-table-wrap table { min-width: 680px; }
    html[data-theme="dark"] .form-grid { grid-template-columns: minmax(0,1fr) !important; }
    html[data-theme="dark"] .mobile-bottom-nav { display: grid; }
}
@media (max-width: 380px) {
    html[data-theme="dark"] .content { padding-inline: 9px; }
    html[data-theme="dark"] .dashboard-kpis .kpi { padding: 10px; }
    html[data-theme="dark"] .dashboard-kpis .kpi-label { font-size: 10px; }
    html[data-theme="dark"] .dashboard-kpis .kpi-value { font-size: 19px; }
    html[data-theme="dark"] .quick-action small { display: none; }
}


/* ============================================================
   REFERENCE MATCH PASS 3 — cohesive desktop + mobile UI
   Visual-only overrides; preserves PHP workflows and data logic.
   ============================================================ */
html[data-theme="dark"] {
  --bg:#07111f;
  --card:#0c1a2b;
  --border:#203550;
  --border-soft:#192d44;
  --primary:#0868ff;
  --primary-dark:#0055e8;
  --primary-light:#12396a;
  --primary-50:#10294a;
  --ink:#f4f8ff;
  --text:#dce8f8;
  --text-soft:#9eb2cc;
  --text-mute:#7188a6;
  --surface:#0c1a2b;
  --surface-muted:#0e2035;
  --surface-hover:#122944;
  --surface-input:#081626;
  --topbar-surface:rgba(6,15,28,.97);
}
html[data-theme="dark"] body { background:#07111f; }
html[data-theme="dark"] .sidebar {
  background:linear-gradient(180deg,#081525 0%,#050d18 100%);
  border-right:1px solid #172b42;
}
html[data-theme="dark"] .sidebar-brand { min-height:58px; padding:12px 15px; border-bottom-color:#172b42; }
html[data-theme="dark"] .brand-logo svg { width:32px;height:32px; }
html[data-theme="dark"] .brand-text { font-size:12px; letter-spacing:.25px; }
html[data-theme="dark"] .brand-sub { font-size:9px; letter-spacing:3px; }
html[data-theme="dark"] .sidebar-nav { padding:10px 8px; }
html[data-theme="dark"] .sidebar-section-label { color:#647b98; }
html[data-theme="dark"] .nav-item { min-height:35px; padding:8px 10px; gap:10px; font-size:12.5px; border-radius:8px; }
html[data-theme="dark"] .nav-item.active { background:linear-gradient(90deg,#0d3b83,#0c2b58); color:#fff; }
html[data-theme="dark"] .nav-item.active::before { left:-8px; background:#1677ff; }
html[data-theme="dark"] .topbar { min-height:58px; height:58px; padding-inline:20px; gap:12px; background:rgba(7,17,31,.96); border-bottom-color:#1a2e45; }
html[data-theme="dark"] .page-title { font-size:15px; }
html[data-theme="dark"] .topbar-search { max-width:520px; }
html[data-theme="dark"] .topbar-search input { min-height:36px; background:#0d1d30 !important; border:1px solid #1e344e; color:#dce8f8; }
html[data-theme="dark"] .topbar-search input:focus { border-color:#2479ff; box-shadow:0 0 0 3px rgba(36,121,255,.12); }
html[data-theme="dark"] .content { max-width:none; padding:22px 26px 30px; }
html[data-theme="dark"] .page-head { margin-bottom:18px; }
html[data-theme="dark"] .page-head h2 { font-size:22px; letter-spacing:-.4px; }
html[data-theme="dark"] .page-head .sub { color:#8ea5c1; }
html[data-theme="dark"] .card,
html[data-theme="dark"] .panel,
html[data-theme="dark"] .sec-card { background:#0b192a; border:1px solid #1c334e; border-radius:14px; box-shadow:0 8px 24px rgba(0,0,0,.12); }
html[data-theme="dark"] .kpi { background:linear-gradient(145deg,#10243a,#0b192a); border-color:#203953; border-radius:13px; }
html[data-theme="dark"] .kpi::after { opacity:.14; }
html[data-theme="dark"] .kpi-label { color:#9db3ce; }
html[data-theme="dark"] .kpi-value { color:#f5f9ff; }
html[data-theme="dark"] .dashboard-quick-actions { margin-top:2px; }
html[data-theme="dark"] .quick-action { background:#0b1b2d; border-color:#1b3450; border-radius:12px; }
html[data-theme="dark"] .table-wrap,
html[data-theme="dark"] .table-responsive,
html[data-theme="dark"] .data-table-wrap,
html[data-theme="dark"] .audit-table-wrap { background:#091727; border:1px solid #1b3149; border-radius:12px; }
html[data-theme="dark"] table.data th,
html[data-theme="dark"] .table-wrap th,
html[data-theme="dark"] .table-responsive th,
html[data-theme="dark"] .data-table-wrap th { background:#0e2035; color:#91a9c5; border-bottom:1px solid #203550; }
html[data-theme="dark"] table.data td,
html[data-theme="dark"] .table-wrap td,
html[data-theme="dark"] .table-responsive td,
html[data-theme="dark"] .data-table-wrap td { border-bottom-color:#172b42; }
html[data-theme="dark"] table.data tbody tr:hover { background:#10243a !important; }
html[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="file"]),
html[data-theme="dark"] select,
html[data-theme="dark"] textarea { border-radius:9px; min-height:39px; }
html[data-theme="dark"] textarea { min-height:88px; }
html[data-theme="dark"] .btn-primary { background:linear-gradient(135deg,#1476ff,#0757e8); border-color:#267dff; color:#fff; box-shadow:0 4px 12px rgba(0,90,255,.18); }
html[data-theme="dark"] .btn-primary:hover:not(:disabled) { filter:brightness(1.08); }
html[data-theme="dark"] .btn-ghost,
html[data-theme="dark"] .icon-btn { background:#0d1e31; border-color:#243b56; color:#d3e3f8; }
html[data-theme="dark"] .badge,
html[data-theme="dark"] .status-badge { font-weight:700; }
html[data-theme="dark"] .profile-btn { border-radius:10px; }
html[data-theme="dark"] .avatar { background:linear-gradient(145deg,#8b3cc7,#d02e69); }
html[data-theme="dark"] .app-footer { color:#627b98; }

/* Responsive reference layout */
@media (min-width:1280px) {
  html[data-theme="dark"] { --sidebar-w:224px; }
  html[data-theme="dark"] .content { padding:22px 24px 28px; }
  html[data-theme="dark"] .grid-2, html[data-theme="dark"] .grid-2-1, html[data-theme="dark"] .grid-1-2 { gap:16px; }
}
@media (max-width:1024px) {
  html[data-theme="dark"] .content { padding:18px 18px 26px; }
}
@media (max-width:767px) {
  html[data-theme="dark"] .content { padding:14px 12px calc(88px + env(safe-area-inset-bottom)); }
  html[data-theme="dark"] .topbar { min-height:58px; height:auto; padding:8px 10px; gap:7px; flex-wrap:wrap; }
  html[data-theme="dark"] .topbar .page-title { font-size:14px; }
  html[data-theme="dark"] .topbar-search { order:10; flex:1 0 100%; width:100%; max-width:none; margin:0; }
  html[data-theme="dark"] .topbar-search input { min-height:41px; }
  html[data-theme="dark"] .page-head { display:flex; align-items:flex-start; justify-content:space-between; flex-wrap:wrap; gap:10px; }
  html[data-theme="dark"] .page-head h2 { font-size:20px; }
  html[data-theme="dark"] .page-head .btn { min-height:40px; }
  html[data-theme="dark"] .dashboard-kpis .kpi { min-height:108px; padding:12px; }
  html[data-theme="dark"] .dashboard-kpis .kpi-value { font-size:clamp(20px,6vw,26px); }
  html[data-theme="dark"] .dashboard-quick-actions { grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px; }
  html[data-theme="dark"] .quick-action { min-height:62px; padding:9px; }
  html[data-theme="dark"] .quick-action small { font-size:10px; }
  html[data-theme="dark"] .card { padding:13px; }
  html[data-theme="dark"] .card-head h3 { font-size:14px; }
  html[data-theme="dark"] .table-wrap, html[data-theme="dark"] .table-responsive, html[data-theme="dark"] .data-table-wrap { overflow-x:auto; -webkit-overflow-scrolling:touch; }
  html[data-theme="dark"] .table-wrap table, html[data-theme="dark"] .table-responsive table, html[data-theme="dark"] .data-table-wrap table { min-width:680px; }
  html[data-theme="dark"] .form-grid, html[data-theme="dark"] .payment-form { grid-template-columns:minmax(0,1fr) !important; }
  html[data-theme="dark"] .payment-form .payment-submit { grid-column:1; }
  html[data-theme="dark"] .mobile-bottom-nav { display:grid; position:fixed; left:0; right:0; bottom:0; z-index:70; padding-bottom:env(safe-area-inset-bottom); }
}
@media (max-width:380px) {
  html[data-theme="dark"] .content { padding-inline:9px; }
  html[data-theme="dark"] .dashboard-kpis .kpi { padding:10px; }
  html[data-theme="dark"] .dashboard-kpis .kpi-label { font-size:9.5px; }
  html[data-theme="dark"] .quick-action small { display:none; }
}

/* ============================================================
   REFERENCE UI IMPLEMENTATION — cohesive desktop + mobile pass
   Uses existing semantic PHP components and existing CRM data.
   ============================================================ */
:root { --sidebar-w: 218px; --topbar-h: 58px; }
html[data-theme="dark"] {
  --bg:#06111f; --card:#0b192a; --border:#203650; --border-soft:#172b42;
  --primary:#0875ff; --primary-dark:#005be7; --primary-light:#143b6b; --primary-50:#10294a;
  --ink:#f4f8ff; --text:#dce8f7; --text-soft:#9eb2ca; --text-mute:#7188a4;
  --surface:#0b192a; --surface-muted:#0e2035; --surface-hover:#122943; --surface-input:#071626;
  --topbar-surface:rgba(5,15,28,.97);
}
html[data-theme="dark"] body { background:#06111f; }
html[data-theme="dark"] .layout { background:#06111f; }
html[data-theme="dark"] .sidebar { width:218px; background:linear-gradient(180deg,#081525 0%,#050c17 100%); border-right:1px solid #172b42; }
html[data-theme="dark"] .sidebar-brand { min-height:58px; padding:11px 14px; border-bottom-color:#172b42; }
html[data-theme="dark"] .sidebar-nav { padding:10px 8px; }
html[data-theme="dark"] .nav-item { min-height:34px; margin:2px 0; padding:7px 10px; gap:10px; border-radius:7px; font-size:12px; color:#9db0c8; }
html[data-theme="dark"] .nav-item.active { background:linear-gradient(90deg,#0b4fc3 0%,#0a2d5b 100%); color:#fff; }
html[data-theme="dark"] .nav-item.active::before { left:-8px; top:4px; bottom:4px; background:#1677ff; }
html[data-theme="dark"] .nav-item.active svg { color:#fff; }
html[data-theme="dark"] .topbar { min-height:58px; height:58px; padding:0 20px; gap:12px; background:rgba(5,15,28,.97); border-bottom-color:#1a2e45; }
html[data-theme="dark"] .page-title { font-size:15px; }
html[data-theme="dark"] .topbar-search { max-width:440px; }
html[data-theme="dark"] .topbar-search input { min-height:35px; background:#0b1c30!important; border:1px solid #1b334d; color:#e3efff; }
html[data-theme="dark"] .topbar-search input:focus { border-color:#1677ff; box-shadow:0 0 0 3px rgba(22,119,255,.13); }
html[data-theme="dark"] .content { width:100%; max-width:none; padding:22px 24px 30px; }
html[data-theme="dark"] .page-head { margin-bottom:18px; }
html[data-theme="dark"] .page-head h2 { font-size:21px; letter-spacing:-.35px; }
html[data-theme="dark"] .page-head .sub { color:#8fa7c3; }
html[data-theme="dark"] .card, html[data-theme="dark"] .panel, html[data-theme="dark"] .sec-card,
html[data-theme="dark"] details.card { background:#0a192a; border:1px solid #1c334d; border-radius:12px; box-shadow:0 6px 18px rgba(0,0,0,.12); }
html[data-theme="dark"] .card-head { margin-bottom:13px; }
html[data-theme="dark"] .card-head h3 { color:#f2f7ff; font-size:14px; }
html[data-theme="dark"] .card-head .sub { color:#8ea5c0; font-size:11.5px; }
html[data-theme="dark"] .kpi { background:linear-gradient(145deg,#10243a,#0b192a); border-color:#203953; border-radius:12px; padding:14px 16px; }
html[data-theme="dark"] .kpi::after { height:0; }
html[data-theme="dark"] .kpi-ico { border:1px solid rgba(255,255,255,.07); background:color-mix(in srgb,var(--kpi-color,#1677ff) 22%,#0b192a); color:var(--kpi-color,#1677ff); }
html[data-theme="dark"] .kpi-label { color:#9db3ce; text-transform:none; letter-spacing:0; font-size:11.5px; }
html[data-theme="dark"] .kpi-value { color:#f5f9ff; font-size:25px; }
html[data-theme="dark"] .dashboard-quick-actions { margin:0 0 18px; }
html[data-theme="dark"] .quick-action { background:#0b1b2d; border-color:#1b3450; border-radius:11px; }
html[data-theme="dark"] .quick-action:hover { border-color:#2e6dbb; background:#0d2137; }
html[data-theme="dark"] .table-wrap, html[data-theme="dark"] .table-responsive, html[data-theme="dark"] .data-table-wrap, html[data-theme="dark"] .audit-table-wrap { background:#081626; border:1px solid #1b3149; border-radius:11px; }
html[data-theme="dark"] table.data th, html[data-theme="dark"] .table-wrap th, html[data-theme="dark"] .table-responsive th, html[data-theme="dark"] .data-table-wrap th { background:#0e2035; color:#91a9c5; border-bottom:1px solid #203550; font-size:10px; }
html[data-theme="dark"] table.data td, html[data-theme="dark"] .table-wrap td, html[data-theme="dark"] .table-responsive td, html[data-theme="dark"] .data-table-wrap td { border-bottom-color:#172b42; }
html[data-theme="dark"] table.data tbody tr:hover, html[data-theme="dark"] .table-wrap tbody tr:hover { background:#10243a!important; }
html[data-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="file"]), html[data-theme="dark"] select, html[data-theme="dark"] textarea { border-radius:8px; min-height:39px; background:#081626; border-color:#233a54; color:#e4efff; }
html[data-theme="dark"] textarea { min-height:88px; }
html[data-theme="dark"] .btn-primary { background:linear-gradient(135deg,#1677ff,#0758e8); border-color:#267dff; color:#fff; box-shadow:0 4px 12px rgba(0,90,255,.18); }
html[data-theme="dark"] .btn-ghost, html[data-theme="dark"] .btn-secondary { background:#0d1e31; border-color:#243b56; color:#d3e3f8; }
html[data-theme="dark"] .icon-btn { color:#a9bdd5; }
html[data-theme="dark"] .icon-btn:hover { background:#122943; color:#fff; }
html[data-theme="dark"] .profile-btn { border-radius:9px; }
html[data-theme="dark"] .avatar { background:linear-gradient(145deg,#7b39c7,#c52e68); }
html[data-theme="dark"] .app-footer { color:#627b98; }

/* Reference dashboard composition */
.dashboard-primary-row { display:grid; grid-template-columns:minmax(0,1.55fr) minmax(300px,1fr); gap:16px; margin:0 0 18px; align-items:stretch; }
.dashboard-primary-row > .card { margin:0; min-width:0; }
.dashboard-trend-card .chart-box { min-height:210px; }
.dashboard-period { padding:5px 9px; border:1px solid var(--border); border-radius:7px; color:var(--text-soft); font-size:10.5px; white-space:nowrap; }
.dashboard-chart-legend { display:flex; gap:15px; flex-wrap:wrap; padding-top:8px; color:var(--text-soft); font-size:11px; }
.dashboard-chart-legend span { display:inline-flex; align-items:center; gap:6px; }
.dashboard-chart-legend i { display:inline-block; width:8px; height:8px; border-radius:3px; }
.dashboard-chart-legend .legend-blue { background:#1677ff; }
.dashboard-chart-legend .legend-green { background:#10b981; }
.dashboard-chart-legend .legend-purple { background:#a855f7; }
.dashboard-followups-card { display:flex; flex-direction:column; }
.dashboard-followup-row { display:flex; align-items:center; gap:10px; padding:12px 0; border-bottom:1px solid var(--border-soft); color:var(--text); min-width:0; }
.dashboard-followup-row:last-child { border-bottom:0; }
.dashboard-followup-row:hover { color:var(--primary); }
.dashboard-followup-avatar { display:flex; flex:0 0 34px; width:34px; height:34px; border-radius:50%; align-items:center; justify-content:center; background:linear-gradient(135deg,#1476ff,#0c9cbd); color:white; font-weight:700; font-size:11px; }
.dashboard-followup-main { display:flex; flex:1; min-width:0; flex-direction:column; gap:2px; }
.dashboard-followup-main strong { font-size:12px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.dashboard-followup-main small, .dashboard-followup-time small { color:var(--text-soft); font-size:10.5px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.dashboard-followup-time { display:flex; flex-direction:column; text-align:right; gap:3px; flex-shrink:0; }
.dashboard-followup-time strong { font-size:10.5px; color:#5ca1ff; }
.grid-4 { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:15px; }
.dashboard-analytics-grid > .card { min-width:0; margin-bottom:18px; padding:15px; }
.dashboard-analytics-grid .chart-box { min-width:0; }

/* All module pages use the same title, filter, table and form rhythm. */
html[data-theme="dark"] .toolbar { gap:8px; }
html[data-theme="dark"] .toolbar .btn { min-height:38px; }
html[data-theme="dark"] .badge, html[data-theme="dark"] .status-badge { font-weight:700; border-radius:6px; }
html[data-theme="dark"] .pagination a, html[data-theme="dark"] .pagination span.pg-cur { border-color:#263e5a; }
html[data-theme="dark"] .pagination span.pg-cur { background:#0868ff; color:white; }
html[data-theme="dark"] .list-row { border-bottom-color:#1a3048; }
html[data-theme="dark"] .list-row:hover { background:#0e2035; }
html[data-theme="dark"] .empty-state { color:#9eb2ca; }
html[data-theme="dark"] .modal-backdrop { background:rgba(0,5,15,.72); }
html[data-theme="dark"] .modal { background:#0b192a; border-color:#203650; }

@media (min-width:1280px) {
  .layout > .sidebar { width:218px; }
  .dashboard-analytics-grid { grid-template-columns:repeat(4,minmax(0,1fr)); }
}
@media (max-width:1279px) {
  .dashboard-analytics-grid { grid-template-columns:repeat(2,minmax(0,1fr)); }
}
@media (max-width:1024px) {
  .dashboard-primary-row { grid-template-columns:minmax(0,1.2fr) minmax(280px,1fr); }
  .dashboard-analytics-grid { grid-template-columns:repeat(2,minmax(0,1fr)); }
}
@media (max-width:767px) {
  html[data-theme="dark"] .content { padding:14px 12px calc(88px + env(safe-area-inset-bottom)); }
  html[data-theme="dark"] .topbar { min-height:58px; height:auto; padding:8px 10px; gap:7px; flex-wrap:wrap; }
  html[data-theme="dark"] .topbar .page-title { font-size:14px; max-width:36vw; }
  html[data-theme="dark"] .topbar-search { order:10; flex:1 0 100%; width:100%; max-width:none; margin:0; }
  html[data-theme="dark"] .topbar-search input { min-height:40px; }
  html[data-theme="dark"] .page-head { display:flex; align-items:flex-start; justify-content:space-between; flex-wrap:wrap; gap:9px; }
  html[data-theme="dark"] .page-head h2 { font-size:19px; }
  html[data-theme="dark"] .page-head .btn { min-height:40px; }
  html[data-theme="dark"] .dashboard-kpis { grid-template-columns:repeat(2,minmax(0,1fr)); gap:9px; }
  html[data-theme="dark"] .dashboard-kpis .kpi { min-height:102px; padding:11px; }
  html[data-theme="dark"] .dashboard-kpis .kpi-value { font-size:clamp(19px,5.6vw,25px); }
  html[data-theme="dark"] .dashboard-kpis .kpi-label { font-size:10px; }
  html[data-theme="dark"] .dashboard-quick-actions { grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px; }
  html[data-theme="dark"] .quick-action { min-height:60px; padding:9px; }
  html[data-theme="dark"] .quick-action small { font-size:10px; }
  .dashboard-primary-row { grid-template-columns:minmax(0,1fr); gap:12px; }
  .dashboard-trend-card .chart-box { min-height:185px; }
  .dashboard-analytics-grid { grid-template-columns:minmax(0,1fr); gap:0; }
  .dashboard-analytics-grid > .card { padding:13px; }
  html[data-theme="dark"] .card { padding:13px; }
  html[data-theme="dark"] .card-head h3 { font-size:13.5px; }
  html[data-theme="dark"] .table-wrap, html[data-theme="dark"] .table-responsive, html[data-theme="dark"] .data-table-wrap { overflow-x:auto; -webkit-overflow-scrolling:touch; }
  html[data-theme="dark"] .table-wrap table, html[data-theme="dark"] .table-responsive table, html[data-theme="dark"] .data-table-wrap table { min-width:680px; }
  html[data-theme="dark"] .form-grid, html[data-theme="dark"] .payment-form { grid-template-columns:minmax(0,1fr)!important; }
  html[data-theme="dark"] .payment-form .payment-submit { grid-column:1; }
  html[data-theme="dark"] .mobile-bottom-nav { display:grid; grid-template-columns:repeat(5,minmax(0,1fr)); position:fixed; left:0; right:0; bottom:0; z-index:70; padding:6px 5px calc(6px + env(safe-area-inset-bottom)); background:rgba(5,15,28,.97); border-top:1px solid #203650; backdrop-filter:blur(16px); }
  html[data-theme="dark"] .mobile-bottom-link { min-width:0; min-height:48px; gap:3px; border-radius:9px; color:#8298b4; font-size:10px; }
  html[data-theme="dark"] .mobile-bottom-link svg { width:20px; height:20px; }
  html[data-theme="dark"] .mobile-bottom-link.is-active { background:#102f59; color:#55a0ff; }
  html[data-theme="dark"] .app-footer { padding-bottom:96px; }
}
@media (max-width:390px) {
  html[data-theme="dark"] .content { padding-inline:9px; }
  html[data-theme="dark"] .dashboard-kpis .kpi { padding:9px; }
  html[data-theme="dark"] .dashboard-kpis .kpi-value { font-size:19px; }
  html[data-theme="dark"] .quick-action small { display:none; }
  .dashboard-followup-row { gap:7px; }
}
