/* ================================================================
   FitCRM — Design System
   CORA-style: minimal, professional, mobile-first
   Colors: #dc3545 red accent, #1a1a1a black, #f8f9fa bg, white
   ================================================================ */

/* ── CSS Variables ─────────────────────────────────────────────── */

:root {
    --primary: #1a1a1a;
    --primary-hover: #333;
    --accent: #dc3545;
    --accent-hover: #c82333;
    --bg: #f8f9fa;
    --bg-white: #ffffff;
    --bg-secondary: #f1f3f5;
    --text: #333;
    --text-muted: #666;
    --text-light: #999;
    --border: #ddd;
    --border-light: #eee;
    --success: #4b5563;
    --success-bg: #f3f4f6;
    --warning: #6b7280;
    --warning-bg: #f3f4f6;
    --danger: #dc3545;
    --danger-bg: #fef2f2;
    --info: #6b7280;
    --info-bg: #f3f4f6;
    --shadow: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --radius: 6px;
    --radius-lg: 10px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --nav-height: 56px;
    --mobile-nav-height: 60px;
}

/* ── Dark Mode ─────────────────────────────────────────────────── */

[data-theme="dark"] {
    --primary: #e0e0e0;
    --primary-hover: #fff;
    --bg: #111;
    --bg-white: #1a1a1a;
    --bg-secondary: #202224;
    --text: #d4d4d4;
    --text-muted: #909090;
    --text-light: #666;
    --border: #333;
    --border-light: #2a2a2a;
    --success-bg: #1f1f1f;
    --warning-bg: #1f1f1f;
    --danger-bg: #2a1215;
    --info-bg: #1f1f1f;
    --shadow: 0 1px 3px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
}

[data-theme="dark"] .btn-primary {
    background: transparent;
    color: #e0e0e0;
    border-color: #555;
}
[data-theme="dark"] .btn-primary:hover {
    background: rgba(255,255,255,0.08);
    border-color: #999;
    color: #fff;
}

/* ── Reset & Base ──────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; line-height: 1.6; -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding-top: calc(var(--nav-height) + env(safe-area-inset-top, 0px));
}

html, body {
    overscroll-behavior-y: contain;
}

a, button, .btn, .action-btn, input[type="button"], input[type="submit"] {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

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

img { max-width: 100%; height: auto; }

/* Keyboard focus visibility */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ── Typography ────────────────────────────────────────────────── */

h1 { font-size: 1.5rem; font-weight: 600; margin-bottom: 0.5rem; color: var(--text); }
h2 { font-size: 1.25rem; font-weight: 600; margin-bottom: 0.5rem; color: var(--text); }
h3 { font-size: 1.1rem; font-weight: 600; margin-bottom: 0.4rem; color: var(--text); }

.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }
.text-sm { font-size: 0.85rem; }

/* ── Layout ────────────────────────────────────────────────────── */

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px 24px 100px;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-header h1 { margin-bottom: 0; }

.row { display: flex; gap: 20px; flex-wrap: wrap; }
.col { flex: 1; min-width: 0; }
.col-2 { flex: 0 0 calc(50% - 10px); }
.col-3 { flex: 0 0 calc(33.33% - 14px); }
.col-4 { flex: 0 0 calc(25% - 15px); }

/* ── Navbar ────────────────────────────────────────────────────── */

.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: calc(var(--nav-height) + env(safe-area-inset-top, 0px));
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: env(safe-area-inset-top, 0px) max(24px, env(safe-area-inset-right, 0px)) 0 max(24px, env(safe-area-inset-left, 0px));
    z-index: 1000;
}

.navbar-brand {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text) !important;
    margin-right: 32px;
    letter-spacing: -0.3px;
}
.navbar-brand span { color: var(--accent); }

.navbar-nav {
    display: flex;
    list-style: none;
    gap: 4px;
}

.navbar-nav a {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: var(--radius);
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.15s;
}

.navbar-nav a:hover,
.navbar-nav a.active {
    color: var(--text);
    background: var(--bg);
}

.navbar-nav a.active {
    color: var(--accent);
}

.navbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}
.nav-settings-link { margin-right: 4px; }
.nav-theme-toggle { margin-right: 8px; }
.navbar-logout-form { display: inline; }

.theme-toggle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-white);
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.15s;
}
.theme-toggle:hover {
    background: var(--bg);
    border-color: var(--text-muted);
}

.hamburger {
    display: none;
    width: 36px;
    height: 36px;
    border: none;
    background: none;
    cursor: pointer;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
}
.hamburger span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text);
    transition: all 0.2s;
}

/* ── Cards ─────────────────────────────────────────────────────── */

.card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: box-shadow 0.15s;
}

.card:hover { box-shadow: var(--shadow-md); }

.card-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-light);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-body { padding: 18px; }

.card-footer {
    padding: 12px 18px;
    border-top: 1px solid var(--border-light);
}

/* ── Stat Cards ────────────────────────────────────────────────── */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-grid-wide {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}

/* Period tabs */
.period-tabs {
    display: flex;
    gap: 4px;
}
.period-tab {
    padding: 6px 14px;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: var(--radius);
    transition: all 0.15s;
}
.period-tab:hover { background: var(--bg-secondary); color: var(--text); }
.period-tab.active {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
    font-weight: 600;
}

.stat-card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
}

.stat-card .stat-label {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 6px;
}

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
}

.stat-card .stat-sub {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ── Buttons ───────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    line-height: 1.4;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    color: #fff;
}

.btn-danger {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.btn-danger:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: #fff;
}

.btn-success {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.btn-outline {
    background: var(--bg-white);
    color: var(--text);
    border-color: var(--border);
}
.btn-outline:hover {
    background: var(--bg);
    border-color: var(--text-muted);
    color: var(--text);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: none;
    padding: 6px 10px;
}
.btn-ghost:hover { color: var(--text); background: var(--bg); }

.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }
.btn-icon { padding: 6px 8px; }
.btn-block { width: 100%; justify-content: center; }

/* ── Forms ──────────────────────────────────────────────────────── */

.form-group { margin-bottom: 16px; }

.form-label {
    display: block;
    font-weight: 500;
    margin-bottom: 4px;
    font-size: 0.85rem;
    color: var(--text);
}

.form-control {
    display: block;
    width: 100%;
    padding: 9px 12px;
    font-size: 0.9rem;
    font-family: var(--font);
    color: var(--text);
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26,26,26,0.08);
}

[data-theme="dark"] .form-control:focus {
    box-shadow: 0 0 0 3px rgba(220,53,69,0.15);
    border-color: var(--accent);
}

select.form-control { cursor: pointer; }
select.form-control option {
    background: var(--bg-white) !important;
    color: var(--text) !important;
}
select.form-control option:checked {
    background: var(--bg) !important;
    color: var(--text) !important;
}
select.form-control option:hover,
select.form-control option:focus,
select.form-control option:active {
    background: var(--bg) !important;
    color: var(--text) !important;
}

/* Global dropdown styling (neutral grayscale, no browser blue accents) */
select.form-control,
.filter-select,
.pipeline-stage-select {
    -webkit-appearance: none;
    appearance: none;
    padding-right: 32px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 9'%3E%3Cpath d='M1 1l6 6 6-6' stroke='%23858585' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 12px 8px;
}

select.form-control:focus,
.filter-select:focus,
.pipeline-stage-select:focus {
    outline: none;
    border-color: #7a7a7a !important;
    box-shadow: 0 0 0 2px rgba(128, 128, 128, 0.16) !important;
}

[data-theme="dark"] select.form-control,
[data-theme="dark"] .filter-select,
[data-theme="dark"] .pipeline-stage-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 9'%3E%3Cpath d='M1 1l6 6 6-6' stroke='%23bbbbbb' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

