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

:root {
    /* === DARK (default) === */
    /* Deep ink with subtle blue undertone */
    --bg: #07080D;
    --surface: #101118;
    --surface2: #181A24;
    --surface3: #232635;
    --border: #222535;
    --border-strong: #363A50;

    /* Translucent surface layers for cards/modal/sidebar */
    --surface-a: rgba(24,26,36,0.65);
    --surface-b: rgba(16,17,24,0.75);
    --surface-strong-a: rgba(28,30,42,0.98);
    --surface-strong-b: rgba(16,17,24,0.98);
    --sidebar-a: rgba(16,17,24,0.95);
    --sidebar-b: rgba(12,13,20,0.95);

    /* Text */
    --text: #F3F4F9;
    --text2: #9DA3B5;
    --text3: #606677;

    /* Primary accent — vivid violet with pink counterpoint (shared across themes) */
    --accent: #8B5CF6;
    --accent2: #A78BFA;
    --accent-bright: #7C3AED;
    --pink: #EC4899;
    --pink-bright: #F472B6;
    --cyan: #06B6D4;

    /* Gradients */
    --grad-primary: linear-gradient(135deg, #8B5CF6 0%, #EC4899 100%);
    --grad-primary-hover: linear-gradient(135deg, #9F7AFA 0%, #F472B6 100%);
    --grad-text: linear-gradient(135deg, #A78BFA 0%, #F472B6 100%);

    /* Soft tints */
    --accent-soft: rgba(139, 92, 246, 0.14);
    --accent-soft-2: rgba(139, 92, 246, 0.22);
    --pink-soft: rgba(236, 72, 153, 0.12);

    /* Status colors */
    --green: #10B981;
    --red: #F43F5E;
    --orange: #F59E0B;
    --blue: #3B82F6;

    --radius: 14px;
    --radius-sm: 10px;
    --radius-xs: 6px;

    /* Shadows + glow */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 8px 28px rgba(0,0,0,0.45);
    --shadow-lg: 0 20px 60px rgba(0,0,0,0.5);
    --glow-accent: 0 0 0 1px rgba(139, 92, 246, 0.25), 0 10px 40px -10px rgba(139, 92, 246, 0.55);
    --glow-pink: 0 10px 40px -10px rgba(236, 72, 153, 0.55);

    /* Ambient body glow intensity */
    --ambient-1: rgba(139, 92, 246, 0.15);
    --ambient-2: rgba(236, 72, 153, 0.08);

    /* Modal overlay */
    --overlay: rgba(5, 6, 12, 0.68);
    --grad-text-fallback: var(--accent);

    color-scheme: dark;
}

:root[data-theme="light"] {
    /* === LIGHT === */
    --bg: #F6F7FB;
    --surface: #FFFFFF;
    --surface2: #F1F2F8;
    --surface3: #E6E8F1;
    --border: #E4E6EE;
    --border-strong: #C7CAD6;

    --surface-a: rgba(255,255,255,0.9);
    --surface-b: rgba(252,252,254,0.95);
    --surface-strong-a: #FFFFFF;
    --surface-strong-b: #FAFAFC;
    --sidebar-a: rgba(255,255,255,0.9);
    --sidebar-b: rgba(248,249,253,0.95);

    --text: #0E1020;
    --text2: #555A6E;
    --text3: #8B90A3;

    --accent-soft: rgba(139, 92, 246, 0.10);
    --accent-soft-2: rgba(139, 92, 246, 0.18);
    --pink-soft: rgba(236, 72, 153, 0.10);

    --shadow-sm: 0 1px 2px rgba(15, 20, 40, 0.06);
    --shadow-md: 0 10px 30px rgba(15, 20, 40, 0.10);
    --shadow-lg: 0 24px 60px rgba(15, 20, 40, 0.14);

    --ambient-1: rgba(139, 92, 246, 0.10);
    --ambient-2: rgba(236, 72, 153, 0.06);

    --overlay: rgba(15, 18, 30, 0.35);

    color-scheme: light;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    letter-spacing: -0.005em;
    min-height: 100vh;
    position: relative;
}

/* Ambient backdrop glow — pulls the eye without being flashy */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background:
        radial-gradient(1100px 600px at 0% -10%, var(--ambient-1), transparent 60%),
        radial-gradient(900px 500px at 100% 0%, var(--ambient-2), transparent 60%);
}
body > * { position: relative; z-index: 1; }

::selection { background: var(--accent-soft-2); color: var(--text); }

a { color: var(--accent2); text-decoration: none; transition: color 0.15s; }
a:hover { color: var(--pink-bright); }

/* Gradient text helper */
.gradient-text {
    background: var(--grad-text);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
}

/* --- Landing / Auth --- */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-card {
    background: linear-gradient(180deg, var(--surface-a) 0%, var(--surface-b) 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 48px 40px;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255,255,255,0.05);
    backdrop-filter: blur(20px);
    position: relative;
}
.auth-card::before {
    content: '';
    position: absolute; inset: -1px;
    border-radius: var(--radius);
    padding: 1px;
    background: linear-gradient(135deg, rgba(139,92,246,0.4), rgba(236,72,153,0.25), transparent 55%);
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    pointer-events: none;
}

.auth-card h1 {
    font-size: 30px;
    font-weight: 800;
    letter-spacing: -0.03em;
    margin-bottom: 8px;
}

.auth-card p.sub {
    color: var(--text2);
    margin-bottom: 32px;
}

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

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text2);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

input, select, textarea {
    width: 100%;
    padding: 11px 14px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

input::placeholder, textarea::placeholder { color: var(--text3); }

input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }

input:focus, select:focus, textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
    background: var(--surface);
}

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.08s ease, background 0.15s, box-shadow 0.15s, opacity 0.15s;
    white-space: nowrap;
    font-family: inherit;
    letter-spacing: -0.005em;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
    background: var(--grad-primary);
    color: white;
    box-shadow:
        0 1px 0 rgba(255,255,255,0.18) inset,
        0 -1px 0 rgba(0,0,0,0.2) inset,
        0 4px 14px -4px rgba(139,92,246,0.55),
        0 2px 6px rgba(0,0,0,0.25);
}
.btn-primary:hover {
    background: var(--grad-primary-hover);
    box-shadow:
        0 1px 0 rgba(255,255,255,0.22) inset,
        0 -1px 0 rgba(0,0,0,0.2) inset,
        0 6px 22px -4px rgba(236,72,153,0.55),
        0 3px 10px rgba(0,0,0,0.3);
}

