/* Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: #f5f7fa;
  color: #333;
  line-height: 1.6;
  padding-top: 80px; /* Adjusted for desktop header height */
}

/* Header Styles */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 40px;
  background-color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 1000;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 20px;
}

.logo {
  max-width: 150px; /* Desktop logo size */
  height: auto;
}

.header h1 {
  font-size: 24px;
  font-weight: 600;
  color: #1a202c;
}

.header-center {
  flex: 1;
  max-width: 400px;
  margin: 0 20px;
}

#order-filter {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 14px;
  color: #4a5568;
  outline: none;
  transition: border-color 0.2s ease;
}

#order-filter:focus {
  border-color: #3182ce;
  box-shadow: 0 0 0 3px rgba(49, 130, 206, 0.1);
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 15px;
}

.welcome-text {
  font-size: 16px;
  color: #ffffff;
}

.nav-link {
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  background-color: #3182ce;
  border-radius: 6px;
  text-decoration: none;
  border: none;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.nav-link:hover {
  background-color: #2b6cb0;
}

/* Add Order Form Styles */
.form-section {
  background-color: #fff;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  margin-bottom: 20px;
}

.add-order-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-input {
    @apply mt-1 p-2 w-full border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-400
      bg-white dark:bg-gray-800 dark:border-gray-600 dark:text-gray-200;
  }

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
}

.form-group {
  flex: 1;
  min-width: 200px;
}

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: #4a5568;
  margin-bottom: 5px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 14px;
  color: #4a5568;
  outline: none;
  transition: border-color 0.2s ease;
}

.form-group input:focus,
.form-group select:focus {
  border-color: #3182ce;
  box-shadow: 0 0 0 3px rgba(49, 130, 206, 0.1);
}

.form-submit {
  display: flex;
  align-items: flex-end;
}

/* Container for the Dashboard */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
  background-color: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

/* Headings */
h2 {
  font-size: 24px;
  font-weight: 600;
  color: #1a202c;
  margin-bottom: 20px;
  border-bottom: 2px solid #e2e8f0;
  padding-bottom: 8px;
}

/* Orders Table Container */
.orders-table-container {
  max-height: 480px;
  overflow-y: auto;
  width: 100%;
  position: relative;
  margin-bottom: 30px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
}

/* Table Styles */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

table th,
table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid #e2e8f0;
}

table th {
  background-color: #2d3748;
  color: #fff;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 20; /* Increased z-index to avoid overlap with modal */
  cursor: pointer;
  transition: background-color 0.2s ease;
}

table th:hover {
  background-color: #4a5568;
}

table tbody tr {
  transition: background-color 0.2s ease;
}

table tbody tr:nth-child(even) {
  background-color: #f7fafc;
}

table tbody tr:hover {
  background-color: #edf2f7;
}

table tbody tr.highlighted {
  background-color: #bee3f8 !important;
  transition: background-color 0.3s ease;
}

table td a {
  color: #3182ce;
  text-decoration: none;
  font-weight: 500;
}

table td a:hover {
  text-decoration: underline;
  color: #2b6cb0;
}

/* Timeline Styles */
#timeline-loading {
  text-align: center;
  color: #718096;
  font-style: italic;
  margin: 20px 0;
}

.timeline-container {
  width: 100%;
  position: relative;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  padding: 10px;
  min-height: 100px;
  max-height: 680px;
  overflow-y: auto;
  overflow-x: hidden;
}

.timeline-controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
}

.timeline-year-filter {
  justify-self: start;
}

canvas#timelineChart {
  display: block;
  width: 100% !important;
  /* height is set dynamically by JS — do not override here */
}

/* Legend Styles */
.legend {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
  justify-content: center;
}

.legend-item {
  display: flex;
  align-items: center;
  font-size: 14px;
  color: #4a5568;
}

.legend-color {
  width: 16px;
  height: 16px;
  display: inline-block;
  margin-right: 8px;
  border-radius: 4px;
}

