:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary: #64748b;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --background: #f3f4f6;
  --surface: #ffffff;
  --text: #1f2937;
  --text-light: #6b7280;
  --border: #e5e7eb;
  --radius: 0.5rem;
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --bg-alt: #f9fafb;
}

[data-theme="dark"] {
  --primary: #60a5fa;
  --primary-hover: #93c5fd;
  --secondary: #94a3b8;
  --danger: #f87171;
  --danger-hover: #fca5a5;
  --success: #4ade80;
  --background: #0f172a;
  --surface: #1e293b;
  --text: #f1f5f9;
  --text-light: #cbd5e1;
  --border: #334155;
  --bg-alt: #0f172a;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.5);
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--background);
  color: var(--text);
  line-height: 1.5;
  margin: 0;
  padding: 0;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

h1, h2, h3, h4 {
  color: var(--text);
  font-weight: 700;
  margin-top: 0;
}

h1 { font-size: 1.875rem; margin-bottom: 1.5rem; }
h2 { font-size: 1.5rem; margin-bottom: 1rem; }
h3 { font-size: 1.25rem; margin-bottom: 0.75rem; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Cards & Layout */
.card, .stat-card, .customer-card, .packing-slip, .customer-info {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  border: 1px solid var(--border);
}

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}
.stat-card {
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.stat-card strong {
  display: block;
  font-size: 2.25rem;
  color: var(--primary);
  line-height: 1;
  margin-bottom: 0.5rem;
}

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
}

label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.25rem;
  color: var(--text);
}

button, input, select, textarea {
  font-family: inherit;
}

input[type="text"], input[type="date"], input[type="number"], 
input[type="email"], input[type="tel"], input[type="time"],
select, textarea {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  background-color: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s;
  background-color: var(--primary);
  color: white;
  text-decoration: none;
  font-size: 0.95rem;
}
.btn:hover { background-color: var(--primary-hover); text-decoration: none; }

.btn-red { background-color: var(--danger); }
.btn-red:hover { background-color: var(--danger-hover); }

.btn-secondary { background-color: var(--secondary); }
.btn-secondary:hover { background-color: #475569; }

.btn-add { margin-left: 1rem; font-size: 0.875rem; }

/* Tables */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
  border: 1px solid var(--border);
}

th {
  background: var(--bg-alt);
  text-align: left;
  padding: 0.75rem 1rem;
  font-weight: 600;
  color: var(--text-light);
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
}

td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background-color: var(--bg-alt); }

/* Filters */
.filter-form .filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  background: var(--surface);
  padding: 1.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  margin-bottom: 2rem;
  align-items: flex-end;
}
.filter-row > div, .filter-row > .form-group {
  flex: 1;
  min-width: 160px;
}

/* Status Badges */
.status-done {
  color: var(--success);
  font-weight: 600;
  background: #dcfce7;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  display: inline-block;
  font-size: 0.875rem;
}
.status-pending {
  color: #d97706;
  font-weight: 600;
  background: #fef3c7;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  display: inline-block;
  font-size: 0.875rem;
}

/* Alerts */
.success, .error {
  padding: 1rem;
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
  font-weight: 500;
}
.success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 2rem;
}
.pagination a {
  padding: 0.5rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
}
.pagination a.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Dynamic Rows (Items) */
.dynamic-row {
  display: flex;
  gap: 1rem;
  align-items: center;
  padding: 0.75rem;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
}

/* Date Picker (Driver) */
.date-picker {
  background: var(--surface);
  padding: 1.25rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

/* Signature Area */
.signature-area {
  background: var(--bg-alt);
  padding: 1.5rem;
  border-radius: var(--radius);
  border: 2px dashed var(--border);
  margin-top: 2rem;
}
canvas#sig-canvas {
  background: white;
  width: 100%;
  height: 200px;
  border-radius: var(--radius);
  border: 1px solid #ccc;
  margin-bottom: 1rem;
}

/* Packing Slip Specifics */
.packing-slip .header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 2px solid var(--border);
  padding-bottom: 1.5rem;
  margin-bottom: 1.5rem;
}
.packing-slip .logo {
  font-weight: 700;
  color: var(--text);
  font-size: 0.9rem;
}

/* Footer */
.footer {
  text-align: center;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  color: var(--text-light);
}

/* Print Overrides */
@media print {
  .no-print, .btn, .filter-form, .pagination, .footer, header { display: none !important; }
  .container { width: 100%; max-width: none; padding: 0; margin: 0; }
  .card, .packing-slip { box-shadow: none; border: none; padding: 0; margin: 0; }
  body { background: white; }
}

/* Navigation Bar */
.main-header {
  background-color: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.header-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 2rem;
  height: 4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  display: flex;
  align-items: center;
}

.nav-links {
  display: flex;
  gap: 2rem;
  height: 100%;
}

.nav-links a {
  display: inline-flex;
  align-items: center;
  color: var(--text-light);
  font-weight: 500;
  font-size: 0.95rem;
  text-decoration: none;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  height: 100%;
  padding: 0 0.25rem;
}

.nav-links a:hover {
  color: var(--primary);
}

.nav-links a.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Mobile Nav */
@media (max-width: 768px) {
  .header-container {
    flex-direction: column;
    height: auto;
    padding: 1rem;
    gap: 1rem;
  }
  .nav-links {
    width: 100%;
    justify-content: center;
    gap: 1.5rem;
    flex-wrap: wrap;
  }
  .nav-links a {
    height: auto;
    padding-bottom: 0.5rem;
  }
}