:root {
  --incident-pane-width: 38%;
  --bg: #0f172a;               /* Slate 900 */
  --surface: #1e293b;          /* Slate 800 */
  --surface-hover: #334155;    /* Slate 700 */
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.15);
  --text: #f8fafc;             /* Slate 50 */
  --muted: #94a3b8;            /* Slate 400 */
  
  --accent: #14b8a6;           /* Teal 500 */
  --accent-glow: rgba(20, 184, 166, 0.4);
  --accent-soft: rgba(20, 184, 166, 0.12);
  
  --good: #22c55e;
  --good-bg: rgba(34, 197, 94, 0.15);
  --warn: #f59e0b;
  --warn-bg: rgba(245, 158, 11, 0.15);
  --bad: #ef4444;
  --bad-bg: rgba(239, 68, 68, 0.15);
  --neutral: #64748b;
  --neutral-bg: rgba(100, 116, 139, 0.15);

  --shadow-sm: 0 4px 6px -1px rgb(0 0 0 / 0.15), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-md: 0 10px 15px -3px rgb(0 0 0 / 0.3), 0 4px 6px -4px rgb(0 0 0 / 0.2);
  --shadow-lg: 0 20px 25px -5px rgb(0 0 0 / 0.4), 0 8px 10px -6px rgb(0 0 0 / 0.3);
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--surface-hover);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100vh;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background-color: var(--bg);
  background-image: 
    radial-gradient(circle at 10% 20%, rgba(20, 184, 166, 0.08), transparent 30%),
    radial-gradient(circle at 90% 80%, rgba(56, 189, 248, 0.06), transparent 30%);
  background-attachment: fixed;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Utilities */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 12px;
  max-width: 1920px;
  margin: 0 auto;
}

.topbar, .panel, .incident-pane, .detail-hero {
  border: 1px solid var(--line);
  background: rgba(30, 41, 59, 0.65);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 20px;
  box-shadow: var(--shadow-sm);
}

/* Transitions */
button, input, select, .incident-item {
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Topbar --- */
.topbar {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand__mark {
  width: 16px;
  height: 48px;
  border-radius: 999px;
  background: linear-gradient(180deg, #2dd4bf, var(--accent));
  box-shadow: 0 0 20px var(--accent-glow);
}

.brand h1 {
  margin: 4px 0 0;
  font-weight: 600;
  font-size: 1.5rem;
  letter-spacing: -0.02em;
}

.brand__eyebrow, .section-eyebrow {
  margin: 0;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.75rem;
  font-weight: 700;
}

.topbar__controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.field, .toggle {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 0.85rem;
}

.toggle {
  flex-direction: row;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
}

.toggle:hover {
  background: rgba(255, 255, 255, 0.05);
}

.toggle input[type="checkbox"] {
  accent-color: var(--accent);
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.field select, .field input, .button {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.6);
  color: var(--text);
  padding: 12px 14px;
  font: inherit;
  font-size: 0.95rem;
  outline: none;
}

.field input::placeholder {
  color: var(--muted);
  opacity: 0.6;
}

.field select:focus, .field input:focus, .button:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.button {
  cursor: pointer;
  font-weight: 600;
  background: var(--surface-hover);
}

.button:hover {
  background: var(--muted);
  color: var(--bg);
}

.button--ghost {
  background: transparent;
  border: 1px solid var(--line-strong);
}

.button--ghost:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.button:active {
  transform: scale(0.97);
}

/* --- Workspace Layout --- */
.workspace {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.pane-resizer {
  display: none;
}

/* --- Incident Pane --- */
.incident-pane {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.pane-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-end;
}

.pane-header h2 {
  margin: 4px 0 0;
  font-weight: 600;
  font-size: 1.25rem;
}

.pane-header__meta, .detail-path, .panel__hint, .card__note, .empty-state, .threshold-box p {
  color: var(--muted);
}

.pane-header__meta {
  font-size: 0.8rem;
}

.overview-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.stat-chip {
  padding: 12px 16px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
}

.stat-chip span, .card__label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 4px;
  font-weight: 500;
}

.stat-chip strong, .card strong {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.incident-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  min-height: 0;
  max-height: 50vh;
  padding-right: 4px;
}

.incident-item {
  padding: 16px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
}

.incident-item:hover {
  transform: translateY(-2px);
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.04);
  box-shadow: var(--shadow-sm);
}

.incident-item.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 16px var(--accent-glow);
}

.incident-item:active {
  transform: scale(0.98);
}

.incident-item__title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.3;
  word-break: break-word;
}

.incident-item__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
}

.incident-item__stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.incident-stat {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.4);
}

.incident-stat span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 500;
}

.incident-stat strong {
  display: block;
  font-size: 1.05rem;
  font-weight: 600;
}

/* --- Status Pills & Tags --- */
.incident-item__statuses, .substatus-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.status-pill, .status-tag, .percentage {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 6px 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  font-size: 0.7rem;
  text-transform: uppercase;
}

