/* ClioForms Design System */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
    --primary: #4F46E5;
    --primary-gradient: linear-gradient(135deg, #4F46E5, #7C3AED);
    --primary-light: #EEF2FF;
    --primary-hover: #4338CA;
    --primary-50: rgba(79, 70, 229, 0.05);
    --primary-100: rgba(79, 70, 229, 0.1);

    --text-primary: #111827;
    --text-secondary: #6B7280;
    --text-muted: #9CA3AF;

    --bg: #FFFFFF;
    --surface: #F9FAFB;
    --border: #E5E7EB;

    --success: #10B981;
    --warning: #F59E0B;
    --error: #EF4444;

    --shadow-card: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-elevated: 0 10px 25px rgba(79,70,229,0.1), 0 4px 10px rgba(0,0,0,0.05);
    --shadow-modal: 0 25px 50px rgba(0,0,0,0.15);

    --radius-card: 16px;
    --radius-btn: 12px;
    --radius-input: 12px;
    --radius-bubble: 16px;

    --font-heading: 'Plus Jakarta Sans', sans-serif;
    --font-body: 'Inter', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Theme */
[data-theme="dark"] {
    --primary: #818CF8;
    --primary-gradient: linear-gradient(135deg, #6366F1, #8B5CF6);
    --primary-light: #1E1B4B;
    --primary-hover: #6366F1;
    --primary-50: rgba(99, 102, 241, 0.08);
    --primary-100: rgba(99, 102, 241, 0.15);

    --text-primary: #F3F4F6;
    --text-secondary: #9CA3AF;
    --text-muted: #6B7280;

    --bg: #0F172A;
    --surface: #1E293B;
    --border: #334155;

    --success: #34D399;
    --warning: #FBBF24;
    --error: #F87171;

    --shadow-card: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
    --shadow-elevated: 0 10px 25px rgba(0,0,0,0.4), 0 4px 10px rgba(0,0,0,0.3);
    --shadow-modal: 0 25px 50px rgba(0,0,0,0.5);
}

@media (prefers-color-scheme: dark) {
    [data-theme="system"] {
        --primary: #818CF8;
        --primary-gradient: linear-gradient(135deg, #6366F1, #8B5CF6);
        --primary-light: #1E1B4B;
        --primary-hover: #6366F1;
        --primary-50: rgba(99, 102, 241, 0.08);
        --primary-100: rgba(99, 102, 241, 0.15);
        --text-primary: #F3F4F6;
        --text-secondary: #9CA3AF;
        --text-muted: #6B7280;
        --bg: #0F172A;
        --surface: #1E293B;
        --border: #334155;
        --success: #34D399;
        --warning: #FBBF24;
        --error: #F87171;
        --shadow-card: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
        --shadow-elevated: 0 10px 25px rgba(0,0,0,0.4), 0 4px 10px rgba(0,0,0,0.3);
        --shadow-modal: 0 25px 50px rgba(0,0,0,0.5);
    }
}

/* Logo dark mode fix — white bg becomes transparent */
[data-theme="dark"] .nav-logo img,
[data-theme="dark"] .nav-brand img,
[data-theme="dark"] .clio-avatar {
    border-radius: 50%;
}

@media (prefers-color-scheme: dark) {
    [data-theme="system"] .nav-logo img,
    [data-theme="system"] .nav-brand img,
    [data-theme="system"] .clio-avatar {
        border-radius: 50%;
    }
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }
body {
    font-family: var(--font-body);
    color: var(--text-primary);
    background: var(--bg);
    line-height: 1.6;
    min-height: 100vh;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    font-weight: 700;
    line-height: 1.3;
}
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }

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

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-btn);
    font-family: var(--font-body);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 150ms var(--ease);
    text-decoration: none;
}
.btn:hover { transform: scale(1.02); }
.btn:active { transform: scale(0.98); }

.btn-primary {
    background: var(--primary-gradient);
    color: white;
    box-shadow: 0 2px 8px rgba(79,70,229,0.3);
}
.btn-primary:hover { box-shadow: 0 4px 16px rgba(79,70,229,0.4); }

.btn-secondary {
    background: var(--primary-light);
    color: var(--primary);
}
.btn-secondary:hover { background: #E0E7FF; }

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1.5px solid var(--primary);
}
.btn-outline:hover { background: var(--primary-light); }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--surface); color: var(--text-primary); }

.btn-danger {
    background: var(--error);
    color: white;
}

.btn-sm { padding: 6px 14px; font-size: 0.8rem; }
.btn-lg { padding: 14px 28px; font-size: 1rem; }

.btn-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}
.btn-loading::after {
    content: '';
    position: absolute;
    width: 20px; height: 20px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* Inputs */
.input, input[type="text"], input[type="email"], input[type="password"], input[type="number"], textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-input);
    font-family: var(--font-body);
    font-size: 0.9375rem;
    color: var(--text-primary);
    background: var(--bg);
    transition: border-color 200ms var(--ease), box-shadow 200ms var(--ease);
    outline: none;
}
.input:focus, input:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-100);
}
.input::placeholder, input::placeholder, textarea::placeholder {
    color: var(--text-muted);
}

.input-group {
    margin-bottom: 16px;
}
.input-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}
.input-error {
    font-size: 0.8rem;
    color: var(--error);
    margin-top: 4px;
}

