/* ═══════════════════════════════════════════════════════════════
   Ops Console — Light theme (matches Intako marketing site)
   ═══════════════════════════════════════════════════════════════ */

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

:root {
  /* Backgrounds — warm cream palette from marketing site */
  --bg-primary:  #f7f3ec;
  --bg-surface:  #ffffff;
  --bg-elevated: #faf8f4;
  --bg-hover:    #efe7db;

  /* Borders */
  --border:       rgba(42, 49, 54, 0.12);
  --border-light: rgba(42, 49, 54, 0.20);

  /* Text */
  --text-primary:   #121315;
  --text-secondary: rgba(18, 19, 21, 0.68);
  --text-muted:     rgba(18, 19, 21, 0.42);

  /* Accent — teal from marketing site */
  --accent:       #2e6a67;
  --accent-hover: #245a57;
  --accent-soft:  #d9e6e1;

  /* Semantic colours (calibrated for light bg) */
  --success:    #2a7d3f;
  --success-bg: rgba(42, 125, 63, 0.10);
  --error:      #c0392b;
  --error-bg:   rgba(192, 57, 43, 0.10);
  --warning:    #b9822a;
  --warning-bg: rgba(185, 130, 42, 0.10);
  --info:       #2563c0;
  --info-bg:    rgba(37, 99, 192, 0.10);

  /* Typography */
  --font-sans:    'Instrument Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-heading: 'Sora', 'Instrument Sans', sans-serif;
  --font-mono:    'SF Mono', 'Fira Code', 'Cascadia Code', monospace;

  /* Shadows */
  --shadow:      0 4px 24px rgba(28, 33, 38, 0.08);
  --shadow-soft: 0 2px 10px rgba(28, 33, 38, 0.05);

  /* Layout */
  --sidebar-width: 220px;
  --radius:    8px;
  --radius-sm: 6px;
}

html { font-size: 13px; }
body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.filter-pill:focus-visible,
.detail-tab:focus-visible,
.period-btn:focus-visible,
.primary-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

h1, h2, h3, h4 {
  font-family: var(--font-heading);
}

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

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

.mobile-topbar {
  display: none;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 10;
  box-shadow: var(--shadow-soft);
}

.sidebar-brand {
  padding: 0 16px 20px;
  font-family: var(--font-heading);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.sidebar-brand .brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #4f8f89);
  position: relative;
  display: inline-block;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.24);
}

.sidebar-brand .brand-mark::before,
.sidebar-brand .brand-mark::after {
  content: "";
  position: absolute;
  background: rgba(247, 243, 236, 0.95);
  border-radius: 999px;
}

.sidebar-brand .brand-mark::before {
  width: 12px;
  height: 3px;
  top: 6px;
  left: 5px;
  transform: rotate(-32deg);
}

.sidebar-brand .brand-mark::after {
  width: 10px;
  height: 3px;
  right: 4px;
  bottom: 6px;
  transform: rotate(-32deg);
}

.sidebar-brand .brand-word {
  font-size: 1rem;
}

.sidebar-nav {
  list-style: none;
  flex: 1;
}

.sidebar-nav li a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  transition: all 150ms ease;
  border-left: 2px solid transparent;
}

.sidebar-nav li a:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

.sidebar-nav li a.active {
  color: var(--accent);
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

.sidebar-nav li a .nav-icon {
  width: 16px;
  text-align: center;
  font-size: 14px;
  opacity: 0.65;
}

.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 12px 16px;
}

.main {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 32px;
  max-width: 1200px;
}

.page-header {
  margin-bottom: 28px;
}

.page-header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.page-header p {
  font-size: 13px;
  color: var(--text-muted);
}

.page-header-split {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.content-grid {
  display: grid;
  gap: 20px;
}

.content-grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* ── Stat Cards ────────────────────────────────────────────── */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.queue-stat-cards {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-bottom: 16px;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-soft);
}

.stat-card .label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 8px;
  font-family: var(--font-heading);
}

.stat-card .value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
  font-family: var(--font-heading);
}

.stat-card .trend {
  font-size: 11px;
  margin-top: 8px;
}

.stat-card .trend.up { color: var(--success); }
.stat-card .trend.down { color: var(--error); }
.stat-card .trend.neutral { color: var(--text-muted); }

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
  font-family: var(--font-heading);
}

.stat-label {
  margin-top: 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-family: var(--font-heading);
}

/* ── Tables ────────────────────────────────────────────────── */
.table-container {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  box-shadow: var(--shadow-soft);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

thead th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
  font-family: var(--font-heading);
}

