/* ============================================================
   Diensten Scraper -- modern light dashboard theme.
   Inspired by clean SaaS admin UIs: white surfaces, soft shadows,
   colored icon chips for stats, plenty of whitespace. Deliberately
   NOT a dark/gradient "AI product" look.
   ============================================================ */

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --border: #e8eaf1;
  --text: #1c2130;
  --text-muted: #767e94;
  --text-faint: #9aa1b5;

  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef0ff;

  --green: #12b76a;
  --green-soft: #e7f9f1;
  --blue: #2f80ed;
  --blue-soft: #eaf2fe;
  --purple: #7c5cff;
  --purple-soft: #f1edff;
  --red: #f04438;
  --red-soft: #fdecea;
  --amber: #f59e0b;
  --amber-soft: #fef3e0;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .04);
  --shadow: 0 2px 8px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .10);
}

/* Dark mode -- toggled via [data-theme="dark"] on <html>, persisted in
   localStorage. Same tokens, different values, so every component below
   just works without extra dark-specific rules. */
html[data-theme="dark"] {
  --bg: #10131c;
  --surface: #171b28;
  --surface-2: #1d2233;
  --border: #2a3044;
  --text: #e8eaf3;
  --text-muted: #9199b3;
  --text-faint: #6b7189;

  --primary: #6d64ff;
  --primary-hover: #7d75ff;
  --primary-soft: #24274a;

  --green: #2fd489;
  --green-soft: #123527;
  --blue: #5b9bf5;
  --blue-soft: #142743;
  --purple: #9c8bff;
  --purple-soft: #262045;
  --red: #ff6b6b;
  --red-soft: #3a1c22;
  --amber: #ffb84f;
  --amber-soft: #3a2c12;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow: 0 2px 8px rgba(0, 0, 0, .35);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
}

html { transition: background .15s; }
body { transition: background .15s, color .15s; }

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app-shell { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 248px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 4px 10px 26px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(160deg, var(--primary), #7c6ff0);
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 700; font-size: 15px; flex-shrink: 0;
}
.brand-text { font-weight: 700; line-height: 1.2; font-size: 15px; color: var(--text); flex: 1; }
.brand-text small { color: var(--text-muted); font-weight: 500; font-size: 11.5px; display: block; }

.theme-toggle {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.theme-toggle:hover { color: var(--text); background: var(--surface); }
.theme-toggle svg { width: 16px; height: 16px; }

.language-selector {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  margin-left: 8px;
}
.language-selector:hover {
  border-color: var(--primary);
}

.health-badge { padding: 5px 12px; border-radius: 20px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.health-badge.healthy { background: var(--green-soft); color: var(--green); }
.health-badge.degraded { background: var(--red-soft); color: var(--red); }

/* SMS Campaigns Styling */
.sms-form-panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.sms-form-panel h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 16px;
}

.sms-form-panel h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sms-inline-form {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.sms-inline-form input,
.sms-inline-form select,
.sms-inline-form textarea {
  flex: 1;
  min-width: 200px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.sms-inline-form input:focus,
.sms-inline-form select:focus,
.sms-inline-form textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.sms-inline-form textarea {
  min-height: 80px;
  resize: vertical;
  font-family: inherit;
}

.sms-template-select {
  flex: 0 0 200px;
  min-width: 200px;
}

.sms-bulk-textarea {
  width: 100%;
  min-height: 120px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  resize: vertical;
}

.sms-bulk-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.sms-btn-group {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.sms-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.sms-stat-card {
  background: var(--surface-2);
  padding: 16px;
  border-radius: var(--radius-sm);
  text-align: center;
}

.sms-stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.sms-stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
}

.sms-stat-value.sent { color: var(--green); }
.sms-stat-value.failed { color: var(--red); }
.sms-stat-value.pending { color: var(--amber); }

.sms-message-preview {
  background: var(--primary-soft);
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--primary);
  font-style: italic;
}

.sms-form-msg {
  margin-top: 12px;
  font-size: 13px;
  font-weight: 500;
}

.sms-form-msg.error {
  color: var(--red);
}

.sms-form-msg:not(.error) {
  color: var(--green);
}

.nav-list { list-style: none; padding: 0; margin: 0; flex: 1; }
.nav-item {
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-muted);
  display: flex; align-items: center; gap: 11px;
  font-size: 14px; font-weight: 500;
  margin-bottom: 3px;
  transition: background .15s, color .15s;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .85; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-item.active svg { opacity: 1; }

.queue-chip {
  margin: 6px 6px 14px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-muted);
}
.queue-chip .queue-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); display: inline-block; margin-right: 6px; }
.queue-chip b { color: var(--text); }

