:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --surface: rgba(255, 255, 255, 0.84);
  --surface-strong: #ffffff;
  --line: rgba(20, 28, 38, 0.1);
  --line-strong: rgba(20, 28, 38, 0.16);
  --text: #111827;
  --muted: #697386;
  --soft: #8b95a5;
  --blue: #0a84ff;
  --cyan: #2dd4bf;
  --green: #0f9f6e;
  --amber: #b7791f;
  --red: #d92d20;
  --shadow: 0 24px 70px rgba(28, 39, 60, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 45% 0%, rgba(45, 212, 191, 0.14), transparent 34rem),
    linear-gradient(180deg, #f8fafc 0%, var(--bg) 100%);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Display",
    "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  min-height: 100vh;
}

.app-shell.locked {
  filter: blur(10px);
  pointer-events: none;
  user-select: none;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: rgba(250, 252, 255, 0.72);
  backdrop-filter: blur(24px);
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background:
    linear-gradient(#fff, #fff) padding-box,
    linear-gradient(140deg, #111827, #0a84ff, #2dd4bf) border-box;
  border: 1px solid transparent;
  box-shadow: inset 0 0 0 6px rgba(10, 132, 255, 0.05);
}

.brand-name {
  font-weight: 650;
  line-height: 1.1;
}

.brand-subtitle,
.system-label,
.panel-head p,
.eyebrow,
.metric span,
.task-meta,
td {
  color: var(--muted);
}

.brand-subtitle,
.system-label {
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav-item {
  width: 100%;
  min-height: 40px;
  border-radius: var(--radius);
  color: var(--muted);
  background: transparent;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  cursor: pointer;
}

.nav-item.active {
  color: var(--text);
  background: rgba(17, 24, 39, 0.06);
}

.nav-item:disabled {
  cursor: default;
  opacity: 0.52;
}

.nav-icon {
  color: var(--blue);
  font-size: 11px;
}

.system-card,
.panel {
  border: 1px solid var(--line);
  background: var(--surface);
  backdrop-filter: blur(20px);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.system-card {
  margin-top: auto;
  padding: 14px;
  display: grid;
  gap: 12px;
  max-height: calc(100vh - 220px);
  overflow: auto;
}

.account-card,
.balance-card,
.ledger-card {
  display: grid;
  gap: 3px;
}

.account-card strong,
.balance-card strong {
  font-size: 15px;
  line-height: 1.25;
}

.account-card span {
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ledger-list {
  display: grid;
  gap: 6px;
  margin-top: 4px;
}

.ledger-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.46);
  padding: 8px;
}

.ledger-item div,
.ledger-item small {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.ledger-item span,
.ledger-item small,
.ledger-empty {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
}

.ledger-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ledger-amount {
  font-size: 12px;
  line-height: 1.3;
}

.ledger-amount.credit {
  color: var(--green);
}

.ledger-amount.debit {
  color: var(--red);
}

.system-state {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.pulse {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--amber);
  box-shadow: 0 0 0 5px rgba(183, 121, 31, 0.12);
}

.pulse.ok {
  background: var(--green);
  box-shadow: 0 0 0 5px rgba(15, 159, 110, 0.12);
}

.workspace {
  padding: 28px;
  min-width: 0;
  overflow-x: hidden;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.12;
  font-weight: 680;
}

h2 {
  font-size: 15px;
  line-height: 1.25;
  font-weight: 650;
}

.topbar-actions,
.form-actions,
.download-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-button,
.primary-button,
.secondary-button,
.ghost-link,
.mode-button,
.logout-button,
.auth-switch {
  min-height: 38px;
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition:
    transform 160ms ease,
    background 160ms ease,
    border-color 160ms ease,
    opacity 160ms ease;
}

.icon-button {
  width: 38px;
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(255, 255, 255, 0.74);
  cursor: pointer;
}

.icon-button svg,
.primary-button svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ghost-link,
.secondary-button,
.mode-button,
.logout-button,
.auth-switch {
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(255, 255, 255, 0.68);
  text-decoration: none;
  padding: 0 14px;
  cursor: pointer;
}

.logout-button,
.auth-switch {
  min-height: 34px;
}

.primary-button {
  color: #fff;
  background: #111827;
  padding: 0 16px;
  cursor: pointer;
}

.primary-button:hover,
.secondary-button:hover,
.icon-button:hover,
.ghost-link:hover,
.mode-button:hover,
.logout-button:hover,
.auth-switch:hover {
  transform: translateY(-1px);
}

.secondary-button:disabled,
.primary-button:disabled {
  cursor: default;
  opacity: 0.5;
  transform: none;
}

.view-section {
  display: none;
}

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

.grid {
  display: grid;
  grid-template-columns: minmax(360px, 1.16fr) minmax(320px, 0.84fr);
  gap: 18px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.36fr) minmax(440px, 0.64fr);
  gap: 18px;
  margin-top: 18px;
}

.panel {
  padding: 18px;
  min-width: 0;
}

.billing-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.82fr) minmax(360px, 1.18fr);
  gap: 18px;
}

.companies-grid {
  display: grid;
  grid-template-columns: minmax(360px, 0.9fr) minmax(320px, 1.1fr);
  gap: 18px;
}

.infrastructure-grid {
  display: grid;
  grid-template-columns: minmax(360px, 0.9fr) minmax(320px, 1.1fr);
  gap: 18px;
}

.companies-results-panel,
.infrastructure-results-panel {
  grid-column: 1 / -1;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field-grid label {
  display: grid;
  gap: 7px;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.check-filter {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.48);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.check-filter input {
  width: 16px;
  min-height: 16px;
  padding: 0;
  accent-color: var(--blue);
}

.billing-ledger-panel {
  grid-column: 1 / -1;
}

.balance-hero {
  min-height: 118px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 100% 0%, rgba(45, 212, 191, 0.16), transparent 18rem),
    rgba(255, 255, 255, 0.52);
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 18px;
}

.balance-hero strong {
  font-size: 42px;
  line-height: 1;
  font-weight: 680;
}

.balance-hero span,
.rate-grid span,
.package-card span,
.package-card small,
.billing-ledger-item span {
  color: var(--muted);
}

.rate-grid,
.package-grid {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

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

.rate-grid div,
.package-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.5);
  padding: 14px;
}

.rate-grid span,
.package-card span,
.package-card small {
  display: block;
  font-size: 12px;
}

.rate-grid strong {
  display: block;
  margin-top: 8px;
  font-size: 14px;
}

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

.package-card {
  min-height: 136px;
  display: grid;
  align-content: space-between;
}

.package-card strong {
  display: block;
  margin-top: 16px;
  font-size: 30px;
  line-height: 1;
}

.package-card.featured {
  border-color: rgba(10, 132, 255, 0.34);
  background: rgba(10, 132, 255, 0.06);
}

.billing-ledger-list {
  display: grid;
  gap: 8px;
}

.billing-ledger-item {
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.5);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px 88px;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
}

