:root {
  color-scheme: light;
  --bg: #f4f5f1;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --ink: #202631;
  --muted: #657083;
  --line: #d8dde5;
  --teal: #0f8f7a;
  --teal-dark: #0b6758;
  --red: #c7505a;
  --amber: #d9902f;
  --navy: #314256;
  --shadow: 0 18px 50px rgba(49, 66, 86, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(244, 245, 241, 0.96)),
    repeating-linear-gradient(90deg, rgba(49, 66, 86, 0.04) 0 1px, transparent 1px 72px);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button,
.button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--teal-dark);
  border-radius: 8px;
  padding: 0 14px;
  background: var(--teal);
  color: white;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

button:hover,
.button:hover {
  background: var(--teal-dark);
}

button.secondary,
.button.secondary {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

button.danger {
  border-color: #a63a44;
  background: var(--red);
  color: white;
}

button.danger:hover {
  background: #a63a44;
}

code,
pre {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.app-shell {
  width: min(1440px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.topbar,
.panel-header,
.toolbar,
.status-strip,
.filters-panel,
.date-filter {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(2rem, 3vw, 3.1rem);
  line-height: 1;
  letter-spacing: 0;
}

.toolbar {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.client-picker {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.client-picker select,
.date-filter input,
.stack-form input,
.stack-form textarea,
.inline-edit-form input,
td textarea,
.login-card input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: white;
  color: var(--ink);
}

.client-picker select,
.date-filter input,
.stack-form input,
.inline-edit-form input,
.login-card input {
  min-height: 40px;
}

.stack-form textarea,
td textarea {
  padding-top: 10px;
  resize: vertical;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--teal-dark);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.status-strip {
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  margin-bottom: 16px;
  background: rgba(255, 255, 255, 0.78);
}

.filters-panel {
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
  background: rgba(255, 255, 255, 0.78);
}

.date-filter {
  flex-wrap: wrap;
  gap: 10px;
}

.date-filter label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.date-filter input {
  min-height: 40px;
}

.status-strip > div {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--teal);
  box-shadow: 0 0 0 4px rgba(15, 143, 122, 0.14);
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric,
.panel,
.login-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.metric {
  min-height: 112px;
  padding: 18px;
}

.metric span,
.muted {
  color: var(--muted);
}

.metric span {
  display: block;
  margin-bottom: 14px;
  font-size: 0.86rem;
  font-weight: 800;
}

.metric strong {
  font-size: clamp(1.9rem, 3vw, 2.9rem);
  line-height: 1;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(300px, 0.75fr);
  gap: 16px;
  margin-bottom: 16px;
}

.clients-grid {
  grid-template-columns: minmax(300px, 420px) minmax(0, 1fr);
}

.panel {
  min-width: 0;
  padding: 18px;
}

.panel-header {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel h2 {
  margin: 0;
  font-size: 1.08rem;
  letter-spacing: 0;
}

.chart-panel {
  grid-row: span 2;
}

canvas {
  width: 100%;
  height: 320px;
  display: block;
}

.funnel,
.rank-list,
.stack-form,
.login-card form {
  display: grid;
  gap: 14px;
}

.funnel-label,
.rank-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.funnel-label span,
.rank-row span {
  color: var(--muted);
}

.bar-track,
.rank-meter {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-2);
}

.bar-track span,
.rank-meter span {
  height: 100%;
  display: block;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--amber));
}

.rank-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(90px, 160px) 42px;
  align-items: center;
}

.rank-row div:first-child {
  display: grid;
  gap: 3px;
}

.rank-row b {
  text-align: right;
}

.snippet-panel pre {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #18202c;
  color: #e7f3ef;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

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

th {
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
}

.event-pill {
  display: inline-flex;
  border-radius: 999px;
  padding: 4px 8px;
  background: var(--surface-2);
  color: var(--navy);
  font-size: 0.82rem;
  font-weight: 800;
}

.success,
.alert {
  border-radius: 8px;
  padding: 12px 14px;
  font-weight: 700;
}

.success {
  border: 1px solid rgba(15, 143, 122, 0.28);
  background: rgba(15, 143, 122, 0.1);
}

.alert {
  border: 1px solid rgba(199, 80, 90, 0.3);
  background: rgba(199, 80, 90, 0.1);
}

.stack-form label,
.login-card label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 800;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: min(420px, 100%);
  padding: 24px;
}

.login-card h1 {
  margin: 0 0 18px;
  font-size: 2.3rem;
  letter-spacing: 0;
}

@media (max-width: 980px) {
  .topbar,
  .status-strip,
  .filters-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar {
    justify-content: flex-start;
  }

  .metrics-grid,
  .workspace-grid,
  .clients-grid {
    grid-template-columns: 1fr;
  }

  .chart-panel {
    grid-row: auto;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100vw - 20px, 100%);
  }

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

  .toolbar,
  .filters-panel > *,
  .date-filter,
  .date-filter > *,
  .toolbar > * {
    width: 100%;
  }
}
