:root {
  color-scheme: light;
  --ink: #17211d;
  --muted: #66756f;
  --line: #d8e0dc;
  --surface: #ffffff;
  --surface-soft: #f4f7f5;
  --teal: #087f7a;
  --teal-dark: #075f5d;
  --coral: #d9664b;
  --amber: #b9770e;
  --green: #2f855a;
  --blue: #3166a8;
  --shadow: 0 16px 40px rgba(27, 39, 33, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top right, rgba(8, 127, 122, 0.14), transparent 28%),
    radial-gradient(circle at bottom left, rgba(217, 102, 75, 0.12), transparent 24%),
    #edf2ef;
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

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

.readonly-field {
  background: #eef3f0;
  color: var(--muted);
  font-weight: 800;
}

.form-hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  margin-top: -8px;
}

.project-cell-label,
td small {
  display: block;
}

td small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

button {
  cursor: pointer;
}

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

body.auth-locked .app-shell {
  display: none;
}

body:not(.auth-locked) .auth-screen {
  display: none;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(520px, 100%);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(216, 224, 220, 0.9);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(27, 39, 33, 0.12);
  padding: 28px;
  display: grid;
  gap: 18px;
}

.auth-brand {
  display: grid;
  gap: 16px;
  justify-items: start;
}

.auth-copy {
  color: var(--muted);
  line-height: 1.6;
}

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

.auth-submit {
  width: 100%;
}

.auth-help,
.session-box {
  display: grid;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.form-message {
  min-height: 20px;
  margin: 0;
  color: #a43f28;
  font-size: 13px;
  font-weight: 700;
}

.session-box {
  background: rgba(255, 255, 255, 0.04);
  border-color: #315650;
  color: #f4fbf8;
}

.sidebar-btn {
  width: 100%;
}

.sidebar {
  background: #10231f;
  color: #f4fbf8;
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.brand {
  display: grid;
  gap: 14px;
}

.brand-logo-image {
  display: block;
  width: 100%;
  height: auto;
}

.auth-brand-logo {
  width: min(280px, 72%);
  filter: drop-shadow(0 12px 26px rgba(7, 95, 93, 0.12));
}

.sidebar-brand-logo {
  width: 100%;
  max-width: 188px;
  padding: 12px 14px;
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(241, 248, 245, 0.94));
  box-shadow:
    inset 0 0 0 1px rgba(216, 224, 220, 0.95),
    0 14px 30px rgba(4, 16, 14, 0.22);
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand strong,
.brand span,
.source-box strong,
.source-box span,
.source-box small {
  display: block;
}

.brand strong {
  font-size: 18px;
}

.brand span,
.source-box span,
.source-box small {
  color: #b9cbc4;
}

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

.nav-tab[hidden] {
  display: none;
}

.nav-tab {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 12px 14px;
  background: transparent;
  color: #eaf5f0;
  text-align: right;
}

.nav-tab.active,
.nav-tab:hover {
  background: #1d3934;
  border-color: #315650;
}

.source-box {
  margin-top: auto;
  border: 1px solid #315650;
  border-radius: 8px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.04);
  display: grid;
  gap: 6px;
}

.workspace {
  padding: 28px;
  display: grid;
  gap: 20px;
  align-content: start;
  min-width: 0;
}

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal-dark);
  font-weight: 700;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.2;
}

h2 {
  font-size: 18px;
}

.top-actions,
.dialog-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-btn,
.secondary-btn,
.icon-btn {
  border: 0;
  border-radius: 8px;
  min-height: 42px;
}

.primary-btn {
  background: var(--teal);
  color: #fff;
  padding: 0 18px;
  font-weight: 700;
}

.secondary-btn {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 0 14px;
}

.icon-btn {
  width: 38px;
  background: var(--surface-soft);
  color: var(--ink);
  font-size: 24px;
}

.filters {
  display: grid;
  grid-template-columns: minmax(240px, 1.4fr) repeat(3, minmax(160px, 1fr));
  gap: 12px;
  padding: 14px;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

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

textarea {
  resize: vertical;
}

input[type="search"] {
  appearance: none;
}

.view {
  display: none;
  min-width: 0;
}

.active-view {
  display: grid;
  gap: 20px;
  min-width: 0;
}

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

.kpi,
.panel,
.table-shell,
.supplier-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.kpi {
  padding: 18px;
  display: grid;
  gap: 8px;
  border-top: 5px solid var(--teal);
}

.kpi span,
.kpi small,
.panel-title span,
.supplier-card small,
.meta {
  color: var(--muted);
}

.kpi strong {
  font-size: 25px;
}

.kpi-open {
  border-top-color: var(--amber);
}

.kpi-paid {
  border-top-color: var(--green);
}

.kpi-total {
  border-top-color: var(--blue);
}

.dashboard-grid,
.payments-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(300px, 0.75fr);
  gap: 18px;
}

