.admin-layout {
  display: flex;
  min-height: calc(100vh - 68px);
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  position: sticky;
  top: 0;
  align-self: flex-start;
  min-height: calc(100vh - 68px);
}

.nav-item {
  display: block;
  padding: 12px 20px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.95rem;
  border-left: 3px solid transparent;
  transition: background 0.15s;
}

.nav-item:hover {
  background: #f5f5f5;
}

.nav-item.active {
  border-left-color: var(--primary);
  background: #e3f2fd;
  color: var(--primary);
  font-weight: 600;
}

.nav-external {
  margin-top: 8px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
  color: var(--muted);
}

.main-content {
  flex: 1;
  padding: 24px;
  max-width: 1200px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.page-header h2 {
  margin: 0;
  font-size: 1.35rem;
}

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

.toolbar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: flex-end;
}

.toolbar .field {
  margin: 0;
  min-width: 160px;
}

.toolbar .field-grow {
  flex: 1;
  min-width: 200px;
}

.list-card {
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  transition: background 0.12s;
}

button.list-row {
  width: 100%;
  margin: 0;
  font: inherit;
  background: transparent;
  border: none;
  border-radius: 0;
  text-align: left;
  appearance: none;
}

.list-row:last-child {
  border-bottom: none;
}

.list-row:hover {
  background: #fafafa;
}

.list-row-main {
  flex: 1;
  min-width: 0;
}

.list-row-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.list-row-sub {
  font-size: 0.85rem;
  color: var(--muted);
}

.list-row-meta {
  text-align: right;
  flex-shrink: 0;
}

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

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.detail-item label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.detail-item p {
  margin: 0;
  font-weight: 500;
}

.detail-item p.pre-wrap {
  white-space: pre-wrap;
}

.form-card {
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 24px;
  max-width: 720px;
}

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

.form-grid .field-full {
  grid-column: 1 / -1;
}

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

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: capitalize;
}

