:root {
  --brand-red: #b71c1c;
  --brand-red-dark: #7f0000;
  --primary: #2196f3;
  --bg: #f5f5f5;
  --card: #ffffff;
  --text: #212121;
  --muted: #757575;
  --border: #e0e0e0;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden {
  display: none !important;
}

.brand-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: linear-gradient(90deg, var(--brand-red-dark), var(--brand-red));
  color: #fff;
  box-shadow: var(--shadow);
}

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

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: #fff;
  color: var(--brand-red);
  display: grid;
  place-items: center;
  font-weight: 700;
}

.brand-header h1 {
  margin: 0;
  font-size: 1.25rem;
}

.brand-header p {
  margin: 2px 0 0;
  font-size: 0.85rem;
  opacity: 0.9;
}

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

.header-link {
  text-decoration: none;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(160deg, #ffebee 0%, #f5f5f5 45%);
}

.login-card {
  width: min(420px, 100%);
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-card h2 {
  margin: 0 0 8px;
  color: var(--brand-red);
}

.login-card p {
  margin: 0 0 20px;
  color: var(--muted);
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9rem;
}

.field input:not([type="checkbox"]),
.field select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.95rem;
  cursor: pointer;
}

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

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.35);
}

.btn-block {
  width: 100%;
}

.error-banner {
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #ffebee;
  color: #c62828;
  font-size: 0.9rem;
}

.filter-bar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
}

.filter-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.chip {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
}

.chip.active {
  border-color: var(--primary);
  color: var(--primary);
  background: #e3f2fd;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.filter-grid .field {
  margin: 0;
}

.filter-actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
}

.report-shell {
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
}

.section-card {
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

.section-card h3 {
  margin: 0;
  flex: 1;
  min-width: 0;
}

.section-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.section-card-header .js-collapse-toggle {
  flex-shrink: 0;
  white-space: nowrap;
}

.section-collapse-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.section-card.is-collapsed .section-card-header {
  margin-bottom: 0;
}

.section-subtitle {
  font-weight: 400;
  font-size: 0.85rem;
  color: var(--muted);
}

.placeholder-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.field-autocomplete {
  position: relative;
}

.suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-height: 200px;
  overflow-y: auto;
}

.suggestions.customer-picker {
  display: flex;
  flex-direction: column;
  max-height: 340px;
  overflow: hidden;
  padding: 0;
  margin-top: 6px;
  border: 1px solid #d6e4f5;
  border-radius: 12px;
  box-shadow: 0 10px 28px rgba(33, 150, 243, 0.14), 0 2px 8px rgba(0, 0, 0, 0.06);
}

.suggestions.customer-picker .suggestion-select-all,
.suggestions.customer-picker .suggestion-check-item {
  display: grid !important;
  grid-template-columns: 16px minmax(0, 1fr);
  align-items: center;
  column-gap: 12px;
  row-gap: 0;
  padding: 8px 14px;
  margin: 0;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 400;
  user-select: none;
  min-height: 40px;
  width: 100%;
  box-sizing: border-box;
}

/* Native checkbox — dấu tích hiển thị đúng (input không hỗ trợ ::after) */
.suggestions.customer-picker .picker-checkbox {
  appearance: auto;
  -webkit-appearance: checkbox;
  width: 16px !important;
  min-width: 16px !important;
  max-width: 16px !important;
  height: 16px !important;
  min-height: 16px !important;
  margin: 0;
  padding: 0 !important;
  flex: none;
  border: none;
  border-radius: 0;
  background: transparent;
  cursor: pointer;
  display: inline-block;
  box-sizing: border-box;
  font-size: inherit !important;
  accent-color: var(--primary);
  box-shadow: none;
}

.suggestions.customer-picker .picker-checkbox:disabled {
  cursor: default;
  accent-color: #43a047;
  opacity: 1;
}

.picker-checkbox {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin: 0;
  flex-shrink: 0;
  border: 2px solid #b0bec5;
  border-radius: 5px;
  background: #fff;
  cursor: pointer;
  display: grid;
  place-content: center;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.picker-checkbox:hover:not(:disabled) {
  border-color: var(--primary);
}

.picker-checkbox:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.25);
}

.picker-checkbox:checked {
  background: var(--primary);
  border-color: var(--primary);
}

