:root {
  --bg-0: #f4f6fb;
  --bg-1: #eef2f8;
  --bg-2: #e9edf6;
  --surface: #ffffff;
  --surface-strong: #f9fbff;
  --text-main: #171d29;
  --text-muted: #81889a;
  --line: #e7ebf2;
  --accent: #1f9e9b;
  --accent-soft: rgba(31, 158, 155, 0.1);
  --safe: #58c88f;
  --warning: #e6b466;
  --critical: #e8797f;
  --shadow: 0 10px 24px rgba(27, 42, 70, 0.06);
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 8px;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Manrope", "Segoe UI", sans-serif;
  color: var(--text-main);
  background: linear-gradient(145deg, var(--bg-0), var(--bg-1) 45%, var(--bg-2));
}

.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 0;
  min-height: calc(100vh - 28px);
  max-width: 1420px;
  margin: 14px auto;
  padding: 0;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  animation: fade-in 320ms ease-out;
}

.glass {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: none;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px 16px;
  border-right: 1px solid var(--line);
  border-radius: 0;
}

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

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--accent);
  background: #f4f9f9;
  border: 1px solid #d8ecec;
}

.material-symbols-rounded {
  font-size: 22px;
  vertical-align: middle;
}

.brand-title {
  margin: 0;
  font-weight: 700;
  letter-spacing: 0;
}

.brand-subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.nav-stack {
  display: grid;
  gap: 8px;
}

.nav-item {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: #3b4355;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 160ms ease;
}

.nav-item:hover {
  border-color: #e8ebf2;
  background: #f8f9fd;
}

.nav-item.active {
  color: #111827;
  border-color: #e8ebf2;
  background: #f6f8fc;
}

.api-settings {
  margin-top: auto;
  display: grid;
  gap: 8px;
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface-strong);
}

.api-settings h2 {
  margin: 0 0 4px;
  font-size: 0.95rem;
}

label {
  color: var(--text-muted);
  font-size: 0.82rem;
}

input,
select,
button {
  font-family: inherit;
}

input,
select {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text-main);
  padding: 9px 10px;
}

input:focus,
select:focus {
  outline: none;
  border-color: rgba(34, 168, 165, 0.55);
  box-shadow: 0 0 0 3px rgba(34, 168, 165, 0.14);
}

.checkbox-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.checkbox-line input {
  width: auto;
  margin: 0;
}

.button-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.btn-primary,
.btn-secondary {
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 160ms ease, filter 160ms ease;
  padding: 9px 10px;
}

.btn-primary {
  color: #ffffff;
  background: #1f9e9b;
  border-color: rgba(31, 158, 155, 0.45);
  font-weight: 600;
}

.btn-secondary {
  color: #444d61;
  background: #f2f5fa;
  border-color: #dfe5ee;
}

.btn-primary:hover,
.btn-secondary:hover {
  transform: translateY(-1px);
  filter: brightness(1.02);
}

.status-badge {
  font-size: 0.78rem;
  border-radius: 999px;
  padding: 6px 10px;
  width: fit-content;
  border: 1px solid var(--line);
}

.status-badge.ok {
  color: var(--safe);
  background: rgba(88, 200, 143, 0.16);
  border-color: rgba(88, 200, 143, 0.36);
}

.status-badge.error {
  color: var(--critical);
  background: rgba(232, 121, 127, 0.15);
  border-color: rgba(232, 121, 127, 0.34);
}

.status-badge.idle {
  color: var(--text-muted);
  background: #f3f6fb;
}

.workspace {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 14px;
  padding: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-radius: 0;
  border: 0;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.74rem;
  letter-spacing: 0.06em;
}

h1 {
  margin: 4px 0 0;
  font-size: 1.42rem;
}

.topbar-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.topbar-controls label {
  font-size: 0.78rem;
}

.view {
  display: none;
  gap: 12px;
  align-content: start;
  padding: 0 18px 18px;
}

.view.active {
  display: grid;
}

.panel {
  padding: 12px;
  border-radius: var(--radius-md);
  background: #ffffff;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.panel-heading h2 {
  margin: 0;
  font-size: 0.98rem;
}

.panel-heading .material-symbols-rounded {
  display: none;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 10px;
}

.kpi-card {
  padding: 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: #ffffff;
}

.kpi-grid .kpi-card:nth-child(4) {
  border-color: #d5eceb;
  background: #f4fafa;
}

.kpi-card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.kpi-card h3 {
  margin: 6px 0 0;
  font-size: 1.25rem;
}

.risk-chip {
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.9rem;
  border: 1px solid transparent;
}

.risk-safe {
  color: var(--safe);
  background: rgba(88, 200, 143, 0.15);
  border-color: rgba(88, 200, 143, 0.36);
}

.risk-warning {
  color: var(--warning);
  background: rgba(230, 180, 102, 0.16);
  border-color: rgba(230, 180, 102, 0.36);
}

.risk-critical {
  color: var(--critical);
  background: rgba(232, 121, 127, 0.16);
  border-color: rgba(232, 121, 127, 0.36);
}

.status-lines p {
  margin: 8px 0;
  color: var(--text-muted);
}

.status-lines strong {
  color: var(--text-main);
}

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

.chart-grid {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 10px;
}

.plot-box {
  width: 100%;
  min-height: 240px;
  border-radius: 12px;
  background: #fcfdff;
}

.leaderboard {
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 6px;
  color: var(--text-muted);
}

.alerts-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
}

.alert-item {
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 8px 10px;
  background: #fcfdff;
  color: var(--text-main);
}

.alert-item.warning {
  border-color: rgba(230, 180, 102, 0.34);
  background: rgba(230, 180, 102, 0.14);
}

.alert-item.critical {
  border-color: rgba(232, 121, 127, 0.35);
  background: rgba(232, 121, 127, 0.14);
}

.alert-item.info {
  color: var(--text-muted);
}

.form-grid {
  display: grid;
  gap: 8px;
}

.error-text {
  margin: 2px 0 0;
  min-height: 1rem;
  color: var(--critical);
  font-size: 0.82rem;
}

.helper-text {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.upload-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.upload-controls input[type="file"] {
  flex: 1;
  min-width: 220px;
}

.analytics-filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  align-items: end;
}

.table-wrap {
  overflow: auto;
  max-height: 340px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

thead th {
  text-align: left;
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8f9fc;
  color: var(--text-muted);
}

th,
td {
  padding: 7px 9px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

tbody tr:hover {
  background: rgba(34, 168, 165, 0.06);
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  border-radius: 8px;
  border: 1px solid rgba(34, 168, 165, 0.35);
  background: #ffffff;
  padding: 9px 11px;
  color: var(--text-main);
  box-shadow: var(--shadow);
  transform: translateY(8px);
  opacity: 0;
  transition: all 180ms ease;
  pointer-events: none;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

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

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
    min-height: 100vh;
    border-radius: 12px;
  }

  .sidebar {
    position: static;
    display: grid;
    grid-template-columns: 1fr;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .chart-grid,
  .dual-grid,
  .analytics-filters {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 680px) {
  .app-shell {
    margin: 0;
    border-radius: 0;
    border: 0;
    box-shadow: none;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .topbar-controls {
    width: 100%;
    flex-wrap: wrap;
  }

  .upload-controls {
    flex-direction: column;
    align-items: stretch;
  }

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

  .view {
    padding: 0 10px 12px;
  }

  .topbar {
    padding: 12px 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-shell,
  .nav-item,
  .btn-primary,
  .btn-secondary,
  .toast {
    animation: none !important;
    transition: none !important;
  }
}
