:root {
  color-scheme: dark;
  --ink: #f8fafc;
  --muted: #9aa8bc;
  --line: #263247;
  --surface: #111827;
  --soft: #172033;
  --soft-strong: #1d2a42;
  --green: #10b981;
  --green-dark: #34d399;
  --blue: #38bdf8;
  --rose: #fb7185;
  --amber: #fbbf24;
  --shadow: 0 20px 54px rgba(0, 0, 0, .34);
  --page-bg: linear-gradient(135deg, rgba(16, 185, 129, .08), transparent 28%),
    linear-gradient(225deg, rgba(56, 189, 248, .08), transparent 30%),
    #080d16;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--page-bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body[data-theme="light"] {
  color-scheme: light;
  --ink: #111827;
  --muted: #64748b;
  --line: #d7dee8;
  --surface: #ffffff;
  --soft: #f5f8fb;
  --soft-strong: #edf3f8;
  --green: #0f8f6f;
  --green-dark: #08624d;
  --blue: #2563eb;
  --rose: #be123c;
  --amber: #d97706;
  --shadow: 0 18px 42px rgba(15, 23, 42, .12);
  --page-bg: #eef3f8;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: .58;
}

.topbar {
  width: min(1320px, calc(100% - 32px));
  min-height: 72px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #10b981, #38bdf8);
  color: #03111f;
  font-weight: 850;
}

.brand-name {
  font-size: 18px;
  font-weight: 850;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.theme-toggle {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--soft);
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .03);
}

.theme-toggle:hover {
  background: var(--soft-strong);
}

.ghost-link,
.solid-link,
.primary-button,
.secondary-button,
.text-button,
.nav-item {
  min-height: 40px;
  border-radius: 8px;
  font-weight: 800;
  text-decoration: none;
}

.ghost-link,
.solid-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  font-size: 14px;
}

.ghost-link {
  color: var(--ink);
  border: 1px solid var(--line);
  background: rgba(17, 24, 39, .72);
}

.solid-link,
.primary-button {
  color: #ffffff;
  border: 0;
  background: var(--green);
}

.primary-button {
  min-height: 48px;
  padding: 0 18px;
  box-shadow: 0 14px 30px rgba(15, 143, 111, .2);
}

.primary-button:hover {
  background: var(--green-dark);
}

.secondary-button {
  min-height: 42px;
  border: 1px solid rgba(56, 189, 248, .2);
  padding: 0 14px;
  color: #dff7ff;
  background: rgba(14, 116, 144, .34);
}

.secondary-button:hover {
  background: rgba(14, 116, 144, .54);
}

.text-button {
  min-height: 36px;
  border: 0;
  background: transparent;
  color: var(--rose);
  padding: 0;
}

.app-shell {
  width: min(1320px, calc(100% - 32px));
  margin: 0 auto 48px;
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.sidebar,
.workspace {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.auth-panel,
.section-nav,
.tab-panel,
.hero-strip {
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid rgba(148, 163, 184, .12);
  box-shadow: var(--shadow);
}

.auth-panel {
  padding: 16px;
}

.email-auth,
.field,
.field-set,
.account-panel {
  display: grid;
  gap: 10px;
}

.auth-head,
.account-actions,
.panel-head,
.action-row,
.profile-switch,
.copy-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.account-actions,
.action-row,
.profile-switch {
  flex-wrap: wrap;
  justify-content: flex-start;
}

.auth-panel span,
.field span,
.field-set legend {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.auth-panel strong {
  display: block;
  font-size: 16px;
}

.auth-panel p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, .14);
}

.section-nav {
  padding: 8px;
  display: grid;
  gap: 6px;
}

.nav-item {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
  padding: 0 12px;
}

.nav-item:hover,
.nav-item.is-active {
  background: rgba(16, 185, 129, .14);
  color: #b7f7dd;
}

.hero-strip {
  position: relative;
  min-height: 190px;
  overflow: hidden;
  color: #ffffff;
}

.hero-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(.95) contrast(.96);
}

.hero-strip::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(6, 12, 22, .86), rgba(6, 12, 22, .56) 58%, rgba(6, 12, 22, .16));
}

