:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-muted: #edf3f4;
  --border: #d5dde5;
  --text: #14212b;
  --muted: #63717f;
  --accent: #0f766e;
  --accent-strong: #0b514c;
  --accent-weak: #dff4ee;
  --blue: #2563eb;
  --cyan: #0891b2;
  --red: #b91c1c;
  --amber: #b45309;
  --rose: #be123c;
  --ink: #13202a;
  --shadow: 0 14px 32px rgba(20, 33, 43, 0.08);
  --shadow-soft: 0 7px 18px rgba(20, 33, 43, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, #f6faf8 0%, #eef5f6 44%, #f8fafc 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  background:
    linear-gradient(180deg, #12202a 0%, #172935 54%, #21312d 100%);
  color: #f8fafc;
  box-shadow: 10px 0 26px rgba(20, 33, 43, 0.12);
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background:
    linear-gradient(135deg, #12a594 0%, #2563eb 100%);
  box-shadow: 0 10px 22px rgba(15, 118, 110, 0.28);
  font-weight: 800;
}

.brand-name,
.brand-subtitle,
.status-card p {
  margin: 0;
}

.brand-name {
  font-weight: 700;
  letter-spacing: 0.01em;
}

.brand-subtitle {
  color: #b7c2cf;
  font-size: 13px;
}

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

.nav-item {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #d7dde6;
  text-align: left;
  font-weight: 650;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.10);
  border-color: rgba(255, 255, 255, 0.18);
  color: #ffffff;
}

.nav-item:hover {
  transform: translateX(2px);
}

.nav-item.active {
  box-shadow: inset 3px 0 0 #5eead4;
}

.status-card {
  margin-top: auto;
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.10);
}

.status-dot {
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 50%;
  background: #94a3b8;
}

.status-dot.ok {
  background: #22c55e;
}

.status-dot.error {
  background: #ef4444;
}

.status-card small {
  display: block;
  margin-top: 3px;
  color: #b7c2cf;
}

.main-content {
  min-width: 0;
  padding: 30px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(213, 221, 229, 0.75);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 4px;
  font-size: 31px;
  line-height: 1.08;
}

h2 {
  margin-bottom: 5px;
  font-size: 22px;
}

h3 {
  margin-bottom: 3px;
  font-size: 16px;
}

.topbar p,
.section-header p,
.panel-header p {
  margin-bottom: 0;
  color: var(--muted);
}

.auth-panel {
  min-width: 360px;
}

.login-form,
.signed-in {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.login-form input {
  width: 132px;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.login-form button,
.ghost-button {
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--accent-strong);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  box-shadow: var(--shadow-soft);
}

.ghost-button {
  background: #fff;
  color: var(--accent);
  box-shadow: none;
}

.hidden {
  display: none !important;
}

.message-panel {
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow-soft);
}

.message-panel.error {
  border-left-color: var(--red);
}

.period-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow-soft);
}

