:root {
  --bg: #050505;
  --bg-elevated: rgba(18, 18, 20, 0.92);
  --bg-sidebar: rgba(10, 10, 12, 0.98);
  --border: rgba(255, 255, 255, 0.08);
  --text: #f5f5f5;
  --muted: #8a8a8a;
  --accent: #e63946;
  --accent-glow: rgba(230, 57, 70, 0.45);
  --accent-dark: #b82d38;
  --success: #81c784;
  --success-border: rgba(76, 175, 80, 0.4);
  --danger: #ef5350;
  --danger-border: rgba(244, 67, 54, 0.4);
  --warn: #ffb74d;
  --serif: "Cormorant Garamond", Georgia, serif;
  --sans: "DM Sans", system-ui, sans-serif;
  --radius: 14px;
  --sidebar-w: 240px;
  --topbar-h: 64px;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
}

body {
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.ambient {
  position: fixed;
  inset: auto;
  pointer-events: none;
  z-index: 0;
  filter: blur(80px);
  opacity: 0.45;
}

.ambient-a {
  top: -120px;
  right: -80px;
  width: 420px;
  height: 420px;
  background: radial-gradient(circle, rgba(230, 57, 70, 0.35), transparent 70%);
}

.ambient-b {
  bottom: -160px;
  left: -100px;
  width: 380px;
  height: 380px;
  background: radial-gradient(circle, rgba(230, 57, 70, 0.18), transparent 70%);
}

/* ---------- Login ---------- */

.login-page {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
}

.login-card {
  width: min(420px, 100%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  padding: 2rem 1.75rem 1.75rem;
  backdrop-filter: blur(16px);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

.login-brand {
  font-family: var(--serif);
  font-size: 1.85rem;
  font-weight: 600;
  margin: 0 0 0.35rem;
  letter-spacing: 0.01em;
}

.brand-accent {
  color: var(--accent);
}

.login-sub {
  margin: 0 0 1.5rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.field span {
  font-size: 0.85rem;
  color: var(--muted);
}

.field input,
.field select,
.filter-bar input,
.filter-bar select {
  width: 100%;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  outline: none;
  transition: border-color 0.15s ease;
}

.field input:focus,
.field select:focus,
.filter-bar input:focus,
.filter-bar select:focus {
  border-color: rgba(230, 57, 70, 0.55);
}

.form-error {
  color: var(--danger);
  font-size: 0.9rem;
  margin: 0 0 0.85rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 0.7rem 1rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  background: transparent;
  color: var(--text);
}

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

.btn-primary {
  background: linear-gradient(135deg, #ff4d5a 0%, var(--accent) 45%, #c42a36 100%);
  color: white;
  font-weight: 600;
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.05);
}

.btn-outline {
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.02);
}

.btn-outline:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.06);
}

.btn-ghost {
  border-color: transparent;
  color: var(--muted);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.btn-success {
  border-color: var(--success-border);
  color: var(--success);
  background: rgba(76, 175, 80, 0.08);
}

.btn-danger {
  border-color: var(--danger-border);
  color: var(--danger);
  background: rgba(244, 67, 54, 0.08);
}

.btn-sm {
  padding: 0.4rem 0.7rem;
  font-size: 0.85rem;
  border-radius: 8px;
}

.btn-block {
  width: 100%;
}

/* ---------- Shell ---------- */

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 1.25rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.sidebar-brand {
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 600;
  padding: 0.35rem 0.65rem;
}

.sidebar-brand small {
  display: block;
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 0.15rem;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.7rem 0.8rem;
  border-radius: 10px;
  color: var(--muted);
  border: 1px solid transparent;
}

.nav-item:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.nav-item.is-active {
  color: var(--text);
  background: rgba(230, 57, 70, 0.12);
  border-color: rgba(230, 57, 70, 0.25);
}

.badge {
  min-width: 1.4rem;
  height: 1.4rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: rgba(230, 57, 70, 0.2);
  color: #ff8a93;
  font-size: 0.72rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}

.badge.is-zero {
  display: none;
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.user-meta {
  padding: 0 0.35rem;
  font-size: 0.85rem;
}

.main-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 1.5rem;
  background: rgba(5, 5, 5, 0.7);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.55rem;
  font-weight: 600;
}

.content {
  padding: 1.35rem 1.5rem 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.view {
  display: none;
  flex-direction: column;
  gap: 1.1rem;
}

.view.is-active {
  display: flex;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.85rem;
}

.kpi-grid-secondary {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.kpi-grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 0.9rem;
}

.kpi-card.is-warn .value {
  color: var(--warn);
}

.kpi-card.is-danger .value {
  color: var(--danger);
}

.attention-item.is-clickable {
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.attention-item.is-clickable:hover {
  border-color: rgba(230, 57, 70, 0.35);
  background: rgba(230, 57, 70, 0.08);
}

.error-cell {
  max-width: 360px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--danger);
  font-size: 0.85rem;
}

.btn-copy {
  border-color: var(--border);
  color: var(--muted);
  background: transparent;
}

.btn-copy:hover:not(:disabled) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.provider-label {
  text-transform: capitalize;
}

.kpi-card,
.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}

.kpi-card .label {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.kpi-card .value {
  font-family: var(--serif);
  font-size: 1.9rem;
  font-weight: 600;
  margin-top: 0.25rem;
}

.kpi-card .sub {
  margin-top: 0.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.9rem;
}

.panel-header h2,
.panel-header h3 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 600;
}

.panel-header h2 {
  font-size: 1.35rem;
}

.panel-header h3 {
  font-size: 1.15rem;
}

.panel-header p {
  margin: 0.25rem 0 0;
}

.split-2 {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 0.85rem;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 0.9rem;
}

.filter-bar input,
.filter-bar select {
  min-width: 160px;
  width: auto;
  flex: 1;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.9rem;
}

.tab {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  cursor: pointer;
}

.tab.is-active {
  color: var(--text);
  border-color: rgba(230, 57, 70, 0.4);
  background: rgba(230, 57, 70, 0.12);
}

.table-wrap {
  overflow: auto;
  max-height: min(70vh, 720px);
  border: 1px solid var(--border);
  border-radius: 12px;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  min-width: 720px;
}

table.data-table th,
table.data-table td {
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

table.data-table th {
  position: sticky;
  top: 0;
  background: rgba(16, 16, 18, 0.98);
  color: var(--muted);
  font-weight: 500;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  z-index: 1;
}

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

.mono {
  font-family: ui-monospace, "Cascadia Mono", "Segoe UI Mono", monospace;
  font-size: 0.82rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  text-transform: lowercase;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
}

.status-approved,
.status-completed,
.status-running,
.status-RUNNING {
  color: var(--success);
  border-color: var(--success-border);
  background: rgba(76, 175, 80, 0.1);
}

.status-waitlisted,
.status-pending,
.status-queued,
.status-submitted {
  color: var(--warn);
  border-color: rgba(255, 183, 77, 0.35);
  background: rgba(255, 183, 77, 0.1);
}

.status-revoked,
.status-failed,
.status-cancelled,
.status-EXITED {
  color: var(--danger);
  border-color: var(--danger-border);
  background: rgba(244, 67, 54, 0.1);
}

.user-cell {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.08);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.empty-state,
.loading-state,
.error-state {
  padding: 1.5rem 0.5rem;
  color: var(--muted);
  text-align: center;
}

.chart-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

.chart-box {
  min-height: 180px;
}

.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 0.35rem;
  height: 140px;
  margin-top: 0.75rem;
}

.chart-bar {
  flex: 1;
  min-width: 8px;
  background: linear-gradient(180deg, rgba(230, 57, 70, 0.85), rgba(230, 57, 70, 0.25));
  border-radius: 4px 4px 0 0;
  position: relative;
}

.chart-bar span {
  position: absolute;
  bottom: -1.3rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.65rem;
  color: var(--muted);
  white-space: nowrap;
}

.attention-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.attention-item {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
}

.attention-item strong {
  font-weight: 600;
}

.system-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.system-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem;
  background: rgba(255, 255, 255, 0.02);
}

.system-item .k {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.system-item .v {
  margin-top: 0.25rem;
  font-weight: 500;
}

.toast {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 50;
  background: rgba(20, 20, 22, 0.96);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  max-width: min(420px, calc(100vw - 2rem));
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.65);
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal {
  width: min(440px, 100%);
  background: rgba(16, 16, 18, 0.98);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.modal h3 {
  margin: 0 0 0.5rem;
  font-family: var(--serif);
  font-size: 1.4rem;
}

.modal p {
  margin: 0 0 1rem;
  color: var(--muted);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.55rem;
}

.forbidden-card {
  max-width: 480px;
  margin: 4rem auto;
  text-align: center;
}

@media (max-width: 1100px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .split-2,
  .chart-row,
  .system-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    height: auto;
    z-index: 6;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .nav-list {
    flex-direction: row;
    overflow-x: auto;
    gap: 0.35rem;
  }

  .nav-item {
    white-space: nowrap;
  }

  .sidebar-footer {
    display: none;
  }

  .content {
    padding: 1rem;
  }
}