[data-theme="dark"] select.form-control:focus,
[data-theme="dark"] .filter-select:focus,
[data-theme="dark"] .pipeline-stage-select:focus {
    border-color: #666 !important;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.12) !important;
}
[data-theme="dark"] select.form-control option,
[data-theme="dark"] .filter-select option,
[data-theme="dark"] .pipeline-stage-select option {
    background: #2a2a2a !important;
    color: var(--text) !important;
}
[data-theme="dark"] select.form-control option:checked,
[data-theme="dark"] .filter-select option:checked,
[data-theme="dark"] .pipeline-stage-select option:checked,
[data-theme="dark"] select.form-control option:hover,
[data-theme="dark"] .filter-select option:hover,
[data-theme="dark"] .pipeline-stage-select option:hover {
    background: #343434 !important;
    color: var(--text) !important;
}

textarea.form-control { resize: vertical; min-height: 80px; }

/* Checkbox styling */
input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border: 1.5px solid var(--border);
    border-radius: 3px;
    background: transparent;
    cursor: pointer;
    position: relative;
    transition: all 0.15s;
}

input[type="checkbox"]:hover {
    border-color: var(--text-muted);
}

input[type="checkbox"]:checked {
    background: transparent;
    border-color: var(--primary);
}

input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 4px;
    top: 1px;
    width: 4px;
    height: 8px;
    border: solid var(--primary);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.form-row {
    display: flex;
    gap: 16px;
}
.form-row .form-group { flex: 1; }

.form-inline {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ── Tables ─────────────────────────────────────────────────────── */

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-white);
}

table th {
    padding: 10px 14px;
    text-align: left;
    font-size: 0.73rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-light);
    font-size: 0.9rem;
    vertical-align: middle;
}

table tbody tr {
    transition: background 0.1s;
}

table tbody tr:hover {
    background: var(--bg);
}

table .lead-name {
    font-weight: 600;
    color: var(--text);
}

table .lead-name:hover {
    color: var(--accent);
}

/* ── Status Pills ──────────────────────────────────────────────── */

.pill {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* Lead status pills */
.pill-cold { background: var(--info-bg); color: var(--info); }
.pill-warm { background: var(--border-light); color: var(--text-muted); }
.pill-hot { background: var(--danger-bg); color: var(--danger); }
.pill-client { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.pill-lost { background: var(--danger-bg); color: var(--danger); }

/* Pipeline stage pills */
.pill-contacted { background: var(--info-bg); color: var(--info); }
.pill-talking { background: var(--border-light); color: var(--text-muted); }
.pill-deciding { background: var(--danger-bg); color: var(--danger); }

/* Priority */
.pill-low { background: var(--info-bg); color: var(--info); }
.pill-medium { background: var(--border-light); color: var(--text-muted); }
.pill-high { background: var(--danger-bg); color: var(--danger); }

/* ── Pipeline / Kanban ─────────────────────────────────────────── */

.kanban {
    display: flex;
    gap: 16px;
    align-items: flex-start;
}

.kanban-column {
    flex: 1;
    min-height: 200px;
    background: var(--bg);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
}

.kanban-header {
    padding: 14px 16px;
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-light);
}

.kanban-header .count {
    background: var(--bg-secondary);
    color: var(--text);
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    border: 1px solid var(--border);
}

.kanban-body {
    padding: 10px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 100px;
}

.kanban-body.drag-over {
    background: rgba(220,53,69,0.04);
    border-radius: var(--radius);
}

.kanban-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    cursor: grab;
    transition: box-shadow 0.15s, transform 0.15s;
    position: relative;
}

.kanban-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.kanban-card.dragging {
    opacity: 0.5;
    transform: rotate(2deg);
}

.kanban-card .card-name {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 4px;
    color: var(--text);
}

.kanban-card .card-name a {
    color: var(--text);
}
.kanban-card .card-name a:hover {
    color: var(--accent);
}

.kanban-card .card-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.kanban-card .card-actions {
    display: flex;
    gap: 4px;
    margin-top: 8px;
}

/* Deal rotting */
.kanban-card.rotting-warn { border-left: 1px solid var(--border); }
.kanban-card.rotting-danger { border-left: 1px solid var(--border); }

/* ── Action Buttons (Quick Actions) ────────────────────────────── */

.action-bar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 7px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-white);
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    font-family: var(--font);
}

.action-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--bg-white);
}

