:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #172033;
  --muted: #64748b;
  --line: #dbe3ec;
  --primary: #d71920;
  --primary-dark: #ad141a;
  --success: #0f766e;
  --warning: #b7791f;
  --info: #2563eb;
  --shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

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

body.login-page {
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(215, 25, 32, 0.08), rgba(37, 99, 235, 0.08)),
    var(--bg);
}

body.page-ready .main,
body.page-ready .sidebar {
  animation: pageIn 0.55s ease both;
}

body.is-leaving {
  overflow: hidden;
}

a {
  color: inherit;
}

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

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px;
  color: #f8fafc;
  background: #171b24;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.brand-name {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 0;
  text-align: center;
}

.sidebar-note {
  color: #aeb8c7;
}

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

.menu a {
  padding: 11px 12px;
  border-radius: 8px;
  color: #d8dee8;
  text-decoration: none;
  font-weight: 700;
}

.menu-group {
  display: block;
}

.menu-group summary {
  padding: 11px 12px;
  border-radius: 8px;
  color: #d8dee8;
  cursor: pointer;
  font-weight: 800;
  list-style: none;
}

.menu-group summary::-webkit-details-marker {
  display: none;
}

.menu-group summary::after {
  content: "▾";
  float: right;
  color: #aeb8c7;
}

.menu-group:not([open]) summary::after {
  content: "▸";
}

.menu-group a {
  display: block;
  margin-left: 12px;
  margin-top: 4px;
  padding: 9px 12px;
  font-size: 13px;
}

.menu a:hover,
.menu a.active,
.menu-group summary:hover {
  color: #fff;
  background: rgba(215, 25, 32, 0.22);
}

.sidebar-note {
  margin-top: auto;
  padding: 14px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  line-height: 1.5;
}

.session-box {
  margin-top: auto;
  display: grid;
  gap: 7px;
  padding: 14px;
  border-radius: 8px;
  color: #e2e8f0;
  background: rgba(255, 255, 255, 0.08);
}

.session-box strong {
  color: #fff;
}

.session-box span {
  color: #cbd5e1;
  font-size: 13px;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

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

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

.login-brand {
  color: var(--text);
  justify-content: center;
}

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

.login-title {
  text-align: center;
}

.page-title h1,
.page-title p {
  margin: 0;
}

.page-title h1 {
  font-size: clamp(24px, 3vw, 34px);
  letter-spacing: 0;
}

.page-title p {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.5;
}

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

.btn {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 15px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  font-weight: 800;
}

.btn.primary {
  color: #fff;
  background: var(--primary);
}

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

.btn.secondary {
  color: var(--text);
  background: #fff;
  border-color: var(--line);
}

.btn.full {
  width: 100%;
}

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

.dashboard-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 2px 0 18px;
}

.dashboard-actions .btn {
  min-width: 180px;
}

.stat-card,
.panel,
.module-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.stat-card {
  padding: 17px;
}

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

.stat-card strong {
  display: block;
  margin: 9px 0;
  font-size: 28px;
}

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

.module-card {
  min-height: 135px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  text-decoration: none;
}

.module-card:hover {
  border-color: var(--primary);
}

.module-card h2,
.module-card p {
  margin: 0;
}

.module-card p {
  color: var(--muted);
  line-height: 1.6;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 18px;
  align-items: start;
}

.panel {
  padding: 18px;
}

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

.panel-head h2,
.panel-head p {
  margin: 0;
}

.panel-head p {
  margin-top: 5px;
  color: var(--muted);
}

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

label {
  display: block;
  color: #475569;
  font-size: 13px;
  font-weight: 800;
}

label input,
label select,
label textarea {
  margin-top: 6px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
}

textarea {
  min-height: 90px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(215, 25, 32, 0.13);
}

.field-help {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.45;
}

.required-mark {
  color: var(--primary);
}

.page-loader {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(243, 245, 248, 0.62);
  backdrop-filter: blur(5px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 50;
}

.page-loader.show {
  opacity: 1;
  pointer-events: auto;
}

.app-dialog {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(15, 23, 42, 0.46);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  z-index: 80;
}

.app-dialog.show {
  opacity: 1;
  pointer-events: auto;
}

.app-dialog-card {
  width: min(460px, 100%);
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
  transform: translateY(8px) scale(0.98);
  transition: transform 0.18s ease;
}

.app-dialog.show .app-dialog-card {
  transform: translateY(0) scale(1);
}

.app-dialog-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--info);
  font-size: 22px;
  font-weight: 900;
}

.app-dialog.success .app-dialog-icon {
  background: var(--success);
}

.app-dialog.warning .app-dialog-icon {
  background: var(--warning);
}

.app-dialog.error .app-dialog-icon {
  background: var(--primary);
}

.app-dialog-content h2,
.app-dialog-content p {
  margin: 0;
}

.app-dialog-content h2 {
  font-size: 20px;
  letter-spacing: 0;
}

.app-dialog-content p {
  margin-top: 7px;
  color: var(--muted);
  line-height: 1.55;
}