.period-control p {
  margin-bottom: 0;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-header {
  margin-bottom: 16px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.kpi-card,
.panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.kpi-card {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 118px;
  padding: 16px;
  border-top: 4px solid var(--accent);
}

.kpi-card:nth-child(4n + 2) {
  border-top-color: var(--blue);
}

.kpi-card:nth-child(4n + 3) {
  border-top-color: var(--cyan);
}

.kpi-card:nth-child(4n) {
  border-top-color: var(--amber);
}

.kpi-card.success {
  border-top-color: #16a34a;
}

.kpi-card.warning {
  border-top-color: var(--amber);
}

.kpi-card.danger {
  border-top-color: var(--red);
}

.kpi-label {
  position: relative;
  z-index: 1;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.kpi-value {
  position: relative;
  z-index: 1;
  margin-bottom: 8px;
  font-size: 26px;
  line-height: 1.05;
  font-weight: 800;
}

.kpi-note {
  position: relative;
  z-index: 1;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.kpi-comparison {
  position: relative;
  z-index: 1;
  margin-top: 4px;
  color: #334155;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.3;
}

.kpi-card.has-sparkline {
  min-height: 156px;
}

.kpi-sparkline {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 34px;
  margin-top: auto;
  padding-top: 7px;
  overflow: visible;
  color: var(--accent);
}

.kpi-sparkline polyline {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.kpi-sparkline circle {
  fill: #ffffff;
  stroke: currentColor;
  stroke-width: 2;
}

.kpi-sparkline.success {
  color: #16a34a;
}

.kpi-sparkline.warning {
  color: var(--amber);
}

.kpi-sparkline.danger {
  color: var(--red);
}

.grid-two {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

.panel {
  margin-bottom: 16px;
  padding: 16px;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(213, 221, 229, 0.72);
}

.warning-panel {
  border-left: 4px solid var(--amber);
  background: #fff8eb;
  color: #3f2b06;
}

.period-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.period-tab {
  min-height: 36px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--text);
  box-shadow: var(--shadow-soft);
}

.period-tab.active {
  border-color: var(--accent);
  background: var(--accent-weak);
  color: #064e45;
  font-weight: 800;
}

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

.funnel-step {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fbfb;
}

.funnel-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
}

.funnel-meta strong,
.funnel-meta span {
  min-width: 0;
}

.funnel-meta span {
  color: var(--muted);
  font-weight: 700;
  text-align: right;
}

.funnel-track,
.bar-track {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #dce7ec;
}

.funnel-track span,
.bar-track i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.funnel-step small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
}

.outcome-summary {
  display: grid;
  grid-template-columns: repeat(6, minmax(110px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.outcome-stat {
  min-width: 0;
  padding: 4px 10px 4px 12px;
  border-left: 3px solid var(--accent);
}

.outcome-stat.win {
  border-left-color: #16a34a;
}

.outcome-stat.loss {
  border-left-color: var(--red);
}

.outcome-stat.withdrawn {
  border-left-color: var(--amber);
}

.outcome-stat.win-rate {
  border-left-color: var(--cyan);
}

.outcome-label,
.outcome-stat small {
  display: block;
  color: var(--muted);
}

.outcome-label {
  min-height: 34px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
}

.outcome-value {
  display: block;
  margin: 3px 0 4px;
  font-size: 22px;
  line-height: 1;
}

.outcome-stat small {
  font-size: 11px;
  line-height: 1.35;
}

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

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

th,
td {
  padding: 10px 11px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: #eaf1f3;
  color: #334155;
  font-size: 12px;
  text-transform: uppercase;
}

tbody tr:nth-child(even) {
  background: #f8fbfb;
}

tbody tr:hover {
  background: #edf7f4;
}

td.numeric,
th.numeric {
  text-align: right;
}

.bar-cell {
  display: grid;
  min-width: 120px;
  gap: 5px;
}

.bar-cell span {
  font-weight: 700;
}

.bar-track i {
  background: var(--blue);
}

.bar-track.success i {
  background: #16a34a;
}

.bar-track.warning i {
  background: var(--amber);
}

.bar-track.danger i {
  background: var(--red);
}

.metric-pill {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--accent-weak);
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.table-empty {
  color: var(--muted);
  text-align: center;
}

.health-list,
.health-grid {
  display: grid;
  gap: 9px;
}

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

.health-item {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow-soft);
}

.health-item strong {
  display: block;
  margin-bottom: 4px;
}

.health-item span {
  color: var(--muted);
  font-size: 13px;
}

canvas {
  width: 100% !important;
  max-height: 360px;
}

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

  .sidebar {
    position: static;
    height: auto;
  }

  .nav-list {
    grid-template-columns: repeat(5, minmax(110px, 1fr));
  }

  .status-card {
    margin-top: 0;
  }

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

@media (max-width: 760px) {
  .main-content,
  .sidebar {
    padding: 16px;
  }

  .topbar,
  .panel-header,
  .period-control {
    display: block;
  }

  .period-control .period-tabs {
    margin-top: 12px;
  }

  .auth-panel {
    min-width: 0;
    margin-top: 14px;
  }

  .login-form,
  .signed-in {
    justify-content: stretch;
  }

  .login-form {
    display: grid;
  }

  .login-form input,
  .login-form button {
    width: 100%;
  }

  .nav-list,
  .kpi-grid,
  .grid-two,
  .health-grid,
  .funnel-grid,
  .outcome-summary {
    grid-template-columns: 1fr;
  }

  .outcome-label {
    min-height: 0;
  }
}
