:root {
  color-scheme: light;

  --bg: #f4f6f8;
  --bg-secondary: #eef2f5;
  --surface: #ffffff;
  --surface-alt: #eef2f5;
  --text: #182230;
  --muted: #667085;
  --border: #d8dee5;
  --primary: #0f2a44;
  --primary-hover: #183b5f;
  --danger: #8a1f1f;
  --danger-soft: #fceaea;
  --warning: #8a4b00;
  --warning-soft: #fff4df;
  --success: #21643c;
  --success-soft: #eaf7ef;
  --shadow-r: 15;
  --shadow-g: 42;
  --shadow-b: 68;
  --shadow-alpha: 0.12;
  --modal-overlay-alpha: 0.42;
  --gradient-angle: 180deg;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background:
    linear-gradient(
      var(--gradient-angle),
      var(--bg) 0%,
      var(--bg-secondary) 100%
    );
}

body.modal-open {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(15, 42, 68, 0.22);
  outline-offset: 2px;
}

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

h1 {
  margin-bottom: 4px;
  color: var(--primary);
  font-size: 24px;
  line-height: 1.2;
}

h2 {
  margin-bottom: 7px;
  color: var(--primary);
  font-size: 19px;
}

h3 {
  margin-bottom: 4px;
  color: var(--primary);
  font-size: 16px;
}

p {
  color: var(--muted);
  line-height: 1.5;
}

.noscript-message {
  max-width: 560px;
  margin: 24px auto;
  padding: 16px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
}

.app-shell {
  min-height: 100vh;
  padding: 34px 24px;
}

.screen {
  width: 100%;
  display: none;
}

.screen.active {
  display: block;
}

#loginScreen.active {
  min-height: calc(100vh - 68px);
  display: grid;
  place-items: center;
}

.login-card {
  width: min(100%, 420px);
  padding: 34px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow:
    0 18px 45px
    rgba(
      var(--shadow-r),
      var(--shadow-g),
      var(--shadow-b),
      var(--shadow-alpha)
    );
}

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

.brand-block p,
.dashboard-header p,
.section-heading p,
.subsection-heading p {
  margin-bottom: 0;
}

.eyebrow {
  display: inline-block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.field-group {
  margin-bottom: 18px;
}

label {
  display: block;
  margin-bottom: 7px;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 44px;
  padding: 11px 12px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 42, 68, 0.1);
}

.message,
.page-message {
  min-height: 20px;
  margin-bottom: 16px;
  color: var(--danger);
  font-size: 13px;
}

.page-message.success-message {
  color: var(--success);
}

.primary-button,
.ghost-button,
.icon-button,
.table-action-button {
  border-radius: 8px;
  transition:
    background 140ms ease,
    border-color 140ms ease,
    box-shadow 140ms ease;
}

.primary-button {
  width: 100%;
  min-height: 44px;
  padding: 11px 16px;
  color: #ffffff;
  background: var(--primary);
  border: 1px solid var(--primary);
  font-weight: 700;
}

.primary-button:hover:not(:disabled),
.primary-button:focus-visible:not(:disabled) {
  background: var(--primary-hover);
}

.compact-button {
  width: auto;
  min-width: 160px;
}

.ghost-button,
.table-action-button {
  min-height: 40px;
  padding: 9px 13px;
  color: var(--primary);
  background: transparent;
  border: 1px solid var(--border);
}

.ghost-button:hover:not(:disabled),
.ghost-button:focus-visible:not(:disabled),
.table-action-button:hover:not(:disabled),
.table-action-button:focus-visible:not(:disabled) {
  background: var(--surface-alt);
}

.table-action-button {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 12px;
  white-space: nowrap;
}

.danger-button {
  color: var(--danger);
  border-color: rgba(138, 31, 31, 0.28);
}

.dashboard {
  width: min(100%, 1120px);
  margin: 0 auto;
}

.payer-dashboard {
  width: min(100%, 920px);
}

.dashboard-header,
.panel-card,
.balance-card,
.support-box,
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 18px;
  padding: 24px;
  box-shadow:
    0 18px 45px
    rgba(
      var(--shadow-r),
      var(--shadow-g),
      var(--shadow-b),
      var(--shadow-alpha)
    );
}

.header-actions,
.inline-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.signed-in-user {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.balance-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-bottom: 18px;
  padding: 24px;
}

.balance-card span {
  color: var(--muted);
  font-size: 14px;
}

.balance-card strong {
  color: var(--primary);
  font-size: 30px;
}

.panel-card,
.support-box {
  margin-bottom: 18px;
  padding: 24px;
}

.support-box {
  color: var(--muted);
  font-size: 13px;
}