.app-dialog-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  margin-top: 4px;
}

.permission-modal {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.42);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.permission-modal.show {
  opacity: 1;
  pointer-events: auto;
}

.permission-modal-card {
  width: min(560px, 100%);
  max-height: min(720px, 92vh);
  display: grid;
  gap: 18px;
  padding: 22px;
  overflow: auto;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 26px 70px rgba(15, 23, 42, 0.26);
}

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

.permission-modal-head h2,
.permission-modal-head p {
  margin: 0;
}

.permission-modal-head h2 {
  font-size: 20px;
  letter-spacing: 0;
}

.permission-modal-head p {
  margin-top: 6px;
  color: var(--muted);
}

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

.permission-check {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-weight: 700;
}

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

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

.loader-spinner {
  width: 76px;
  height: 76px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: conic-gradient(var(--primary), var(--success), var(--info), var(--primary));
  animation: loaderSpin 0.8s linear infinite;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
}

.loader-spinner::after {
  content: "";
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--panel);
}

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

@keyframes pageIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

form {
  display: grid;
  gap: 13px;
}

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

.checkbox-field {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  align-self: end;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  cursor: pointer;
}

.checkbox-field input {
  width: 18px;
  min-height: 18px;
  margin: 0;
  accent-color: var(--primary);
}

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

.select-combo {
  position: relative;
  display: block;
  margin-top: 6px;
}

label .select-combo input {
  margin-top: 0;
}

.select-combo-list {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  display: none;
  max-height: 230px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  z-index: 10;
}

.select-combo.open .select-combo-list {
  display: grid;
}

.select-combo-list button,
.select-combo-empty {
  min-height: 42px;
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  text-align: left;
}

.select-combo-list button {
  cursor: pointer;
}

.select-combo-list button:last-child {
  border-bottom: 0;
}

.select-combo-list button:hover,
.select-combo-list button:focus,
.select-combo-list button.is-active {
  background: var(--panel-soft);
}

.select-combo-empty {
  color: var(--muted);
  font-weight: 600;
}

.searchable-native-select {
  width: 100%;
  min-height: 0;
  height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

.combo-field {
  position: relative;
  display: block;
}

.combo-list {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  display: none;
  max-height: 210px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  z-index: 8;
}

.combo-field.open .combo-list {
  display: grid;
}

.combo-field.is-selected input[data-vehicle-search] {
  background: #f8fafc;
  border-color: #cbd5e1;
  cursor: pointer;
}

.combo-list button {
  min-height: 42px;
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.combo-list button:last-child {
  border-bottom: 0;
}

.combo-list button:hover,
.combo-list button:focus {
  background: var(--panel-soft);
}

.combo-list button[hidden] {
  display: none;
}

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

table {
  width: 100%;
  min-width: 780px;
  border-collapse: collapse;
  background: #fff;
}

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

th {
  color: var(--muted);
  background: var(--panel-soft);
  font-size: 12px;
  text-transform: uppercase;
}

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

.name-cell {
  display: grid;
  gap: 3px;
}

.name-cell small {
  color: var(--muted);
  font-size: 12px;
}

.money-in {
  color: var(--success);
  font-weight: 800;
}

.money-out {
  color: var(--primary);
  font-weight: 800;
}

.table-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn.compact {
  min-height: 32px;
  padding: 0 12px;
  font-size: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.pill.green {
  color: #065f46;
  background: #def7ec;
}

.pill.red {
  color: #9f1239;
  background: #ffe4e6;
}

.pill.yellow {
  color: #7c4a03;
  background: #fff2bd;
}

.pill.blue {
  color: #1d4ed8;
  background: #dbeafe;
}

.note-box {
  margin-top: 14px;
  padding: 13px;
  border-radius: 8px;
  color: #475569;
  background: var(--panel-soft);
  line-height: 1.55;
}

.sql-block {
  margin: 0;
  max-height: 520px;
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #d8dee8;
  background: #171b24;
  line-height: 1.55;
  white-space: pre;
}

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

.report-box,
.schema-box {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.report-box strong {
  display: block;
  margin-bottom: 8px;
  color: var(--primary);
  font-size: 28px;
}

.report-box span,
.schema-box p {
  color: var(--muted);
  line-height: 1.5;
}

.schema-box h3,
.schema-box p {
  margin: 0;
}

.schema-box h3 {
  margin-bottom: 8px;
}

@media (max-width: 1180px) {
  .summary-grid,
  .module-grid,
  .report-grid,
  .schema-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .content-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

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

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

  .top-actions,
  .dashboard-actions,
  .filters,
  .form-grid {
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .dashboard-actions .btn {
    width: 100%;
  }

  .summary-grid,
  .module-grid,
  .report-grid,
  .schema-grid {
    grid-template-columns: 1fr;
  }

  .app-dialog-card {
    grid-template-columns: 1fr;
  }

  .app-dialog-actions {
    justify-content: stretch;
  }
}
