:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #eef3f7;
  --ink: #1d2733;
  --muted: #687483;
  --line: #dce3ea;
  --accent: #0f766e;
  --accent-dark: #0b5d57;
  --accent-soft: #dff5f1;
  --danger: #c24135;
  --danger-soft: #fdecea;
  --warning: #a16207;
  --warning-soft: #fff3d6;
  --shadow: 0 18px 50px rgba(28, 43, 58, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background: #eaf2f0;
}

.login-shell {
  width: min(420px, 100%);
}

.login-card {
  display: grid;
  gap: 22px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-brand {
  color: var(--ink);
}

.login-brand span {
  color: var(--muted);
}

.login-card h1 {
  margin: 0;
  font-size: 28px;
}

.login-form {
  display: grid;
  gap: 14px;
}

.form-error {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid #f2c4bf;
  border-radius: 8px;
  color: var(--danger);
  background: #fff8f7;
  font-weight: 700;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px;
  color: #eaf5f2;
  background: #0d302e;
}

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

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  color: #0d302e;
  background: #a7f3d0;
  font-weight: 800;
}

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

.brand span,
.sidebar-note span {
  color: rgba(234, 245, 242, 0.72);
  font-size: 13px;
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 14px;
  border: 0;
  border-radius: 8px;
  color: rgba(234, 245, 242, 0.82);
  background: transparent;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.12);
}

.nav-item span {
  width: 22px;
  color: #a7f3d0;
}

.sidebar-note {
  margin-top: auto;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.sidebar-note strong {
  display: block;
  margin-top: 6px;
  font-size: 24px;
}

.main {
  min-width: 0;
  padding: 28px;
}

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

.topbar h1,
.panel h2 {
  margin: 0;
}

.topbar h1 {
  font-size: 28px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

.filters {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.invoice-filters {
  max-width: 980px;
}

.filters input[type="search"] {
  width: min(420px, 100%);
  min-width: 310px;
}

.invoice-filters select {
  width: auto;
  min-width: 150px;
}

.invoice-filters #invoiceProviderFilter {
  min-width: 230px;
}

.date-filter {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 42px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  white-space: nowrap;
}

.date-filter input {
  width: 136px;
  min-height: 32px;
  padding: 5px 7px;
  border: 0;
  background: transparent;
  color: var(--ink);
}

.compact-button {
  min-height: 42px;
  padding-inline: 14px;
}

.check-filters {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.check-filters label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 4px 9px;
  border-radius: 7px;
  color: var(--ink);
  font-size: 13px;
  text-transform: none;
  white-space: nowrap;
}

.check-filters input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--accent);
}

.primary-button,
.secondary-button,
.ghost-button,
.text-button,
.icon-button {
  border: 0;
  border-radius: 8px;
  font-weight: 700;
}

.primary-button {
  padding: 11px 16px;
  color: #ffffff;
  background: var(--accent);
}

.primary-button:hover {
  background: var(--accent-dark);
}

.secondary-button,
.ghost-button {
  padding: 10px 14px;
  color: var(--ink);
  background: var(--surface-soft);
}

.ghost-button {
  border: 1px solid var(--line);
  background: var(--surface);
}

.text-button {
  padding: 8px 0;
  color: var(--accent);
  background: transparent;
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 20px;
}

.openfactura-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(360px, 0.85fr);
  gap: 0;
}

.sync-status {
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  background: #fbfcfe;
  font-size: 13px;
  font-weight: 700;
}

.openfactura-detail {
  min-width: 0;
  border-left: 1px solid var(--line);
  background: #fbfcfe;
}

.openfactura-drawer-panel {
  width: min(880px, 100%);
}

.detail-actions {
  display: flex;
  justify-content: flex-end;
  margin: 16px 0;
}

.detail-city-field {
  max-width: 180px;
  margin-top: 16px;
}

.pdf-preview {
  height: min(72vh, 780px);
  min-height: 520px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #f8fafc;
}

.pdf-preview iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

.json-preview {
  min-height: 420px;
  max-height: 620px;
  margin: 0;
  overflow: auto;
  padding: 18px;
  color: #263442;
  background: #fbfcfe;
  font: 13px/1.5 Consolas, "Courier New", monospace;
  white-space: pre-wrap;
}

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

.metric,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 1px 1px rgba(28, 43, 58, 0.04);
}

.metric {
  padding: 18px;
}

.metric span,
.metric small {
  display: block;
  color: var(--muted);
}

.metric strong {
  display: block;
  margin: 10px 0 4px;
  font-size: 28px;
}

.metric.urgent {
  border-color: #b9e6df;
  background: var(--accent-soft);
}

.metric.warning {
  border-color: #f4d690;
  background: var(--warning-soft);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(300px, 0.8fr);
  gap: 20px;
}

.panel {
  min-width: 0;
  overflow: hidden;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.panel-heading.compact {
  padding-bottom: 12px;
}

.invoice-form,
.provider-form {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) repeat(5, minmax(140px, 1fr)) auto;
  gap: 14px;
  align-items: end;
  padding: 18px;
}

.provider-form {
  grid-template-columns: repeat(4, minmax(160px, 1fr)) auto;
}

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

label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
}

input:focus,
select:focus {
  outline: 3px solid rgba(15, 118, 110, 0.16);
  border-color: var(--accent);
}

.provider-field {
  position: relative;
}

.combo-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  right: 0;
  left: 0;
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.combo-option {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 11px 12px;
  border: 0;
  border-radius: 0;
  background: #ffffff;
  text-align: left;
}

.combo-option:hover {
  background: var(--surface-soft);
}

.combo-option small {
  color: var(--muted);
}