.billing-ledger-item div {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.billing-ledger-item div span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.billing-ledger-item > strong {
  text-align: right;
}

.placeholder-panel {
  min-height: 180px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.panel-head.compact {
  margin-bottom: 12px;
}

.panel-head p {
  margin-top: 3px;
  font-size: 13px;
}

.mode-toggle {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  padding: 3px;
  background: rgba(17, 24, 39, 0.05);
  border-radius: var(--radius);
}

.mode-button {
  min-height: 32px;
  border: 0;
  padding: 0 11px;
  color: var(--muted);
  background: transparent;
}

.mode-button.active {
  color: var(--text);
  background: var(--surface-strong);
  box-shadow: 0 8px 24px rgba(17, 24, 39, 0.08);
}

.form-stack {
  display: grid;
  gap: 10px;
}

.cost-preview {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.5);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 12px;
  align-items: center;
  padding: 10px 12px;
}

.cost-preview span,
.cost-preview small {
  color: var(--muted);
  font-size: 12px;
}

.cost-preview strong {
  font-size: 15px;
}

.cost-preview small {
  grid-column: 1 / -1;
}

.cost-preview.warning {
  border-color: rgba(217, 45, 32, 0.24);
  background: rgba(217, 45, 32, 0.04);
}

.cost-preview.warning strong {
  color: var(--red);
}

.field-label {
  font-size: 13px;
  color: var(--muted);
}

textarea {
  width: 100%;
  min-height: 168px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.72);
  outline: none;
  line-height: 1.45;
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.72);
  outline: none;
}

select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.72);
  outline: none;
}

textarea:focus,
input:focus,
select:focus,
.upload-zone:focus-within {
  border-color: rgba(10, 132, 255, 0.46);
  box-shadow: 0 0 0 4px rgba(10, 132, 255, 0.1);
}

.upload-zone {
  margin-top: 14px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  min-height: 74px;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.42);
}

.upload-zone input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.upload-zone strong,
.upload-zone span {
  display: block;
}

.upload-zone span {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-orbit {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(10, 132, 255, 0.32);
  box-shadow: inset 0 0 0 8px rgba(10, 132, 255, 0.06);
}

.status-pill {
  min-width: 78px;
  min-height: 28px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 11px;
  color: var(--muted);
  background: rgba(17, 24, 39, 0.06);
  font-size: 12px;
  text-transform: uppercase;
}

.status-pill.finished {
  color: var(--green);
  background: rgba(15, 159, 110, 0.1);
}

.status-pill.failed {
  color: var(--red);
  background: rgba(217, 45, 32, 0.1);
}

.status-pill.canceled {
  color: var(--muted);
  background: rgba(17, 24, 39, 0.08);
}

.status-pill.running,
.status-pill.queued {
  color: var(--blue);
  background: rgba(10, 132, 255, 0.1);
}

.progress-track {
  height: 8px;
  overflow: hidden;
  background: rgba(17, 24, 39, 0.07);
  border-radius: 999px;
  margin-bottom: 14px;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--cyan));
  border-radius: inherit;
  transition: width 220ms ease;
}

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