.hero-copy {
  position: relative;
  z-index: 1;
  max-width: 620px;
  padding: 32px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--green);
  font-size: 13px;
  font-weight: 850;
  text-transform: uppercase;
}

.hero-copy .eyebrow {
  color: #9ef0d8;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.08;
  letter-spacing: 0;
}

h1 {
  font-size: 44px;
  font-weight: 900;
}

h2 {
  font-size: 24px;
  font-weight: 850;
}

h3 {
  font-size: 17px;
}

.hero-copy p:last-child {
  max-width: 520px;
  margin: 14px 0 0;
  color: rgba(255, 255, 255, .84);
  line-height: 1.55;
}

.message {
  min-height: 24px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.message.is-error {
  color: var(--rose);
}

.message.is-success {
  color: var(--green-dark);
}

.tab-panel {
  display: none;
  padding: 22px;
}

.tab-panel.is-active {
  display: grid;
  gap: 18px;
}

.status-pill {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0 10px;
  background: rgba(16, 185, 129, .16);
  color: #b7f7dd;
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.status-pill.is-offline {
  background: rgba(251, 113, 133, .14);
  color: var(--rose);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.metric-card,
.tool-panel,
.summary,
.link-item,
.device-item,
.server-item,
.payment-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  min-width: 0;
}

.metric-card {
  min-height: 112px;
  padding: 16px;
  overflow: hidden;
}

.metric-card span,
.summary-row span,
.summary-total span,
.payment-item span {
  color: var(--muted);
  font-size: 13px;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: clamp(19px, 2.2vw, 22px);
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.metric-card p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

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

.order-column {
  display: grid;
  gap: 16px;
}

.field-set {
  margin: 0;
  padding: 0;
  border: 0;
}

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

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

.segment,
.payment-option {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 10px 12px;
  text-align: left;
  display: grid;
  gap: 2px;
}

.segment span,
.payment-option span {
  color: var(--muted);
  font-size: 12px;
}

.segment.is-active,
.payment-option.is-active {
  border-color: var(--green);
  background: rgba(16, 185, 129, .14);
  box-shadow: inset 0 0 0 1px rgba(15, 143, 111, .22);
}

.split-fields,
.promo-row,
.mini-shop {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stepper {
  height: 46px;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  overflow: hidden;
}

.icon-button {
  width: 44px;
  height: 46px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 22px;
  font-weight: 800;
}

.icon-button:hover {
  background: rgba(148, 163, 184, .12);
}

#deviceCount {
  text-align: center;
  font-weight: 850;
}

.range {
  min-height: 28px;
  padding: 0;
  accent-color: var(--green);
  background: transparent;
  border: 0;
}

.summary {
  align-self: start;
  display: grid;
  gap: 10px;
  padding: 16px;
}

.summary-row,
.summary-total {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.summary-row strong,
.summary-total strong {
  text-align: right;
}

.summary-row.muted strong {
  color: var(--amber);
}

.summary-total {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.summary-total strong {
  font-size: 26px;
}

.tool-panel {
  padding: 16px;
  display: grid;
  gap: 12px;
}

.link-list,
.device-list,
.server-list,
.payment-list {
  display: grid;
  gap: 10px;
}

.link-item,
.device-item,
.server-item,
.payment-item {
  padding: 14px;
  display: grid;
  gap: 10px;
}

.link-line,
.device-line,
.server-line,
.payment-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.url-box {
  width: 100%;
  min-height: 44px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 10px;
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  white-space: nowrap;
}

.copy-row {
  align-items: stretch;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  color: var(--muted);
  background: var(--soft);
}

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

  .section-nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

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

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

  .ghost-link {
    display: none;
  }

  .section-nav,
  .metric-grid,
  .order-grid,
  .segmented-grid,
  .payment-grid,
  .split-fields,
  .promo-row,
  .mini-shop {
    grid-template-columns: 1fr;
  }

  .panel-head,
  .auth-head,
  .link-line,
  .device-line,
  .server-line,
  .payment-line,
  .copy-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .tab-panel {
    padding: 16px;
  }

  .hero-copy {
    padding: 24px;
  }

  h1 {
    font-size: 36px;
  }
}