.support-box span {
  color: var(--text);
  font-weight: 700;
}

.section-heading,
.subsection-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
}

.section-heading {
  margin-bottom: 20px;
}

.subsection-heading {
  margin-top: 26px;
  margin-bottom: 14px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
}

.count-pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.count-pill {
  padding: 7px 10px;
  color: var(--muted);
  background: var(--surface-alt);
  border: 1px solid var(--border);
}

.status-pill {
  padding: 5px 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-active,
.status-paid,
.status-completed {
  color: var(--success);
  background: var(--success-soft);
}

.status-disabled,
.status-cancelled,
.status-failed {
  color: var(--danger);
  background: var(--danger-soft);
}

.status-pending,
.status-pending_provider,
.status-provider_created {
  color: var(--primary);
  background: var(--surface-alt);
}

.status-overdue {
  color: var(--warning);
  background: var(--warning-soft);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stat-card {
  min-height: 110px;
  padding: 18px;
}

.stat-card span,
.detail-item span,
.modal-summary span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.stat-card strong {
  color: var(--primary);
  font-size: 22px;
}

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

.detail-item {
  min-height: 88px;
  padding: 15px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 9px;
  overflow-wrap: anywhere;
}

.detail-item strong {
  color: var(--primary);
  font-size: 14px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.data-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  background: var(--surface);
}

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

.data-table th {
  color: var(--muted);
  background: var(--surface-alt);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.data-table td {
  color: var(--text);
  font-size: 13px;
}

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

.data-table tbody tr.selected-row td {
  background: rgba(15, 42, 68, 0.05);
}

.table-actions {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.table-primary-text {
  display: block;
  color: var(--primary);
  font-weight: 700;
}

.table-secondary-text {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.empty-state {
  margin: 0;
  padding: 20px;
  color: var(--muted);
  background: var(--surface-alt);
  border: 1px dashed var(--border);
  border-radius: 10px;
  text-align: center;
  font-size: 13px;
}

.invoice-list {
  display: grid;
  gap: 12px;
}

.invoice-card {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  transition:
    border-color 140ms ease,
    box-shadow 140ms ease;
}

.invoice-card.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 42, 68, 0.09);
}

.invoice-card-header,
.invoice-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
}

.invoice-card-header {
  margin-bottom: 10px;
}

.invoice-card-footer {
  align-items: center;
  margin-top: 14px;
}

.invoice-number,
.invoice-amount {
  color: var(--primary);
  font-weight: 700;
}

.invoice-number {
  display: block;
  margin-bottom: 4px;
}

.invoice-amount {
  font-size: 18px;
  white-space: nowrap;
}

.invoice-description {
  margin-bottom: 0;
  font-size: 14px;
}

.invoice-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
}

.selection-panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.selection-summary {
  margin-bottom: 0;
  font-size: 13px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    rgba(
      var(--shadow-r),
      var(--shadow-g),
      var(--shadow-b),
      var(--modal-overlay-alpha)
    );
}

.modal {
  width: min(100%, 760px);
  max-height: calc(100vh - 48px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow:
    0 18px 45px
    rgba(
      var(--shadow-r),
      var(--shadow-g),
      var(--shadow-b),
      var(--shadow-alpha)
    );
}

.modal-small {
  width: min(100%, 520px);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 20px 22px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin-bottom: 3px;
}

.modal-header p {
  margin-bottom: 0;
  font-size: 13px;
}

.modal-body {
  padding: 22px;
}

.icon-button {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  color: var(--primary);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  font-size: 24px;
  line-height: 1;
}

.icon-button:hover,
.icon-button:focus-visible {
  background: #dde5ec;
}

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

.form-span-2 {
  grid-column: 1 / -1;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 18px;
}

.modal-summary > div,
.notice-box {
  padding: 16px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.modal-summary strong {
  color: var(--primary);
}

.notice-box {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 1000px) {
  .stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

@media (max-width: 700px) {
  .app-shell {
    padding: 18px 14px;
  }

  #loginScreen.active {
    min-height: calc(100vh - 36px);
  }

  .login-card,
  .dashboard-header,
  .panel-card,
  .balance-card,
  .support-box {
    padding: 20px;
  }

  .dashboard-header,
  .section-heading,
  .subsection-heading,
  .selection-panel,
  .invoice-card-header,
  .invoice-card-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .header-actions,
  .inline-actions,
  .modal-actions {
    justify-content: stretch;
  }

  .header-actions > button,
  .inline-actions > button,
  .modal-actions > button,
  .compact-button {
    width: 100%;
  }

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

  .form-span-2 {
    grid-column: auto;
  }

  .balance-card {
    align-items: flex-start;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