.action-btn svg { width: 15px; height: 15px; flex-shrink: 0; }

/* ── Timeline ──────────────────────────────────────────────────── */

.timeline {
    position: relative;
    padding-left: 24px;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 7px;
    top: 4px;
    bottom: 4px;
    width: 2px;
    background: var(--border);
}

.timeline-item {
    position: relative;
    margin-bottom: 20px;
    padding-bottom: 2px;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -20px;
    top: 6px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--border);
    border: 2px solid var(--bg-white);
}

.timeline-item.type-system::before { background: var(--info); }
.timeline-item.type-manual::before { background: var(--accent); }
.timeline-item.type-ai_draft::before { background: var(--success); }
.timeline-item.type-call_log::before { background: var(--accent); }
.timeline-item.type-sms_log::before { background: var(--warning); }

.timeline-time {
    font-size: 0.75rem;
    color: var(--text-light);
    margin-bottom: 2px;
}

.timeline-content {
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--text);
}

.timeline-badge {
    font-size: 0.7rem;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.03em;
    color: var(--text-muted);
}

/* ── Flash Messages (Toast Overlay) ────────────────────────────── */

.flash-messages {
    position: fixed;
    top: calc(var(--nav-height) + env(safe-area-inset-top, 0px) + 8px);
    right: 16px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 6px;
    pointer-events: none;
    max-width: 360px;
}

.flash {
    padding: 10px 16px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.85rem;
    animation: flashIn 0.3s ease;
    pointer-events: auto;
    box-shadow: var(--shadow-md);
    transition: opacity 0.3s, transform 0.3s;
}

@keyframes flashIn {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

.flash-success { background: var(--success-bg); color: var(--success); }
.flash-error { background: var(--danger-bg); color: var(--danger); }
.flash-warning { background: var(--warning-bg); color: var(--warning); }
.flash-info { background: var(--info-bg); color: var(--info); }

.flash-close {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    opacity: 0.5;
    color: inherit;
    padding: 0 4px;
}
.flash-close:hover { opacity: 1; }

/* ── Search & Filter Bar ───────────────────────────────────────── */

.filter-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: center;
}

.search-input {
    flex: 1;
    min-width: 200px;
    padding: 9px 14px 9px 36px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--bg-white);
    font-size: 0.9rem;
    color: var(--text);
    font-family: var(--font);
    transition: border-color 0.15s;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 12px center;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
}

.filter-select {
    padding: 9px 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-white);
    font-size: 0.85rem;
    color: var(--text);
    font-family: var(--font);
    cursor: pointer;
}

.pipeline-stage-select {
    padding: 4px 8px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-white);
    font-size: 0.8rem;
    color: var(--text);
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    min-width: 110px;
}

.pipeline-stage-select:hover {
    border-color: var(--text-muted);
    background: var(--bg);
}

.pipeline-stage-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: none;
}

/* ── Pagination ────────────────────────────────────────────────── */

.pagination {
    display: flex;
    gap: 4px;
    justify-content: center;
    margin-top: 24px;
    flex-wrap: wrap;
}

.pagination a,
.pagination span {
    padding: 6px 12px;
    border-radius: var(--radius);
    font-size: 0.85rem;
    border: 1px solid var(--border);
    color: var(--text-muted);
    text-decoration: none;
    transition: all 0.15s;
}

.pagination a:hover {
    background: var(--bg);
    border-color: var(--text-muted);
    color: var(--text);
}

.pagination .active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

[data-theme="dark"] .pagination .active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* ── Lead Detail Layout ────────────────────────────────────────── */

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 20px;
}

.detail-info {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px 24px;
}

.detail-field {
    margin-bottom: 0;
}

.detail-label {
    font-size: 0.73rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.detail-value {
    font-size: 0.95rem;
    color: var(--text);
    word-break: break-word;
}

/* ── Tasks ──────────────────────────────────────────────────────── */

.task-list { list-style: none; }

.task-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
    transition: background 0.1s;
}

.task-item:hover { background: var(--bg); }

.task-item.overdue { background: var(--danger-bg); }

