:root {
  --primary: #4F46E5;
  /* Indigo 600 */
  --primary-hover: #4338CA;
  --bg-color: #F3F4F6;
  /* Gray 100 */
  --sidebar-bg: #111827;
  /* Gray 900 */
  --sidebar-hover: #1F2937;
  --text-primary: #111827;
  --text-secondary: #6B7280;
  --text-light: #F9FAFB;
  --card-bg: #FFFFFF;
  --border-color: #E5E7EB;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --table-header-bg: #F8FAFC;
  --table-row-hover: #F3F4F6;

  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
}

[data-theme="dark"] {
  --primary: #6366F1;
  --primary-hover: #4F46E5;
  --bg-color: #030712;
  --sidebar-bg: #111827;
  --sidebar-hover: #1F2937;
  --text-primary: #F9FAFB;
  --text-secondary: #9CA3AF;
  --text-light: #F9FAFB;
  --card-bg: #111827;
  --border-color: #374151;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.5);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.6), 0 4px 6px -2px rgba(0, 0, 0, 0.4);
  --table-header-bg: #1F2937;
  --table-row-hover: #1F2937;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Inter', sans-serif;
}

body {
  background-color: var(--bg-color);
  color: var(--text-primary);
  overflow-x: hidden;
}

/* Utilities */
.w-100 {
  width: 100%;
  margin-top: 1rem;
}

.error-msg {
  color: var(--danger);
  font-size: 0.875rem;
  margin-top: 1rem;
  text-align: center;
}

/* Login Container */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background-color: var(--sidebar-bg);
}

.login-box {
  background: var(--card-bg);
  padding: 3rem;
  border-radius: 12px;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
}

.brand-logo {
  font-size: 1.6rem;
  white-space: nowrap;
  font-weight: 700;
  text-align: center;
  margin-bottom: 2rem;
  color: var(--text-primary);
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.brand-logo img {
  flex-shrink: 0;
}


.brand-logo i {
  color: var(--primary);
}

.input-group {
  margin-bottom: 1.5rem;
}

.input-group label {
  display: block;
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.input-group input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-color);
  background-color: var(--card-bg);
  color: var(--text-primary);
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color 0.2s;
}

.input-group input:focus {
  outline: none;
  border-color: var(--primary);
}

.app-container {
  display: flex;
  height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background-color: var(--sidebar-bg);
  color: var(--text-light);
  display: flex;
  flex-direction: column;
  transition: width 0.3s ease;
  overflow: hidden;
  white-space: nowrap;
}

.sidebar.collapsed {
  width: 80px;
  overflow: visible;
}

.sidebar.collapsed .sidebar-brand {
  justify-content: center;
  padding: 1.5rem 0;
}

.sidebar.collapsed .nav-text,
.sidebar.collapsed .sidebar-brand .nav-text {
  display: none;
}

.sidebar-brand {
  padding: 0.75rem 1rem;
  font-size: 1.25rem;
  font-weight: 700;
  border-bottom: 1px solid var(--sidebar-hover);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 50px;
  overflow: hidden;
}

.sidebar-brand .nav-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-brand i {
  color: var(--primary);
}

.nav-list {
  list-style: none;
  padding: 0.25rem 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Custom scrollbar for sidebar */
.nav-list::-webkit-scrollbar {
  width: 4px;
}

.nav-list::-webkit-scrollbar-track {
  background: transparent;
}

.nav-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
}


.nav-item {
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.2s;
  cursor: pointer;
}

.nav-item:hover,
.nav-item.active {
  background-color: var(--sidebar-hover);
  color: var(--text-light);
  border-left: 4px solid var(--primary);
}

.nav-item i {
  font-size: 1.25rem;
}

.nav-item-header {
  padding: 1rem 1.5rem 0.4rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12rem;
  color: #94a3b8;
  /* Slate 400 - clean and visible on dark BG */
  opacity: 0.7;
  transition: opacity 0.3s;
}

.sidebar.collapsed .nav-item-header {
  display: none;
}


/* Collapsed sidebar nav tooltips */
.nav-item {
  position: relative;
}