.supplier-admin-grid {
  margin-bottom: 18px;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(150px, 0.7fr) minmax(180px, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.inline-form input,
.inline-form select {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  font: inherit;
  background: #fff;
}

.supplier-request-trigger {
  width: 100%;
  justify-content: center;
  margin-bottom: 14px;
}

.show-more-btn {
  width: 100%;
  margin-top: 10px;
  justify-content: center;
}

.split-editor {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-soft);
}

.split-editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.split-editor-head small {
  display: block;
  color: var(--muted);
  margin-top: 4px;
}

.split-rows {
  display: grid;
  gap: 8px;
}

.split-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) 90px 120px minmax(120px, 0.8fr) auto;
  gap: 8px;
  align-items: center;
}

.split-ok {
  color: var(--green) !important;
}

.split-error {
  color: var(--coral) !important;
}

.supplier-master-item {
  grid-template-columns: minmax(220px, 1fr) auto minmax(220px, 1fr) auto;
}

.vehicles-layout {
  margin-top: 18px;
}

.vehicles-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.section-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.vehicles-toolbar label {
  min-width: 220px;
}

.table-sort-btn {
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  padding: 0;
  cursor: pointer;
}

.table-sort-btn:hover,
.table-sort-btn:focus-visible {
  color: var(--teal-dark);
  outline: none;
}

.table-sort-btn.active-sort {
  color: var(--teal);
}

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

.module-view {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.module-hero {
  display: grid;
  gap: 10px;
  max-width: 720px;
}

.module-hero p {
  color: var(--muted);
  line-height: 1.7;
}

.project-grid {
  margin-top: 20px;
}

.project-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.project-pill {
  padding: 6px 10px;
  border-radius: 999px;
  background: #e8f2ef;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  margin-bottom: 16px;
}

.panel-title-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.bar-chart {
  display: grid;
  gap: 13px;
}

.month-row {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr) 98px;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  text-align: right;
  padding: 6px 8px;
  border-radius: 8px;
}

.bar-track {
  display: flex;
  overflow: hidden;
  height: 18px;
  border-radius: 999px;
  background: #e7eeea;
}

.bar-open {
  background: #d0a43d;
}

.bar-paid {
  background: var(--green);
}

.rank-list,
.attention-list,
.payment-queue,
.batch-list {
  display: grid;
  gap: 10px;
}

.rank-item,
.attention-item,
.payment-item,
.batch-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  background: var(--surface-soft);
  border-radius: 8px;
}

.merge-suggestion {
  grid-template-columns: minmax(260px, 1fr) auto minmax(240px, 1fr) auto;
}

.merge-suggestion > strong {
  display: none;
}

.merge-names {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}

.merge-names small {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  margin-bottom: 4px;
}

.merge-arrow {
  color: var(--teal);
  font-size: 1.4rem;
  font-weight: 800;
}

.linked-item {
  width: 100%;
  border: 1px solid transparent;
  text-align: right;
  transition:
    border-color 140ms ease,
    background-color 140ms ease,
    transform 140ms ease;
}

.linked-item:hover {
  background: #fbfdfc;
  border-color: #bfd0c9;
  transform: translateY(-1px);
}

.linked-item:focus-visible {
  outline: 0;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(8, 127, 122, 0.14);
}

.rank-item strong,
.attention-item strong,
.payment-item strong,
.batch-item strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table-shell {
  width: 100%;
  max-width: 100%;
  overflow: auto;
  scrollbar-gutter: stable both-edges;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 880px;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  background: #f8faf9;
  z-index: 1;
  color: var(--muted);
  font-size: 13px;
}

tr:hover td {
  background: #fbfdfc;
}

.amount {
  direction: ltr;
  text-align: left;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.badge.open {
  background: #fbe8e2;
  color: #a43f28;
}

.badge.paid {
  background: #dff2e8;
  color: #216a46;
}

.badge.credit {
  background: #fff1cd;
  color: #805409;
}

.row-actions {
  display: flex;
  gap: 8px;
  flex-direction: column;
  align-items: stretch;
}

.mini-btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 34px;
  padding: 0 10px;
  background: #fff;
  color: var(--ink);
}

.danger-btn {
  color: var(--coral);
  border-color: rgba(217, 102, 75, 0.45);
}