.task-check {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid var(--border);
    cursor: pointer;
    flex-shrink: 0;
    margin-top: 2px;
    transition: all 0.15s;
    appearance: none;
    -webkit-appearance: none;
    background: var(--bg-white);
}

.task-check:checked {
    background: var(--success);
    border-color: var(--success);
}

.task-item.done .task-title {
    text-decoration: line-through;
    color: var(--text-muted);
}

.task-title {
    flex: 1;
    font-size: 0.9rem;
    color: var(--text);
    font-weight: 500;
}

.task-due {
    font-size: 0.78rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.task-due.overdue { color: var(--danger); font-weight: 600; }

/* ── Today's Actions (Dashboard) ───────────────────────────────── */

.action-list { list-style: none; }

.action-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-light);
    transition: background 0.1s;
}

.action-item:last-child { border-bottom: none; }
.action-item:hover { background: var(--bg); }

.action-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 16px;
}

.action-icon.call { background: var(--danger-bg); color: var(--danger); }
.action-icon.text { background: var(--info-bg); color: var(--info); }

.action-info { flex: 1; min-width: 0; }
.action-info .name { font-weight: 600; font-size: 0.9rem; }
.action-info .detail { font-size: 0.8rem; color: var(--text-muted); }
.action-preview { margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.action-buttons {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

/* ── Selection Bar ────────────────────────────────────────────── */

.select-bar {
    display: none;
    position: sticky;
    top: calc(var(--nav-height) + env(safe-area-inset-top, 0px));
    z-index: 100;
    margin-bottom: 12px;
}

.select-bar.active {
    display: block;
}

.select-bar-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text);
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: none;
    transition: none;
}

.lead-select-check {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--accent);
}

/* ── Modal ─────────────────────────────────────────────────────── */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    z-index: 5000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active { display: flex; }

.modal {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.modal-header {
    padding: 18px 20px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
}

.modal-body { padding: 20px; }

.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border-light);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ── Slide-out Panel ───────────────────────────────────────────── */

.slide-panel-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 4000;
}

.slide-panel-overlay.active { display: block; }

.slide-panel {
    position: fixed;
    top: 0;
    right: -460px;
    width: 450px;
    height: 100%;
    background: var(--bg-white);
    box-shadow: -4px 0 20px rgba(0,0,0,0.1);
    z-index: 4001;
    transition: right 0.3s ease;
    overflow-y: auto;
}

.slide-panel.active { right: 0; }

.slide-panel-header {
    padding: 18px 20px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    background: var(--bg-white);
    z-index: 1;
}

.slide-panel-body { padding: 20px; }

/* ── Empty State ───────────────────────────────────────────────── */

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state svg { margin-bottom: 16px; opacity: 0.3; }
.empty-state p { font-size: 0.95rem; margin-bottom: 16px; }

/* ── AI Chat ───────────────────────────────────────────────────── */

.ai-chat {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.ai-messages {
    padding: 16px;
    max-height: 400px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ai-msg {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    line-height: 1.5;
    max-width: 85%;
}

.ai-msg.user {
    background: var(--primary);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}

[data-theme="dark"] .ai-msg.user {
    background: var(--accent);
}

.ai-msg.assistant {
    background: var(--bg);
    color: var(--text);
    align-self: flex-start;
    border-bottom-left-radius: 2px;
}

.ai-input-bar {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--border-light);
}

.ai-input-bar input {
    flex: 1;
    padding: 9px 14px;
    border-radius: 20px;
    border: 1px solid var(--border);
    font-size: 0.9rem;
    font-family: var(--font);
    color: var(--text);
    background: var(--bg-white);
}

.ai-input-bar input:focus {
    outline: none;
    border-color: var(--primary);
}

/* ── Scrollbar ─────────────────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Utility ───────────────────────────────────────────────────── */

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.gap-sm { gap: 8px; }
.gap-md { gap: 16px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Mobile Bottom Nav ─────────────────────────────────────────── */

.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--bg-white);
    border-top: 1px solid var(--border);
    z-index: 1000;
}