.badge-pending { background: #fff3e0; color: #ef6c00; }
.badge-approved { background: #e8f5e9; color: #2e7d32; }
.badge-rejected { background: #ffebee; color: #c62828; }
.badge-locked { background: #eceff1; color: #546e7a; }
.badge-draft { background: #eceff1; color: #546e7a; }
.badge-assigned { background: #e3f2fd; color: #1565c0; }
.badge-in_progress { background: #fff8e1; color: #f57f17; }
.badge-awaiting_approval { background: #fce4ec; color: #c2185b; }
.badge-completed { background: #e8f5e9; color: #2e7d32; }
.badge-cancelled_by_admin { background: #ffebee; color: #c62828; }
.badge-super_admin { background: #ede7f6; color: #4527a0; }
.badge-staff { background: #e3f2fd; color: #1565c0; }
.badge-active { background: #e8f5e9; color: #2e7d32; }
.badge-suspended { background: #ffebee; color: #c62828; }

.list-row-static {
  cursor: default;
}

.list-row-static:hover {
  background: var(--surface, #fff);
}

.field-hint {
  margin: 4px 0 0;
  font-size: 0.8rem;
  color: #666;
}

.permission-block {
  margin-bottom: 20px;
}

.permission-block h4 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.permission-note {
  margin: 0 0 16px;
  padding: 10px 12px;
  background: #f5f5f5;
  border-radius: 8px;
  font-size: 0.9rem;
  color: #555;
}

.multi-select-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
  min-height: 4px;
}

.multi-select-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: #e3f2fd;
  color: #1565c0;
  border-radius: 999px;
  font-size: 0.85rem;
}

.multi-select-chip button {
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  padding: 0 2px;
  font-size: 1rem;
  line-height: 1;
}

.expense-perm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px 16px;
}

.expense-perm-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  cursor: pointer;
}

.admin-layout.password-gate .main-content {
  max-width: 640px;
  margin: 0 auto;
}

.btn-warning {
  background: #fff3e0;
  color: #e65100;
  border: 1px solid #ffcc80;
}

.btn-warning:hover {
  background: #ffe0b2;
}

.btn-danger {
  background: #f44336;
  color: #fff;
}

.btn-success {
  background: #4caf50;
  color: #fff;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.85rem;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.image-thumb {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 4/3;
  background: #fafafa;
}

.image-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: pointer;
}

.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 16px;
  border-radius: 8px;
  background: #323232;
  color: #fff;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  animation: fadeIn 0.2s ease;
}

.toast-error { background: #c62828; }
.toast-success { background: #2e7d32; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: grid;
  place-items: center;
  z-index: 900;
  padding: 24px;
}

.modal-box {
  background: var(--card);
  border-radius: 12px;
  padding: 24px;
  width: min(480px, 100%);
  box-shadow: var(--shadow);
}

.modal-box h3 {
  margin: 0 0 12px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

.noti-btn {
  position: relative;
}

.noti-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ff5722;
  color: #fff;
  font-size: 0.7rem;
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  padding: 0 4px;
}

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

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

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

.shortcut-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.shortcut-card {
  display: block;
  padding: 16px;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s;
}

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

.shortcut-card strong {
  display: block;
  margin-bottom: 4px;
}

.shortcut-card span {
  font-size: 0.85rem;
  color: var(--muted);
}

.shortcut-badge {
  float: right;
  background: var(--brand-red);
  color: #fff;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.8rem;
}

.catalog-table {
  width: 100%;
  margin-top: 12px;
}

.catalog-row td {
  vertical-align: middle;
}

.catalog-row input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.noti-unread {
  background: #e3f2fd;
}

.field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  min-height: 80px;
  resize: vertical;
}

.field input[type="file"] {
  font-size: 0.9rem;
  margin-top: 8px;
}

.image-upload-field .image-upload-preview {
  margin: 8px 0;
  max-width: 200px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  aspect-ratio: 4/3;
  background: #fafafa;
}

.image-upload-field .image-upload-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: pointer;
}

.image-upload-empty {
  display: grid;
  place-items: center;
  min-height: 100px;
  color: var(--muted);
  font-size: 0.85rem;
}

.image-upload-hint {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 4px;
}

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

.chip.chip-pending {
  border-color: #ef6c00;
}

.chip.chip-pending.active {
  background: #ef6c00;
  border-color: #ef6c00;
  color: #fff;
}

.chip-count {
  display: inline-block;
  margin-left: 6px;
  min-width: 18px;
  padding: 0 6px;
  border-radius: 999px;
  background: #ff5722;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.4;
  vertical-align: middle;
}

.chip.active .chip-count {
  background: rgba(255, 255, 255, 0.9);
  color: #ef6c00;
}

.driver-status-chips {
  margin-bottom: 16px;
}

.assigned-vehicles-inline {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
}

.assigned-vehicles-inline li {
  padding: 4px 0;
}

.assigned-vehicles-inline a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

.assigned-vehicles-inline a:hover {
  text-decoration: underline;
}

.detail-item-full {
  grid-column: 1 / -1;
}

.trip-filter-toolbar .field-autocomplete {
  min-width: 180px;
}

.form-hint {
  margin: 0 0 16px;
  padding: 10px 14px;
  background: #fff8e1;
  border-radius: 8px;
  color: #f57f17;
  font-size: 0.9rem;
}

.trip-timeline {
  display: grid;
  gap: 10px;
  margin-top: 8px;
}

.timeline-item {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 14px;
  border-radius: 8px;
  background: #fafafa;
  border-left: 3px solid var(--border);
}

.timeline-item.timeline-done {
  border-left-color: var(--primary);
  background: #e3f2fd;
}

.timeline-label {
  font-weight: 500;
}

.timeline-time {
  color: var(--muted);
  font-size: 0.9rem;
  text-align: right;
}

.field.hidden {
  display: none;
}

.required-label::after {
  content: ' *';
  color: #c62828;
}

.expense-list-card .expense-list-row {
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}

.expense-list-card .expense-list-row:last-child {
  border-bottom: none;
}

.expense-list-link {
  flex: 1;
  min-width: 0;
  border-bottom: none !important;
}

.list-row-quick {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  padding-right: 12px;
}

.expense-filter-toolbar {
  align-items: flex-end;
}

.assigned-drivers-list {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
}

.assigned-drivers-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.assigned-drivers-list li:last-child {
  border-bottom: none;
}

.field input[type="checkbox"] {
  width: auto;
  margin-right: 8px;
}

.field.has-error input,
.field.has-error select,
.field.has-error textarea {
  border-color: #c62828;
}

.field-error {
  color: #c62828;
  font-size: 0.82rem;
  margin-top: 4px;
}

.lightbox-overlay {
  position: fixed;
  inset: 0;
  z-index: 1100;
  background: rgba(0, 0, 0, 0.88);
  display: grid;
  place-items: center;
  padding: 24px;
  cursor: zoom-out;
}

.lightbox-image {
  max-width: min(96vw, 1200px);
  max-height: 90vh;
  object-fit: contain;
  border-radius: 4px;
  cursor: default;
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 20px;
  border: none;
  background: transparent;
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
}

.field-autocomplete {
  position: relative;
}

.field-autocomplete .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;
}

.field-money {
  position: relative;
}

.field-money .money-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.field-money .money-suggestions.hidden {
  display: none;
}

.money-suggestion-item {
  display: inline-block;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.money-suggestion-item:hover {
  background: var(--primary-soft, #e3f2fd);
  border-color: var(--primary, #1976d2);
}

.checkbox-label {
  display: flex;
  align-items: center;
  cursor: pointer;
}

/* Skeleton loading */
.loading-skeleton {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
}

.skeleton-block {
  border-radius: 8px;
  background: linear-gradient(90deg, #eceff1 25%, #f5f5f5 50%, #eceff1 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.2s ease-in-out infinite;
}

.skeleton-header {
  height: 28px;
  width: 40%;
}

.skeleton-line {
  height: 16px;
  width: 100%;
}

.skeleton-line-short {
  width: 65%;
}

@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 32px 20px;
  color: var(--muted);
}

.empty-state-icon {
  font-size: 2rem;
  margin-bottom: 8px;
  opacity: 0.7;
}

.empty-state-text {
  margin: 0;
  font-size: 0.95rem;
}

.list-card .empty-state {
  padding: 40px 20px;
}

.catalog-table .empty-state {
  padding: 16px;
  text-align: left;
}

.catalog-table .empty-state-icon {
  display: none;
}

@media (max-width: 768px) {
  .admin-layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    min-height: auto;
    display: flex;
    flex-wrap: wrap;
    padding: 8px;
    gap: 4px;
    position: static;
  }

  .nav-item {
    padding: 8px 12px;
    border-left: none;
    border-radius: 8px;
    font-size: 0.85rem;
  }

  .nav-item.active {
    border-left: none;
  }

  .main-content {
    padding: 16px;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .page-actions {
    width: 100%;
  }

  .page-actions .btn {
    flex: 1;
    min-width: 0;
  }

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

  .toolbar .field,
  .toolbar .field-grow,
  .trip-filter-toolbar .field-autocomplete {
    min-width: 0;
    width: 100%;
  }

  .list-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .list-row-meta {
    text-align: left;
    width: 100%;
  }

  .expense-list-card .expense-list-row {
    flex-wrap: wrap;
  }

  .list-row-quick {
    width: 100%;
    padding: 0 16px 12px;
    justify-content: flex-end;
  }

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

  .form-card {
    padding: 16px;
  }

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

  .modal-overlay {
    padding: 12px;
  }

  .toast-container {
    left: 12px;
    right: 12px;
    bottom: 12px;
  }

  .toast {
    text-align: center;
  }

  #admin-label {
    display: none;
  }

  .header-actions .btn-ghost {
    padding: 8px 10px;
    font-size: 0.85rem;
  }

  .shortcut-cards {
    grid-template-columns: 1fr;
  }

  .pagination-bar {
    flex-wrap: wrap;
    gap: 8px;
  }
}

@media (max-width: 375px) {
  .nav-item {
    padding: 6px 10px;
    font-size: 0.8rem;
  }

  .brand-header h1 {
    font-size: 1.1rem;
  }

  .page-header h2 {
    font-size: 1.15rem;
  }

  .btn-sm {
    padding: 5px 10px;
    font-size: 0.8rem;
  }
}

/* Trip detail/edit drawer (list overlay) */
.trip-drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 800;
  animation: tripDrawerFadeIn 0.18s ease;
}

.trip-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(560px, 100%);
  background: var(--bg, #f5f5f5);
  z-index: 801;
  box-shadow: -8px 0 28px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  animation: tripDrawerSlideIn 0.22s ease;
}

.trip-drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.trip-drawer-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.trip-drawer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.trip-drawer-body {
  flex: 1;
  overflow: auto;
  padding: 16px 20px 28px;
  -webkit-overflow-scrolling: touch;
}

.trip-drawer-body .detail-card,
.trip-drawer-body .form-card {
  margin: 0;
}

.trip-drawer-body .page-header {
  display: none;
}

body.trip-drawer-open {
  overflow: hidden;
}

@keyframes tripDrawerFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes tripDrawerSlideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

@media (max-width: 640px) {
  .trip-drawer {
    width: 100%;
  }

  .trip-drawer-header {
    flex-direction: column;
    align-items: stretch;
  }

  .trip-drawer-actions {
    justify-content: stretch;
  }

  .trip-drawer-actions .btn {
    flex: 1;
    min-width: 0;
  }
}

.edit-history-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border, #e5e7eb);
}

.edit-history-item:last-child {
  border-bottom: none;
}

.edit-history-meta {
  margin-bottom: 6px;
  color: var(--text-muted, #6b7280);
  font-size: 0.9rem;
}

.edit-history-changes {
  margin: 0;
  padding-left: 18px;
  font-size: 0.9rem;
}

.edit-history-changes li {
  margin-bottom: 4px;
}