.timeline-week-header {
  position: sticky;
  top: 0;
  z-index: 25;
  margin: -10px -10px 6px -10px;
  padding: 0 10px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(248, 250, 252, 0.95);
  backdrop-filter: blur(2px);
}

.timeline-week-track {
  display: grid;
  grid-template-columns: repeat(52, minmax(0, 1fr));
  gap: 0;
}

.timeline-week-track span {
  font-size: 10px;
  font-weight: 600;
  color: #334155;
  text-align: center;
  line-height: 1;
  padding: 5px 0;
  border-right: 1px solid rgba(148, 163, 184, 0.22);
  white-space: nowrap;
}

.timeline-week-track span[data-emphasis="month"],
.timeline-week-track span[data-emphasis="quarter"] {
  font-size: 11px;
  font-weight: 700;
  color: #e2e8f0;
  letter-spacing: 0.04em;
}

.dark .timeline-week-header {
  background: rgba(15, 23, 42, 0.95);
}

.dark .timeline-week-track span {
  color: #e2e8f0;
}

.dashboard-shell,
#kpi-cards,
#dashboard-orders-pane,
#dashboard-timeline-pane {
  max-width: 100%;
}

/* ==================== Add Order Form ==================== */
.form-section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: #94a3b8;
  padding-bottom: 5px;
  border-bottom: 1px solid rgba(100, 116, 139, 0.2);
  margin-top: 6px;
  grid-column: 1 / -1;
}