.mobile-nav-inner {
    display: flex;
    height: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 0 4px;
}
.mobile-nav-inner::-webkit-scrollbar { display: none; }

.mobile-nav a {
    flex: 0 0 74px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--text-muted);
    font-size: 0.62rem;
    font-weight: 500;
    text-decoration: none;
    transition: color 0.15s;
    min-height: 44px;
}

.mobile-nav a svg { width: 22px; height: 22px; }

.mobile-nav a.active { color: var(--accent); }
.mobile-nav a:hover { color: var(--text); }

.mobile-theme-toggle {
    flex: 0 0 74px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--text-muted);
    font-size: 0.62rem;
    font-weight: 500;
    min-height: 44px;
    border: none;
    background: none;
    cursor: pointer;
    transition: color 0.15s;
}

.mobile-theme-toggle svg { width: 22px; height: 22px; }
.mobile-theme-toggle:hover { color: var(--text); }

.mobile-utility-footer {
    display: none;
}

.desktop-only { display: flex; }
.mobile-only { display: none; }

/* ── FAB (Floating Action Button) ──────────────────────────────── */

.fab {
    display: none;
    position: fixed;
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    right: max(20px, env(safe-area-inset-right, 0px));
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(220,53,69,0.3);
    z-index: 999;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s;
}

.fab:hover { transform: scale(1.08); }

/* ── Responsive ────────────────────────────────────────────────── */

@media (max-width: 768px) {
    :root {
        --mobile-nav-height: 96px;
    }

    .container {
        padding: 12px 14px calc(var(--mobile-nav-height) + 22px + env(safe-area-inset-bottom, 0px));
        padding-left: max(16px, env(safe-area-inset-left, 0px));
        padding-right: max(16px, env(safe-area-inset-right, 0px));
    }

    .navbar-nav { display: none; }
    .desktop-only { display: none !important; }
    .mobile-only { display: block; }

    .mobile-nav { display: block; }
    .mobile-nav {
        height: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom, 0px));
    }
    .mobile-nav-inner {
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        grid-auto-rows: minmax(44px, 1fr);
        overflow-x: hidden;
        padding: 2px 6px 1px;
    }
    .mobile-nav a,
    .mobile-theme-toggle {
        flex: 0 0 auto;
        width: 100%;
        min-width: 0;
        min-height: 44px;
        padding: 2px 3px;
        font-size: 0.61rem;
        line-height: 1.15;
    }
    .mobile-nav a svg,
    .mobile-theme-toggle svg {
        width: 20px;
        height: 20px;
    }

    .mobile-utility-footer {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 14px;
        padding: 10px 0 2px;
        margin-top: 8px;
        margin-bottom: 8px;
        font-size: 0.8rem;
        color: var(--text-muted);
    }
    .mobile-utility-footer a,
    .mobile-utility-theme-toggle {
        color: inherit;
        text-decoration: none;
        background: none;
        border: none;
        padding: 4px 2px;
        font: inherit;
        cursor: pointer;
        opacity: 0.9;
    }
    .mobile-utility-footer a.active {
        color: var(--accent);
        opacity: 1;
    }
    .mobile-utility-footer a:hover,
    .mobile-utility-theme-toggle:hover {
        color: var(--text);
        opacity: 1;
    }
    .fab {
        display: flex;
        bottom: calc(var(--mobile-nav-height) + 16px + env(safe-area-inset-bottom, 0px));
    }

    /* Outline button on mobile for Add Lead */
    .btn-add-lead {
        background: transparent;
        color: var(--text);
        border: 1px solid var(--border);
    }
    .btn-add-lead:hover {
        background: var(--bg);
        border-color: var(--text-muted);
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        margin-bottom: 16px;
    }
    .page-header h1 { font-size: 1.35rem; }

    .stat-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .stat-card { padding: 14px; }
    .stat-card .stat-value { font-size: 1.4rem; }

    .filter-bar {
        flex-direction: column;
        align-items: stretch;
        margin-bottom: 14px;
    }
    .period-tabs {
        flex-wrap: wrap;
        gap: 6px;
    }
    .period-tab {
        padding: 7px 12px;
    }
    .search-input { min-width: unset; }

    .detail-grid {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    .detail-info {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .col-2, .col-3, .col-4 { flex: 0 0 100%; }

    .row { flex-direction: column; }
    .form-row { flex-direction: column; gap: 0; }

    /* Prevent iOS/Android focus-zoom on form fields */
    .form-control,
    .search-input,
    .filter-select,
    .pipeline-stage-select,
    .ai-input-bar input,
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="url"],
    input[type="password"],
    input[type="search"],
    input[type="date"],
    input[type="datetime-local"],
    textarea,
    select {
        font-size: 16px !important;
    }

    table { font-size: 0.82rem; }
    table th, table td { padding: 10px 10px; }

    .slide-panel { width: 100%; right: -100%; }
    .card-header {
        padding: 12px 14px;
    }
    .card-body {
        padding: 14px;
    }
    .card-footer {
        padding: 10px 14px;
    }

    /* Card layout for leads on mobile */
    .lead-table-mobile .table-wrap { display: none; }
    .lead-cards-mobile { display: block; }

    .lead-card-m {
        display: block;
        text-decoration: none;
        color: var(--text);
        background: var(--bg-white);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        padding: 14px;
        margin-bottom: 10px;
    }

    .lead-card-m .name { font-weight: 600; font-size: 0.95rem; }
    .lead-card-m .meta { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }
    .lead-card-m .actions { margin-top: 10px; display: flex; gap: 8px; }

    /* Action bar scrollable on mobile */
    .action-bar {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
        gap: 6px;
    }
    .action-btn {
        flex-shrink: 0;
        min-height: 42px;
        padding: 8px 12px;
    }

    /* Dashboard action items - stack on small screens */
    .action-item {
        flex-wrap: wrap;
        gap: 10px;
        padding: 12px 14px;
    }
    .action-preview { max-width: 100%; }
    .action-buttons { flex-shrink: 0; }
    .action-buttons .btn { min-height: 44px; }

    /* Touch targets min 44px */
    .btn { min-height: 44px; }
    .btn-sm { min-height: 40px; }
    .btn-ghost { min-height: 44px; }

    /* Pipeline touch-friendly cards */
    .kanban-card { padding: 14px 16px; cursor: default; -webkit-user-select: none; user-select: none; }

    /* Modal full-width on mobile */
    .modal { width: 95%; }

    .empty-state {
        padding: 34px 14px;
    }
}