.btn-secondary {
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--surface3); border-color: var(--border-strong); }

.btn-danger {
    background: linear-gradient(135deg, #F43F5E 0%, #E11D48 100%);
    color: white;
    box-shadow: 0 4px 14px -4px rgba(244, 63, 94, 0.5);
}
.btn-danger:hover { filter: brightness(1.08); }

.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-block { width: 100%; }

.link-btn {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 14px;
}

.error-msg {
    color: var(--red);
    font-size: 13px;
    margin-top: 8px;
}

.success-msg {
    color: var(--green);
    font-size: 13px;
    margin-top: 8px;
}

/* --- Dashboard Layout --- */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 240px;
    background: linear-gradient(180deg, var(--sidebar-a) 0%, var(--sidebar-b) 100%);
    border-right: 1px solid var(--border);
    padding: 20px 14px;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(10px);
    z-index: 10;
}

.sidebar .logo {
    font-size: 18px;
    font-weight: 800;
    margin-bottom: 18px;
    padding: 0 8px;
    letter-spacing: -0.02em;
}

.sidebar .logo span {
    background: var(--grad-text);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Sidebar profile block */
.sidebar-profile {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 10px 8px 18px;
    margin-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.sidebar-portrait {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--surface2) center/cover no-repeat;
    color: var(--text2);
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700;
    flex-shrink: 0;
    border: 1px solid var(--border);
}

.sidebar-who { min-width: 0; flex: 1; }
.sidebar-name { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-biz { font-size: 11px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.nav-items { flex: 1; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text2);
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.12s ease;
    margin-bottom: 2px;
    position: relative;
}

.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active {
    background: var(--accent-soft);
    color: var(--text);
    font-weight: 600;
}
.nav-item.active::before {
    content: '';
    position: absolute; left: 0; top: 20%; bottom: 20%;
    width: 3px; border-radius: 3px;
    background: var(--grad-primary);
    box-shadow: 0 0 12px -2px var(--accent);
}
.nav-item.active svg {
    color: var(--accent2);
}

.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }

.sidebar-footer {
    padding-top: 14px;
    border-top: 1px solid var(--border);
}

/* Portrait preview in settings */
.portrait-preview {
    width: 96px; height: 96px;
    border-radius: 50%;
    background: var(--surface2) center/cover no-repeat;
    border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    color: var(--text3); font-size: 11px;
    flex-shrink: 0;
}

/* Color legend */
.legend-row {
    display: flex; gap: 16px; flex-wrap: wrap;
    margin-bottom: 14px; padding: 10px 14px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-sm); font-size: 12px;
    color: var(--text2);
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

.main-content {
    flex: 1;
    margin-left: 240px;
    padding: 32px;
    max-width: 1200px;
}

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

.page-header h2 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.025em;
}
.page-header h2 span {
    background: var(--grad-text);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* --- Cards / Panels --- */
.card {
    background: linear-gradient(180deg, var(--surface-a), var(--surface-b));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    margin-bottom: 14px;
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(4px);
    transition: border-color 0.15s, box-shadow 0.2s;
}
.card:hover { border-color: var(--border-strong); }

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.card-header h3 {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.card h3 { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }

/* --- Stats Row --- */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: linear-gradient(180deg, var(--surface-a), var(--surface-b));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    transition: border-color 0.15s, transform 0.15s, box-shadow 0.2s;
    position: relative;
    overflow: hidden;
}
.stat-card::after {
    content: '';
    position: absolute;
    top: -60%; right: -40%;
    width: 160px; height: 160px;
    background: radial-gradient(circle, rgba(139,92,246,0.18), transparent 70%);
    pointer-events: none;
    transition: opacity 0.2s;
    opacity: 0.7;
}
.stat-card:hover {
    border-color: var(--border-strong);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}
.stat-card:hover::after { opacity: 1; }

.stat-card .label {
    font-size: 11px;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    font-weight: 600;
    position: relative; z-index: 1;
}

.stat-card .value {
    font-size: 32px;
    font-weight: 800;
    margin-top: 6px;
    letter-spacing: -0.025em;
    background: var(--grad-text);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    position: relative; z-index: 1;
}

/* --- Table --- */
.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text2);
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