.invoice-danger-action {
  margin-inline-end: auto;
  border: 1px solid rgba(217, 102, 75, 0.5);
  background: #fff;
  color: var(--coral);
  border-radius: 8px;
  min-height: 40px;
  padding: 0 14px;
  font-weight: 800;
}

#invoicesView .table-shell {
  direction: ltr;
}

#invoicesView table {
  direction: rtl;
}

.vehicles-table-shell {
  margin-top: 18px;
}

.credit-months {
  display: grid;
  gap: 18px;
}

.credit-month-panel {
  padding: 18px;
}

.credit-month-title {
  margin-bottom: 12px;
}

.credit-entry-list {
  display: grid;
  gap: 10px;
}

.credit-entry-card {
  display: grid;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.credit-entry-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.credit-entry-head strong {
  font-size: 18px;
  line-height: 1.35;
}

.credit-entry-amount {
  direction: ltr;
  text-align: left;
  white-space: nowrap;
  font-size: 24px;
  font-weight: 800;
}

.credit-entry-meta,
.credit-entry-extra {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  color: var(--muted);
}

.credit-entry-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.credit-entry-stats div {
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 4px;
}

.credit-entry-stats small {
  color: var(--muted);
}

.credit-entry-stats strong {
  direction: ltr;
  text-align: left;
  white-space: nowrap;
}

#vehicleForm {
  padding: 22px;
}

#invoicesView th:last-child,
#invoicesView td:last-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #fff;
  box-shadow: -10px 0 16px rgba(23, 33, 29, 0.05);
}

#invoicesView th:last-child {
  background: #f8faf9;
  z-index: 3;
}

.supplier-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.users-panel {
  padding: 0;
  border: 0;
  box-shadow: none;
  background: transparent;
}

.users-list {
  display: grid;
  gap: 10px;
}

.user-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  background: var(--surface-soft);
  border-radius: 8px;
}

.user-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 13px;
}

.user-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.users-form-grid {
  margin-top: 8px;
}

.user-editor-panel {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.compact-title {
  margin-bottom: 12px;
}

.permissions-fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin: 0;
  min-width: 0;
}

.permissions-fieldset legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

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

.permission-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface-soft);
  border-radius: 8px;
  min-height: 44px;
}

.permission-chip input {
  width: 18px;
  min-height: 18px;
  margin: 0;
}

.supplier-card {
  padding: 16px;
  display: grid;
  gap: 12px;
}

.supplier-card h3 {
  margin: 0;
  font-size: 17px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.supplier-metrics div {
  background: var(--surface-soft);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  gap: 3px;
  min-width: 0;
}

.supplier-metrics strong {
  display: block;
  min-width: 0;
  white-space: nowrap;
  direction: ltr;
  text-align: left;
  font-size: clamp(18px, 1.35vw, 24px);
  line-height: 1.2;
}

.supplier-metrics .amount {
  white-space: nowrap;
}

.supplier-metric-box small {
  font-size: 12px;
}

.supplier-metric-compact {
  color: #10231f;
  letter-spacing: 0;
}

.supplier-metric-full {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  direction: ltr;
  text-align: left;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

dialog {
  width: min(760px, calc(100% - 24px));
  border: 0;
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.24);
  padding: 0;
}

dialog::backdrop {
  background: rgba(11, 20, 18, 0.5);
}

dialog > form {
  padding: 22px;
  box-sizing: border-box;
  max-width: 100%;
}

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

.dialog-head h2 {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

.dialog-head .icon-btn {
  flex: 0 0 auto;
}

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

.wide {
  grid-column: 1 / -1;
}

.dialog-actions {
  justify-content: flex-start;
  margin-top: 18px;
}

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

  .sidebar {
    position: static;
  }

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

  .source-box {
    margin-top: 0;
  }

  .filters,
  .kpi-grid,
  .dashboard-grid,
  .payments-layout,
  .supplier-grid,
  .vehicles-toolbar {
    grid-template-columns: 1fr 1fr;
  }

  .credit-entry-stats {
    grid-template-columns: 1fr;
  }
}

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

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

  .topbar-title {
    flex-direction: column;
    align-items: flex-start;
  }

  .filters,
  .kpi-grid,
  .dashboard-grid,
  .payments-layout,
  .supplier-grid,
  .form-grid,
  .nav-tabs {
    grid-template-columns: 1fr;
  }

  .vehicles-toolbar {
    display: grid;
  }

  .credit-entry-head,
  .credit-entry-meta,
  .credit-entry-extra {
    display: grid;
  }

  .credit-entry-amount {
    text-align: right;
  }

  h1 {
    font-size: 24px;
  }
}