@media (max-width: 420px) {
    :root {
        --mobile-nav-height: 102px;
    }
    .stat-grid {
        grid-template-columns: 1fr;
    }

    .container {
        padding-left: max(12px, env(safe-area-inset-left, 0px));
        padding-right: max(12px, env(safe-area-inset-right, 0px));
    }
}

@media (max-width: 1100px) and (min-width: 769px) {
    .navbar {
        padding-left: 14px;
        padding-right: 14px;
    }
    .navbar-brand {
        margin-right: 16px;
    }
    .navbar-nav a {
        padding: 8px 10px;
        font-size: 0.84rem;
        gap: 4px;
    }
}

@media (min-width: 769px) {
    .lead-cards-mobile { display: none; }
}

/* ── Touch Clone (pipeline mobile drag) ───────────────────────── */

.touch-clone {
    border-radius: var(--radius);
    background: var(--bg);
    border: 1px solid var(--accent);
}

/* ── Print ─────────────────────────────────────────────────────── */

@media print {
    .navbar, .mobile-nav, .fab, .theme-toggle { display: none !important; }
    body { padding: 0; background: #fff; }
}

/* Dark mode: improve pipeline-stage-select contrast */
[data-theme="dark"] .pipeline-stage-select {
    background: #2a2a2a;
    border-color: #444;
}

[data-theme="dark"] .pipeline-stage-select:hover {
    background: #333;
    border-color: #666;
}

[data-theme="dark"] .pipeline-stage-select option {
    background: #2a2a2a;
    color: var(--text);
}
[data-theme="dark"] .pipeline-stage-select option:checked {
    background: #343434;
    color: var(--text);
}
