/* ── Reset / Base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background: #f1f5f9;
  color: #1e293b;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Top Bar ──────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #0f172a;
  color: #e2e8f0;
  padding: 10px 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  grid-column: 1 / -1;
}
.topbar-logo { font-weight: 700; font-size: 16px; letter-spacing: 1px; }
.topbar-sub  { font-size: 12px; color: #94a3b8; }
.topbar-status { margin-left: auto; font-size: 12px; color: #94a3b8; }
.topbar-status.online  { color: #4ade80; }
.topbar-status.offline { color: #f87171; }

/* ── Layout ───────────────────────────────────────────────────── */
body { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto 1fr; }
.sidebar { grid-column: 1; grid-row: 2; }
.container { grid-column: 2; grid-row: 2; overflow-y: auto; }

/* ── Sidebar ──────────────────────────────────────────────────── */
.sidebar {
  background: #1e293b;
  padding: 16px 0;
  width: 200px;
  border-right: 1px solid #334155;
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-link {
  display: block;
  padding: 10px 16px;
  color: #cbd5e1;
  text-decoration: none;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  border-left: 3px solid transparent;
}

.nav-link:hover {
  background: #334155;
  color: #f1f5f9;
}

.nav-link.active {
  background: #0f172a;
  color: #38bdf8;
  border-left-color: #38bdf8;
  font-weight: 600;
}

/* ── Container ────────────────────────────────────────────────── */
.container { max-width: 1200px; margin: 0 auto; padding: 24px; width: 100%; }

/* ── Page Header ──────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header h1 { margin: 0; font-size: 24px; font-weight: 600; }

/* ── Alert ────────────────────────────────────────────────────── */
.alert {
  padding: 10px 16px;
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 13px;
}
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-info    { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

/* ── Settings row / API URL ───────────────────────────────────── */
.settings-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 16px;
}
.settings-row label { margin: 0; font-size: 12px; color: #64748b; white-space: nowrap; }
.settings-row input { flex: 1; min-width: 240px; margin: 0; }

/* ── Card ─────────────────────────────────────────────────────── */
.card {
  background: white;
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}
.card h2 { margin: 0 0 16px; font-size: 16px; font-weight: 600; }

/* ── Screens ──────────────────────────────────────────────────── */
.screen { display: none; }
.screen.active { display: block; }

/* ── Stats Card ───────────────────────────────────────────────── */
.stats-card { margin-bottom: 20px; }

.stats-frame {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px;
  background: linear-gradient(135deg, #dbeafe 0%, #e0e7ff 100%);
  border-radius: 8px;
}

.stat-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; color: #64748b; font-weight: 600; }
.stat-value { font-size: 28px; font-weight: 700; color: #0f172a; }

/* ── Chart Card ───────────────────────────────────────────────── */
.chart-card { margin-bottom: 20px; }

.chart-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.chart-controls label { margin: 0; font-size: 12px; color: #64748b; font-weight: 500; white-space: nowrap; }
.chart-controls select, .chart-controls input { padding: 6px 10px; border: 1px solid #e2e8f0; border-radius: 6px; font-size: 13px; }

#chart-container { position: relative; height: 320px; margin-top: 16px; }

/* ── Filter Card ──────────────────────────────────────────────── */
.filter-card { margin-bottom: 16px; }

.filter-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.filter-controls label { margin: 0; font-size: 12px; color: #64748b; font-weight: 500; }
.filter-controls select { padding: 6px 10px; border: 1px solid #e2e8f0; border-radius: 6px; font-size: 13px; }

/* ── Forms ────────────────────────────────────────────────────── */
label {
  display: block;
  margin-top: 8px;
  font-size: 12px;
  color: #64748b;
  font-weight: 500;
}
input[type=text], input[type=number] {
  width: 100%;
  margin-top: 4px;
  margin-bottom: 8px;
  padding: 8px 10px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}
input:focus { border-color: #2563eb; }

.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-col { flex: 1; min-width: 160px; }
.form-col.flex-grow { flex: 2; }
.form-col.form-col-btn { flex: 0 0 auto; display: flex; flex-direction: column; justify-content: flex-end; }
.form-col.form-col-btn button { width: 100%; margin-top: 0; }

button {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  background: #2563eb;
  color: white;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s;
}
button:hover { background: #1d4ed8; }
button.btn-sm { padding: 6px 12px; font-size: 12px; white-space: nowrap; }
button.btn, .btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  color: white;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s;
  display: inline-block;
  text-decoration: none;
}
.btn-primary { background: #2563eb; }
.btn-primary:hover { background: #1d4ed8; }
.btn-secondary { background: #6b7280; }
.btn-secondary:hover { background: #4b5563; }
.btn-close { padding: 4px 8px; font-size: 20px; color: #64748b; background: none; border: none; cursor: pointer; }
.btn-link {
  background: none;
  color: #2563eb;
  padding: 0;
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
  border: none;
  margin-top: 8px;
}

/* ── Badges ───────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.badge-green { background: #dcfce7; color: #166534; }
.badge-blue  { background: #dbeafe; color: #1e40af; }
.badge-red   { background: #fee2e2; color: #991b1b; }
.badge-gray  { background: #f1f5f9; color: #64748b; }

.pill {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 10px;
  background: #f1f5f9;
  color: #475569;
  font-size: 11px;
  font-weight: 600;
}

/* ── Modal ────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal.hidden { display: none !important; }

.modal-content {
  background: white;
  border-radius: 12px;
  padding: 24px;
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 25px rgba(0,0,0,0.15);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.modal-header h2 { margin: 0; }

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ── Status Badges ────────────────────────────────────────────── */
.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: capitalize;
}

.status-running { background: #dcfce7; color: #166534; }
.status-pending { background: #fef3c7; color: #92400e; }
.status-paused { background: #dbeafe; color: #1e40af; }
.status-completed { background: #dcfce7; color: #166534; }
.status-waiting { background: #f1f5f9; color: #64748b; }

/* ── Icon Button ──────────────────────────────────────────────── */
.btn-icon {
  background: none;
  border: none;
  color: #2563eb;
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background 0.2s;
}
.btn-icon:hover {
  background: #dbeafe;
}

/* ── Task meta grid ───────────────────────────────────────────── */
.task-meta-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px;
  background: #f8fafc;
  border-radius: 8px;
  margin-bottom: 20px;
}
.meta-item { display: flex; flex-direction: column; gap: 2px; min-width: 140px; }
.meta-item.meta-wide { flex: 1 1 100%; }
.meta-key { font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; color: #94a3b8; font-weight: 600; }
.meta-val { font-size: 13px; color: #1e293b; font-weight: 500; }
a.link { color: #2563eb; font-size: 12px; word-break: break-all; }

/* ── Section headers ──────────────────────────────────────────── */
.section-header {
  font-size: 13px;
  font-weight: 600;
  color: #475569;
  margin: 20px 0 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Timeline ─────────────────────────────────────────────────── */
.timeline { display: flex; flex-direction: column; gap: 0; }
.timeline-item {
  display: flex;
  gap: 12px;
  padding: 8px 0;
  border-left: 2px solid #e2e8f0;
  margin-left: 7px;
  padding-left: 16px;
  position: relative;
}
.timeline-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #94a3b8;
  position: absolute;
  left: -7px;
  top: 12px;
  flex-shrink: 0;
}
.timeline-dot.status-ok,
.timeline-dot.status-completed { background: #22c55e; }
.timeline-dot.status-processing,
.timeline-dot.status-queued    { background: #3b82f6; }
.timeline-dot.status-failed,
.timeline-dot.status-error     { background: #ef4444; }
.timeline-body { flex: 1; }
.timeline-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.timeline-stage { font-weight: 600; font-size: 13px; color: #334155; }
.timeline-time  { font-size: 11px; color: #94a3b8; margin-left: auto; }
.timeline-msg   { font-size: 12px; color: #64748b; margin-top: 2px; }

/* ── Tables ───────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
th {
  background: #f8fafc;
  color: #64748b;
  text-align: left;
  padding: 7px 10px;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border-bottom: 1px solid #e2e8f0;
}
td {
  padding: 7px 10px;
  border-bottom: 1px solid #f1f5f9;
  color: #334155;
  vertical-align: top;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }
code {
  font-family: "Consolas", monospace;
  font-size: 11px;
  background: #f1f5f9;
  padding: 1px 4px;
  border-radius: 4px;
}

/* ── Retry success card ───────────────────────────────────────── */
.retry-success-card {
  margin-top: 14px;
  padding: 14px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ── Accounts list ────────────────────────────────────────────── */
.acct-list {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.acct-list li { display: flex; align-items: center; gap: 8px; font-size: 13px; }

/* ── Misc ─────────────────────────────────────────────────────── */
.muted      { color: #94a3b8; font-size: 13px; margin-top: 12px; }
.hidden     { display: none !important; }
.error-text { color: #dc2626; font-size: 13px; margin-top: 10px; }

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 768px) {
  body { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .container { grid-column: 1; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-header h1 { margin-bottom: 12px; }
  .stats-frame { grid-template-columns: 1fr; }
  .modal-content { max-width: 90vw; }
  .form-row { flex-direction: column; }
  .table-wrap { overflow-x: auto; }
}

