:root {
  color-scheme: light;
  --bg: #f7fbff;
  --bg-2: #ffffff;
  --card: #ffffff;
  --card-soft: #f8fbff;
  --text: #132033;
  --muted: #607086;
  --line: #dfe8f2;
  --line-strong: #cbd8e6;
  --brand: #071b4d;
  --brand-2: #1267e8;
  --accent: #14b8a6;
  --accent-2: #20c997;
  --danger: #b42318;
  --danger-bg: #fff1f0;
  --warning: #a15c07;
  --warning-bg: #fffaeb;
  --success: #147647;
  --success-bg: #ecfdf5;
  --info-bg: #eaf4ff;
  --shadow: 0 18px 45px rgba(7, 27, 77, 0.08);
  --shadow-soft: 0 10px 24px rgba(7, 27, 77, 0.06);
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 14px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #07111f;
  --bg-2: #0b1628;
  --card: #0f1d33;
  --card-soft: #0b1729;
  --text: #e8eef8;
  --muted: #9fb0c8;
  --line: #213653;
  --line-strong: #304a6d;
  --brand: #7db7ff;
  --brand-2: #4f9cff;
  --accent: #2dd4bf;
  --accent-2: #5eead4;
  --danger: #ff9b91;
  --danger-bg: rgba(180, 35, 24, 0.16);
  --warning: #fbbf24;
  --warning-bg: rgba(251, 191, 36, 0.14);
  --success: #7ee2a8;
  --success-bg: rgba(20, 118, 71, 0.18);
  --info-bg: rgba(79, 156, 255, 0.16);
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.34);
  --shadow-soft: 0 12px 28px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(18, 103, 232, .10), transparent 32rem),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 52%, var(--bg) 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a { color: inherit; }

.app-header {
  position: relative;
  overflow: hidden;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  padding: 34px clamp(18px, 4vw, 48px);
  background: linear-gradient(120deg, #071b4d 0%, #0b2b6f 58%, #1267e8 118%);
  color: white;
  border-bottom: 1px solid rgba(255,255,255,.18);
}

.app-header::before {
  content: "";
  position: absolute;
  inset: -60% -20% auto auto;
  width: 440px;
  height: 440px;
  border-radius: 50%;
  background: rgba(20, 184, 166, .18);
  filter: blur(2px);
}

.app-header > * { position: relative; z-index: 1; }

.app-header.compact {
  align-items: center;
  padding-block: 22px;
}

.header-copy { max-width: 760px; }

h1 {
  margin: 4px 0 8px;
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: .95;
  letter-spacing: -0.055em;
}

.app-header.compact h1 { font-size: clamp(1.9rem, 4vw, 2.8rem); }

h2 { margin: 0; font-size: 1.45rem; letter-spacing: -0.03em; }
h3 { margin: 26px 0 10px; letter-spacing: -0.02em; }
p { line-height: 1.5; }

.eyebrow {
  margin: 0 0 6px;
  color: #b7fff1;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  font-size: 0.76rem;
  opacity: .98;
  font-weight: 900;
}

.app-header p { margin: 8px 0 0; color: #dbeafe; }

.header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
}

.header-status {
  width: 100%;
  text-align: right;
  color: rgba(219, 234, 254, .92);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .02em;
}

main {
  width: min(1180px, calc(100% - 32px));
  margin: 26px auto 80px;
}

.card, .lead-card {
  background: linear-gradient(135deg, var(--card) 0%, var(--card-soft) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-soft);
}

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

.metric {
  min-height: 116px;
  display: grid;
  align-content: center;
  gap: 7px;
  position: relative;
  overflow: hidden;
}

.metric::after {
  content: "";
  position: absolute;
  right: -34px;
  top: -34px;
  width: 92px;
  height: 92px;
  border-radius: 50%;
  background: rgba(18, 103, 232, .08);
}

.metric-value {
  font-size: clamp(1.8rem, 3vw, 2.25rem);
  font-weight: 900;
  letter-spacing: -0.055em;
  color: var(--text);
}

.metric-label {
  color: var(--muted);
  font-weight: 800;
  font-size: 0.86rem;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr 220px auto;
  gap: 12px;
  margin-bottom: 18px;
  align-items: end;
}

input, select, button, .button, textarea {
  border: 1px solid var(--line-strong);
  border-radius: 13px;
  padding: 10px 12px;
  font: inherit;
}

input, select, textarea {
  background: var(--card);
  color: var(--text);
  min-width: 190px;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--brand-2);
  box-shadow: 0 0 0 3px rgba(18,103,232,.13);
}

input::placeholder { color: color-mix(in srgb, var(--muted), transparent 18%); }

button, .button {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: white;
  border-color: transparent;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-weight: 900;
  white-space: nowrap;
  box-shadow: 0 10px 18px rgba(18,103,232,.16);
}

button:hover, .button:hover {
  filter: brightness(1.04);
  transform: translateY(-1px);
}