/* Cards */
.card {
    background: var(--bg);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    border: 1px solid var(--border);
    padding: 24px;
    transition: transform 200ms var(--ease), box-shadow 200ms var(--ease);
}
.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-elevated);
}
.card-flat {
    box-shadow: none;
}
.card-flat:hover {
    transform: none;
    box-shadow: none;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-active { background: #D1FAE5; color: #065F46; }
.badge-paused { background: #FEF3C7; color: #92400E; }
.badge-closed { background: #FEE2E2; color: #991B1B; }
.badge-primary { background: var(--primary-light); color: var(--primary); }

/* Navigation */
.nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 32px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}
.nav-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 1.25rem;
    color: var(--text-primary);
}
.nav-logo svg { width: 28px; height: 28px; }
.nav-links {
    display: flex;
    align-items: center;
    gap: 8px;
}
.nav-link {
    padding: 8px 16px;
    border-radius: var(--radius-btn);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 150ms var(--ease);
}
.nav-link:hover, .nav-link.active {
    background: var(--primary-light);
    color: var(--primary);
}
.nav-right {
    display: flex;
    align-items: center;
    gap: 12px;
}
.nav-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--primary-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 0.875rem;
    cursor: pointer;
}

/* Page Container */
.page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px;
}

/* Grid */
.grid { display: grid; gap: 24px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 768px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .nav { padding: 10px 12px; }
    .nav-links { display: none !important; }
    .page { padding: 12px; }
    h1 { font-size: 1.3rem; }
    h2 { font-size: 1.15rem; }

    /* Tables scroll horizontally */
    .table-container { margin: 0 -12px; border-radius: 0; border-left: none; border-right: none; }
    .table th, .table td { padding: 8px 6px; font-size: 0.75rem; white-space: nowrap; }

    /* Tabs scroll */
    .tabs { overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
    .tabs::-webkit-scrollbar { display: none; }
    .tab { padding: 10px 14px; font-size: 0.8rem; flex-shrink: 0; }

    /* Panels full width */
    .side-panel { width: 100% !important; }
    .modal { max-width: 95% !important; padding: 24px !important; }

    /* Stack layouts */
    .flex-between { flex-wrap: wrap; gap: 8px; }
    .responses-header { flex-direction: column; align-items: flex-start; }
    .insights-grid { grid-template-columns: 1fr !important; }
    .forms-grid { grid-template-columns: 1fr !important; }
    .replay-container { grid-template-columns: 1fr !important; }

    /* Buttons smaller */
    .btn { padding: 8px 16px; font-size: 0.8rem; }
    .btn-lg { padding: 12px 24px; }
}

/* Tables */
.table-container {
    overflow-x: auto;
    border-radius: var(--radius-card);
    border: 1px solid var(--border);
}
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
.table th {
    background: var(--surface);
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}
.table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}
.table tr:nth-child(even) { background: var(--primary-50); }
.table tr:hover { background: var(--primary-light); cursor: pointer; }
.table tr:last-child td { border-bottom: none; }

/* Tabs */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid var(--border);
    margin-bottom: 24px;
}
.tab {
    padding: 12px 20px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    transition: all 150ms var(--ease);
}
.tab:hover { color: var(--primary); }
.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}

/* Progress Bar */
.progress-bar {
    width: 100%;
    height: 4px;
    background: var(--primary-light);
    border-radius: 2px;
    overflow: hidden;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 200;
}
.progress-bar-fill {
    height: 100%;
    background: var(--primary-gradient);
    transition: width 400ms var(--ease);
    border-radius: 2px;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 64px 32px;
}
.empty-state-icon {
    width: 80px; height: 80px;
    margin: 0 auto 24px;
    background: var(--primary-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.empty-state-icon svg { width: 36px; height: 36px; color: var(--primary); }
.empty-state h3 { margin-bottom: 8px; }
.empty-state p { color: var(--text-secondary); margin-bottom: 24px; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
    padding: 8px 16px;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 150ms var(--ease);
}
.chip:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

/* Dropdown */
.dropdown {
    position: relative;
    display: inline-block;
}
.dropdown-menu {
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-elevated);
    min-width: 200px;
    z-index: 50;
    display: none;
    overflow: hidden;
}
.dropdown-menu.show { display: block; }
.dropdown-item {
    display: block;
    padding: 10px 16px;
    font-size: 0.875rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 100ms;
}
.dropdown-item:hover { background: var(--surface); }

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    padding: 14px 20px;
    border-radius: var(--radius-btn);
    background: var(--bg);
    box-shadow: var(--shadow-elevated);
    border-left: 4px solid var(--primary);
    font-size: 0.875rem;
    animation: slideInRight 300ms var(--ease);
    max-width: 400px;
}
.toast-error { border-left-color: var(--error); }
.toast-success { border-left-color: var(--success); }

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    animation: fadeIn 200ms var(--ease);
}
.modal {
    background: var(--bg);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-modal);
    padding: 32px;
    max-width: 480px;
    width: 90%;
    animation: slideUp 300ms var(--ease);
}
.modal h3 { margin-bottom: 16px; }
.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 24px;
}

/* Confidence bar */
.confidence-bar {
    display: flex;
    align-items: center;
    gap: 8px;
}
.confidence-track {
    flex: 1;
    height: 6px;
    background: var(--surface);
    border-radius: 3px;
    overflow: hidden;
}
.confidence-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 400ms var(--ease);
}
.confidence-high { background: var(--success); }
.confidence-medium { background: var(--warning); }
.confidence-low { background: var(--error); }
.confidence-label {
    font-size: 0.75rem;
    font-weight: 600;
    min-width: 36px;
    text-align: right;
}

/* Utility */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-primary-color { color: var(--primary); }
.text-success { color: var(--success); }
.text-error { color: var(--error); }
.text-sm { font-size: 0.8rem; }
.text-xs { font-size: 0.75rem; }
.font-mono { font-family: var(--font-mono); }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mt-4 { margin-top: 32px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.gap-3 { gap: 24px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

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