.metric {
  min-height: 78px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.56);
  padding: 12px;
}

.metric span {
  display: block;
  font-size: 12px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
  line-height: 1;
}

.metric.valid strong {
  color: var(--green);
}

.metric.risky strong {
  color: var(--amber);
}

.metric.invalid strong {
  color: var(--red);
}

.download-actions {
  justify-content: flex-end;
  margin-top: 14px;
}

.input-stats {
  margin-right: auto;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.download-meta {
  margin-top: 8px;
  color: var(--soft);
  font-size: 12px;
  text-align: right;
}

.task-list {
  display: grid;
  gap: 8px;
  max-height: 430px;
  overflow: auto;
  padding-right: 3px;
}

.task-item {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.58);
  padding: 10px;
  text-align: left;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.task-item.active {
  border-color: rgba(10, 132, 255, 0.42);
  background: rgba(10, 132, 255, 0.06);
}

.task-main {
  min-width: 0;
  padding: 2px 0;
  color: inherit;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.task-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-weight: 590;
}

.task-title span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-meta {
  margin-top: 6px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.mode-pill {
  min-height: 22px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  padding: 0 8px;
  font-size: 11px;
  color: var(--blue);
  background: rgba(10, 132, 255, 0.09);
}

.mode-pill.deep {
  color: #4338ca;
  background: rgba(67, 56, 202, 0.09);
}

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

.mini-button {
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.7);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.mini-button svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mini-button:hover {
  color: var(--text);
  border-color: var(--line-strong);
}

.mini-button.danger:hover {
  color: var(--red);
}

.table-wrap {
  width: 100%;
  max-height: 430px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  background: rgba(255, 255, 255, 0.5);
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 13px;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: rgba(248, 250, 252, 0.94);
  color: #3b4352;
  font-weight: 640;
  z-index: 1;
}

tr:last-child td {
  border-bottom: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 620;
}

.badge.valid {
  color: var(--green);
  background: rgba(15, 159, 110, 0.1);
}

.badge.risky,
.badge.catch_all {
  color: var(--amber);
  background: rgba(183, 121, 31, 0.11);
}

.badge.invalid {
  color: var(--red);
  background: rgba(217, 45, 32, 0.1);
}

.empty-state {
  color: var(--soft);
  padding: 18px;
  font-size: 13px;
}

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 0%, rgba(45, 212, 191, 0.18), transparent 34rem),
    rgba(248, 250, 252, 0.9);
  backdrop-filter: blur(22px);
}

.auth-screen.hidden {
  display: none;
}

.auth-panel {
  width: min(100%, 420px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
  padding: 22px;
}

.auth-brand {
  margin-bottom: 28px;
}

.auth-copy {
  margin-bottom: 18px;
}

.auth-copy h1 {
  font-size: 24px;
}

.auth-form {
  display: grid;
  gap: 10px;
}

.auth-submit,
.auth-switch {
  width: 100%;
}

.auth-submit {
  margin-top: 6px;
}

.auth-switch {
  margin-top: 10px;
}

.register-only {
  display: none;
}

.auth-screen.register-mode .register-only {
  display: block;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(380px, calc(100vw - 44px));
  transform: translateY(18px);
  opacity: 0;
  pointer-events: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(17, 24, 39, 0.92);
  color: #fff;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

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

  .sidebar {
    position: sticky;
    top: 0;
    height: auto;
    overflow: visible;
    z-index: 4;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    flex-direction: row;
    align-items: center;
    padding: 14px 18px;
  }

  .nav {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    overflow: auto;
  }

  .system-card {
    display: none;
  }
}

@media (max-width: 900px) {
  .workspace {
    padding: 18px;
  }

  .grid,
  .content-grid,
  .billing-grid,
  .companies-grid,
  .infrastructure-grid {
    grid-template-columns: 1fr;
  }

  .billing-ledger-panel,
  .companies-results-panel,
  .infrastructure-results-panel {
    grid-column: auto;
  }

  .topbar {
    align-items: flex-start;
  }
}

@media (max-width: 620px) {
  .sidebar {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .topbar {
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  h1 {
    font-size: 24px;
  }

  .panel-head,
  .upload-zone {
    grid-template-columns: 1fr;
  }

  .upload-zone {
    display: grid;
  }

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

  .rate-grid,
  .package-grid,
  .billing-ledger-item,
  .field-grid {
    grid-template-columns: 1fr;
  }

  .billing-ledger-item > strong {
    text-align: left;
  }
}
