:root {
  --bg: #0b0d12;
  --bg-grad: radial-gradient(ellipse 80% 50% at 50% -20%, rgba(79,140,255,0.12), transparent);
  --surface: #13161e;
  --surface-2: #1a1e28;
  --surface-3: #222733;
  --border: #2a3040;
  --text: #eef1f7;
  --text-muted: #7d8799;
  --primary: #4f8cff;
  --primary-hover: #3a7af5;
  --primary-glow: rgba(79, 140, 255, 0.25);
  --success: #34d399;
  --success-bg: rgba(52, 211, 153, 0.1);
  --danger: #f87171;
  --taken: #1e2330;
  --taken-text: #5c6578;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "SF Mono", "Fira Code", "Consolas", monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  background-image: var(--bg-grad);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 24px 40px;
}

/* Header */
.header {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 16px;
}

.brand-bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 20px 24px;
  padding: 18px 22px;
  border-radius: 18px;
  border: 1px solid rgba(232, 121, 249, 0.22);
  background:
    linear-gradient(135deg, rgba(255, 107, 157, 0.08), rgba(99, 102, 241, 0.06)),
    var(--surface);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.04) inset,
    0 16px 40px rgba(0, 0, 0, 0.28);
}

.header__brand {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
}

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

.refresh-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
}

.refresh-bar[hidden] { display: none; }

.refresh-bar__top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 0.82rem;
}

.refresh-bar__label { color: var(--text-muted); }