tbody tr {
  transition: background 150ms ease;
  cursor: pointer;
}

tbody tr:hover {
  background: var(--bg-hover);
}

tbody td {
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}

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

td.primary { color: var(--text-primary); font-weight: 500; }
td.mono { font-family: var(--font-mono); font-size: 12px; }
td.amount { text-align: right; font-family: var(--font-mono); }

/* ── Status Badges ─────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 18px;
  font-family: var(--font-heading);
}

.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.badge-completed, .badge-success { background: var(--success-bg); color: var(--success); }
.badge-completed::before, .badge-success::before { background: var(--success); }

.badge-failed, .badge-error { background: var(--error-bg); color: var(--error); }
.badge-failed::before, .badge-error::before { background: var(--error); }

.badge-extracting, .badge-automating, .badge-received, .badge-processing, .badge-queued, .badge-info {
  background: var(--info-bg); color: var(--info);
}
.badge-extracting::before, .badge-automating::before, .badge-received::before, .badge-processing::before, .badge-queued::before, .badge-info::before {
  background: var(--info);
}

.badge-needs_review, .badge-skipped, .badge-retry_wait, .badge-blocked {
  background: var(--warning-bg); color: var(--warning);
}
.badge-needs_review::before, .badge-skipped::before, .badge-retry_wait::before, .badge-blocked::before {
  background: var(--warning);
}

.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-warning::before { background: var(--warning); }

.badge-static::before {
  display: none;
}

/* ── Filter Bar ────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  align-items: center;
  flex-wrap: wrap;
}

.filter-pill {
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 150ms ease;
  font-family: var(--font-sans);
}

.filter-pill:hover {
  color: var(--text-primary);
  border-color: var(--border-light);
  background: var(--bg-elevated);
}

.filter-pill.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* ── Detail Panel ──────────────────────────────────────────── */
.detail-panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 16px;
  padding: 20px;
}

.detail-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.detail-tab {
  appearance: none;
  background: transparent;
  border: none;
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font-sans);
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 150ms ease;
}

.detail-tab:hover { color: var(--text-primary); }
.detail-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

pre.json-block {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-secondary);
  overflow-x: auto;
  max-height: 400px;
}

/* ── Activity Timeline ─────────────────────────────────────── */
.timeline {
  list-style: none;
}

.timeline-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.timeline-item:last-child { border-bottom: none; }

.timeline-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
  margin-top: 2px;
}

.timeline-icon.success { background: var(--success-bg); color: var(--success); }
.timeline-icon.error   { background: var(--error-bg);   color: var(--error); }
.timeline-icon.info    { background: var(--info-bg);    color: var(--info); }
.timeline-icon.warning { background: var(--warning-bg); color: var(--warning); }

.timeline-content { flex: 1; min-width: 0; }
.timeline-content .message {
  font-size: 13px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.timeline-content .time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Cost Bar Chart ────────────────────────────────────────── */
.cost-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 120px;
  padding: 16px 0;
}

.cost-bar {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
}

.cost-bar .bar {
  width: 100%;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  transition: height 300ms ease;
  position: relative;
  opacity: 0.85;
}

.cost-bar .bar:hover {
  background: var(--accent-hover);
  opacity: 1;
}

.cost-bar .bar-label {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 6px;
  white-space: nowrap;
}

/* ── Screenshot Gallery ────────────────────────────────────── */
.screenshot-thumb {
  width: 120px;
  height: 80px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 150ms ease;
}