.req-star {
  color: #f87171;
  margin-left: 1px;
  font-weight: 600;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: #374151;
  margin-bottom: 3px;
}
.dark .form-label { color: #d1d5db; }

.form-input {
  padding: 7px 10px;
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
  color: #111827;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  box-sizing: border-box;
}
.form-input:focus {
  border-color: #60a5fa;
  box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.18);
}
.dark .form-input { background: #1f2937; border-color: #4b5563; color: #e5e7eb; }
.dark .form-input:focus { border-color: #60a5fa; }
/* TomSelect wrapper sizing */
.ts-wrapper.form-input { padding: 0; }

/* Inline form notification */
.form-notify {
  display: none;
  padding: 9px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 14px;
  line-height: 1.5;
}
.form-notify-success {
  background: rgba(16, 185, 129, 0.09);
  border: 1px solid rgba(16, 185, 129, 0.35);
  color: #065f46;
}
.dark .form-notify-success { color: #6ee7b7; }
.form-notify-error {
  background: rgba(239, 68, 68, 0.07);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #991b1b;
}
.dark .form-notify-error { color: #fca5a5; }

/* Table header — sortable columns */
.th-sortable {
  cursor: pointer;
  transition: background-color 0.15s ease;
}
.th-sortable:hover {
  background-color: rgba(100, 116, 139, 0.35);
}
.th-sort-active {
  background-color: rgba(59, 130, 246, 0.18) !important;
  color: #93c5fd;
}
.sort-indicator {
  display: inline-block;
  margin-left: 2px;
  font-size: 9px;
  font-weight: 700;
  color: #60a5fa;
  vertical-align: middle;
  line-height: 1;
}

/* Action icon buttons in orders table */
/* Use element+class selectors (0,1,1) to beat the global button{color:#fff} rule (0,0,1)
   while still losing to Tailwind hover utilities (0,2,0) so hover colours work normally */
button.action-icon-btn,
a.action-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 5px;
  background: transparent;
  color: #94a3b8;
  padding: 0;
  border: none;
  cursor: pointer;
  transition: color 0.15s ease, background-color 0.15s ease;
}

/* Buttons and Links */
a,
button {
  transition: all 0.2s ease;
}

button {
  background-color: #3182ce;
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
}

button:hover {
  background-color: #2b6cb0;
}

#load-more-btn {
  display: none; /* Initially hidden, controlled by JS */
}

/* Modal Styles */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
  background-color: #fff;
  margin: 5% auto;
  padding: 20px;
  border-radius: 8px;
  width: 90%;
  max-width: 800px;
  max-height: 80vh;
  overflow-y: auto;
}

.close {
  color: #aaa;
  float: right;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
}

.close:hover,
.close:focus {
  color: #000;
  text-decoration: none;
}

/* Responsive Design */
@media (max-width: 768px) {
  body {
    padding-top: 60px; /* Reduced from 120px to account for smaller header */
  }

  .header {
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
    padding: 5px 10px;
  }

  .header-left {
    flex-direction: row;
    align-items: center;
    gap: 10px;
    width: 100%;
  }

  .logo {
    max-width: 100px; /* Reduced from 150px */
  }

  .header h1 {
    font-size: 16px; /* Reduced from 24px */
  }

  .header-center {
    width: 100%;
    margin: 0;
  }

  #order-filter {
    width: 100%;
    padding: 6px 8px;
    font-size: 12px;
  }

  .header-nav {
    width: 100%;
    flex-wrap: wrap;
    gap: 5px;
  }

  .welcome-text {
    font-size: 12px; /* Reduced from 16px */
  }

  .nav-link {
    padding: 6px 12px;
    font-size: 12px;
    flex: 1;
    text-align: center;
  }

  .container {
    padding: 10px;
  }

  h2 {
    font-size: 20px;
  }

  .form-row {
    flex-direction: column;
  }

  .form-group {
    min-width: 100%;
  }

  table th,
  table td {
    padding: 8px;
    font-size: 12px;
  }

  .orders-table-container {
    max-height: 300px;
  }

  .timeline-container {
    min-height: 150px; /* Adjusted for mobile */
  }

  .timeline-controls {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .timeline-year-filter {
    width: 100%;
  }

  .timeline-week-track span {
    font-size: 10px;
    padding: 5px 0;
  }
}

@media (max-width: 1279px) {
  html,
  body {
    max-width: 100%;
    overflow-x: hidden;
  }

  header {
    align-items: flex-start;
    gap: 10px;
  }

  header > div,
  header > nav {
    width: 100%;
    min-width: 0;
  }

  header > nav {
    flex-wrap: wrap;
    justify-content: flex-start;
    row-gap: 8px;
  }

  #toast-global {
    right: 12px;
    left: 12px;
    max-width: none;
  }

  .dashboard-tab-list,
  .dashboard-pagination,
  .timeline-pagination,
  .timeline-sort-controls,
  .legend {
    flex-wrap: wrap;
  }

  .dashboard-tab-list > button,
  .timeline-sort-controls > button,
  .timeline-pagination > div,
  .timeline-year-filter,
  .legend-item {
    min-width: 0;
  }

  .dashboard-pagination,
  .timeline-pagination {
    justify-content: center;
    gap: 8px;
  }

  .timeline-controls {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .timeline-year-filter {
    justify-self: stretch;
  }

  .timeline-year-filter label,
  .timeline-year-filter select {
    display: block;
    width: 100%;
  }

  .timeline-year-filter label {
    margin: 0 0 6px 0;
  }

  .timeline-sort-controls {
    justify-content: flex-start;
  }

  .legend {
    justify-content: flex-start;
    margin-bottom: 0;
  }

  .orders-table-container {
    overflow-x: hidden;
    padding: 0;
  }

  .orders-responsive-table {
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0 10px;
    background: transparent;
  }

  .orders-responsive-table thead {
    display: none;
  }

  .orders-responsive-table tbody,
  .orders-responsive-table tr,
  .orders-responsive-table td {
    display: block;
    width: 100%;
  }

  .orders-responsive-table tbody {
    padding: 10px;
  }

  .orders-responsive-table tbody tr {
    margin: 0;
    padding: 12px;
    border: 1px solid rgba(203, 213, 225, 0.9);
    border-radius: 14px;
    background: #f8fafc;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
    overflow: hidden;
  }

  .dark .orders-responsive-table tbody tr {
    background: #0f172a;
    border-color: rgba(71, 85, 105, 0.9);
    box-shadow: 0 12px 28px rgba(2, 6, 23, 0.35);
  }

  .orders-responsive-table tbody td.order-cell {
    display: grid;
    grid-template-columns: minmax(92px, 120px) minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    padding: 6px 0;
    white-space: normal;
    word-break: break-word;
    border-bottom: 1px solid rgba(226, 232, 240, 0.85);
  }

  .dark .orders-responsive-table tbody td.order-cell {
    border-bottom-color: rgba(51, 65, 85, 0.9);
  }

  .orders-responsive-table tbody td.order-cell:last-child {
    border-bottom: 0;
    padding-bottom: 0;
  }

  .orders-responsive-table tbody td.order-cell::before {
    content: attr(data-label);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #64748b;
  }

  .dark .orders-responsive-table tbody td.order-cell::before {
    color: #94a3b8;
  }

  .orders-responsive-table tbody td.order-cell .order-action-group {
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 6px;
  }

  .orders-responsive-table tbody td.order-cell .action-icon-btn {
    width: 30px;
    height: 30px;
  }

  .orders-responsive-table tbody td.order-empty-state {
    display: block;
    width: 100%;
    padding: 20px 12px;
    border: 1px dashed rgba(148, 163, 184, 0.8);
    border-radius: 12px;
    background: #f8fafc;
  }

  .dark .orders-responsive-table tbody td.order-empty-state {
    background: #0f172a;
    border-color: rgba(71, 85, 105, 0.85);
  }
}

@media (max-width: 768px) {
  .timeline-container {
    padding: 8px;
  }

  .timeline-week-header {
    margin-bottom: 4px;
  }

  .timeline-week-track span {
    font-size: 9px;
    padding: 4px 0;
    border-right-color: rgba(71, 85, 105, 0.35);
  }

  .timeline-pagination {
    align-items: stretch;
  }

  .timeline-pagination > div {
    width: 100%;
    justify-content: stretch;
  }

  .timeline-pagination > div > button {
    flex: 1 1 0;
    justify-content: center;
  }
}

/* Improve dark mode text contrast for select and labels */
.dark label,
.dark select,
.dark .legend-label {
  color: #e5e7eb !important; /* text-gray-200 */
}

/* Button hover improvements */
.edit-button:hover {
  background-color: #2563eb !important; /* blue-600 */
}

.delete-button:hover {
  background-color: #dc2626 !important; /* red-600 */
}

/* Enhanced Edit Order Modal Layer */
#edit-order-modal {
  position: fixed;
  inset: 0;
  z-index: 1050;
  display: none;
  background-color: rgba(0, 0, 0, 0.5);
}

/* Prevent sticky headers from overlapping modal */
table thead th {
  z-index: 20;
}

/* Improved modal content layout */
#edit-order-modal .modal-content form {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

#edit-order-modal .modal-content .form-group {
  flex: 1 1 45%;
  min-width: 200px;
}

/* Modal action buttons layout */
#edit-order-modal .modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 16px;
}

/* Base Button Style */
.btn {
  @apply inline-flex items-center justify-center gap-1 px-3 py-1.5 rounded text-sm font-medium transition-colors duration-200 focus:outline-none;
}

.btn svg {
  @apply w-4 h-4;
}

/* Button Variants */
.btn-primary {
  @apply bg-blue-600 text-white hover:bg-blue-700;
}

.btn-danger {
  @apply bg-red-600 text-white hover:bg-red-700;
}

.btn-warning {
  @apply bg-yellow-500 text-white hover:bg-yellow-600;
}

.btn-success {
  @apply bg-green-600 text-white hover:bg-green-700;
}

.btn-icon {
  @apply flex items-center justify-center gap-1 px-2.5 py-1 text-xs sm:text-sm text-center whitespace-nowrap;
}

.btn-disabled {
  @apply opacity-40 cursor-not-allowed;
}