.sidebar.collapsed .nav-item::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin-left: 12px;
  background: var(--sidebar-bg);
  color: var(--text-light);
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 200;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.sidebar.collapsed .nav-item:hover::after {
  opacity: 1;
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.top-header {
  height: 70px;
  background-color: var(--card-bg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 2rem;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-secondary);
  transition: color 0.2s;
}

.icon-btn:hover {
  color: var(--primary);
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 500;
}

.avatar {
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

.main-scroll-area {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.content-area {
  flex: 1;
  padding: 2rem;
}


/* Dashboard Cards */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--card-bg);
  padding: 1.25rem;
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.stat-info h3 {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
  margin-bottom: 0.25rem;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.stat-info .value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

.stat-icon {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border-radius: 10px;
  background-color: rgba(79, 70, 229, 0.1);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

/* Tables Structure */
.table-container {
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  overflow: visible;
  /* allows dropdown popups to break outside element boundaries */
  padding-bottom: 2rem;
  /* Buffer room when list has 1 item so container doesn't shrink immediately tight against it */
}

.table-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  border-radius: 12px 12px 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.table-title {
  font-weight: 600;
  font-size: 1.125rem;
}

.btn-primary {
  background-color: var(--primary);
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

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

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

th,
td {
  padding: 1rem 1.5rem;
  text-align: left;
}

th {
  background-color: var(--table-header-bg);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-color);
}

td {
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 0.95rem;
}

tr:last-child td {
  border-bottom: none;
}

tr:hover {
  background-color: var(--table-row-hover);
}

/* Status Badges */
.badge {
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  display: inline-block;
}

.badge-success {
  background: rgba(16, 185, 129, 0.1);
  color: var(--success);
}

.badge-warning {
  background: rgba(245, 158, 11, 0.1);
  color: var(--warning);
}

.badge-primary {
  background: rgba(79, 70, 229, 0.1);
  color: var(--primary);
}

.badge-danger {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
}

.badge-info {
  background: rgba(59, 130, 246, 0.1);
  color: #60a5fa;
  /* light enough for dark mode, subtle enough for light mode */
}

.badge-dispatched {
  background: rgba(245, 158, 11, 0.1);
  color: var(--warning);
}

.badge-booked {
  background: rgba(107, 114, 128, 0.1);
  color: var(--text-secondary);
}

.badge-ofd {
  background: rgba(79, 70, 229, 0.1);
  color: var(--primary);
}

.spinner {
  border: 3px solid rgba(0, 0, 0, 0.1);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border-left-color: var(--primary);
  animation: spin 1s linear infinite;
  margin: 2rem auto;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

/* Form Styles */
.form-section {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.form-section h3 {
  margin-bottom: 1rem;
  color: var(--primary);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
}

.form-group {
  display: flex;
  flex-direction: column;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
}

.form-group input,
.form-group select,
.form-group textarea,
.form-select,
.form-control {
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  background-color: var(--card-bg);
  color: var(--text-primary);
  border-radius: 6px;
  outline: none;
  font-size: 0.95rem;
}

/* Custom styled select with better arrow spacing */
select,
.form-group select,
.form-select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%236B7280' stroke-width='2'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 1rem;
  padding-right: 2.5rem !important;
}

[data-theme="dark"] select,
[data-theme="dark"] .form-group select,
[data-theme="dark"] .form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%239CA3AF' stroke-width='2'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
}


.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus,
.form-select:focus,
.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.disabled-input {
  background-color: var(--bg-color);
  color: var(--text-secondary);
  cursor: not-allowed;
}

/* Buttons */
.btn-secondary {
  background-color: var(--card-bg);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-secondary:hover {
  background-color: var(--bg-color);
}

.icon-btn.delete-btn:hover {
  color: var(--danger);
}

.icon-btn.edit-btn:hover {
  color: var(--primary);
}

/* Tracking Timeline */
.timeline {
  position: relative;
  max-width: 1200px;
  margin: 0 auto;
}

.timeline-item {
  padding: 10px 16px 10px 52px;
  position: relative;
  background-color: inherit;
  width: 100%;
}

/* Vertical connecting line — from this dot center to the bottom of item */
.timeline-item::before {
  content: '';
  position: absolute;
  width: 2px;
  background-color: var(--primary);
  top: 21px;
  bottom: 0;
  left: 20px;
}

.timeline-item:last-child::before {
  display: none;
}

/* Dot */
.timeline-item::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  right: auto;
  background-color: var(--card-bg);
  border: 3px solid var(--primary);
  top: 14px;
  border-radius: 50%;
  z-index: 1;
  left: 14px;
  /* center = 14 + 7 = 21px, matches line at left:20px + 1px center */
}

/* Custom Action Dropdown */
.action-dropdown {
  position: relative;
  display: inline-block;
}

.action-btn {
  background: none;
  border: 1px solid var(--border-color);
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.action-btn:hover {
  background: var(--bg-color);
  color: var(--primary);
  border-color: var(--primary);
}

.action-menu {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 5px;
  background-color: var(--card-bg);
  min-width: 170px;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.12);
  border-radius: 8px;
  border: 1px solid var(--border-color);
  z-index: 100;
  overflow: hidden;
  text-align: left;
}

.action-menu.show {
  display: block;
}

.action-item {
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.2s;
  font-size: 0.85rem;
}

.action-item i {
  font-size: 1.1rem;
}

.action-item:hover {
  background-color: var(--bg-color);
  color: var(--primary);
}

.action-item.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.action-item.danger:hover {
  color: var(--danger);
  background-color: rgba(239, 68, 68, 0.08);
}

/* ---- RESPONSIVE MOBILE OPTIMIZATION ---- */
@media (max-width: 1024px) {
  .dashboard-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {

  /* Convert Sidebar into sliding overlay */
  .sidebar {
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    z-index: 2100;
    width: 280px;
    transform: translateX(0);
    box-shadow: 10px 0 25px rgba(0, 0, 0, 0.5);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .sidebar.collapsed {
    transform: translateX(-100%);
    width: 280px !important;
    /* Keep width consistent for animation */
    box-shadow: none;
  }

  /* Overlay when sidebar is open */
  .sidebar:not(.collapsed)::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: -1;
  }

  .sidebar.collapsed .sidebar-brand,
  .sidebar.collapsed .nav-item {
    opacity: 0;
    /* Fade out content while sliding */
  }

  .sidebar:not(.collapsed) .nav-text,
  .sidebar:not(.collapsed) .sidebar-brand .nav-text {
    display: inline-block !important;
  }

  .main-content {
    width: 100%;
    margin-left: 0 !important;
  }

  /* Compress Headers */
  .top-header {
    padding: 0 1rem;
    height: auto;
    min-height: 60px;
    flex-wrap: nowrap;
    gap: 0.5rem;
  }

  .header-left {
    min-width: 0;
    flex-shrink: 1;
    overflow: hidden;
  }

  #page-title {
    font-size: 1.1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .header-right {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  #user-name {
    display: none;
  }

  .user-profile {
    padding: 0.2rem 0.5rem !important;
  }

  #live-clock {
    display: none !important;
    /* Save upper real-estate */
  }

  .content-area {
    padding: 1rem;
  }

  /* Dashboard Adjustments */
  .dashboard-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  /* Tables & Filters Wrapping Logic */
  .table-header {
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
    padding: 1.25rem 1rem;
  }

  .table-header h2,
  .table-title {
    text-align: center;
    font-size: 1.25rem;
    margin-bottom: 0.25rem;
  }

  /* Force filter row items to wrap into stacked blocks */
  div[style*="display: flex; gap: 1rem"] {
    flex-direction: column !important;
    gap: 0.75rem !important;
  }

  div[style*="display: flex; gap: 1rem"]>div,
  div[style*="display: flex; gap: 1rem"]>input,
  div[style*="display: flex; gap: 1rem"]>select,
  div[style*="display: flex; gap: 1rem"]>button {
    width: 100% !important;
    min-width: 100% !important;
  }

  .btn-primary,
  .btn-secondary {
    width: 100%;
    justify-content: center;
  }

  /* Table Horizontal Scraping Lock */
  .table-container {
    overflow-x: auto;
    width: 100%;
    border-radius: 8px;
  }

  table {
    min-width: 800px;
    /* Protect data grid layout structure by enforcing scrolling on small screens */
  }

  /* Form Stack Alignment */
  .form-section {
    padding: 1rem;
    margin-bottom: 1.25rem;
  }

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

  /* Rip out forced spans */
  .form-group[style*="grid-column: span 2"] {
    grid-column: 1 / -1 !important;
  }

  /* Force modal card scaling */
  .modal-card {
    width: 92% !important;
    padding: 1.5rem !important;
    max-height: 85vh !important;
  }
}

@media (max-width: 480px) {

  /* Smaller screens */
  .login-box {
    margin: 1rem;
    padding: 1.5rem;
  }

  .table-container {
    padding-bottom: 3rem;
  }
}

/* Footer Styles */
.app-footer {
  padding: 1.5rem 2rem;
  border-top: 1px solid var(--border-color);
  background: var(--card-bg);
  margin-top: auto;
}

.footer-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  width: 100%;
}

.copyright {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.copyright strong {
  color: var(--text-primary);
}

.built-by {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.built-by a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  transition: all 0.2s;
}

.built-by a:hover {
  text-decoration: underline;
  opacity: 0.8;
}

@media (max-width: 768px) {
  .footer-content {
    flex-direction: column;
    text-align: center;
    gap: 0.5rem;
  }
}

/* Search Bar Clear Button Styles */
.search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.search-wrapper input {
  width: 100%;
  flex: 1;
  padding-right: 2.5rem !important;
}

.search-clear-btn {
  position: absolute;
  right: 0.75rem;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  transition: all 0.2s;
  opacity: 0;
  pointer-events: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
}

.search-clear-btn:hover {
  color: var(--primary);
  background-color: var(--bg-color);
}

.search-wrapper input:not(:placeholder-shown)~.search-clear-btn {
  opacity: 1;
  pointer-events: auto;
}


.footer-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  width: 100%;
}


.copyright {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.copyright strong {
  color: var(--text-primary);
}

.built-by {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.built-by a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  transition: all 0.2s;
}

.built-by a:hover {
  text-decoration: underline;
  opacity: 0.8;
}

@media (max-width: 768px) {
  .footer-content {
    flex-direction: column;
    text-align: center;
    gap: 0.5rem;
  }
}