.refresh-bar__pct {
  font-weight: 700;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.refresh-bar__track {
  height: 8px;
  background: var(--surface-3);
  border-radius: 4px;
  overflow: hidden;
}

.refresh-bar__fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #7c5cff);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.refresh-bar--done .refresh-bar__fill {
  background: linear-gradient(90deg, var(--success), #22c55e);
}

.refresh-bar--error .refresh-bar__fill,
.refresh-bar--cancelled .refresh-bar__fill {
  background: var(--danger);
}

.emblem-wrap {
  width: 80px;
  height: 80px;
  flex-shrink: 0;
  border-radius: 22px;
  overflow: hidden;
  box-shadow:
    0 0 0 2px rgba(255, 107, 157, 0.4),
    0 10px 30px rgba(196, 77, 255, 0.35);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.emblem-wrap:hover {
  transform: scale(1.05) rotate(-2deg);
  box-shadow:
    0 0 0 3px rgba(255, 107, 157, 0.55),
    0 14px 36px rgba(196, 77, 255, 0.45);
}

.emblem-svg,
.emblem-wrap svg {
  display: block;
  width: 100%;
  height: 100%;
}

.brand-title {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.header h1,
.brand-title__name {
  font-size: clamp(1.8rem, 4vw, 2.35rem);
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1.05;
  color: #faf6ff;
  text-shadow:
    0 0 28px rgba(232, 121, 249, 0.45),
    0 2px 12px rgba(167, 139, 250, 0.25);
}

.header__subtitle,
.brand-title__sub {
  color: rgba(238, 241, 247, 0.78);
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}

@media (max-width: 900px) {
  .brand-bar {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .header__actions {
    justify-content: flex-start;
  }
}

@media (max-width: 640px) {
  .brand-bar {
    padding: 14px 16px;
    gap: 14px;
  }
  .emblem-wrap {
    width: 64px;
    height: 64px;
    border-radius: 18px;
  }
  .header__subtitle,
  .brand-title__sub {
    font-size: 0.82rem;
  }
}

.logo {
  display: none;
}

.header__stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  min-width: 96px;
  text-align: center;
}

.stat-card__value {
  font-size: 1.35rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.stat-card__label {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 2px;
}

.stat-card--success .stat-card__value { color: var(--success); }
.stat-card--muted .stat-card__value { color: var(--text-muted); }

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 20px;
  width: fit-content;
}

.tab {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 8px 20px;
  border-radius: 9px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.tab:hover { color: var(--text); }

.tab--active {
  background: var(--surface-3);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.view { display: none; }
.view--active { display: block; }

/* Dashboard */
.dashboard-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.dashboard-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.mix-option {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  padding: 10px 12px;
  border: 1px solid rgba(59, 130, 246, 0.45);
  border-radius: 10px;
  background: rgba(59, 130, 246, 0.14);
  cursor: pointer;
  user-select: none;
  color: var(--text, #eef1f7);
  font-size: 0.85rem;
  font-weight: 600;
}

.mix-option input[type="checkbox"] {
  accent-color: #3b82f6;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  cursor: pointer;
}

.legend {
  display: flex;
  gap: 16px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.legend__item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot--free { background: var(--success); }
.dot--taken { background: var(--taken-text); }

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}

.state-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s;
}

.state-card:hover { border-color: #3a4258; }

.state-card__head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.state-card__name {
  font-weight: 700;
  font-size: 0.95rem;
}

.state-card__code {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-top: 2px;
}

.state-card__totals {
  text-align: right;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.state-card__totals strong {
  display: block;
  font-size: 1.1rem;
  color: var(--success);
  font-variant-numeric: tabular-nums;
}

.progress-bar {
  height: 4px;
  background: var(--surface-3);
  margin: 0 16px 12px;
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar__fill {
  height: 100%;
  background: linear-gradient(90deg, var(--success), #22c55e);
  border-radius: 2px;
  transition: width 0.3s;
}

.price-rows { padding: 0 12px 12px; }

.price-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  margin-bottom: 4px;
  background: var(--surface-2);
}

.price-row__price {
  font-weight: 700;
  color: var(--primary);
  min-width: 52px;
  font-size: 0.88rem;
}

.price-row__counts {
  flex: 1;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.price-row__counts strong { color: var(--success); }

.price-row__btn {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 7px;
  padding: 6px 12px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  transition: background 0.12s, box-shadow 0.12s;
}

.price-row__btn:hover {
  background: var(--primary-hover);
  box-shadow: 0 0 12px var(--primary-glow);
}

.price-row__btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: none;
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .tabs { width: 100%; }
  .tab { flex: 1; text-align: center; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.panel h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.panel--danger { border-color: #3d2028; }

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 11px;
}

.field span {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.field input,
.field select,
.field textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 0.88rem;
  font-family: inherit;
  width: 100%;
  transition: border-color 0.12s;
}

.field textarea {
  font-family: var(--mono);
  font-size: 0.8rem;
  resize: vertical;
  line-height: 1.6;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.field__hint {
  font-size: 0.7rem;
  color: var(--text-muted);
  opacity: 0.85;
  line-height: 1.4;
}

.hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 12px;
  line-height: 1.5;
}

.hint code {
  font-family: var(--mono);
  font-size: 0.72rem;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  width: 100%;
  transition: background 0.15s, opacity 0.15s, box-shadow 0.15s;
}

.btn + .btn { margin-top: 8px; }

.btn--inline { width: auto; }

.btn--primary {
  background: var(--primary);
  color: #fff;
}

.btn--primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 16px var(--primary-glow);
}

.btn--secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn--secondary:hover { background: var(--surface-3); }

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn--ghost:hover { color: var(--text); background: var(--surface-2); }

.btn--danger {
  background: #2d1518;
  color: var(--danger);
  border: 1px solid #4a2028;
}

.btn--danger:hover { background: #3a1a20; }

.btn--sm { width: auto; padding: 5px 11px; font-size: 0.78rem; }
.btn:disabled { opacity: 0.35; cursor: not-allowed; box-shadow: none; }

.copy-preview {
  margin-top: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.copy-preview__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 0.76rem;
  color: var(--text-muted);
}

.copy-preview pre {
  padding: 10px;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  max-height: 140px;
  overflow: auto;
  white-space: pre;
  line-height: 1.7;
}

/* Numbers grid */
.main { min-width: 0; }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.toolbar__left, .toolbar__right {
  display: flex;
  gap: 7px;
  align-items: center;
  flex-wrap: wrap;
}

.badge {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 11px;
  font-size: 0.78rem;
}

.badge--muted { color: var(--text-muted); }

.state-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}

.state-group__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.state-group__title { font-weight: 600; font-size: 0.9rem; }
.state-group__meta { font-size: 0.76rem; color: var(--text-muted); }

.price-section { border-bottom: 1px solid var(--border); }
.price-section:last-child { border-bottom: none; }

.price-section__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  font-size: 0.82rem;
  background: rgba(255,255,255,0.015);
}

.price-section__price { font-weight: 600; color: var(--primary); }
.price-section__count { color: var(--text-muted); font-size: 0.75rem; }

.number-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 5px;
  padding: 10px 14px 14px;
}

.number-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 9px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
  transition: border-color 0.1s, background 0.1s;
  user-select: none;
}

.number-item:hover { border-color: #3d4a60; }
.number-item input[type="checkbox"] { accent-color: var(--primary); flex-shrink: 0; cursor: pointer; }

.number-item__digits {
  font-family: var(--mono);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.number-item--taken {
  background: var(--taken);
  border-color: #1e2433;
  opacity: 0.7;
}

.number-item--taken .number-item__digits {
  color: var(--taken-text);
  text-decoration: line-through;
}

.number-item--selected {
  border-color: var(--primary);
  background: rgba(79, 140, 255, 0.07);
}

/* Import */
.import-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  align-items: start;
}

@media (max-width: 760px) {
  .import-layout { grid-template-columns: 1fr; }
}

.import-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.import-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.import-actions .btn { width: auto; flex-shrink: 0; }

.import-counter {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.dropzone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 32px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  transition: border-color 0.15s, background 0.15s;
  cursor: pointer;
}

.dropzone p { margin-bottom: 10px; }

.dropzone--over {
  border-color: var(--primary);
  background: rgba(79, 140, 255, 0.05);
}

.manage-btns {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.panel--danger .manage-btns .btn { width: 100%; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.empty-state__icon { font-size: 2rem; margin-bottom: 8px; }
.empty-state h3 { color: var(--text); margin-bottom: 6px; font-size: 1rem; }
.empty-state p { margin-bottom: 16px; font-size: 0.85rem; }

/* Loader */
.loader {
  position: fixed;
  inset: 0;
  background: rgba(11, 13, 18, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.loader[hidden] { display: none; }

.loader__box {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.loader__spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 0.86rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  z-index: 1000;
  max-width: 380px;
  animation: slideIn 0.2s ease;
}

.toast--success { border-color: #1f4d38; color: var(--success); }

@keyframes slideIn {
  from { transform: translateY(10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Login */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
  background:
    radial-gradient(ellipse 90% 60% at 50% -10%, rgba(232, 121, 249, 0.18), transparent),
    radial-gradient(ellipse 50% 40% at 100% 100%, rgba(79, 140, 255, 0.12), transparent),
    var(--bg);
}

.login-shell {
  width: 100%;
  max-width: 440px;
}

.login-panel {
  border-radius: 22px;
  border: 1px solid rgba(232, 121, 249, 0.22);
  background:
    linear-gradient(160deg, rgba(255, 107, 157, 0.07), rgba(99, 102, 241, 0.05)),
    var(--surface);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.04) inset,
    0 28px 72px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.login-panel__hero {
  text-align: center;
  padding: 36px 32px 28px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(232, 121, 249, 0.06), transparent);
}

.login-panel__hero .emblem-wrap {
  width: 112px;
  height: 112px;
  margin: 0 auto 18px;
  border-radius: 28px;
}

.login-panel__hero .brand-title__name {
  font-size: clamp(2rem, 6vw, 2.75rem);
  letter-spacing: 0.1em;
}

.login-panel__hero .brand-title__sub {
  margin-top: 10px;
  font-size: 1rem;
  color: rgba(238, 241, 247, 0.82);
}

.login-panel__form {
  padding: 28px 32px 32px;
}

.login-panel__form label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 7px;
}

.login-panel__form input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 12px 14px;
  font-size: 1rem;
  margin-bottom: 16px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.login-panel__form input:focus {
  outline: none;
  border-color: #e879f9;
  box-shadow: 0 0 0 3px rgba(232, 121, 249, 0.15);
}

.login-panel__form button[type="submit"] {
  width: 100%;
  margin-top: 8px;
  padding: 13px;
  font-size: 1rem;
  border: none;
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, #ff6b9d, #c44dff, #6366f1);
  box-shadow: 0 8px 24px rgba(196, 77, 255, 0.35);
  transition: transform 0.15s, box-shadow 0.15s;
}

.login-panel__form button[type="submit"]:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 32px rgba(196, 77, 255, 0.45);
}

.login-panel__form button[type="submit"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.login-error {
  background: #2d1518;
  border: 1px solid #4a2028;
  color: var(--danger);
  padding: 11px 14px;
  border-radius: 10px;
  font-size: 0.88rem;
  margin-bottom: 16px;
  display: none;
}

.login-error.show { display: block; }