.provider-create {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(180px, 260px) auto;
  gap: 14px;
  align-items: end;
  padding: 14px;
  border: 1px dashed #98cfc8;
  border-radius: 8px;
  background: #f1fbf8;
}

.provider-create span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

.select-col {
  width: 44px;
  text-align: center;
}

.select-col input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

.city-select {
  width: 86px;
  min-height: 34px;
  padding: 6px 8px;
  font-size: 13px;
  font-weight: 800;
}

.city-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 26px;
  padding: 4px 8px;
  border-radius: 999px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  font-size: 12px;
  font-weight: 800;
}

.city-pill.empty {
  color: var(--muted);
  background: var(--surface-soft);
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  background: #fbfcfe;
}

tbody tr:hover {
  background: #fbfcfe;
}

.right {
  text-align: right;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.status.pending {
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.status.partial {
  color: #315f92;
  background: #e6f0ff;
}

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

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

.status.paid {
  color: #28613c;
  background: #e7f7eb;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.action-cell {
  width: 184px;
}

.invoice-actions {
  justify-content: space-between;
  min-width: 156px;
}

.small-button {
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  font-weight: 700;
}

.small-button:hover {
  background: var(--surface-soft);
}

.danger-button {
  color: var(--danger);
  border-color: #f2c4bf;
  background: #fff8f7;
}

.danger-button:hover {
  background: var(--danger-soft);
}

.delete-icon-button {
  display: inline-grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid #f2c4bf;
  border-radius: 8px;
  color: var(--danger);
  background: #fff8f7;
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
}

.delete-icon-button:hover {
  background: var(--danger-soft);
}

.aging-list {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.aging-item {
  display: grid;
  gap: 7px;
}

.aging-row {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.bar {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}

.bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.bar.warning span {
  background: #d99a18;
}

.bar.danger span {
  background: var(--danger);
}

.empty-state {
  padding: 28px 16px;
  color: var(--muted);
  text-align: center;
}

.drawer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  justify-content: flex-end;
  background: rgba(13, 28, 36, 0.34);
}

.drawer.open {
  display: flex;
}

.drawer-panel {
  position: relative;
  width: min(720px, 100%);
  height: 100%;
  overflow: auto;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.close-drawer {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 38px;
  height: 38px;
  color: var(--ink);
  background: var(--surface-soft);
  font-size: 24px;
  line-height: 1;
}

.detail {
  padding: 28px;
}

.detail h2 {
  margin: 0 44px 4px 0;
  font-size: 24px;
}

.detail-subtitle {
  margin: 0 0 18px;
  color: var(--muted);
}

.detail-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.detail-summary div {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.detail-summary span,
.payment-form label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.detail-summary strong {
  display: block;
  margin-top: 6px;
  font-size: 20px;
}

.payment-form {
  display: grid;
  grid-template-columns: minmax(120px, 0.9fr) minmax(150px, 1.1fr) minmax(120px, 0.8fr) minmax(170px, 1.3fr);
  gap: 12px;
  align-items: end;
  padding: 16px;
  margin-bottom: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.payment-form .primary-button {
  grid-column: 1 / -1;
  justify-self: end;
  min-width: 150px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 80;
  padding: 12px 16px;
  border-radius: 8px;
  color: #ffffff;
  background: #193b38;
  box-shadow: var(--shadow);
}

.app-alert-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: none;
  place-items: center;
  padding: 24px;
  background: rgba(13, 28, 36, 0.34);
}

.app-alert-overlay.open {
  display: grid;
}

.app-alert {
  width: min(420px, 100%);
  padding: 24px;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.app-alert h2 {
  margin: 0 0 8px;
  font-size: 22px;
}

.app-alert p {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.45;
}

.app-alert-progress {
  height: 10px;
  margin-bottom: 18px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}

.app-alert-progress span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 180ms ease;
}

.dm-swal-popup {
  border-radius: 10px;
  color: var(--ink);
  font-family: inherit;
}

.dm-swal-confirm,
.dm-swal-cancel {
  min-height: 42px;
  margin: 0 5px;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: 8px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.dm-swal-confirm {
  color: #ffffff;
  background: var(--accent);
}

.dm-swal-confirm.danger {
  background: var(--danger);
}

.dm-swal-cancel {
  color: var(--ink);
  border-color: var(--line);
  background: #ffffff;
}

.dm-swal-toast {
  border-radius: 8px;
  font-family: inherit;
}

.swal-progress-copy {
  margin: 2px 0 18px;
  color: var(--muted);
  line-height: 1.45;
}

.swal-progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--accent-soft);
}

.swal-progress-bar {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 180ms ease;
}

@media (max-width: 1120px) {
  .metric-grid,
  .dashboard-grid,
  .openfactura-grid,
  .invoice-form,
  .provider-form,
  .payment-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .provider-create {
    grid-template-columns: 1fr;
  }
}

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

  .sidebar {
    position: static;
    height: auto;
    padding: 16px;
  }

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

  .nav-item {
    justify-content: center;
    padding: 10px 8px;
  }

  .nav-item span {
    display: none;
  }

  .sidebar-note {
    display: none;
  }

  .main {
    padding: 18px;
  }

  .topbar,
  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .filters,
  .invoice-form,
  .provider-form,
  .payment-form,
  .detail-summary,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  .topbar-actions,
  .filters,
  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .filters input[type="search"],
  .invoice-filters select,
  .invoice-filters #invoiceProviderFilter,
  .date-filter,
  .date-filter input {
    width: 100%;
    min-width: 0;
  }

  .date-filter {
    justify-content: space-between;
  }

  .check-filters {
    justify-content: space-between;
  }

  .primary-button,
  .secondary-button,
  .ghost-button {
    width: 100%;
  }
}