.sidebar-footer { color: var(--text-faint); font-size: 11px; padding: 10px 10px 2px; }

/* ---------- Content ---------- */
.content { flex: 1; padding: 30px 38px 60px; max-width: 1280px; }
.page-header { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 22px; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
.page-sub { color: var(--text-muted); font-size: 13.5px; margin-top: 4px; }
h2 { font-size: 13.5px; margin: 0 0 16px; color: var(--text); font-weight: 700; }
.tab-pane.hidden { display: none; }

/* ---------- Stat cards ---------- */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 26px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 20px 22px; box-shadow: var(--shadow-sm);
  display: flex; align-items: center; gap: 15px;
}
.stat-icon {
  width: 44px; height: 44px; border-radius: 12px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 19px;
}
.stat-icon.green { background: var(--green-soft); color: var(--green); }
.stat-icon.blue { background: var(--blue-soft); color: var(--blue); }
.stat-icon.purple { background: var(--purple-soft); color: var(--purple); }
.stat-icon.red { background: var(--red-soft); color: var(--red); }
.stat-icon.amber { background: var(--amber-soft); color: var(--amber); }
.stat-label { color: var(--text-muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 24px; font-weight: 700; margin-top: 2px; }

/* ---------- Panels ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 22px 24px; margin-bottom: 22px; box-shadow: var(--shadow-sm);
}
.panel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }

/* ---------- Tables ---------- */
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th {
  text-align: left; color: var(--text-muted); font-weight: 600; padding: 10px 12px;
  border-bottom: 1px solid var(--border); font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em;
}
.data-table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--text); }
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table tbody tr:last-child td { border-bottom: none; }

