/* ===== CSS Variables (Light / Dark) ===== */
:root {
  --bg: #f5f7fa;
  --bg-card: #ffffff;
  --bg-nav: #1a1f2e;
  --text: #1a1f2e;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;
  --info: #3b82f6;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --radius: 8px;
}
[data-theme="dark"] {
  --bg: #0f1117;
  --bg-card: #1a1f2e;
  --bg-nav: #0f1117;
  --text: #e5e7eb;
  --text-muted: #9ca3af;
  --border: #374151;
  --shadow: 0 1px 3px rgba(0,0,0,0.4);
}

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
       background: var(--bg); color: var(--text); line-height: 1.6; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Navbar ===== */
.navbar {
  display: flex; align-items: center; background: var(--bg-nav);
  padding: 0 1.5rem; height: 56px; position: sticky; top: 0; z-index: 100;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
.nav-brand { display: flex; align-items: center; gap: 8px; color: #fff;
             font-size: 1.1rem; font-weight: 700; margin-right: 2rem; }
.nav-icon { font-size: 1.3rem; }
.nav-links { display: flex; list-style: none; gap: 4px; flex: 1; }
.nav-link { color: rgba(255,255,255,0.75); padding: 6px 12px; border-radius: 6px;
            font-size: 0.875rem; transition: all 0.15s; }
.nav-link:hover, .nav-link.active { color: #fff; background: rgba(255,255,255,0.1); text-decoration: none; }
.theme-toggle { background: rgba(255,255,255,0.1); border: none; color: #fff;
                width: 36px; height: 36px; border-radius: 6px; cursor: pointer;
                font-size: 1.1rem; display: flex; align-items: center; justify-content: center; }
.theme-toggle:hover { background: rgba(255,255,255,0.2); }

/* ===== Main Content ===== */
.main-content { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }

/* ===== Page Header ===== */
.page-header { display: flex; align-items: center; justify-content: space-between;
               margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.5rem; font-weight: 700; }

/* ===== Cards ===== */
.card, .stat-card, .account-card, .account-card-full, .info-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow);
}
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; }
.card-body { margin-bottom: 0.75rem; }
.card-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { text-align: center; }
.stat-value { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-label { color: var(--text-muted); font-size: 0.875rem; }

/* Account cards */
.account-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.account-card { display: flex; flex-direction: column; gap: 0.5rem; }
.account-card-full { margin-bottom: 1rem; }
.account-header { display: flex; align-items: center; gap: 0.75rem; }
.account-avatar { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center;
                  justify-content: center; color: #fff; font-weight: 700; font-size: 1.1rem; flex-shrink: 0; }
.account-info h3 { font-size: 1rem; font-weight: 600; }
.account-info p, .account-info small { color: var(--text-muted); font-size: 0.8rem; }
.account-badges { display: flex; gap: 0.25rem; flex-wrap: wrap; margin-left: auto; }
.account-actions { display: flex; gap: 0.5rem; margin-top: 0.75rem; }
.account-meta { font-size: 0.8rem; color: var(--text-muted); }

/* ===== Section ===== */
.section { margin-bottom: 2rem; }
.section h2 { font-size: 1.125rem; font-weight: 600; margin-bottom: 0.75rem;
              padding-bottom: 0.5rem; border-bottom: 1px solid var(--border); }

/* ===== Tables ===== */
.table-container { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; background: var(--bg-card);
         border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.table th { background: var(--bg); font-size: 0.75rem; text-transform: uppercase;
            letter-spacing: 0.05em; color: var(--text-muted); padding: 0.75rem 1rem; text-align: left; }
.table td { padding: 0.75rem 1rem; border-top: 1px solid var(--border); font-size: 0.875rem; }
.table tr:hover td { background: rgba(79,70,229,0.04); }

/* ===== Badges ===== */
.badge { display: inline-flex; align-items: center; justify-content: center;
         width: 28px; height: 28px; border-radius: 50%; color: #fff; font-weight: 700; font-size: 0.875rem; }
.badge-pill { display: inline-block; padding: 2px 8px; border-radius: 99px;
              font-size: 0.75rem; font-weight: 500; background: var(--border); }
.badge-success { background: var(--success); color: #fff; }
.badge-error { background: var(--error); color: #fff; }
.badge-secondary { background: var(--border); color: var(--text-muted); }

.badge-cat { display: inline-block; padding: 2px 8px; border-radius: 4px;
             font-size: 0.75rem; font-weight: 600; }
.badge-newsletter { background: #dbeafe; color: #1e40af; }
.badge-werbung { background: #fef3c7; color: #92400e; }
.badge-rechnung { background: #dcfce7; color: #166534; }
.badge-bestellung { background: #f3e8ff; color: #6b21a8; }
.badge-vertrag { background: #ffedd5; color: #9a3412; }
.badge-service { background: #e0f2fe; color: #0c4a6e; }
.badge-arbeit { background: #f0fdf4; color: #14532d; }
.badge-privat { background: #fdf4ff; color: #701a75; }
.badge-system { background: #f1f5f9; color: #475569; }
.badge-unklar, .badge-zur_pruefung { background: #fef2f2; color: #7f1d1d; }
[data-theme="dark"] .badge-newsletter { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .badge-rechnung { background: #14532d; color: #86efac; }
[data-theme="dark"] .badge-unklar, [data-theme="dark"] .badge-zur_pruefung { background: #450a0a; color: #fca5a5; }

.badge-status.badge-completed { background: #dcfce7; color: #166534; }
.badge-status.badge-running { background: #dbeafe; color: #1e40af; }
.badge-status.badge-error { background: #fee2e2; color: #991b1b; }

/* ===== Buttons ===== */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px;
       border-radius: 6px; font-size: 0.875rem; font-weight: 500; cursor: pointer;
       border: none; transition: all 0.15s; text-decoration: none; }
.btn:hover { text-decoration: none; opacity: 0.9; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: #d1d5db; }
.btn-danger { background: var(--error); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }

/* ===== Forms ===== */
.form-container { max-width: 720px; }
.form-section { background: var(--bg-card); border: 1px solid var(--border);
                border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem; }
.form-section h3 { font-size: 1rem; font-weight: 600; margin-bottom: 1rem;
                   padding-bottom: 0.5rem; border-bottom: 1px solid var(--border); color: var(--text-muted); }
.form-group { margin-bottom: 0.875rem; }
.form-group label { display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 4px; }
.form-control { width: 100%; padding: 8px 12px; border: 1px solid var(--border);
                border-radius: 6px; background: var(--bg); color: var(--text);
                font-size: 0.875rem; transition: border-color 0.15s; }
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,0.1); }
.form-control-sm { padding: 4px 8px; font-size: 0.8rem; border: 1px solid var(--border);
                   border-radius: 4px; background: var(--bg); color: var(--text); }
.form-control-color { width: 60px; padding: 4px; cursor: pointer; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-group-sm { max-width: 120px; }
.form-check { display: flex; align-items: center; gap: 8px; margin-bottom: 0.5rem; }
.form-check input { width: 16px; height: 16px; cursor: pointer; }
.form-actions { display: flex; gap: 0.75rem; justify-content: flex-end; padding-top: 0.5rem; }
.form-hint { font-size: 0.75rem; color: var(--text-muted); display: block; margin-top: 3px; }
.radio-group { display: flex; flex-wrap: wrap; gap: 1rem; }
.radio-group label { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 0.875rem; }
.select-sm { padding: 3px 6px; font-size: 0.8rem; border: 1px solid var(--border);
             border-radius: 4px; background: var(--bg); color: var(--text); }

/* ===== Alerts ===== */
.alert { padding: 0.75rem 1rem; border-radius: 6px; margin-bottom: 0.75rem; font-size: 0.875rem; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.alert-error, .alert-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }
[data-theme="dark"] .alert-success { background: #14532d; color: #86efac; }
[data-theme="dark"] .alert-error { background: #450a0a; color: #fca5a5; }
[data-theme="dark"] .alert-warning { background: #451a03; color: #fde68a; }
.flash-container { margin-bottom: 1rem; }

/* ===== Progress ===== */
.progress-bar-container { background: var(--border); border-radius: 99px; height: 12px;
                           overflow: hidden; margin-bottom: 0.75rem; }
.progress-bar { height: 100%; background: var(--primary); border-radius: 99px; transition: width 0.3s; }

/* ===== Welcome Screen ===== */
.welcome-screen { display: flex; justify-content: center; align-items: center; min-height: 60vh; }
.welcome-card { text-align: center; background: var(--bg-card); padding: 3rem;
                border-radius: 16px; box-shadow: var(--shadow); max-width: 480px; }
.welcome-icon { font-size: 4rem; margin-bottom: 1rem; }
.welcome-card h1 { font-size: 1.5rem; margin-bottom: 0.75rem; }
.welcome-sub { color: var(--text-muted); margin-bottom: 1.5rem; }

/* ===== Empty State ===== */
.empty-state { text-align: center; padding: 3rem; color: var(--text-muted); }
.empty-icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state h3 { font-size: 1.125rem; font-weight: 600; color: var(--text); margin-bottom: 0.5rem; }
.empty-state p { margin-bottom: 1.5rem; }

/* ===== Test Result ===== */
.test-result { margin-top: 0.5rem; font-size: 0.875rem; }
.text-success { color: var(--success); }
.text-error { color: var(--error); }
.text-muted { color: var(--text-muted); }
.loading::after { content: '...'; animation: dots 1s steps(3, end) infinite; }

/* ===== Toolbar ===== */
.toolbar { display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem;
           background: var(--bg-card); border: 1px solid var(--border);
           border-radius: var(--radius); margin-bottom: 1rem; flex-wrap: wrap; }
.toolbar-sep { color: var(--border); }

/* ===== Log Output ===== */
.log-output { background: #0f1117; color: #e5e7eb; padding: 1rem; border-radius: 6px;
              font-size: 0.75rem; overflow-x: auto; max-height: 400px; overflow-y: auto;
              white-space: pre-wrap; word-break: break-all; }

/* ===== Misc ===== */
.mt { margin-top: 1.5rem; }
.mt-sm { margin-top: 0.5rem; }

@keyframes dots { 0%, 20% { content: '.'; } 40% { content: '..'; } 60%, 100% { content: '...'; } }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .nav-links { display: none; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .page-header { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
}

/* ===== Settings Tabs ===== */
.tab-nav { display: flex; gap: 4px; border-bottom: 2px solid var(--border);
           margin-bottom: 1.5rem; flex-wrap: wrap; }
.tab-link { padding: 8px 16px; font-size: 0.875rem; font-weight: 500;
            color: var(--text-muted); border-radius: 6px 6px 0 0; cursor: pointer;
            border: 1px solid transparent; text-decoration: none; }
.tab-link:hover { color: var(--text); background: var(--border); text-decoration: none; }
.tab-link.active { color: var(--primary); background: var(--bg-card);
                   border-color: var(--border) var(--border) var(--bg-card);
                   border-bottom: 2px solid var(--primary); }

/* ===== Provider Cards ===== */
.provider-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; }
.provider-card { display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
                 padding: 1.25rem 1rem; border: 2px solid var(--border); border-radius: var(--radius);
                 cursor: pointer; text-align: center; transition: all 0.15s; background: var(--bg-card); }
.provider-card:hover { border-color: var(--primary); }
.provider-card.selected { border-color: var(--primary); background: rgba(79,70,229,0.05); }
.provider-card input[type="radio"] { display: none; }
.provider-logo { font-size: 2rem; }
.provider-name { font-weight: 700; font-size: 0.9rem; }
.provider-desc { font-size: 0.75rem; color: var(--text-muted); }

/* ===== Category Grid ===== */
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0.5rem; }
.cat-chip { padding: 0.5rem 0.75rem; border-radius: 6px; border: 1px solid var(--border);
            background: var(--bg); display: flex; flex-direction: column; gap: 2px; }
.cat-chip.builtin { border-left: 3px solid var(--primary); }
.cat-chip strong { font-size: 0.875rem; }
.cat-chip small { color: var(--text-muted); font-size: 0.7rem; }

/* ===== Suggested Category Row ===== */
.suggested-cat-row { display: flex; justify-content: space-between; align-items: center;
                     padding: 0.75rem; border: 1px solid var(--border); border-radius: 6px;
                     margin-bottom: 0.5rem; flex-wrap: wrap; gap: 0.5rem; }

/* ===== Modal ===== */
.modal { display: flex; position: fixed; inset: 0; z-index: 1000;
         align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.5); }
.modal-box { position: relative; background: var(--bg-card); border-radius: var(--radius);
             padding: 1.5rem; width: 100%; max-width: 520px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.modal-box h3 { margin-bottom: 1rem; }

/* ===== Misc ===== */
.req { color: var(--error); }
details summary { list-style: none; }
details summary::-webkit-details-marker { display: none; }

/* ===== Analysis Run Progress ===== */
.run-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.run-elapsed { font-size: 0.875rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.phase-steps { display: flex; align-items: flex-start; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.phase-arrow { color: var(--text-muted); padding-top: 10px; }
.phase-step { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 80px; }
.phase-dot { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--border);
             background: var(--bg); transition: all 0.3s; }
.phase-step.active .phase-dot { border-color: var(--primary); background: var(--primary);
                                  box-shadow: 0 0 0 4px rgba(79,70,229,0.2);
                                  animation: pulse 1.2s infinite; }
.phase-step.done .phase-dot { border-color: var(--success); background: var(--success); }
.phase-step.done .phase-dot::after { content: '✓'; color: #fff; display: flex;
                                      align-items: center; justify-content: center;
                                      font-size: 0.75rem; height: 100%; }
.phase-label { font-size: 0.75rem; font-weight: 600; color: var(--text-muted); }
.phase-step.active .phase-label { color: var(--primary); }
.phase-step.done .phase-label { color: var(--success); }
.phase-detail { font-size: 0.7rem; color: var(--text-muted); text-align: center; }

.progress-meta { display: flex; justify-content: space-between; font-size: 0.8rem;
                 color: var(--text-muted); margin-top: 0.25rem; }
.progress-pct { font-weight: 700; color: var(--primary); }

.current-item { display: flex; gap: 0.5rem; align-items: center; font-size: 0.8rem;
                padding: 0.5rem 0.75rem; background: var(--bg); border-radius: 6px;
                border-left: 3px solid var(--primary); margin: 0.75rem 0; }
.current-item-label { color: var(--text-muted); flex-shrink: 0; }

.live-log { margin-top: 1rem; max-height: 180px; overflow-y: auto;
            font-size: 0.75rem; border: 1px solid var(--border); border-radius: 6px; }
.log-row { display: flex; gap: 0.5rem; padding: 4px 8px; border-bottom: 1px solid var(--border); }
.log-row:last-child { border-bottom: none; }
.log-ts { color: var(--text-muted); flex-shrink: 0; font-variant-numeric: tabular-nums; }
.log-icon { flex-shrink: 0; width: 16px; text-align: center; }
.log-text { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-warn .log-text { color: var(--warning); }
.log-error .log-text { color: var(--error); }

@keyframes pulse { 0%,100% { box-shadow: 0 0 0 4px rgba(79,70,229,0.2); }
                   50%      { box-shadow: 0 0 0 8px rgba(79,70,229,0.05); } }

.checkbox-group { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.25rem; }
.checkbox-label { display: flex; align-items: center; gap: 0.35rem; font-size: 0.875rem;
                  cursor: pointer; padding: 0.25rem 0.6rem; border-radius: 6px;
                  border: 1px solid var(--border); background: var(--bg);
                  transition: border-color 0.15s, background 0.15s; }
.checkbox-label:hover { border-color: var(--primary); background: var(--primary-light, #ede9fe); }
.checkbox-label input { margin: 0; cursor: pointer; }