.picker-checkbox:checked::after {
  content: '';
  width: 5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) translate(-1px, -1px);
}

.picker-checkbox.is-indeterminate {
  background: var(--primary);
  border-color: var(--primary);
}

.picker-checkbox.is-indeterminate::after {
  content: '';
  width: 10px;
  height: 2px;
  background: #fff;
  border-radius: 1px;
  transform: none;
}

.picker-checkbox:disabled {
  cursor: default;
  opacity: 1;
}

.picker-checkbox:disabled:checked {
  background: #43a047;
  border-color: #43a047;
}

.suggestion-select-all {
  border-bottom: 1px solid #e8eef5;
  font-weight: 600;
  background: linear-gradient(180deg, #f8fbff 0%, #f3f7fc 100%);
  flex-shrink: 0;
  color: #1565c0;
}

.suggestion-select-all-info {
  display: block;
  cursor: default;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.82rem;
  padding: 10px 14px;
  background: #f8fafc;
  border-bottom: 1px solid #e8eef5;
}

.suggestion-check-content {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.suggestion-check-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.35;
  color: var(--text);
}

.suggestion-check-item {
  border-bottom: 1px solid #f0f4f8;
  transition: background 0.12s ease;
}

.suggestion-check-item:last-child {
  border-bottom: none;
}

.suggestion-check-item:hover:not(.suggestion-check-item--committed) {
  background: #f0f7ff;
}

.suggestion-check-item--committed {
  background: #fafbfc;
  cursor: default;
}

.suggestion-check-item--committed .suggestion-check-label {
  color: var(--muted);
}

.suggestion-selected-badge {
  flex-shrink: 0;
  padding: 2px 8px;
  border-radius: 999px;
  background: #e8f5e9;
  color: #2e7d32;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.suggestion-list {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  padding: 4px 0;
}

.suggestion-list::-webkit-scrollbar {
  width: 6px;
}

.suggestion-list::-webkit-scrollbar-thumb {
  background: #cfd8dc;
  border-radius: 999px;
}

.suggestion-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid #e8eef5;
  background: #f8fafc;
  flex-shrink: 0;
}

.btn-picker {
  padding: 7px 16px;
  font-size: 0.84rem;
  font-weight: 600;
  min-width: 72px;
  border-radius: 8px;
}

.suggestion-actions .btn-secondary {
  background: #fff;
  color: #546e7a;
  border: 1px solid #cfd8dc;
}

.suggestion-actions .btn-secondary:hover {
  background: #f5f5f5;
}

.suggestion-actions .btn-primary {
  box-shadow: 0 2px 6px rgba(33, 150, 243, 0.35);
}

.field-customer-multi input#filter-customer {
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field-customer-multi input#filter-customer:focus {
  border-color: #90caf9;
  box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.12);
  outline: none;
}

.field-customer-multi .customer-selection {
  margin-top: 10px;
  padding: 10px 12px 12px;
  background: linear-gradient(180deg, #f8fbff 0%, #f3f8fe 100%);
  border: 1px solid #dbeafe;
  border-radius: 10px;
}

.customer-selection-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px dashed #cfe3f9;
}

.customer-selection-count {
  font-size: 0.78rem;
  font-weight: 600;
  color: #1565c0;
  letter-spacing: 0.01em;
}

.btn-clear-all-customers {
  padding: 4px 10px;
  border: 1px solid #ffcdd2;
  border-radius: 999px;
  background: #fff;
  color: #c62828;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-clear-all-customers:hover {
  background: #ffebee;
  border-color: #ef9a9a;
}

.field-customer-multi .selected-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.selected-chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  max-width: 100%;
  padding: 5px 6px 5px 11px;
  border-radius: 999px;
  border: 1px solid #90caf9;
  background: #fff;
  color: #1565c0;
  font-size: 0.8rem;
  line-height: 1.3;
  box-shadow: 0 1px 3px rgba(21, 101, 192, 0.1);
}

.selected-chip-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.selected-chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #64b5f6;
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.12s ease, color 0.12s ease;
}

.selected-chip-remove:hover {
  background: #e3f2fd;
  color: #1565c0;
}

.suggestion-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 0.9rem;
}

.suggestion-item:hover {
  background: #e3f2fd;
}

.suggestion-empty {
  padding: 10px 12px;
  font-size: 0.9rem;
  color: var(--muted);
}

