/* Theme variables */
[data-theme="dark"] {
    --bg: #0f1117;
    --text: #e4e4e7;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --surface: #1a1b23;
    --surface-deep: #111118;
    --border: #27272a;
    --border-hover: #3f3f46;
    --input-bg: #27272a;
    --thead-bg: #27272a;
    --row-hover: rgba(99, 102, 241, 0.05);
    --row-border: #1f1f26;
}

[data-theme="light"] {
    --bg: #f4f4f5;
    --text: #18181b;
    --text-secondary: #52525b;
    --text-muted: #a1a1aa;
    --surface: #ffffff;
    --surface-deep: #f9fafb;
    --border: #e4e4e7;
    --border-hover: #d4d4d8;
    --input-bg: #f4f4f5;
    --thead-bg: #f4f4f5;
    --row-hover: rgba(99, 102, 241, 0.05);
    --row-border: #e4e4e7;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

header {
    margin-bottom: 1.5rem;
}

.header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-left {
    text-align: left;
}

header h1 {
    font-size: 2.2rem;
    font-weight: 700;
    background: linear-gradient(135deg, #6366f1, #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-muted);
    margin-top: 0.2rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.theme-toggle:hover {
    border-color: #6366f1;
    color: #a78bfa;
}

.logout-link {
    font-size: 0.78rem;
    color: var(--text-muted);
    text-decoration: none;
}

.logout-link:hover {
    color: var(--text-secondary);
}

/* Stats bar */
.stats-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.stat {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.7rem 0.8rem;
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 1.3rem;
    font-weight: 700;
    color: #a78bfa;
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* Onboarding */
.onboarding {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.08), rgba(167, 139, 250, 0.08));
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: 12px;
    padding: 1rem 1.5rem;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    animation: fadeIn 0.5s ease;
}

.onboarding.hidden {
    display: none;
}

.onboarding-steps {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.step {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.88rem;
    color: #c4b5fd;
}

.step-num {
    background: rgba(99, 102, 241, 0.3);
    color: #a78bfa;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
}

.step-arrow {
    color: #4b4b5e;
    font-size: 1rem;
}

.onboarding-close {
    background: none;
    border: none;
    color: #4b4b5e;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    flex-shrink: 0;
}

.onboarding-close:hover {
    color: var(--text-secondary);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Tooltips */
.tooltip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #3f3f46;
    color: var(--text-secondary);
    font-size: 0.65rem;
    font-weight: 700;
    cursor: help;
    position: relative;
    margin-left: 0.3rem;
    flex-shrink: 0;
}

.tooltip:hover::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: #27272a;
    color: #e4e4e7;
    border: 1px solid #3f3f46;
    padding: 0.5rem 0.7rem;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 400;
    white-space: nowrap;
    max-width: 280px;
    white-space: normal;
    z-index: 10;
    line-height: 1.4;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.tooltip-wrap {
    position: relative;
}

/* Progress hint */
.progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.progress-header h2 {
    font-size: 1.1rem;
    color: #a78bfa;
    margin: 0;
}

.progress-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-style: italic;
}

/* File hint */
.file-hint {
    font-size: 0.78rem;
    color: #52525b;
}

/* Table hint */
.table-hint {
    text-align: center;
    font-size: 0.8rem;
    color: #52525b;
    margin-top: 0.8rem;
    font-style: italic;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.tab {
    padding: 0.6rem 1.2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px 8px 0 0;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
}

.tab:hover {
    color: #e4e4e7;
    background: #27272a;
}

.tab.active {
    color: #a78bfa;
    background: #1a1b23;
    border-bottom-color: #1a1b23;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Search Section */
.search-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.search-row {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
    align-items: center;
}

.search-row input,
.search-row select {
    background: var(--input-bg);
    border: 1px solid var(--border-hover);
    color: var(--text);
    padding: 0.7rem 1rem;
    border-radius: 8px;
    font-size: 0.95rem;
    transition: border-color 0.2s;
}

.search-row input:focus,
.search-row select:focus {
    outline: none;
    border-color: #6366f1;
}

.input-activite { flex: 2; }
.input-ville { flex: 1.5; }
.input-rayon { flex: 0.6; min-width: 90px; }

.btn-supprimer {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0.3rem 0.6rem;
    border-radius: 6px;
    transition: all 0.2s;
}

.btn-supprimer:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

.search-actions {
    display: flex;
    justify-content: space-between;
    margin-top: 1rem;
}

.btn {
    padding: 0.7rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: linear-gradient(135deg, #6366f1, #7c3aed);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-secondary {
    background: #27272a;
    color: var(--text-secondary);
    border: 1px solid #3f3f46;
}

.btn-secondary:hover {
    background: #3f3f46;
    color: #e4e4e7;
}

/* Progress Section */
.progress-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.progress-section h2 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    color: #a78bfa;
}

.progress-bar-container {
    background: #27272a;
    border-radius: 6px;
    height: 6px;
    overflow: hidden;
    margin-bottom: 1rem;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #6366f1, #a78bfa);
    border-radius: 6px;
    width: 0%;
    transition: width 0.3s;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.log {
    background: var(--surface-deep);
    border-radius: 8px;
    padding: 1rem;
    max-height: 250px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.82rem;
    line-height: 1.6;
}

.log-line {
    color: var(--text-secondary);
}

.log-line.highlight {
    color: #6366f1;
    font-weight: 600;
}

.log-line.success {
    color: #22c55e;
}

.log-line.error {
    color: #ef4444;
}

/* Results Section */
.results-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.results-header h2 {
    font-size: 1.1rem;
    color: #a78bfa;
}

#results-count {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 400;
}

.results-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.checkbox-label input {
    accent-color: #6366f1;
}

.table-container {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid #27272a;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

thead {
    background: var(--thead-bg);
}

th {
    text-align: left;
    padding: 0.7rem 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}

td {
    padding: 0.6rem 0.8rem;
    border-top: 1px solid var(--row-border);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

tr:hover td {
    background: rgba(99, 102, 241, 0.05);
}

td.email-cell {
    color: #6366f1;
    font-weight: 500;
}

td.no-email {
    color: var(--text-muted);
    font-style: italic;
}

a {
    color: #6366f1;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Actions right */
.actions-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Info text */
.info-text {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

/* CSV Form */
.csv-form .search-row {
    margin-bottom: 1rem;
}

.file-upload {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.file-upload input[type="file"] {
    display: none;
}

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

/* History */
.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem 1rem;
    background: var(--surface-deep);
    border-radius: 8px;
    margin-bottom: 0.5rem;
    border: 1px solid #27272a;
}

.history-item:hover {
    border-color: #3f3f46;
}

.history-info {
    flex: 1;
    min-width: 0;
}

.history-title {
    font-weight: 500;
    margin-bottom: 0.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.history-actions {
    display: flex;
    gap: 0.4rem;
    flex-shrink: 0;
    margin-left: 1rem;
}

.history-actions .btn {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
}

/* Login */
.login-container {
    max-width: 400px;
    margin: 15vh auto 0;
    text-align: center;
}

.login-form {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
    margin-top: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.login-form input {
    background: var(--input-bg);
    border: 1px solid var(--border-hover);
    color: var(--text);
    padding: 0.8rem 1rem;
    border-radius: 8px;
    font-size: 1rem;
    text-align: center;
}

.login-form input:focus {
    outline: none;
    border-color: #6366f1;
}

.login-error {
    color: #ef4444;
    font-size: 0.85rem;
}

/* Stop button */
.btn-stop {
    background: #27272a;
    color: #ef4444;
    border: 1px solid #3f3f46;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-stop:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: #ef4444;
}

/* ETA */
.eta-display {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-left: 0.5rem;
}

/* Responsive */
@media (max-width: 768px) {
    .container { padding: 1rem; }
    .search-row { flex-wrap: wrap; }
    .input-activite, .input-ville { flex: 1 1 100%; }
    .input-rayon { flex: 1; }
    .search-actions { flex-direction: column; gap: 0.5rem; }
    .results-header { flex-direction: column; align-items: flex-start; }
}
