/* Import Prompt font for a modern Thai/English typeface */
@import url('https://fonts.googleapis.com/css2?family=Prompt:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* Base CSS Variables for Light / Dark Mode */
:root {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-surface-hover: #f1f5f9;
  --border-color: #e2e8f0;
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-light: #e0e7ff;
  
  --success: #10b981;
  --success-bg: #d1fae5;
  --warning: #f59e0b;
  --warning-bg: #fef3c7;
  --info: #3b82f6;
  --info-bg: #dbeafe;
  --danger: #ef4444;
  --danger-bg: #fee2e2;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
  --font-sans: 'Prompt', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --radius: 12px;
}

html.dark {
  --bg-primary: #0b0f19;
  --bg-secondary: #131a26;
  --bg-surface-hover: #1e2638;
  --border-color: #222d3f;
  
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #475569;
  
  --accent: #818cf8;
  --accent-hover: #6366f1;
  --accent-light: rgba(99, 102, 241, 0.15);
  
  --success: #34d399;
  --success-bg: rgba(52, 211, 153, 0.1);
  --warning: #fbbf24;
  --warning-bg: rgba(251, 191, 36, 0.1);
  --info: #60a5fa;
  --info-bg: rgba(96, 165, 250, 0.1);
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.1);

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.5);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.3);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.4);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.5), 0 8px 10px -6px rgb(0 0 0 / 0.5);
}

/* Global resets */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  transition: background-color 0.3s, color 0.3s;
}

/* Scrollbar styles */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Dashboard container */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem;
}

/* Header styling */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #f43f5e);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.theme-btn {
  padding: 0.5rem 1rem;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: 8px;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.2s;
}

.theme-btn:hover {
  background-color: var(--bg-surface-hover);
  transform: translateY(-1px);
}

.theme-btn:disabled {
  opacity: 0.4 !important;
  cursor: not-allowed !important;
  pointer-events: none;
}

/* Stats panel */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.stat-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
  transition: all 0.3s;
}

.stat-card::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
}

.stat-card.total::after { background-color: var(--accent); }
.stat-card.closed::after { background-color: var(--success); }
.stat-card.transit::after { background-color: var(--info); }
.stat-card.preparing::after { background-color: var(--warning); }
.stat-card.unpaid::after { background-color: var(--danger); }

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

.stat-card h3 {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
  margin-bottom: 0.5rem;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
  font-family: var(--font-mono);
}

/* Charts Section Styling */
.charts-section {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

@media (min-width: 1024px) {
  .charts-section {
    grid-template-columns: 1fr 1.2fr !important;
  }
}

.chart-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: all 0.3s;
}

.chart-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.chart-card h3 {
  width: 100%;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.75rem;
}

.chart-canvas-wrapper {
  position: relative;
  width: 100%;
  max-width: 320px;
  height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* For the bar chart, we allow it to stretch wider */
.chart-card:nth-child(2) .chart-canvas-wrapper {
  max-width: 100%;
  height: 240px;
}

/* Search and Filters container */
.filters-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  margin-bottom: 1.5rem;
}

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

@media (min-width: 768px) {
  .filters-grid {
    grid-template-columns: 2fr repeat(3, 1fr);
  }
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.filter-group label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.input-control {
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  outline: none;
  transition: all 0.2s;
}

.input-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.input-control[readonly] {
  background-color: var(--border-color);
  opacity: 0.6;
  cursor: not-allowed;
}

/* Table styling */
.table-container {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow-x: auto;
  margin-bottom: 2rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

th {
  background-color: var(--bg-secondary);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.875rem;
  padding: 1rem;
  border-bottom: 2px solid var(--border-color);
}

td {
  padding: 1rem;
  font-size: 0.925rem;
  vertical-align: middle;
}

/* Left status border styling on table rows */
tr.status-preparing td:first-child {
  border-left: 4px solid var(--warning) !important;
  padding-left: 1.25rem;
}
tr.status-transit td:first-child {
  border-left: 4px solid var(--info) !important;
  padding-left: 1.25rem;
}
tr.status-closed td:first-child {
  border-left: 4px solid var(--success) !important;
  padding-left: 1.25rem;
}

/* Transition on hover for status border */
tr.status-preparing td:first-child,
tr.status-transit td:first-child,
tr.status-closed td:first-child {
  transition: border-left-width 0.15s ease, padding-left 0.15s ease;
}

tr.status-preparing:hover td:first-child {
  border-left-width: 8px !important;
  padding-left: 1rem;
}
tr.status-transit:hover td:first-child {
  border-left-width: 8px !important;
  padding-left: 1rem;
}
tr.status-closed:hover td:first-child {
  border-left-width: 8px !important;
  padding-left: 1rem;
}

/* Copy button utility */
.copy-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

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

/* Category Badge tags */
.category-tag {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
}

/* Modal details */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 1000;
  display: none; /* Controlled by js */
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal.flex {
  display: flex !important;
}

.modal.hidden {
  display: none !important;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.modal-content {
  position: relative;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 800px;
  max-height: 90vh;
  overflow-y: auto;
  z-index: 1010;
  display: flex;
  flex-direction: column;
  transform: scale(0.95);
  opacity: 0;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s;
}

.modal.flex .modal-content {
  transform: scale(1);
  opacity: 1;
}

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

.modal-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  transition: all 0.2s;
}

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

.modal-body {
  padding: 1.5rem;
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
}

@media (min-width: 768px) {
  .modal-body {
    grid-template-columns: 1fr 1fr;
  }
}

.info-section {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.detail-row {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.detail-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-secondary);
  font-weight: 600;
  letter-spacing: 0.05em;
}

.detail-val {
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-primary);
}

.detail-val.address-box {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  padding: 0.75rem;
  border-radius: 8px;
  font-size: 0.875rem;
  line-height: 1.6;
}

/* Action buttons inside details */
.action-btn {
  width: 100%;
  padding: 0.75rem 1rem;
  background-color: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
}

.action-btn:hover {
  background-color: var(--accent-hover);
  transform: translateY(-1px);
}

/* Timeline/tracking styling */
.tracking-section {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.timeline {
  display: flex;
  flex-direction: column;
  position: relative;
  padding-left: 0.5rem;
}

/* Form row grids */
.form-row-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 500px) {
  .form-row-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* Spinner styling */
@keyframes spin {
  to { transform: rotate(360deg); }
}
.animate-spin {
  animation: spin 1s linear infinite;
}

/* Responsive styles */
@media (max-width: 640px) {
  .container {
    padding: 1rem;
  }
  
  header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }
  
  th, td {
    padding: 0.75rem 0.5rem;
    font-size: 0.85rem;
  }
}