.badge { padding: 4px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 600; display: inline-block; }
.badge-pending { background: #eef0f5; color: #667085; }
.badge-running { background: var(--blue-soft); color: var(--blue); }
.badge-completed { background: var(--green-soft); color: var(--green); }
.badge-failed { background: var(--red-soft); color: var(--red); }
.badge-cancelled { background: var(--amber-soft); color: #b45309; }

.progress-mini { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; height: 7px; width: 84px; overflow: hidden; display: inline-block; vertical-align: middle; margin-right: 8px; }
.progress-mini-fill { background: var(--primary); height: 100%; transition: width .3s; }

.icon-btn { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 15px; padding: 5px 7px; border-radius: 7px; line-height: 1; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { background: var(--red-soft); color: var(--red); }

/* ---------- Forms ---------- */
.form-panel form { display: flex; flex-direction: column; gap: 17px; max-width: 580px; }
.form-row label { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.form-row input, .form-row select {
  width: 100%; padding: 10px 13px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); font-size: 14px; font-family: inherit;
}
.form-row input:focus, .form-row select:focus { outline: none; border-color: var(--primary); background: var(--surface); }
.form-row small { color: var(--text-muted); font-size: 11.5px; display: block; margin-top: 5px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.hidden { display: none !important; }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-2); }
.seg-btn { background: transparent; border: none; color: var(--text-muted); padding: 8px 16px; cursor: pointer; font-size: 13px; font-weight: 600; }
.seg-btn.active { background: var(--primary); color: white; }

.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.switch-row .switch-label { font-size: 13.5px; font-weight: 600; color: var(--text); }
.switch-row .switch-desc { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.toggle { position: relative; width: 42px; height: 24px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .slider { position: absolute; inset: 0; background: #d3d7e3; border-radius: 24px; cursor: pointer; transition: .2s; }
.toggle .slider::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: white; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.toggle input:checked + .slider { background: var(--primary); }
.toggle input:checked + .slider::before { transform: translateX(18px); }

.btn-primary {
  background: var(--primary); color: white; border: none; padding: 11px 22px;
  border-radius: var(--radius-sm); font-size: 14px; font-weight: 600; cursor: pointer; width: fit-content;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary {
  background: var(--surface); color: var(--text); border: 1px solid var(--border); padding: 9px 16px;
  border-radius: var(--radius-sm); font-size: 13px; cursor: pointer; font-weight: 600;
}
.btn-secondary:hover { background: var(--surface-2); }
.form-msg { font-size: 13px; color: var(--green); font-weight: 500; }
.form-msg.error { color: var(--red); }

.inline-form { flex-direction: row !important; flex-wrap: wrap; align-items: center; max-width: none !important; gap: 10px !important; }
.inline-form input { width: auto; min-width: 160px; }

.file-drop {
  border: 1.5px dashed var(--border); border-radius: var(--radius); padding: 18px;
  text-align: center; color: var(--text-muted); font-size: 13px; cursor: pointer; background: var(--surface-2);
}
.file-drop:hover { border-color: var(--primary); color: var(--primary); }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(23, 27, 40, .45); display: flex; align-items: center; justify-content: center; z-index: 50; backdrop-filter: blur(2px); }
.modal.hidden { display: none; }
.modal-box { background: var(--surface); border-radius: var(--radius-lg); width: 900px; max-width: 95vw; max-height: 90vh; overflow: hidden; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 18px 24px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.modal-header h2 { margin: 0; font-size: 15px; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 22px; cursor: pointer; line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
.log-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; font-family: "SF Mono", Consolas, monospace; font-size: 11.5px; max-height: 250px; overflow-y: auto; white-space: pre-wrap; color: var(--text-muted); }

/* ---------- Misc ---------- */
.hint-text { font-size: 12.5px; color: var(--text-muted); }
.hint-text.error { color: var(--red); }
.stack-gap-8 > * + * { margin-top: 8px; }

/* ---------- Mobile Responsive ---------- */
@media (max-width: 768px) {
  .app-shell { flex-direction: column; }
  
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    padding: 16px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  
  .sidebar-footer { display: none; }
  
  .nav-list { display: flex; flex-wrap: wrap; gap: 8px; }
  .nav-item { flex: 1 1 auto; min-width: 80px; justify-content: center; flex-direction: column; text-align: center; padding: 12px 8px; }
  .nav-item svg { margin-bottom: 4px; }
  
  .content { padding: 20px 16px 40px; }
  
  .cards-grid { grid-template-columns: 1fr; }
  
  .panel-grid { grid-template-columns: 1fr; }
  
  .two-col { grid-template-columns: 1fr; }
  
  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 8px 6px; }
  
  .data-table thead { display: none; }
  .data-table tbody tr { display: flex; flex-direction: column; border-bottom: 1px solid var(--border); padding: 12px 0; }
  .data-table tbody td { border: none; padding: 4px 0; }
  .data-table tbody td::before { content: attr(data-label); font-weight: 600; color: var(--text-muted); margin-right: 8px; }
  
  .modal-box { width: 100%; max-width: 100%; max-height: 100vh; border-radius: 0; }
  
  .form-panel form { max-width: 100%; }
  
  .inline-form { flex-direction: column !important; }
  .inline-form input { width: 100%; min-width: auto; }
  
  .segmented { width: 100%; }
  .seg-btn { flex: 1; text-align: center; }
  
  .page-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  
  .queue-chip { font-size: 11px; padding: 8px 10px; }
  
  .icon-btn { padding: 8px 10px; font-size: 16px; }
  
  .stat-card { padding: 16px; }
  .stat-value { font-size: 20px; }
}

@media (max-width: 480px) {
  .sidebar { padding: 12px; }
  .brand { padding: 0 8px 16px; }
  .nav-item { font-size: 12px; padding: 10px 6px; }
  .nav-item svg { width: 16px; height: 16px; }
  
  .content { padding: 16px 12px 32px; }
  
  h1 { font-size: 18px; }
  h2 { font-size: 12px; }
  
  .btn-primary, .btn-secondary { width: 100%; padding: 12px 16px; }
  
  .modal-header { padding: 14px 16px; }
  .modal-body { padding: 16px; }
  
  .log-box { font-size: 10px; max-height: 150px; }
}
