:root {
  color-scheme: light;
  --ink: #14213d;
  --muted: #61708a;
  --line: #dce3ee;
  --line-strong: #c6d0df;
  --surface: #ffffff;
  --surface-soft: #f5f7fb;
  --blue: #2357d7;
  --blue-dark: #173fa4;
  --green: #15845c;
  --green-soft: #eaf8f2;
  --amber: #9a5b00;
  --amber-soft: #fff6df;
  --red: #bc2942;
  --red-soft: #fff0f2;
  --shadow: 0 20px 55px rgba(28, 45, 77, 0.09);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #eef2f8;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% -10%, rgba(74, 115, 230, 0.15), transparent 32rem),
    linear-gradient(180deg, #f8faff 0, #eef2f8 32rem);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button,
label[for] {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: var(--blue);
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 72px;
}

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

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

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(145deg, #2c67ed, #153b9a);
  box-shadow: 0 9px 24px rgba(35, 87, 215, 0.24);
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  letter-spacing: -0.01em;
}

.brand small {
  color: var(--muted);
  font-size: 0.78rem;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 18px;
  font-size: clamp(2rem, 4.4vw, 3.7rem);
  line-height: 1.04;
  letter-spacing: -0.045em;
}

h2 {
  margin-bottom: 3px;
  font-size: 1.42rem;
  letter-spacing: -0.025em;
}

h3 {
  margin-bottom: 4px;
  font-size: 1.12rem;
}

.eyebrow {
  margin-bottom: 10px;
  color: var(--blue);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.lead {
  max-width: 720px;
  color: var(--muted);
  font-size: 1.06rem;
}

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

.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 17px;
  border: 1px solid transparent;
  border-radius: 11px;
  cursor: pointer;
  text-decoration: none;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease, opacity 120ms ease;
  font-weight: 750;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.button:focus-visible,
input:focus-visible,
select:focus-visible,
.drop-zone:focus-within {
  outline: 3px solid rgba(35, 87, 215, 0.22);
  outline-offset: 2px;
}

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

.button-primary {
  color: #fff;
  background: var(--blue);
  box-shadow: 0 8px 20px rgba(35, 87, 215, 0.2);
}

.button-primary:hover:not(:disabled) {
  background: var(--blue-dark);
}

.button-ghost {
  color: var(--ink);
  border-color: var(--line-strong);
  background: #fff;
}

.button-ghost:hover:not(:disabled) {
  border-color: #99a9c0;
  background: var(--surface-soft);
}

.button-small {
  min-height: 36px;
  padding: 7px 12px;
  font-size: 0.82rem;
}

.logout-form {
  margin: 0;
}

.notice {
  margin: 0 0 24px;
  padding: 14px 17px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 8px 25px rgba(28, 45, 77, 0.04);
}

.notice-info {
  color: #264b8c;
  border-color: #cbdaf8;
  background: #f1f6ff;
}

.notice-success {
  color: #116445;
  border-color: #bfe5d6;
  background: var(--green-soft);
}

.notice-warning {
  color: var(--amber);
  border-color: #efd9a4;
  background: var(--amber-soft);
}

.notice-error {
  color: var(--red);
  border-color: #f1bec7;
  background: var(--red-soft);
}

.auth-card {
  width: min(720px, 100%);
  margin: 7vh auto 0;
  padding: clamp(24px, 5vw, 48px);
  border: 1px solid rgba(198, 208, 223, 0.8);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.auth-card h1 {
  font-size: clamp(2rem, 5vw, 3rem);
}

.auth-card-narrow {
  width: min(510px, 100%);
}

.stacked-form {
  display: grid;
  gap: 17px;
  margin-top: 28px;
}

.stacked-form label,
.global-settings label {
  display: grid;
  gap: 7px;
  color: #273551;
  font-size: 0.9rem;
  font-weight: 700;
}

.stacked-form label small {
  color: var(--muted);
  font-weight: 450;
}

input[type="text"],
input[type="email"],
input[type="password"],
select {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  color: var(--ink);
  background: #fff;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.check-row {
  display: flex !important;
  grid-template-columns: unset !important;
  align-items: flex-start;
  gap: 10px !important;
  cursor: pointer;
  font-weight: 520 !important;
}

.check-row input {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  margin: 2px 0 0;
  accent-color: var(--blue);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(300px, 0.75fr);
  gap: 48px;
  align-items: end;
  margin: 42px 0 38px;
}

.connection-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 12px 32px rgba(28, 45, 77, 0.06);
}

.connection-card strong,
.connection-card small {
  display: block;
}

.connection-card strong {
  font-size: 0.9rem;
}

.connection-card small {
  overflow: hidden;
  max-width: 260px;
  color: var(--muted);
  font-size: 0.72rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #97a3b7;
  box-shadow: 0 0 0 4px rgba(151, 163, 183, 0.14);
}

.status-ok {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(21, 132, 92, 0.14);
}

.status-error {
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(188, 41, 66, 0.13);
}

.status-pending {
  background: #d98a13;
  box-shadow: 0 0 0 4px rgba(217, 138, 19, 0.14);
}

.workflow-card {
  overflow: hidden;
  border: 1px solid rgba(198, 208, 223, 0.86);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.step-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.step-strip span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 10px;
  color: var(--muted);
  border-right: 1px solid var(--line);
  font-size: 0.8rem;
  font-weight: 700;
}

.step-strip span:last-child {
  border-right: 0;
}

.step-strip span.active {
  color: var(--blue);
  background: #f0f5ff;
}

.step-strip b {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: #9caac0;
  font-size: 0.7rem;
}

.step-strip .active b {
  background: var(--blue);
}

.drop-zone {
  display: grid;
  min-height: 250px;
  place-items: center;
  align-content: center;
  gap: 7px;
  margin: 24px;
  padding: 32px;
  border: 2px dashed #b7c4d8;
  border-radius: 14px;
  cursor: pointer;
  text-align: center;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
}

.drop-zone:hover,
.drop-zone.drag-active {
  border-color: var(--blue);
  background: #f2f6ff;
  transform: translateY(-1px);
}

.drop-zone input {
  position: absolute;
  overflow: hidden;
  width: 1px;
  height: 1px;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.drop-zone small {
  color: var(--muted);
}

.upload-icon {
  display: grid;
  width: 48px;
  height: 48px;
  margin-bottom: 5px;
  place-items: center;
  border-radius: 14px;
  color: var(--blue);
  background: #e7efff;
  font-size: 1.55rem;
  font-weight: 750;
}

.global-settings {
  padding: 18px 24px 22px;
  border-top: 1px solid var(--line);
  background: var(--surface-soft);
}

.global-settings label {
  width: min(480px, 100%);
}

.global-settings p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.global-settings-attention {
  background: var(--amber-soft);
  box-shadow: inset 4px 0 0 #d98a13;
}

.global-settings-attention label > span,
.global-settings-attention p {
  color: var(--amber);
  font-weight: 700;
}

#app-message {
  margin-top: 22px;
}

.invoice-list {
  display: grid;
  gap: 22px;
  margin-top: 22px;
}

.invoice-card {
  overflow: hidden;
  border: 1px solid rgba(198, 208, 223, 0.9);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 15px 40px rgba(28, 45, 77, 0.07);
}

.invoice-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fff, #fbfcff);
}

.invoice-header small {
  color: var(--muted);
}

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

.badge {
  display: inline-flex;
  min-height: 29px;
  align-items: center;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 800;
}

.badge-ok {
  color: #126546;
  background: var(--green-soft);
}

.badge-error {
  color: var(--red);
  background: var(--red-soft);
}

.badge-warning,
.badge-pending {
  color: var(--amber);
  background: var(--amber-soft);
}

.invoice-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 0.8fr);
  gap: 30px;
  padding: 24px;
}

