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

body {
  font-family: system-ui, sans-serif;
  font-size: 14px;
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: #c8cdd6;
  color: #222;
}

/* Sidebar */
#sidebar {
  width: 180px;
  background: #1e2a3a;
  color: #cdd;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

#sidebar h1 {
  padding: 16px 12px;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid #2e3f54;
}

#sidebar nav a {
  display: block;
  padding: 10px 14px;
  color: #aac;
  text-decoration: none;
  font-size: 13px;
  cursor: pointer;
  border-left: 3px solid transparent;
}

#sidebar nav .nav-group-label {
  padding: 14px 14px 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #6b7f95;
  user-select: none;
}

#sidebar nav .nav-group-label:first-child {
  padding-top: 10px;
}

#sidebar nav a:hover,
#sidebar nav a.active {
  background: #2e3f54;
  color: #fff;
  border-left-color: #4fa3e0;
}

/* Main content */
#main {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: #c8cdd6;
}

/* Section root — sits directly on the dark base, no outer card */
#main > div[x-data] {
  min-height: 100%;
}

/* Section header */
.section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.section-header h2 {
  font-size: 18px;
  font-weight: 600;
}

/* Buttons */
button, .btn {
  padding: 6px 12px;
  border: 1px solid #bbb;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.4;
  white-space: nowrap;
}

button:hover, .btn:hover { background: #eee; }

button.primary, .btn-primary {
  background: #2563eb;
  color: #fff;
  border-color: #1d4ed8;
}

button.primary:hover, .btn-primary:hover { background: #1d4ed8; }

button.danger, .btn-danger {
  background: #dc2626;
  color: #fff;
  border-color: #b91c1c;
}

button.danger:hover, .btn-danger:hover { background: #b91c1c; }

button.small { padding: 3px 8px; font-size: 12px; white-space: nowrap; }

/* Tables */
table + table, .filter-bar + table, .filter-card + table {
  margin-top: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,.10), 0 0 0 1px rgba(0,0,0,.05);
}
.box table { box-shadow: none; border-radius: 0; }

.history-row { transition: background 0.12s ease; }
.history-row:hover { background: #f3f4f6; }

.ut-pill {
  display: inline-flex;
  align-items: center;
  margin-right: 6px;
  padding: 4px 10px;
  border-radius: 14px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

th {
  background: #f0f0f0;
  text-align: left;
  padding: 8px 12px;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid #ddd;
}

td {
  padding: 8px 12px;
  border-bottom: 1px solid #eee;
  vertical-align: top;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafafa; }

/* Forms */
.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
  align-items: flex-end;
}

label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 3px; color: #555; }

input[type=text], input[type=number], input[type=date], select, textarea {
  padding: 6px 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
  width: 100%;
  height: 32px;
  box-sizing: border-box;
  background: #fff;
  font-family: inherit;
}
textarea { height: auto; }

input[type=text]:focus, select:focus { outline: 2px solid #2563eb; }

input.small, select.small {
  height: 26px;
  padding: 3px 6px;
  font-size: 12px;
}

.field { flex: 1; min-width: 120px; }
.field-sm { flex: 0 0 120px; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: #fff;
  border-radius: 8px;
  padding: 24px;
  width: 520px;
  max-width: 95vw;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
}

.modal h3 { font-size: 16px; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* Alerts */
.alert {
  padding: 10px 14px;
  border-radius: 4px;
  margin-bottom: 12px;
  font-size: 13px;
}

.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }

/* Dashboard stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card {
  background: #fff;
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,.10), 0 0 0 1px rgba(0,0,0,.05);
}

.stat-card .label { font-size: 11px; font-weight: 600; text-transform: uppercase; color: #888; margin-bottom: 6px; }
.stat-card .value { font-size: 28px; font-weight: 700; color: #1e2a3a; }

/* Convention: expanded inline block = .sub-panel card (left accent + bottom border + margin-bottom); the triggering header row gets .is-expanded */
.sub-panel {
  background: #f8fafc;
  border: none;
  box-shadow: none;
  border-top: 2px solid #e2e8f0;
  border-left: 3px solid #4fa3e0;
  border-bottom: 2px solid #cbd5e1;
  border-radius: 0 0 6px 6px;
  padding: 14px 16px;
  margin: 0 0 12px;
}

/* Expanded bucket header row fuses with its .sub-panel body below */
tr.is-expanded > td {
  background: #eef4fb;
  border-bottom: none;
}

/* Nested tables inside sub-panels: no shadow at all */
.sub-panel table {
  box-shadow: none;
  border: 1px solid #e5e7eb;
}

.sub-panel th {
  background: #f2f4f7;
}

/* Code / JSON */
pre {
  background: #1e2a3a;
  color: #cef;
  padding: 12px;
  border-radius: 4px;
  font-size: 12px;
  overflow: auto;
  max-height: 300px;
  white-space: pre-wrap;
}

/* Toggle */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.toggle input { width: auto; }

/* Key reveal box */
.key-box {
  font-family: monospace;
  background: #f0f4ff;
  border: 1px solid #93c5fd;
  border-radius: 4px;
  padding: 10px;
  word-break: break-all;
  font-size: 13px;
  margin: 10px 0;
}

/* Filter bar */
.filter-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.filter-bar .field { flex: 0 1 200px; }

.loading-bar {
  height: 2px;
  background: #e5e7eb;
  border-radius: 1px;
  position: relative;
  overflow: hidden;
  margin-bottom: -2px;
}
.loading-bar::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 30%;
  background: #2563eb;
  border-radius: 1px;
  animation: loading-bar-slide 1.1s ease-in-out infinite;
}
@keyframes loading-bar-slide {
  0%   { left: -30%; }
  100% { left: 100%; }
}

/* Generic content card */
.box {
  background: #fff;
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,.10), 0 0 0 1px rgba(0,0,0,.05);
}

/* Filter / run-billing control bars */
.filter-card {
  background: #fff;
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,.10), 0 0 0 1px rgba(0,0,0,.05);
  margin-bottom: 16px;
}

/* API key setup overlay */
#key-setup {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

#key-setup .box {
  background: #fff;
  border-radius: 8px;
  padding: 32px;
  width: 420px;
  text-align: center;
}