tr:hover td { background: var(--surface2); }

/* --- Badge --- */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    border: 1px solid transparent;
}

.badge-lead { background: rgba(59,130,246,0.14); color: #93C5FD; border-color: rgba(59,130,246,0.25); }
.badge-active { background: rgba(16,185,129,0.14); color: #6EE7B7; border-color: rgba(16,185,129,0.25); }
.badge-inactive { background: rgba(148,163,184,0.12); color: #CBD5E1; border-color: rgba(148,163,184,0.2); }

/* --- Chat / Messages --- */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 180px);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.chat-input {
    display: flex;
    gap: 8px;
    padding: 16px;
    border-top: 1px solid var(--border);
}

.chat-input input,
.chat-input textarea {
    flex: 1;
    resize: vertical;
    min-height: 36px;
    max-height: 200px;
    font-family: inherit;
    font-size: inherit;
    line-height: 1.4;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
}

/* --- Calendar --- */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
}

.calendar-day {
    background: var(--surface2);
    border-radius: 8px;
    padding: 8px;
    min-height: 100px;
    font-size: 13px;
    cursor: pointer;
    transition: border-color 0.15s;
    border: 1px solid transparent;
}
.calendar-day:hover { border-color: var(--accent); }

.calendar-day .day-num {
    font-weight: 600;
    margin-bottom: 4px;
}

.calendar-event {
    background: var(--accent);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    margin-bottom: 2px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: filter 0.12s;
}
.calendar-event:hover { filter: brightness(1.08); }

/* --- Day timeline view --- */
.day-hour-row {
    display: flex;
    border-bottom: 1px solid var(--border);
    min-height: 48px;
    position: relative;
}
.day-hour-label {
    width: 64px;
    padding: 4px 12px 0;
    font-size: 11px;
    color: var(--text2);
    text-align: right;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
}
.day-hour-cell {
    flex: 1;
    position: relative;
}
.day-event {
    position: absolute;
    left: 4px;
    right: 4px;
    background: var(--accent);
    color: white;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    overflow: hidden;
    cursor: pointer;
    z-index: 2;
    border-left: 3px solid rgba(0,0,0,0.25);
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    transition: filter 0.12s, transform 0.08s;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    line-height: 1.25;
}
.day-event:hover { filter: brightness(1.08); }
.day-event:active { transform: translateY(1px); }
.day-event .event-time,
.day-event .event-title,
.day-event .event-client {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.day-event .event-time { font-size: 10px; opacity: 0.85; }
.day-event .event-title { font-size: 12.5px; font-weight: 600; }
.day-event .event-client { font-size: 11px; opacity: 0.85; }
.day-event .event-title-compact { font-size: 11px; font-weight: 600; }
.day-event .event-recur { font-size: 10px; opacity: 0.9; margin-right: 2px; }

/* Now line */
.now-line {
    position: absolute;
    left: 64px;
    right: 0;
    height: 2px;
    background: var(--red);
    z-index: 5;
    pointer-events: none;
}
.now-line::before {
    content: '';
    position: absolute;
    left: -5px;
    top: -4px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--red);
}
.now-label {
    position: absolute;
    left: 4px;
    font-size: 10px;
    color: var(--red);
    font-weight: 600;
    transform: translateY(-50%);
    z-index: 5;
}

/* --- Modal --- */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--overlay);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: overlayIn 0.18s ease;
}
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }

.modal-overlay.hidden { display: none; }

.modal {
    background: linear-gradient(180deg, var(--surface-strong-a), var(--surface-strong-b));
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    padding: 32px;
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.22s cubic-bezier(.17,.67,.3,1.17);
}
@keyframes modalIn { from { opacity: 0; transform: translateY(12px) scale(0.97); } to { opacity: 1; transform: none; } }

.modal h3 { font-size: 18px; font-weight: 700; letter-spacing: -0.015em; margin-bottom: 20px; }
}

.modal h3 { margin-bottom: 20px; }

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 24px;
}

/* --- Tabs --- */
.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.tab {
    padding: 10px 20px;
    background: none;
    border: none;
    color: var(--text2);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}

.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* --- Toggle switch --- */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.toggle-row:last-child { border-bottom: none; }

.toggle-label { font-size: 14px; }
.toggle-desc { font-size: 12px; color: var(--text2); }

.toggle {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle .slider {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--border);
    border-radius: 24px;
    cursor: pointer;
    transition: 0.2s;
}

.toggle .slider:before {
    content: '';
    position: absolute;
    width: 18px; height: 18px;
    left: 3px; top: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.2s;
}

.toggle input:checked + .slider {
    background: var(--grad-primary);
    box-shadow: 0 0 14px -3px var(--accent);
}
.toggle input:checked + .slider:before { transform: translateX(20px); }

/* --- Empty state --- */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text2);
}

.empty-state h3 { color: var(--text); margin-bottom: 8px; }

/* --- Contact list (Messages + Email sidebar) --- */
.msg-contact {
    padding: 14px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: all 0.15s;
    position: relative;
    border-left: 3px solid transparent;
}
.msg-contact:hover { background: var(--surface2); }
.msg-contact.active {
    background: var(--surface2);
    border-left-color: var(--accent);
}
.msg-contact .contact-name {
    font-weight: 600;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
}
.msg-contact .contact-preview {
    font-size: 12px;
    color: var(--text2);
    margin-top: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}
.msg-contact .contact-time {
    position: absolute;
    top: 14px;
    right: 16px;
    font-size: 11px;
    color: var(--text2);
}
.msg-contact.unread .contact-name { color: #fff; }
.msg-contact.unread .contact-preview { color: var(--text); font-weight: 500; }
.msg-contact.unread {
    border-left-color: var(--accent);
    background: var(--accent-soft);
}
.msg-contact.unread:hover {
    background: var(--accent-soft-2);
}
.unread-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--pink);
    box-shadow: 0 0 8px var(--pink), 0 0 16px rgba(236, 72, 153, 0.5);
    flex-shrink: 0;
    animation: pulse-dot 2s ease-in-out infinite;
}
@keyframes pulse-dot {
    0%, 100% { box-shadow: 0 0 6px var(--accent), 0 0 12px rgba(108, 99, 255, 0.4); }
    50% { box-shadow: 0 0 10px var(--accent), 0 0 20px rgba(108, 99, 255, 0.6); }
}

