/* ===== CSS Variables ===== */
:root,
[data-theme="light"] {
    --bg-primary: #F8F7F4;
    --bg-surface: #FFFFFF;
    --bg-hover: #F2F1EE;
    --text-primary: #1A1A1A;
    --text-secondary: #6B6B6B;
    --text-muted: #9A9A9A;
    --accent: #2D5A27;
    --accent-hover: #234A1E;
    --accent-light: #E8F0E7;
    --border: #E5E3DF;
    --border-light: #F0EEEA;
    --danger: #C44536;
    --danger-hover: #A83A2D;
    --danger-light: #FCEAE8;
    --warning: #B8860B;
    --warning-light: #FFF8E1;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.06);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.08);
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

[data-theme="dark"] {
    --bg-primary: #141414;
    --bg-surface: #1E1E1E;
    --bg-hover: #252525;
    --text-primary: #E8E6E3;
    --text-secondary: #8A8A8A;
    --text-muted: #5A5A5A;
    --accent: #5BAD4E;
    --accent-hover: #4A9A3E;
    --accent-light: #1A2E19;
    --border: #2A2A2A;
    --border-light: #222222;
    --danger: #E55A4A;
    --danger-hover: #D04A3A;
    --danger-light: #2A1A18;
    --warning: #D4A017;
    --warning-light: #2A2510;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.3);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.4);
}

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

html {
    font-size: 14px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ===== Typography ===== */
h1 { font-size: 1.5rem; font-weight: 600; letter-spacing: -0.02em; }
h2 { font-size: 1.25rem; font-weight: 600; letter-spacing: -0.01em; }
h3 { font-size: 1.1rem; font-weight: 600; }

.mono { font-family: 'JetBrains Mono', monospace; font-size: 0.85em; }
.text-muted { color: var(--text-muted); }

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

/* ===== Sidebar ===== */
.sidebar {
    width: 240px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
}

.sidebar-header {
    padding: 20px 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--accent);
}

.sidebar-title {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    font-size: 1.1rem;
    letter-spacing: 0.05em;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.15s ease;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--accent-light);
    color: var(--accent);
}