.kpi-label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.kpi-value {
  font-size: 1.25rem;
  font-weight: 600;
}

.kpi-revenue .kpi-value { color: var(--primary); }
.kpi-expense .kpi-value { color: #f44336; }
.kpi-profit .kpi-value { color: #4caf50; }

.chart-wrap {
  position: relative;
  height: 320px;
  margin-bottom: 24px;
}

.tab-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

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

.data-table th {
  background: #fafafa;
  font-weight: 600;
}

.data-table td.num {
  white-space: nowrap;
}

.empty-cell {
  text-align: center;
  color: var(--muted);
  padding: 20px !important;
}

.empty-note {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.loading-state {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px;
  color: var(--muted);
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

#summary-error {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.btn-link {
  background: transparent;
  border: none;
  color: #c62828;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
  font-size: 0.9rem;
}

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

.btn-secondary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chart-wrap-sm {
  height: 280px;
  max-width: 520px;
}

.subsection-title {
  margin: 20px 0 10px;
  font-size: 1rem;
  font-weight: 600;
}

.table-scroll {
  overflow-x: auto;
  margin-bottom: 12px;
}

.table-block {
  position: relative;
}

.table-block.is-loading .table-scroll {
  opacity: 0.45;
  pointer-events: none;
}

.table-loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.65);
  font-size: 0.9rem;
  color: var(--muted);
}

.data-table-wide {
  min-width: 1100px;
}

.pagination-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 8px 0;
}

.export-kpi-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 10px 24px;
  box-shadow: var(--shadow);
}

.export-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}

.export-kpi-group {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-left: auto;
}

.export-kpi {
  padding: 6px 12px;
  border-radius: 8px;
  background: #fafafa;
  border: 1px solid var(--border);
  min-width: 120px;
}

.export-kpi .kpi-label {
  margin-bottom: 2px;
  font-size: 0.75rem;
}

.export-kpi .kpi-value {
  font-size: 1rem;
  white-space: nowrap;
}

.export-kpi-loading {
  display: inline-flex;
  align-items: center;
}

.spinner-sm {
  width: 18px;
  height: 18px;
  border-width: 2px;
}

.export-kpi-error {
  flex-basis: 100%;
  margin-bottom: 0;
}

.export-label {
  font-size: 0.9rem;
  color: var(--muted);
}

.export-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 4px;
}

.export-status {
  font-size: 0.85rem;
  color: var(--primary);
}

.export-status.export-error {
  color: #c62828;
}

.debt-total-card {
  padding: 16px;
  border-radius: 10px;
  background: #fff3e0;
  border: 1px solid #ffe0b2;
  margin-bottom: 16px;
  max-width: 280px;
}

.debt-total-card .kpi-value {
  color: #ef6c00;
}

.debt-hint {
  margin: 0 0 12px;
  font-size: 0.85rem;
  color: var(--muted);
}

.edit-trip-cell {
  min-width: 120px;
}

.edit-trip-cell .trip-id {
  display: block;
  font-weight: 600;
}

.edit-hint {
  display: block;
  margin-top: 4px;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.3;
}

a.admin-trip-link {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

a.admin-trip-link:hover {
  text-decoration: underline;
}

#revenue-lines-error,
#expense-lines-error,
#debt-lines-error {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.badge-external {
  display: inline-block;
  margin-left: 4px;
  padding: 2px 6px;
  border-radius: 4px;
  background: #fff8e1;
  color: #f57f17;
  font-size: 0.75rem;
  font-weight: 600;
}

.row-external td {
  background: #fffde7;
}

.login-footer-link {
  margin: 16px 0 0;
  text-align: center;
  font-size: 0.9rem;
}

.login-footer-link a {
  color: var(--primary);
}

@media (max-width: 768px) {
  .brand-header {
    flex-direction: column;
    align-items: flex-start;
    padding: 12px 16px;
    gap: 10px;
  }

  .header-actions {
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
  }

  .export-kpi-bar {
    padding: 10px 16px;
  }

  .export-kpi-group {
    margin-left: 0;
    width: 100%;
  }

  .export-kpi {
    flex: 1 1 calc(33.333% - 8px);
    min-width: 0;
  }

  .export-kpi .kpi-value {
    font-size: 0.9rem;
  }
}
