:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f6f8fb;
  --line: #e2e6ec;
  --text: #161a22;
  --muted: #535c6b;
  --tertiary: #8b94a2;
  --nav: #ffffff;
  --nav-soft: rgba(15, 23, 42, 0.05);
  --accent: #3d8bff;
  --accent-dark: #1d5fd7;
  --ok: #10b981;
  --warn: #f59e0b;
  --bad: #ef4444;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
  --sidebar-text: #2b3240;
  --sidebar-muted: #6b7280;
  font-family: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html,
body {
  min-height: 100%;
  background: var(--bg);
}

[hidden] { display: none !important; }

body {
  overflow-x: hidden;
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

.app {
  display: block;
  min-height: 100vh;
  background: var(--bg);
}

aside {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  width: 256px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  color: var(--sidebar-text);
  background: linear-gradient(180deg, #fff 0%, #f6f8fb 100%);
  border-right: 1px solid #e6e9ef;
  box-shadow: none;
}

.brand {
  min-height: 69px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid #e6e9ef;
}

.brand-mark,
.mobile-brand-mark {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  color: #fff;
  background: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: -.04em;
}

.brand-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.brand-copy strong {
  overflow: hidden;
  color: var(--sidebar-text);
  font-size: 16px;
  font-weight: 800;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-copy span {
  margin-top: 2px;
  color: var(--sidebar-muted);
  font-size: 10px;
  font-weight: 500;
}

nav {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  padding: 14px 12px;
}

.nav-group {
  margin: 12px 10px 3px;
  color: var(--tertiary);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.nav-group:first-child { margin-top: 0; }

.nav-button {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px 10px;
  border: 0;
  border-radius: 12px;
  color: var(--sidebar-muted);
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  transition: color 120ms ease, background-color 120ms ease;
}

.nav-button:hover {
  border: 0;
  color: var(--sidebar-text);
  background: var(--nav-soft);
}

.nav-button.active,
.nav-button.active:hover {
  color: #fff;
  background: var(--accent);
}

.nav-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  font-size: 16px;
  line-height: 1;
}

.nav-button.active .nav-icon { background: rgba(255, 255, 255, .18); }

.scope {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 9px;
  margin: 0 14px 8px;
  padding: 10px 12px;
  border: 1px solid #e6e9ef;
  border-radius: 12px;
  color: var(--sidebar-text);
  background: var(--nav-soft);
}

.scope > span:last-child { min-width: 0; }
.scope small { display: block; color: var(--sidebar-muted); font-size: 10px; }
.scope strong {
  display: block;
  margin: 2px 0;
  overflow: hidden;
  color: var(--sidebar-text);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scope-dot {
  width: 8px;
  height: 8px;
  margin-top: 4px;
  border-radius: 999px;
  background: var(--tertiary);
}

.app:not(.is-signed-out) .scope-dot { background: var(--ok); }

.sidebar-signout {
  min-height: 36px;
  margin: 0 14px 14px;
  border: 0;
  color: var(--sidebar-muted);
  background: transparent;
  justify-content: flex-start;
  text-align: left;
}

.sidebar-signout:hover { border: 0; color: var(--sidebar-text); background: var(--nav-soft); }
.sidebar-signout[hidden],
.app.is-signed-out #signOut { display: none; }

main {
  min-width: 0;
  width: 100%;
  padding: 24px;
  padding-left: 280px;
  background: var(--bg);
}

header {
  min-height: 54px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  max-width: 1720px;
  margin: 0 auto 18px;
}

.eyebrow {
  margin-bottom: 4px;
  color: var(--tertiary);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: var(--text);
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -.025em;
}

header p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.status {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 520px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 12px;
  font-weight: 600;
}

.status-dot { width: 7px; height: 7px; border-radius: 999px; background: var(--tertiary); }
.status.ok { color: #047857; }
.status.ok .status-dot { background: var(--ok); }
.status.bad { color: #b91c1c; border-color: rgba(239, 68, 68, .25); background: #fffafa; }
.status.bad .status-dot { background: var(--bad); }

.card,
.metrics,
.panel {
  max-width: 1720px;
  margin-right: auto;
  margin-left: auto;
}

.card {
  margin-bottom: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.card-head {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 16px;
  border-bottom: 1px solid var(--line);
}

.card-head h2,
.card-head h3 { margin: 0; color: var(--text); font-size: 15px; font-weight: 700; }
.card-kicker { display: block; margin-bottom: 2px; color: var(--tertiary); font-size: 9px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
.card-body { min-width: 0; padding: 16px; }

button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
  padding: 0 12px;
  font-weight: 600;
  cursor: pointer;
}

button:hover { border-color: #c7cdd6; background: var(--surface-soft); }
button.primary { border-color: var(--accent); color: #fff; background: var(--accent); }
button.primary:hover { background: var(--accent-dark); }
button.secondary { color: var(--accent-dark); border-color: rgba(61, 139, 255, .25); background: rgba(61, 139, 255, .06); }
button:disabled { opacity: .5; cursor: not-allowed; }

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
  box-shadow: none;
}

input::placeholder,
textarea::placeholder { color: var(--tertiary); }
input:focus,
select:focus,
textarea:focus { outline: 2px solid rgba(61, 139, 255, .18); border-color: var(--accent); }
input[readonly], select:disabled { color: var(--muted); background: var(--surface-soft); }
textarea { min-height: 112px; resize: vertical; font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

label { min-width: 0; display: grid; align-content: start; gap: 6px; color: var(--muted); font-size: 11px; font-weight: 700; }
.field-help { color: var(--tertiary); font-size: 10px; font-weight: 500; }

.grid { min-width: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-4 { grid-column: span 4; }
.actions { min-width: 0; display: flex; align-items: end; gap: 8px; flex-wrap: wrap; }

.panel { display: none; }
.panel.active { display: block; }
.split { min-width: 0; display: grid; grid-template-columns: minmax(360px, 420px) minmax(0, 1fr); align-items: start; gap: 16px; }
.split > *, .split > * > * { min-width: 0; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.metric { min-width: 0; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); }
.metric small { display: block; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.metric strong { display: block; margin-top: 8px; overflow: hidden; color: var(--text); font-size: 21px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }

.table-wrap { width: 100%; min-width: 0; overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; min-width: 720px; border-collapse: separate; border-spacing: 0; }
th,
td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); background: #f1f4f7; font-size: 10px; font-weight: 700; letter-spacing: .015em; text-transform: uppercase; }
tbody tr { transition: background-color 120ms ease; }
tbody tr:hover { background: rgba(61, 139, 255, .06); }
tr:last-child td { border-bottom: 0; }
.mono { font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; font-variant-numeric: tabular-nums; }

.pill { display: inline-flex; min-height: 23px; align-items: center; padding: 0 8px; border: 1px solid var(--line); border-radius: 999px; font-size: 10px; font-weight: 700; }
.pill.ok { color: #047857; border-color: rgba(16, 185, 129, .25); background: rgba(16, 185, 129, .08); }
.pill.warn { color: #a16207; border-color: rgba(245, 158, 11, .25); background: rgba(245, 158, 11, .08); }

.empty { min-height: 132px; display: grid; place-items: center; padding: 28px; border: 1px dashed var(--line); border-radius: 10px; color: var(--tertiary); background: rgba(244, 246, 248, .35); text-align: center; }
.empty strong { display: block; margin-bottom: 3px; color: var(--muted); font-size: 13px; }
.empty span { font-size: 11px; }
.hint { margin: 0 0 12px; color: var(--muted); font-size: 12px; line-height: 1.55; }

.auth-card .card-body { display: grid; grid-template-columns: minmax(220px, 380px) minmax(0, 1fr); gap: 18px; }
.auth-intro { display: flex; align-items: flex-start; gap: 12px; padding: 13px; border: 1px solid rgba(61, 139, 255, .18); border-radius: 10px; background: rgba(61, 139, 255, .05); }
.auth-intro strong { font-size: 12px; }
.auth-intro p { margin: 4px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.auth-shield { display: grid; place-items: center; flex: 0 0 auto; width: 28px; height: 28px; border-radius: 8px; color: #fff; background: var(--accent); font-weight: 800; }
.auth-grid { grid-template-columns: minmax(180px, 1fr) minmax(220px, 2fr) auto; align-items: end; }
.auth-choice-field { grid-column: auto; }
.auth-actions { flex-wrap: nowrap; }
.app:not(.is-signed-out) .auth-intro { display: none; }
.app:not(.is-signed-out) .auth-card .card-body { display: block; }

.visual-builder { min-width: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-soft); }
.builder-head { min-height: 50px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.builder-head strong { display: block; font-size: 12px; }
.builder-head span { display: block; margin-top: 2px; color: var(--tertiary); font-size: 10px; font-weight: 500; }
.builder-list { display: grid; gap: 10px; padding: 10px; }
.builder-empty { padding: 22px 14px; color: var(--tertiary); font-size: 11px; text-align: center; }
.builder-row { position: relative; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; padding: 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.builder-row.rate-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.builder-row.discount-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.builder-row .row-wide { grid-column: 1 / -1; }
.builder-row .remove-row { position: absolute; top: 8px; right: 8px; width: 28px; min-height: 28px; padding: 0; border-radius: 8px; color: var(--bad); }
.builder-row > label:first-of-type { padding-right: 30px; }

.advanced-editor { overflow: hidden; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.advanced-editor summary { padding: 11px 12px; color: var(--muted); font-size: 11px; font-weight: 700; cursor: pointer; }
.advanced-editor[open] summary { border-bottom: 1px solid var(--line); }
.advanced-editor > p { margin: 12px 12px 0; color: var(--tertiary); font-size: 10px; }
.advanced-editor > label { margin: 12px; }
.advanced-editor:not([open]) > :not(summary) { display: none !important; }

.mobile-topbar,
.sidebar-scrim,
.close-sidebar { display: none; }

@media (max-width: 1439px) {
  .metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .auth-card .card-body { grid-template-columns: 1fr; }
}

@media (max-width: 1279px) {
  .split { grid-template-columns: minmax(330px, 390px) minmax(0, 1fr); }
}

@media (max-width: 1023px) {
  .split { grid-template-columns: 1fr; }
  .split > div:first-child { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
  .split > div:first-child > .card { margin-bottom: 0; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .auth-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .auth-actions { grid-column: 1 / -1; }
}

@media (max-width: 767px) {
  .mobile-topbar { position: fixed; inset: 0 0 auto 0; z-index: 30; min-height: 48px; display: flex; align-items: center; gap: 10px; padding: 0 14px; border-bottom: 1px solid #e6e9ef; color: var(--sidebar-text); background: #fff; }
  .mobile-topbar .icon-button { width: 32px; min-height: 32px; padding: 0; border: 0; background: transparent; }
  .mobile-brand-mark { width: 30px; height: 30px; border-radius: 8px; font-size: 9px; }
  .mobile-topbar strong { font-size: 13px; }
  aside { transform: translateX(-100%); transition: transform 180ms ease; }
  .app.sidebar-open aside { transform: translateX(0); }
  .sidebar-scrim { position: fixed; inset: 0; z-index: 35; width: 100%; min-height: 100vh; border: 0; border-radius: 0; background: rgba(0, 0, 0, .4); }
  .app.sidebar-open .sidebar-scrim { display: block; }
  .close-sidebar { display: inline-flex; margin-left: auto; width: 30px; min-height: 30px; padding: 0; border: 0; background: transparent; }
  main { padding: 68px 14px 20px; }
  header { display: block; margin-bottom: 14px; }
  h1 { font-size: 21px; }
  .status { width: 100%; max-width: none; margin-top: 12px; }
  .grid, .grid.two, .auth-grid { grid-template-columns: 1fr; }
  .span-2, .span-4, .auth-actions { grid-column: auto; }
  .split > div:first-child { display: block; }
  .split > div:first-child > .card { margin-bottom: 16px; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .auth-card .card-body { display: block; }
  .auth-intro { margin-bottom: 14px; }
  .auth-actions { flex-wrap: wrap; }
  .auth-actions button { flex: 1 1 150px; }
  .builder-row, .builder-row.rate-row, .builder-row.discount-row { grid-template-columns: 1fr; }
  .builder-row .row-wide { grid-column: auto; }
}

@media (max-width: 420px) {
  .metrics { grid-template-columns: 1fr; }
  .card-head { align-items: flex-start; }
  .card-body { padding: 13px; }
  .builder-head { align-items: flex-start; flex-direction: column; }
}
