:root {
  color-scheme: light dark;
  --canvas: #f3f6f4;
  --surface: #ffffff;
  --surface-soft: #e9f0ed;
  --text: #17201d;
  --muted: #5c6964;
  --line: #cfd8d4;
  --accent: #176b5b;
  --accent-hover: #115447;
  --accent-text: #ffffff;
  --danger: #a23c46;
  --warning: #8b4c18;
  --focus: #c27332;
  --radius: 18px;
  --control-radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --canvas: #101614;
    --surface: #18201d;
    --surface-soft: #202c28;
    --text: #f0f4f2;
    --muted: #aebbb6;
    --line: #35423d;
    --accent: #65b7a5;
    --accent-hover: #79c9b7;
    --accent-text: #10201b;
    --danger: #ef8c94;
    --warning: #e3a267;
    --focus: #e3a267;
  }
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--canvas); }

body {
  min-height: 100dvh;
  margin: 0;
  background: var(--canvas);
  color: var(--text);
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }

button, a { -webkit-tap-highlight-color: transparent; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

[hidden] { display: none !important; }

.clipboard-fallback { position: fixed; opacity: 0; pointer-events: none; }

.site-header, .shell {
  width: min(100% - 32px, 1120px);
  margin-inline: auto;
}

.site-header {
  display: flex;
  min-height: 64px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand {
  color: var(--text);
  font-size: 22px;
  font-weight: 850;
  letter-spacing: -0.04em;
  text-decoration: none;
}

.text-button {
  min-height: 44px;
  padding: 8px 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.shell { padding: 36px 0 64px; }

.login-view { width: 100%; max-width: 400px; margin-inline: auto; }
.account-view { max-width: 720px; margin-inline: auto; }

body[data-view="login"] .shell {
  display: grid;
  min-height: calc(100dvh - 64px);
  align-items: center;
  padding-block: 24px 72px;
}

.account-name {
  margin: 0 0 12px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 800;
}

h1, h2, p { overflow-wrap: break-word; }

h1 {
  max-width: 14ch;
  margin: 0;
  font-size: clamp(34px, 8vw, 52px);
  line-height: 1.05;
  letter-spacing: -0.055em;
}

h2 {
  margin: 0;
  font-size: clamp(22px, 4vw, 28px);
  line-height: 1.2;
  letter-spacing: -0.03em;
}

.lead {
  max-width: 52ch;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 18px;
}

.login-note { margin: 10px 0 0; color: var(--muted); }

.login-form {
  display: grid;
  gap: 16px;
  margin-top: 24px;
}

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

.field { display: grid; min-width: 0; align-content: start; gap: 8px; }
.field label { font-weight: 750; }
.field small, .muted { color: var(--muted); font-size: 15px; }

.field input, .field select {
  width: 100%;
  min-height: 54px;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: var(--control-radius);
  background: var(--canvas);
  color: var(--text);
}

.field select { appearance: auto; }

.field input::placeholder { color: var(--muted); opacity: 0.85; }
.field input:focus, .field select:focus { border-color: var(--accent); }

.field-error { margin: 0; color: var(--danger); font-size: 14px; font-weight: 700; }

.button {
  display: inline-flex;
  min-height: 52px;
  align-items: center;
  justify-content: center;
  padding: 13px 20px;
  border: 1px solid transparent;
  border-radius: var(--control-radius);
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.button:active { transform: scale(0.98); }
.button:disabled { cursor: wait; opacity: 0.65; }
.button-primary { background: var(--accent); color: var(--accent-text); }
.button-primary:hover { background: var(--accent-hover); }
.button-secondary { border-color: var(--line); background: var(--surface); color: var(--text); }
.button-secondary:hover { border-color: var(--accent); background: var(--surface-soft); }

.account-heading { margin-bottom: 30px; }
.account-heading h1 { max-width: 16ch; }

.subscription-summary {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.subscription-summary.is-active { border-color: color-mix(in srgb, var(--accent) 58%, var(--line)); }
.subscription-summary.is-expired { border-color: color-mix(in srgb, var(--danger) 58%, var(--line)); }
.subscription-summary.is-pending { border-color: color-mix(in srgb, var(--focus) 62%, var(--line)); }

.summary-primary { padding: 26px; }
.summary-primary span, .summary-metrics span { display: block; color: var(--muted); font-size: 14px; }
.summary-primary strong { display: block; margin-top: 5px; font-size: clamp(26px, 6vw, 36px); line-height: 1.2; letter-spacing: -0.04em; }

.summary-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-top: 1px solid var(--line);
}

.summary-metrics > div { min-width: 0; padding: 20px 26px; }
.summary-metrics > div + div { border-left: 1px solid var(--line); }
.summary-metrics strong { display: block; margin-top: 3px; font-size: 18px; font-variant-numeric: tabular-nums; }

.renewal-section, .connect-section {
  display: grid;
  gap: 22px;
  margin-top: 20px;
  padding: 28px;
  border-radius: var(--radius);
}

.renewal-section { background: var(--accent); color: var(--accent-text); }
.renewal-section p { margin: 8px 0 0; color: inherit; opacity: 0.86; }
.renewal-section .payment-note { margin: -10px 0 0; font-size: 13px; opacity: 0.8; }
.renewal-section .button-primary { background: var(--surface); color: var(--text); }
.renewal-section .button-primary:hover { background: var(--surface-soft); }

.connect-section { border: 1px solid var(--line); background: var(--surface); }
.connect-section p { margin: 8px 0 0; color: var(--muted); }
.device-picker { display: grid; min-width: 0; margin: 0; padding: 0; border: 0; grid-template-columns: 1fr 1fr; gap: 10px; }
.device-picker legend { grid-column: 1 / -1; margin-bottom: 2px; font-weight: 800; }
.device-option { position: relative; min-width: 0; cursor: pointer; }
.device-option input { position: absolute; opacity: 0; pointer-events: none; }
.device-option span { display: grid; min-height: 82px; align-content: center; gap: 3px; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--control-radius); background: var(--canvas); }
.device-option strong, .device-option small { overflow-wrap: anywhere; }
.device-option small { color: var(--muted); font-size: 14px; }
.device-option input:checked + span { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.device-option input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.connect-guide { display: grid; gap: 12px; padding: 18px; border-radius: var(--control-radius); background: var(--surface-soft); }
.connect-guide h3, .connect-guide p { margin: 0; }
.connect-guide h3 { font-size: 20px; letter-spacing: -0.02em; }
.connect-guide .button { width: 100%; white-space: normal; }
.connect-step { font-size: 16px; }
.connect-fallback { border-top: 1px solid var(--line); padding-top: 12px; }
.connect-fallback summary { min-height: 34px; color: var(--accent); font-weight: 800; cursor: pointer; }
.connect-fallback > div { display: grid; gap: 12px; padding-top: 8px; }
.connect-fallback .inline-status { margin: 0 !important; }

.inline-status { margin: -8px 0 0 !important; font-size: 14px; font-weight: 750; }

.disclosure {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.disclosure summary {
  min-height: 58px;
  padding: 16px 20px;
  font-weight: 800;
  cursor: pointer;
}

.disclosure[open] summary { border-bottom: 1px solid var(--line); }
.device-list, #lastPayment { padding: 16px 20px 20px; }
.device-list > p, #lastPayment > p { margin: 0; }

.device-row, .payment-row {
  display: flex;
  min-height: 54px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 0;
}

.device-row + .device-row { border-top: 1px solid var(--line); }
.device-name { min-width: 0; }
.device-name strong, .device-name span { display: block; }
.device-name span { color: var(--muted); font-size: 13px; }
.device-remove { min-height: 44px; border: 0; background: transparent; color: var(--danger); font-weight: 750; cursor: pointer; }

.payment-row strong, .payment-row span { display: block; }
.payment-row span { color: var(--muted); font-size: 14px; }

.account-error {
  display: grid;
  gap: 14px;
  margin-top: 20px;
  padding: 20px;
  border: 1px solid color-mix(in srgb, var(--danger) 48%, var(--line));
  border-radius: var(--radius);
  background: var(--surface);
}
.account-error p { margin: 0; }

.admin-heading, .section-heading, .dialog-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
}

.admin-heading h1 { max-width: none; font-size: clamp(34px, 6vw, 44px); }
.admin-heading .lead { margin-top: 6px; font-size: 16px; }
.compact-button { width: auto; }

.statement-panel {
  margin-top: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.statement-panel > summary { min-height: 58px; padding: 15px 20px; font-weight: 800; cursor: pointer; }
.statement-panel[open] > summary { border-bottom: 1px solid var(--line); }
.statement-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  overflow: hidden;
}

.statement-grid > div { padding: 22px; }
.statement-grid > div + div { border-left: 1px solid var(--line); }
.statement-grid span, .statement-grid strong { display: block; }
.statement-grid span { color: var(--muted); font-size: 14px; }
.statement-grid strong { margin-top: 4px; font-size: 24px; font-variant-numeric: tabular-nums; }

.check-row { display: flex; min-height: 44px; align-items: center; gap: 10px; cursor: pointer; }
.check-row input { flex: 0 0 auto; width: 22px; height: 22px; accent-color: var(--accent); }

.modal, .invoice-dialog {
  width: min(100% - 32px, 560px);
  max-height: min(90dvh, 760px);
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

.modal::backdrop, .invoice-dialog::backdrop { background: rgb(10 16 14 / 62%); }
.modal-body, .invoice-dialog form { display: grid; gap: 20px; padding: 26px; }
.dialog-heading { align-items: flex-start; }
.dialog-heading > div { min-width: 0; }
.dialog-heading > .text-button { flex: 0 0 auto; }
.dialog-heading .muted { margin: 4px 0 0; }

.mode-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0; padding: 0; border: 0; }
.mode-switch legend { margin-bottom: 8px; font-weight: 750; }
.mode-switch label { position: relative; display: block; cursor: pointer; }
.mode-switch input { position: absolute; inset: 0; opacity: 0; }
.mode-switch span { display: grid; min-height: 84px; align-content: center; gap: 2px; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--control-radius); background: var(--canvas); }
.mode-switch small { color: var(--muted); }
.mode-switch input:checked + span { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.mode-switch input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.paid-fields { display: grid; grid-template-columns: 1fr 1fr 1fr; align-items: start; gap: 14px; }

.creation-result {
  display: grid;
  gap: 20px;
}

.result-code { display: grid; gap: 12px; padding: 18px; border-radius: var(--control-radius); background: var(--surface-soft); }
.result-code > span, .detail-code span, .detail-facts span { color: var(--muted); font-size: 14px; }
.secret-code { font-size: clamp(24px, 5vw, 34px); letter-spacing: 0.06em; font-variant-numeric: tabular-nums; }
.small-code { font-size: 24px; }
.result-actions, .detail-actions { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.result-actions > *, .detail-actions > * { width: 100%; min-width: 0; white-space: normal; }
.detail-next-step { display: grid; gap: 5px; padding: 16px 18px; border-left: 3px solid var(--accent); border-radius: 0 var(--control-radius) var(--control-radius) 0; background: color-mix(in srgb, var(--accent) 9%, var(--surface)); }
.detail-next-step span { color: var(--muted); font-size: 14px; }
.detail-next-step strong { line-height: 1.35; }
.invoice-explanation { margin: -4px 0 0; color: var(--muted); line-height: 1.45; }

.customers-section { margin-top: 34px; }
.section-heading { align-items: center; margin-bottom: 14px; }
.customer-search { max-width: 440px; margin-bottom: 14px; }
.customer-list { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.customer-row { display: grid; width: 100%; min-height: 82px; grid-template-columns: minmax(180px, 1.5fr) minmax(180px, 1.2fr) minmax(150px, 1fr) auto; align-items: center; gap: 20px; padding: 16px 18px; border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--text); text-align: left; cursor: pointer; }
.customer-row:last-child { border-bottom: 0; }
.customer-row:hover { background: var(--surface-soft); }
.customer-main { min-width: 0; }
.customer-main strong, .customer-main small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.customer-main small, .customer-price { color: var(--muted); font-size: 14px; }
.customer-state { font-weight: 750; }
.customer-state.is-active { color: var(--accent); }
.customer-state.is-waiting { color: var(--warning); }
.customer-state.is-error { color: var(--danger); }
.customer-open { color: var(--accent); font-weight: 800; text-align: right; }
.empty-state { padding: 28px; border: 1px dashed var(--line); border-radius: var(--radius); text-align: center; }

.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.detail-facts { display: grid; grid-template-columns: 1fr 1fr; overflow: hidden; border: 1px solid var(--line); border-radius: var(--control-radius); }
.detail-facts > div { padding: 16px; }
.detail-facts > div + div { border-left: 1px solid var(--line); }
.detail-facts span, .detail-facts strong { display: block; }
.detail-facts strong { margin-top: 3px; }
.detail-code { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 10px; padding: 18px; border-radius: var(--control-radius); background: var(--surface-soft); }
.detail-code > div { min-width: 0; }
.detail-code span, .detail-code strong { display: block; }
.detail-links { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.detail-links a { color: var(--accent); font-weight: 750; }
.danger-text { color: var(--danger); }

.loading-view { display: grid; gap: 18px; }
.skeleton { border-radius: var(--radius); background: var(--surface-soft); animation: pulse 1.2s ease-in-out infinite alternate; }
.skeleton-title { width: min(80%, 430px); height: 96px; }
.skeleton-block { height: 210px; }

@keyframes pulse { from { opacity: 0.55; } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}

@media (max-width: 820px) {
  .customer-row { grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px; }
  .customer-main { grid-column: 1; }
  .customer-open, .customer-state, .customer-price { grid-column: 1 / -1; }
  .customer-open { grid-row: auto; text-align: left; }
}

@media (max-width: 560px) {
  .shell { padding-top: 22px; }
  body[data-view="login"] .shell { padding-block: 16px 56px; }
  .renewal-section, .connect-section { padding: 22px; }
  .summary-metrics { grid-template-columns: 1fr; }
  .summary-metrics > div + div { border-top: 1px solid var(--line); border-left: 0; }
  .device-picker { grid-template-columns: 1fr; }
  .admin-heading { align-items: flex-start; flex-direction: column; }
  .admin-heading .compact-button { width: 100%; }
  .statement-grid { grid-template-columns: 1fr; }
  .statement-grid > div + div { border-top: 1px solid var(--line); border-left: 0; }
  .modal-body, .invoice-dialog form { padding: 20px; }
  .mode-switch, .paid-fields, .dialog-actions, .detail-facts { grid-template-columns: 1fr; }
  .detail-facts > div + div { border-top: 1px solid var(--line); border-left: 0; }
  .detail-code { grid-template-columns: 1fr; }
  .button { width: 100%; white-space: normal; }
}