.status-pill--good, .status-tag--good {
  color: var(--good);
  background: var(--good-bg);
  border: 1px solid rgba(34, 197, 94, 0.2);
}

.status-pill--warning, .status-tag--warning {
  color: var(--warn);
  background: var(--warn-bg);
  border: 1px solid rgba(245, 158, 11, 0.2);
}

.status-pill--bad, .status-tag--bad {
  color: var(--bad);
  background: var(--bad-bg);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.status-pill--neutral, .status-tag--neutral {
  color: var(--text);
  background: var(--neutral-bg);
  border: 1px solid var(--line);
}

/* --- Detail Pane --- */
.detail-pane {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.detail-hero {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.detail-hero h2 {
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.2;
  margin-top: 4px;
}

.detail-path {
  margin: 6px 0 0;
  font-size: 0.85rem;
  line-height: 1.5;
  word-break: break-word;
}

.detail-subtitle {
  margin: 12px 0 0;
  font-size: 0.95rem;
  color: var(--muted);
}

.detail-status {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
}

/* --- Panels --- */
.panel {
  padding: 20px;
}

.panel__header {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 20px;
}

.panel__header h3 {
  margin: 4px 0 0;
  font-size: 1.15rem;
  font-weight: 600;
}

.panel__hint {
  font-size: 0.85rem;
}

/* Horizontal Metric Rail */
.metric-rail {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(180px, 85vw);
  gap: 16px;
  overflow-x: auto;
  padding-bottom: 12px;
  scroll-snap-type: x mandatory;
}

.metric-rail::-webkit-scrollbar {
  height: 4px; /* Hide slightly to make it look mobile native */
}

.card {
  padding: 18px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
  min-height: 120px;
  scroll-snap-align: start;
}

.card__note {
  margin-top: 12px;
  font-size: 0.8rem;
  line-height: 1.4;
}

/* Details Columns */
.detail-columns {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.thresholds {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.threshold-box {
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
  padding: 16px;
}

.threshold-box h4 {
  margin: 0 0 12px;
  font-size: 1rem;
  font-weight: 600;
}

.threshold-box p {
  font-size: 0.9rem;
  margin: 6px 0;
}

/* Tables */
.table-wrap {
  overflow: auto;
  border-radius: 16px;
  border: 1px solid var(--line);
}

.table-wrap--compact {
  max-height: 450px;
}

.data-table {
  width: 100%;
  min-width: 600px;
  border-collapse: collapse;
}

.data-table th, .data-table td {
  text-align: left;
  vertical-align: middle;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: rgba(30, 41, 59, 0.95);
  backdrop-filter: blur(8px);
  color: var(--muted);
  font-weight: 600;
}

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

.data-table tbody tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.trace-button {
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  font-family: inherit;
  font-weight: 600;
}

.trace-button:hover {
  text-decoration: underline;
  color: #2dd4bf;
}

.json-preview {
  margin-top: 20px;
  background: rgba(15, 23, 42, 0.4);
  border-radius: 16px;
  border: 1px solid var(--line);
  overflow: hidden;
}

.json-preview summary {
  padding: 16px;
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
  outline: none;
  user-select: none;
}

.json-preview summary:hover {
  background: rgba(255, 255, 255, 0.02);
}

.json-preview pre {
  margin: 0;
  padding: 16px;
  border-top: 1px solid var(--line);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.85rem;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.empty-state {
  padding: 32px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
}

/* --- Media Queries --- */
@media (min-width: 640px) {
  .topbar__controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .field--search {
    grid-column: span 2;
  }
}

@media (min-width: 960px) {
  .app-shell {
    padding: 24px;
    height: 100vh;
    overflow: hidden;
  }

  .topbar {
    padding: 20px 24px;
  }

  .topbar__controls {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: end;
  }
  .field--search {
    grid-column: span 2;
  }

  .workspace {
    grid-template-columns: minmax(360px, var(--incident-pane-width, 38%)) 12px minmax(500px, 1fr);
    align-items: stretch;
    flex: 1;
    min-height: 0;
  }

  .pane-resizer {
    display: block;
    cursor: col-resize;
    position: relative;
    border-radius: 999px;
    z-index: 10;
  }

  .pane-resizer::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    height: 60px;
    width: 4px;
    border-radius: 4px;
    background: var(--line-strong);
    transition: all 0.2s ease;
  }

  .pane-resizer:hover::after,
  .pane-resizer:active::after {
    background: var(--accent);
    box-shadow: 0 0 12px var(--accent-glow);
    height: 100px;
  }

  .incident-pane, .detail-pane {
    height: 100%;
    overflow: hidden;
  }

  .incident-list {
    max-height: none;
    flex: 1;
  }

  .detail-pane {
    overflow-y: auto;
  }

  .detail-hero {
    position: sticky;
    top: 0;
    z-index: 20;
    margin-bottom: 16px;
  }

  .detail-columns {
    grid-template-columns: 1fr 1fr;
  }

  .metric-rail {
    grid-auto-columns: minmax(200px, 1fr);
    overflow-x: visible;
  }

  .incident-item__stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

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