#key-setup h2 { margin-bottom: 12px; font-size: 18px; }
#key-setup p { color: #555; margin-bottom: 16px; font-size: 13px; }
#key-setup input { margin-bottom: 12px; }

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 600;
}
.badge-green { background: #d1fae5; color: #065f46; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-gray { background: #f3f4f6; color: #4b5563; }

/* Review badge — static layout in the class, color via .ok/.warn modifier.
   Pure class binding (no reactive :style) so the Alpine :style string-vs-object
   gotcha cannot regress this to a square rectangle. */
.review-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.review-badge.ok { background: #d1fae5; color: #065f46; }
.review-badge.warn { background: #fef3c7; color: #92400e; }

/* Clickable source-type badge + active (selected-filter) state. Active state
   is a pure class toggle (.badge-active) — no reactive :style — so the Alpine
   :style string-vs-object gotcha cannot regress badge layout. */
.badge-click { cursor: pointer; }
.badge.badge-active { background: #1e40af; color: #fff; }
.unreviewed-count {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
  background: #fef3c7;
  color: #92400e;
}

/* Nav icons */
#sidebar nav a i {
  width: 16px;
  margin-right: 6px;
  text-align: center;
  opacity: 0.7;
}

#sidebar nav a:hover i,
#sidebar nav a.active i {
  opacity: 1;
}

/* User popover menu item hover */
.user-menu-item:hover {
  background: #2e3f54 !important;
  color: #fff !important;
}

/* Spinner */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(0,0,0,0.1);
  border-top-color: #4fa3e0;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.spinner-sm {
  width: 14px;
  height: 14px;
  border-width: 2px;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.loading-row td {
  text-align: center;
  padding: 32px;
  color: #999;
}

/* Skeleton loading */
.skeleton {
  display: block;
  background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
  border-radius: 4px;
}
@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Modal tabs */
.modal-tab {
  all: unset;
  padding: 9px 18px;
  cursor: pointer;
  font-size: 13px;
  border-radius: 6px 6px 0 0;
  margin-bottom: -1px;
  position: relative;
  z-index: 1;
  color: rgba(255,255,255,0.5);
}
.modal-tab:hover {
  color: #fff;
  background: rgba(255,255,255,0.15);
}
.modal-tab.active {
  background: #fff;
  color: #111;
  font-weight: 600;
}
