/* ============================================================
   EVV Monitor — Dashboard UI
   ============================================================ */

:root {
  --bg:           #0f1117;
  --bg-surface:   #1a1d27;
  --bg-card:      #222533;
  --bg-hover:     #2a2e3d;
  --border:       #2e3348;
  --text:         #e1e4ed;
  --text-muted:   #8b90a5;
  --text-dim:     #5c6178;
  --accent:       #6c8cff;
  --accent-hover: #8aa4ff;
  --green:        #34d399;
  --green-bg:     rgba(52,211,153,.12);
  --yellow:       #fbbf24;
  --yellow-bg:    rgba(251,191,36,.12);
  --red:          #f87171;
  --red-bg:       rgba(248,113,113,.12);
  --blue:         #60a5fa;
  --blue-bg:      rgba(96,165,250,.12);
  --purple:       #a78bfa;
  --purple-bg:    rgba(167,139,250,.12);
  --radius:       8px;
  --radius-lg:    12px;
  --sidebar-w:    240px;
  --font:         'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  overflow: hidden;
  font-size: 14px;
  line-height: 1.5;
}

/* ---- SIDEBAR ---- */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -.02em;
  border-bottom: 1px solid var(--border);
}

.brand-icon {
  width: 32px;
  height: 32px;
  background: var(--accent);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: var(--radius);
  font-weight: 500;
  font-size: 13.5px;
  transition: background .15s, color .15s;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.nav-item.active {
  background: var(--accent);
  color: #fff;
}

.nav-item.active svg { stroke: #fff; }

.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.health-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}

.health-dot.ok   { background: var(--green); box-shadow: 0 0 6px var(--green); }
.health-dot.fail { background: var(--red); }

/* ---- MAIN CONTENT ---- */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
}

.view { display: none; }
.view.active { display: block; }

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
}

.view-header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.02em;
}

.subtitle {
  color: var(--text-muted);
  font-size: 13px;
  width: 100%;
}

/* ---- STATS GRID ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -.03em;
  margin-bottom: 2px;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  font-weight: 600;
}

.stat-active  .stat-value { color: var(--green); }
.stat-pending .stat-value { color: var(--yellow); }
.stat-error   .stat-value { color: var(--red); }
.stat-changes .stat-value { color: var(--blue); }
.stat-recent  .stat-value { color: var(--purple); }

/* ---- PANEL ---- */
.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  margin-bottom: 20px;
}

.panel h2 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 14px;
}

/* ---- FILTERS BAR ---- */
.filters-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-hover);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--border); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 6px 10px;
}
.btn-ghost:hover { color: var(--text); }

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.btn-approve { background: var(--green-bg); color: var(--green); border: 1px solid rgba(52,211,153,.25); }
.btn-approve:hover:not(:disabled) { background: rgba(52,211,153,.22); }

.btn-pause  { background: var(--yellow-bg); color: var(--yellow); border: 1px solid rgba(251,191,36,.25); }
.btn-pause:hover:not(:disabled) { background: rgba(251,191,36,.22); }

.btn-resume { background: var(--blue-bg); color: var(--blue); border: 1px solid rgba(96,165,250,.25); }
.btn-resume:hover:not(:disabled) { background: rgba(96,165,250,.22); }

.btn-danger { background: var(--red-bg); color: var(--red); border: 1px solid rgba(248,113,113,.25); }
.btn-danger:hover:not(:disabled) { background: rgba(248,113,113,.22); }

/* ---- INPUTS ---- */
.input {
  padding: 8px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  outline: none;
  transition: border-color .15s;
}

.input:focus { border-color: var(--accent); }

select.input { cursor: pointer; }

/* ---- TABLE ---- */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

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

/* ---- BADGES ---- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .02em;
}

.badge-active         { background: var(--green-bg); color: var(--green); }
.badge-paused         { background: var(--yellow-bg); color: var(--yellow); }
.badge-pending_review { background: var(--blue-bg); color: var(--blue); }
.badge-error_paused   { background: var(--red-bg); color: var(--red); }
.badge-manual         { background: var(--purple-bg); color: var(--purple); }
.badge-discovered     { background: var(--blue-bg); color: var(--blue); }

.tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  background: var(--bg-hover);
  color: var(--text-muted);
  margin: 1px 2px;
}

.state-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  background: var(--purple-bg);
  color: var(--purple);
  cursor: default;
}

/* ---- URL CELL ---- */
.url-cell {
  min-width: 280px;
  max-width: 280px;
  overflow-wrap: break-word;
  word-break: break-all;
  white-space: normal;
  line-height: 1.4;
}

.url-cell a {
  color: var(--accent);
  text-decoration: none;
}
.url-cell a:hover { text-decoration: underline; }

/* ---- CHANGES FEED ---- */
.changes-feed { display: flex; flex-direction: column; gap: 12px; }

.change-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.change-card:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}

.change-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.change-card-url {
  color: var(--accent);
  font-weight: 600;
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.change-card-score {
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.change-card-meta {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.change-card-preview {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 11.5px;
  line-height: 1.6;
  max-height: 160px;
  overflow: hidden;
  white-space: pre-wrap;
  color: var(--text-muted);
}

.diff-line-add { color: var(--green); }
.diff-line-rm  { color: var(--red); }

/* ---- DIFF VIEWER ---- */
.diff-meta {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  font-size: 13px;
  color: var(--text-muted);
}

.diff-meta strong { color: var(--text); }

.diff-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 12px;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-x: auto;
  max-height: 70vh;
  overflow-y: auto;
}

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

.modal-backdrop[hidden] { display: none; }

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 480px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 { font-size: 16px; font-weight: 700; }

.modal-close { font-size: 22px; line-height: 1; }

.modal-body {
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 6px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.field span {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.field-row {
  display: flex;
  gap: 12px;
}

/* ---- TOAST ---- */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  animation: toastIn .25s ease;
  max-width: 360px;
}

.toast-success { background: var(--green-bg); color: var(--green); border: 1px solid rgba(52,211,153,.3); }
.toast-error   { background: var(--red-bg);   color: var(--red);   border: 1px solid rgba(248,113,113,.3); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- EMPTY STATE ---- */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
  font-size: 14px;
}

/* ---- RESPONSIVE ---- */
@media (max-width: 768px) {
  .sidebar { width: 56px; min-width: 56px; }
  .sidebar-brand span, .nav-item span:not(.nav-item), .sidebar-footer span:not(.health-dot) { display: none; }
  .nav-item { justify-content: center; padding: 12px; }
  .content { padding: 18px 14px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ---- ACTION CELL ---- */
.action-cell {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

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

/* ---- DISCOVERY TABLE ---- */
.change-summary-cell {
  font-size: 12.5px;
  color: var(--text-muted);
  max-width: 340px;
  line-height: 1.5;
}

.run-query {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  color: var(--text-muted);
  max-width: 400px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