.screenshot-thumb:hover {
  border-color: var(--accent);
  transform: scale(1.02);
  box-shadow: var(--shadow);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(18, 19, 21, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.modal-overlay img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ── Section Cards ─────────────────────────────────────────── */
.section-title {
  font-family: var(--font-heading);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.section-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-soft);
}

.section-card-muted {
  opacity: 0.75;
}

.customer-card {
  cursor: pointer;
  transition: border-color 150ms ease, transform 150ms ease, box-shadow 150ms ease;
}

.customer-card:hover {
  border-color: var(--accent-soft);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

/* ── Alerts ────────────────────────────────────────────────── */
.alert {
  margin-bottom: 16px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
}

.alert-success {
  background: var(--success-bg);
  border: 1px solid rgba(42, 125, 63, 0.25);
  color: var(--success);
}

.alert-error {
  background: var(--error-bg);
  border: 1px solid rgba(192, 57, 43, 0.25);
  color: var(--error);
}

/* ── Buttons ───────────────────────────────────────────────── */
.primary-button {
  appearance: none;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-family: var(--font-heading);
  font-size: 13px;
  font-weight: 600;
  padding: 10px 18px;
  transition: background 150ms ease, transform 150ms ease, box-shadow 150ms ease;
  letter-spacing: -0.01em;
}

.primary-button:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(46, 106, 103, 0.25);
}

/* ── Data / Detail Tables ──────────────────────────────────── */
.data-table,
.detail-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th,
.data-table td,
.detail-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.data-table thead th {
  position: static;
}

.detail-table td:first-child {
  color: var(--text-muted);
  font-weight: 500;
}

.detail-table tr:last-child td,
.data-table tbody tr:last-child td {
  border-bottom: none;
}

/* ── Action Timeline (Automation Logs) ─────────────────────── */
.action-step {
  display: flex;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  align-items: flex-start;
}

.action-step:last-child { border-bottom: none; }

.action-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 4px;
  white-space: nowrap;
  flex-shrink: 0;
  font-family: var(--font-heading);
}

.action-badge.login           { background: var(--info-bg);            color: var(--info); }
.action-badge.fill_field      { background: rgba(139, 92, 246, 0.10); color: #6d3fcc; }
.action-badge.submit_form     { background: var(--warning-bg);         color: var(--warning); }
.action-badge.verify_entry    { background: var(--success-bg);         color: var(--success); }
.action-badge.navigate_project { background: rgba(6, 182, 212, 0.10); color: #0e7490; }

.action-detail {
  flex: 1;
  font-size: 13px;
  color: var(--text-secondary);
}

.action-meta {
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
  white-space: nowrap;
}

/* ── Empty State ───────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state .icon {
  font-size: 32px;
  margin-bottom: 12px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 14px;
}

/* ── Period Selector ───────────────────────────────────────── */
.period-selector {
  display: flex;
  gap: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.period-btn {
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 150ms ease;
  font-family: var(--font-sans);
}

.period-btn:hover { color: var(--text-primary); }
.period-btn.active {
  background: var(--bg-surface);
  color: var(--accent);
  box-shadow: var(--shadow-soft);
}

/* ── Stack Trace ───────────────────────────────────────────── */
.stack-trace {
  background: var(--error-bg);
  border: 1px solid rgba(192, 57, 43, 0.2);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.6;
  color: var(--error);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── HTMX Loading States ──────────────────────────────────── */
.htmx-indicator {
  display: none;
}

.htmx-request .htmx-indicator {
  display: inline-block;
}

.htmx-request.htmx-indicator {
  display: inline-block;
}

[hx-get].htmx-request,
[hx-post].htmx-request,
[hx-put].htmx-request,
[hx-delete].htmx-request {
  opacity: 0.6;
  pointer-events: none;
  transition: opacity 200ms ease;
}

.htmx-loading-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: htmx-spin 600ms linear infinite;
}

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

/* ── HTMX Error Fragment ──────────────────────────────────── */
.htmx-error-fragment {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--error-bg);
  border: 1px solid rgba(192, 57, 43, 0.25);
  color: var(--error);
  font-size: 13px;
  font-weight: 500;
}

/* ── Responsive (basic) ────────────────────────────────────── */
@media (max-width: 900px) {
  .mobile-topbar {
    display: block;
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(247, 243, 236, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-soft);
  }

  .mobile-topbar .sidebar-brand {
    padding: 14px 16px 10px;
  }

  .mobile-nav {
    overflow-x: auto;
    padding: 0 8px 12px;
  }

  .mobile-nav-list {
    display: flex;
    gap: 8px;
    list-style: none;
    min-width: max-content;
  }

  .mobile-nav-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    background: var(--bg-surface);
    white-space: nowrap;
    font-size: 12px;
    font-weight: 500;
  }

  .mobile-nav-link.active {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-soft);
  }

  .stat-cards,
  .content-grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .page-header-split {
    flex-direction: column;
  }

  .sidebar {
    display: none;
  }

  .main {
    margin-left: 0;
    max-width: none;
    padding: 20px 16px 28px;
  }

  table,
  .data-table,
  .detail-table {
    min-width: 640px;
  }
}

@media (max-width: 640px) {
  .stat-cards,
  .stats-row,
  .content-grid-2 {
    grid-template-columns: 1fr;
  }

  .detail-panel,
  .section-card,
  .stat-card {
    padding: 16px;
  }
}