.button.small { padding: 7px 10px; font-size: 0.9rem; }

.button.secondary, button.secondary {
  background: rgba(255,255,255,0.14);
  border-color: rgba(255,255,255,0.28);
  color: white;
  box-shadow: none;
}

.card button.secondary, .lead-card button.secondary {
  background: var(--card);
  border-color: var(--line-strong);
  color: var(--text);
}

button.secondary:hover, .button.secondary:hover { background: rgba(255,255,255,0.22); }
.card button.secondary:hover, .lead-card button.secondary:hover { background: var(--info-bg); }

.lead-list { display: grid; gap: 14px; }

.lead-card {
  cursor: pointer;
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}

.lead-card:hover {
  transform: translateY(-2px);
  border-color: rgba(18, 103, 232, .42);
  box-shadow: var(--shadow);
}

.lead-topline {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.lead-topline strong { font-size: 1.05rem; }

.lead-meta {
  color: var(--muted);
  margin: 7px 0;
  font-weight: 650;
}

.lead-actions-row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 12px;
  color: var(--muted);
}

.badge {
  background: var(--info-bg);
  color: #18466d;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.76rem;
  font-weight: 900;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

html[data-theme="dark"] .badge { color: #dbeafe; }
.badge.danger { color: var(--danger); background: var(--danger-bg); }
.badge.warning { color: var(--warning); background: var(--warning-bg); }
.badge.success { color: var(--success); background: var(--success-bg); }

.grid.two {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.grid.two > div {
  background: var(--card-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 12px;
}

pre {
  white-space: pre-wrap;
  background: #101828;
  color: #d0d5dd;
  padding: 18px;
  border-radius: 14px;
  overflow: auto;
  border: 1px solid rgba(255,255,255,.08);
}

html[data-theme="dark"] pre { background: #060b14; color: #d8e1ee; }

.event {
  padding: 12px 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.event span { float: right; font-size: 0.9rem; }
.error { color: var(--danger); font-weight: 800; margin: 10px 0; }
.empty { color: var(--muted); padding: 30px; text-align: center; }
.back-link { color: white; opacity: 0.88; text-decoration: none; font-weight: 800; }
.back-link:hover { opacity: 1; }

.user-pill {
  border: 1px solid rgba(255,255,255,0.28);
  background: rgba(255,255,255,0.14);
  color: white;
  border-radius: 999px;
  padding: 10px 12px;
  font-weight: 800;
  box-shadow: none;
}

.login-page {
  min-height: 100vh;
  background:
    radial-gradient(circle at top right, rgba(20,184,166,.24), transparent 26rem),
    linear-gradient(120deg, #071b4d 0%, #0b2b6f 58%, #1267e8 118%);
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  margin: 0 auto;
  padding: 24px;
}

.login-card {
  width: min(470px, 100%);
  background: rgba(255,255,255,.96);
}

html[data-theme="dark"] .login-card { background: rgba(15,29,51,.96); }
.login-card h1 { color: var(--text); }
.login-card form { display: grid; gap: 10px; margin-top: 18px; }
.login-card input, .login-card button { width: 100%; }
.eyebrow.dark { color: var(--brand-2); opacity: 1; }
html[data-theme="dark"] .eyebrow.dark { color: var(--accent-2); }

.muted { color: var(--muted); }
.small { font-size: 0.9rem; }

.user-form {
  display: grid;
  grid-template-columns: 1fr 1.1fr 1fr 180px auto;
  gap: 12px;
  align-items: end;
}

.user-edit-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr)) auto auto;
  gap: 10px;
  align-items: center;
  margin-top: 14px;
}

.danger-text { color: #ffd2cd !important; }
.card .danger-text, .lead-card .danger-text { color: var(--danger) !important; }

.refresh-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(255,255,255,.25);
  background: rgba(255,255,255,.12);
  color: #dbeafe;
  border-radius: 999px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 900;
}

.refresh-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--accent-2);
  box-shadow: 0 0 0 4px rgba(20,184,166,.16);
}

@media (max-width: 1080px) {
  .summary-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .user-form, .user-edit-grid { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .app-header { flex-direction: column; align-items: flex-start; }
  .header-actions { justify-content: flex-start; width: 100%; }
  .header-status { text-align: left; }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar { grid-template-columns: 1fr; }
  input, select, button, .button { width: 100%; }
  .grid.two { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  main { width: min(100% - 22px, 1180px); margin-top: 16px; }
  .app-header { padding: 24px 16px; }
  .summary-grid { grid-template-columns: 1fr; }
  .card, .lead-card { padding: 16px; }
  .lead-topline { align-items: flex-start; flex-direction: column; }
}

.inline-edit {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
  margin: 14px 0 18px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card-soft);
}

.inline-edit label {
  display: block;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  width: 100%;
}

.inline-edit input {
  min-width: 220px;
  flex: 1;
}