.nav-item svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.nav-item.active svg {
    opacity: 1;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent-light);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.user-details {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.user-name {
    font-weight: 500;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    margin-left: 240px;
    display: flex;
    flex-direction: column;
}

.main-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 32px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.header-left {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.header-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.content {
    flex: 1;
    padding: 24px 32px;
}

/* ===== Theme Toggle ===== */
.theme-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
}

.theme-toggle-track {
    width: 44px;
    height: 24px;
    background: var(--border);
    border-radius: 12px;
    position: relative;
    transition: background 0.2s ease;
}

[data-theme="dark"] .theme-toggle-track {
    background: var(--accent);
}

.theme-toggle-thumb {
    width: 20px;
    height: 20px;
    background: var(--bg-surface);
    border-radius: 50%;
    position: absolute;
    top: 2px;
    left: 2px;
    transition: transform 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

[data-theme="dark"] .theme-toggle-thumb {
    transform: translateX(20px);
}

.theme-toggle .icon-sun { display: block; color: #B8860B; }
.theme-toggle .icon-moon { display: none; color: #E8E6E3; }

[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

.theme-toggle-sm {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.theme-toggle-sm:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.theme-toggle-sm .icon-sun { display: block; }
.theme-toggle-sm .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle-sm .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle-sm .icon-moon { display: block; }

/* ===== Cards ===== */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.card-body {
    padding: 20px;
}

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

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: var(--shadow-sm);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-icon-total { background: var(--accent-light); color: var(--accent); }
.stat-icon-new { background: #E8F0F8; color: #2563EB; }
[data-theme="dark"] .stat-icon-new { background: #1A2332; }
.stat-icon-progress { background: #FFF8E1; color: #B8860B; }
[data-theme="dark"] .stat-icon-progress { background: #2A2510; }
.stat-icon-closed { background: var(--accent-light); color: var(--accent); }

.stat-content {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.5rem;
    font-weight: 600;
    line-height: 1;
}

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

/* ===== Banner ===== */
.banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    margin-bottom: 24px;
    font-size: 0.9rem;
}

.banner-warning {
    background: var(--warning-light);
    color: var(--warning);
    border: 1px solid var(--warning);
    border-color: rgba(184, 134, 11, 0.3);
}

.banner-link {
    margin-left: auto;
    color: var(--warning);
    text-decoration: none;
    font-weight: 500;
}

.banner-link:hover {
    text-decoration: underline;
}

/* ===== Tables ===== */
.table-responsive {
    overflow-x: auto;
}

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

.table th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 500;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
    font-size: 0.9rem;
}

.table tr:last-child td {
    border-bottom: none;
}

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

/* ===== Badges ===== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    font-family: 'JetBrains Mono', monospace;
}

.badge-new { background: #E8F0F8; color: #2563EB; }
.badge-progress { background: #FFF8E1; color: #B8860B; }
.badge-closed { background: var(--accent-light); color: var(--accent); }
.badge-admin { background: var(--accent-light); color: var(--accent); }
.badge-manager { background: #E8F0F8; color: #2563EB; }

[data-theme="dark"] .badge-new { background: #1A2332; }
[data-theme="dark"] .badge-manager { background: #1A2332; }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-hover);
}

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

.btn-danger:hover {
    background: var(--danger-hover);
}

.btn-sm {
    padding: 4px 10px;
    font-size: 0.8rem;
}

.btn-full {
    width: 100%;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.btn-icon:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

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

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

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color 0.15s ease;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

.form-error {
    background: var(--danger-light);
    color: var(--danger);
    padding: 10px 12px;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    margin-top: 12px;
}

/* ===== Form Section ===== */
.form-divider {
    border-top: 1px solid var(--border);
    margin: 20px 0 16px;
}

.form-section-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 14px;
}

textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: 'JetBrains Mono', monospace;
    resize: vertical;
    transition: border-color 0.15s ease;
}

textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.badge-active { background: var(--accent-light); color: var(--accent); }
.badge-none { background: var(--bg-hover); color: var(--text-muted); }

/* ===== Select ===== */
.select {
    padding: 8px 32px 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
    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' fill='none' stroke='%236B6B6B' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
}

.select:focus {
    outline: none;
    border-color: var(--accent);
}

.select-sm {
    padding: 4px 28px 4px 8px;
    font-size: 0.8rem;
}

.select-full {
    width: 100%;
}

/* ===== Progress Bar ===== */
.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.3s ease;
}

/* ===== Filters ===== */
.filters-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 12px;
}

.filters-left {
    display: flex;
    gap: 8px;
}

.leads-count {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.4);
}

[data-theme="dark"] .modal-backdrop {
    background: rgba(0,0,0,0.6);
}

.modal-content {
    position: relative;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 440px;
    margin: 16px;
}

.modal-sm {
    max-width: 360px;
}

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

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
}

.modal-body p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.5;
}

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

/* ===== Login ===== */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    width: 100%;
    max-width: 380px;
    padding: 32px;
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo {
    width: 56px;
    height: 56px;
    background: var(--accent-light);
    color: var(--accent);
    border-radius: var(--radius-md);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
}

.login-header h1 {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.5rem;
    letter-spacing: 0.1em;
    margin-bottom: 4px;
}

.login-header p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.login-footer {
    display: flex;
    justify-content: center;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* ===== Empty State ===== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 20px;
    color: var(--text-muted);
}

.empty-state p {
    margin-top: 12px;
    font-size: 0.9rem;
}

/* ===== Spinner ===== */
.spinner {
    width: 18px;
    height: 18px;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.btn-loader {
    display: inline-flex;
    align-items: center;
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .main-content {
        margin-left: 0;
    }

    .main-header {
        padding: 16px 20px;
    }

    .content {
        padding: 16px 20px;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .filters-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .filters-left {
        flex-direction: column;
    }
}

/* ===== Status select colors ===== */
.status-select {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
}

.status-select option[value="new"] { color: #2563EB; }
.status-select option[value="in_progress"] { color: #B8860B; }
.status-select option[value="closed"] { color: #2D5A27; }

/* ===== Transitions ===== */
* {
    transition-property: background-color, border-color, color, box-shadow;
    transition-duration: 0s;
}

html {
    transition: none;
}

html[data-theme-transition] * {
    transition-duration: 0.2s;
    transition-timing-function: ease;
}

/* ===== Log Viewer ===== */
.log-container {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    height: calc(100vh - 160px);
    overflow-y: auto;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    line-height: 1.6;
    padding: 12px 16px;
}

.log-empty {
    color: var(--text-muted);
    text-align: center;
    padding: 40px;
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
}

.log-line {
    padding: 2px 0;
    border-bottom: 1px solid var(--border-light);
    word-break: break-all;
}

.log-line:last-child {
    border-bottom: none;
}

.log-time {
    color: var(--text-muted);
    margin-right: 6px;
}

.log-level {
    display: inline-block;
    min-width: 56px;
    text-align: center;
    padding: 0 6px;
    border-radius: 3px;
    font-weight: 600;
    font-size: 0.7rem;
    margin-right: 6px;
}

.log-info { background: #E8F0F8; color: #2563EB; }
.log-warn { background: #FFF8E1; color: #B8860B; }
.log-error { background: #FCEAE8; color: #C44536; }
.log-debug { background: var(--bg-hover); color: var(--text-muted); }

[data-theme="dark"] .log-info { background: #1A2332; }
[data-theme="dark"] .log-warn { background: #2A2510; }
[data-theme="dark"] .log-error { background: #2A1A18; }

.log-name {
    color: var(--text-muted);
    margin-right: 6px;
}

.log-msg {
    color: var(--text-primary);
}

.log-toggle-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
}

.log-toggle-label input {
    accent-color: var(--accent);
}

/* ===== Help Icon Tooltip ===== */
.help-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--border);
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 700;
    cursor: help;
    margin-left: 5px;
    vertical-align: middle;
    position: relative;
    line-height: 1;
    flex-shrink: 0;
}

.help-icon:hover {
    background: var(--accent);
    color: #fff;
}

.help-icon[data-tip]:hover::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    font-size: 0.78rem;
    font-weight: 400;
    font-family: 'JetBrains Mono', monospace;
    white-space: pre-wrap;
    text-align: left;
    min-width: 320px;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
    z-index: 300;
    pointer-events: none;
    line-height: 1.5;
}
/* ===== Toggle Switch ===== */
.toggle {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
    flex-shrink: 0;
}

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

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

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    left: 3px;
    bottom: 3px;
    background: var(--bg-surface);
    border-radius: 50%;
    transition: transform 0.2s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.toggle input:checked + .toggle-slider {
    background: var(--accent);
}

.toggle input:checked + .toggle-slider::before {
    transform: translateX(18px);
}

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

.settings-tab {
    padding: 8px 16px;
    border: none;
    background: none;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: all 0.15s ease;
}

.settings-tab:hover {
    color: var(--text-primary);
}

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