.section-label,
.detail-item span {
  display: block;
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 780;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.client-block p {
  margin-bottom: 4px;
  font-size: 0.9rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 18px;
}

.detail-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.detail-item strong {
  font-size: 0.9rem;
}

.financial-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 24px;
  align-items: start;
  padding: 0 24px 24px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.line-table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  font-size: 0.82rem;
}

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

.line-table th {
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

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

.line-table td small,
.line-table td strong {
  display: block;
}

.line-table td small {
  margin-top: 3px;
  color: var(--muted);
}

.line-table .numeric {
  text-align: right;
  white-space: nowrap;
}

.discount-row {
  color: var(--amber);
  background: #fffdf7;
}

.totals {
  margin: 0;
  padding: 4px 0;
}

.totals > div {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.85rem;
}

.totals dt,
.totals dd {
  margin: 0;
}

.totals dd {
  font-weight: 750;
  white-space: nowrap;
}

.totals .total-prominent {
  padding-top: 13px;
  border-bottom: 0;
  color: var(--blue-dark);
  font-size: 1rem;
}

.validation-messages {
  display: grid;
  gap: 8px;
  padding: 0 24px 20px;
}

.inline-alert {
  padding: 10px 12px;
  border-radius: 9px;
  font-size: 0.8rem;
}

.inline-alert-ok {
  color: #116445;
  background: var(--green-soft);
}

.inline-alert-warning {
  color: var(--amber);
  background: var(--amber-soft);
}

.inline-alert-error {
  color: var(--red);
  background: var(--red-soft);
}

.invoice-controls {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 28px;
  padding: 20px 24px;
  border-top: 1px solid var(--line);
  background: var(--surface-soft);
}

.control-checks {
  display: grid;
  gap: 6px;
}

.control-checks small {
  margin-left: 28px;
  color: var(--muted);
  font-size: 0.74rem;
}

.check-row.compact {
  font-size: 0.86rem;
}

.confirm-row {
  margin-top: 5px;
  font-weight: 720 !important;
}

.issue-actions {
  display: grid;
  min-width: 220px;
  justify-items: end;
  gap: 8px;
}

.issue-help {
  max-width: 290px;
  color: var(--amber);
  font-size: 0.76rem;
  font-weight: 700;
  text-align: right;
}

.card-result {
  display: none;
}

.card-result:not(:empty) {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid var(--line);
  font-size: 0.86rem;
}

.card-result-success {
  color: #116445;
  background: var(--green-soft);
}

.card-result-warning,
.card-result-pending {
  color: var(--amber);
  background: var(--amber-soft);
}

.card-result-error {
  color: var(--red);
  background: var(--red-soft);
}

.card-result strong {
  margin-right: auto;
}

.spv-message,
.spv-error {
  font-weight: 700;
}

.spv-error {
  color: var(--red);
}

.spinner {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  border: 2px solid rgba(154, 91, 0, 0.2);
  border-top-color: var(--amber);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.safety-note {
  margin-top: 32px;
  padding: 20px 24px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.6);
  font-size: 0.87rem;
}

.safety-note strong {
  color: var(--ink);
}

.safety-note p {
  margin: 5px 0 0;
}

[hidden] {
  display: none !important;
}

@media (max-width: 900px) {
  .hero,
  .invoice-summary,
  .financial-grid {
    grid-template-columns: 1fr;
  }

  .hero {
    gap: 22px;
  }

  .connection-card {
    max-width: 560px;
  }

  .financial-grid {
    gap: 14px;
  }

  .totals {
    padding-left: 50%;
  }
}

@media (max-width: 660px) {
  .shell {
    width: min(100% - 20px, 1180px);
    padding-top: 14px;
  }

  .topbar {
    margin-bottom: 28px;
  }

  .hero {
    margin-top: 26px;
  }

  h1 {
    font-size: 2.15rem;
  }

  .form-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .step-strip {
    grid-template-columns: 1fr 1fr;
  }

  .step-strip span:nth-child(2) {
    border-right: 0;
  }

  .step-strip span:nth-child(-n + 2) {
    border-bottom: 1px solid var(--line);
  }

  .drop-zone {
    min-height: 210px;
    margin: 14px;
    padding: 24px 14px;
  }

  .invoice-header,
  .invoice-controls,
  .card-result:not(:empty) {
    align-items: stretch;
    flex-direction: column;
  }

  .header-actions {
    justify-content: space-between;
  }

  .invoice-summary,
  .financial-grid,
  .validation-messages,
  .invoice-controls {
    padding-right: 16px;
    padding-left: 16px;
  }

  .totals {
    padding-left: 0;
  }

  .invoice-controls .button-primary {
    width: 100%;
  }

  .issue-actions {
    width: 100%;
    justify-items: stretch;
  }

  .issue-help {
    max-width: none;
    text-align: left;
  }

  .connection-card {
    grid-template-columns: auto 1fr;
  }

  .connection-card .button {
    grid-column: 1 / -1;
  }
}