/* Contact list container */
.contact-list-wrap {
    width: 300px;
    overflow-y: auto;
    flex-shrink: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.contact-list-wrap .search-bar {
    padding: 12px;
    border-bottom: 1px solid var(--border);
}
.contact-list-wrap .search-bar input {
    font-size: 13px;
    padding: 10px 12px;
    background: var(--bg);
    border-radius: 8px;
}

/* Unread badge on nav item */
.nav-badge {
    background: var(--grad-primary);
    color: white;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: inline-flex;
    box-shadow: 0 0 12px -2px var(--pink);
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    margin-left: auto;
}

/* Chat bubble improvements */
.chat-bubble {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 16px;
    margin-bottom: 6px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
}
.chat-bubble.inbound {
    background: var(--surface2);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}
.chat-bubble.outbound {
    background: var(--grad-primary);
    color: white;
    box-shadow: 0 4px 14px -4px rgba(139, 92, 246, 0.4);
    align-self: flex-end;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}
.chat-bubble.pending {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #000;
    border-bottom-right-radius: 4px;
    align-self: flex-end;
    margin-left: auto;
}
.chat-bubble .bubble-time {
    font-size: 10px;
    opacity: 0.5;
    margin-top: 3px;
}
.chat-bubble .bubble-ai {
    font-size: 10px;
    opacity: 0.7;
    margin-left: 4px;
}

/* Date separator in chat */
.chat-date-sep {
    text-align: center;
    font-size: 11px;
    color: var(--text2);
    padding: 12px 0 6px;
    position: relative;
}
.chat-date-sep::before {
    content: '';
    position: absolute;
    left: 0; right: 0; top: 50%;
    border-top: 1px solid var(--border);
}
.chat-date-sep span {
    background: var(--surface);
    padding: 0 12px;
    position: relative;
}

/* --- Event category colors --- */
.day-event.event-recurring,
.calendar-event.event-recurring {
    background: linear-gradient(135deg, #8B5CF6 0%, #EC4899 100%);
    box-shadow: 0 2px 8px -2px rgba(139, 92, 246, 0.5);
}
.day-event.event-consult,
.calendar-event.event-consult {
    background: linear-gradient(135deg, #F59E0B 0%, #F97316 100%);
    box-shadow: 0 2px 8px -2px rgba(245, 158, 11, 0.45);
}
.day-event.event-session,
.calendar-event.event-session {
    background: linear-gradient(135deg, #10B981 0%, #059669 100%);
    box-shadow: 0 2px 8px -2px rgba(16, 185, 129, 0.45);
}
.day-event.event-virtual-session,
.calendar-event.event-virtual-session {
    background: linear-gradient(135deg, #06B6D4 0%, #3B82F6 100%);
    box-shadow: 0 2px 8px -2px rgba(6, 182, 212, 0.45);
}
.day-event.event-video-consult,
.calendar-event.event-video-consult {
    background: linear-gradient(135deg, #3B82F6 0%, #6366F1 100%);
    box-shadow: 0 2px 8px -2px rgba(59, 130, 246, 0.5);
}

/* Swatches for the legend */
.swatch-recurring { background: linear-gradient(135deg, #8B5CF6, #EC4899); }
.swatch-session { background: linear-gradient(135deg, #10B981, #059669); }
.swatch-virtual-session { background: linear-gradient(135deg, #06B6D4, #3B82F6); }
.swatch-consult { background: linear-gradient(135deg, #F59E0B, #F97316); }
.swatch-video-consult { background: linear-gradient(135deg, #3B82F6, #6366F1); }

/* --- Series day chips --- */
.series-day-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    user-select: none;
    background: var(--surface);
}
.series-day-chip input[type="checkbox"] { margin: 0; }
.series-day-chip:has(input:checked) {
    background: var(--grad-primary);
    color: white;
    border-color: transparent;
    box-shadow: 0 2px 10px -2px rgba(139, 92, 246, 0.55);
}

/* --- Sections hidden by default --- */
.section { display: none; }
.section.active { display: block; }

/* ─── Responsive ─────────────────────────────────────────────────────────
   Global overflow guard + three breakpoints (tablet / phone / small phone).
   Targets every section that has fixed widths, inline display:flex, or
   side-by-side layouts that don't fit on a narrow viewport. */

/* Global: never allow horizontal scroll of the page itself. Individual
   scrollable areas (tables, calendar timelines) opt in below. */
html, body { overflow-x: hidden; }
img, video, svg { max-width: 100%; height: auto; }

/* --- Tablet / small laptop (≤ 1024px) --- */
@media (max-width: 1024px) {
    .main-content { padding: 24px; }
    .modal { padding: 24px; }
}

/* --- Phone landscape / small tablet (≤ 768px) --- */
@media (max-width: 768px) {
    /* Sidebar shrinks to icon rail */
    .sidebar {
        width: 60px;
        padding: 16px 8px;
    }
    .sidebar .logo span,
    .nav-item span,
    .sidebar-footer span,
    .sidebar-who { display: none; }
    .sidebar-profile {
        justify-content: center;
        padding: 8px 0 14px;
        gap: 0;
    }
    .sidebar-portrait { width: 32px; height: 32px; }
    .nav-item { justify-content: center; padding: 10px; }
    .nav-item.active::before { display: none; }

    .main-content {
        margin-left: 60px;
        padding: 16px;
        max-width: calc(100vw - 60px);
    }

    /* Page header — wraps already, just tighten */
    .page-header { margin-bottom: 16px; gap: 8px; }
    .page-header h2 { font-size: 20px; }

    /* Cards — less padding, full-width */
    .card { padding: 16px; border-radius: 12px; }

    /* Forms — full-width inputs, 16px font prevents iOS auto-zoom on focus */
    .form-group input,
    .form-group textarea,
    .form-group select {
        width: 100%;
        font-size: 16px;
    }

    /* Auth (login / signup) — tighter card padding */
    .auth-card { padding: 24px 20px; margin: 16px auto; }

    /* Stats row — 2 columns */
    .stats-row { grid-template-columns: repeat(2, 1fr); gap: 10px; }

    /* Tables — horizontal scroll inside container */
    .table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Tabs — horizontal scroll if too many */
    .tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
    }
    .tab { padding: 10px 14px; font-size: 13px; white-space: nowrap; flex-shrink: 0; }

    /* Modal — closer to edges, scroll if tall */
    .modal {
        max-width: calc(100vw - 24px);
        max-height: calc(100vh - 24px);
        padding: 20px;
        border-radius: 14px;
    }
    .modal-actions { flex-wrap: wrap; }
    .modal-actions .btn { flex: 1; min-width: 0; }

    /* Messages section — stack contact list ABOVE chat instead of side-by-side.
       Inline `display:flex` on #sec-messages > div needs !important to win. */
    #sec-messages > div[style*="flex"] {
        flex-direction: column !important;
        height: auto !important;
    }
    .contact-list-wrap {
        width: 100% !important;
        max-height: 240px;
    }
    .msg-contact .contact-preview { max-width: 100%; }
    .chat-messages { padding: 12px; }
    .chat-input { padding: 12px; }

    /* Toggle row — keep horizontal but tighten gap */
    .toggle-row { gap: 12px; }

    /* Calendar — month grid: smaller cells */
    .calendar-day {
        min-height: 72px;
        padding: 6px 5px;
        font-size: 11px;
    }
    .calendar-event { font-size: 10px; padding: 1px 4px; }

    /* Calendar — day view timeline: narrower hour gutter */
    .day-hour-label { width: 48px; padding: 4px 8px 0; font-size: 10px; }
    .now-line { left: 48px; }
    .day-event { font-size: 11px; padding: 3px 8px; }
    .day-event .event-title { font-size: 12px; }

    /* Legend wraps tighter */
    .legend-row { gap: 8px; padding: 8px 10px; font-size: 11px; }
}

/* --- Phone portrait (≤ 480px) --- */
@media (max-width: 480px) {
    .sidebar {
        width: 52px;
        padding: 12px 4px;
    }
    .main-content {
        margin-left: 52px;
        padding: 12px;
        max-width: calc(100vw - 52px);
    }

    .page-header h2 { font-size: 18px; }
    .page-header { gap: 6px; }

    /* Stats — 1 column */
    .stats-row { grid-template-columns: 1fr; gap: 8px; }

    /* Cards — smaller padding/radius */
    .card { padding: 14px; border-radius: 10px; margin-bottom: 10px; }

    /* Auth — closer to edges */
    .auth-card { padding: 20px 16px; margin: 8px auto; }

    /* Modal — near full-screen */
    .modal {
        max-width: calc(100vw - 12px);
        max-height: calc(100vh - 12px);
        padding: 16px;
        border-radius: 12px;
    }

    /* Calendar — month grid: very compact */
    .calendar-day {
        min-height: 56px;
        padding: 4px;
        font-size: 10px;
    }
    .calendar-event { font-size: 9px; padding: 1px 3px; }

    /* Day view — even narrower gutter */
    .day-hour-label { width: 40px; font-size: 9px; padding: 3px 6px 0; }
    .now-line { left: 40px; }

    /* Buttons — tap-friendly minimum height */
    .btn { min-height: 40px; }
    .btn-sm { min-height: 36px; padding: 8px 12px; }

    /* Chat list — tighter rows */
    .msg-contact { padding: 10px 12px; }
    .msg-contact .contact-time { top: 10px; right: 12px; font-size: 10px; }

    /* Contact list cap shorter so chat thread has room */
    .contact-list-wrap { max-height: 200px; }
}

/* --- iOS safe area (notch / home indicator) --- */
@supports (padding: max(0px)) {
    .sidebar { padding-bottom: max(20px, env(safe-area-inset-bottom)); }
    .main-content { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
}
