/* ===== Base & Reset ===== */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary: #64748b;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --background: #f8fafc;
  --surface: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow: 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);
  --radius: 0.5rem;
}

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

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--background);
  color: var(--text);
  line-height: 1.5;
}

/* ===== Layout ===== */
#app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 250px;
  background-color: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: all 0.3s ease;
}

.sidebar-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-menu {
  flex: 1;
  padding: 1rem 0;
  overflow-y: auto;
}

.nav-group-title {
  padding: 0.5rem 1.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  margin-top: 0.5rem;
}

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

.nav-item:hover, .nav-item.active {
  background-color: #eff6ff;
  color: var(--primary);
  border-right: 3px solid var(--primary);
}

.nav-item i {
  width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
  color: var(--text-muted);
}

#logout-btn {
  width: 100%;
  margin-top: 0.5rem;
}

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

.topbar {
  height: 64px;
  background-color: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
}

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

/* ===== Components ===== */
/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s;
}

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

.btn-secondary {
  background-color: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
.btn-secondary:hover {
  background-color: var(--background);
}

.btn-danger {
  background-color: var(--danger);
  color: white;
}
.btn-danger:hover {
  background-color: #dc2626;
}

.btn-icon {
  padding: 0.5rem;
}

/* Forms */
.form-group {
  margin-bottom: 1rem;
}

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

.form-control {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Autocomplete Dropdown */
.autocomplete-wrapper {
  position: relative;
}
.autocomplete-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 1000;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: 200px;
  overflow-y: auto;
  display: none;
}
.autocomplete-item {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}
.autocomplete-item:last-child {
  border-bottom: none;
}
.autocomplete-item:hover, .autocomplete-item.active {
  background-color: #eff6ff;
  color: var(--primary);
}
.autocomplete-detail {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Cards & Sections */
.card {
  background-color: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  margin-bottom: 1.5rem;
}

.card-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.card-header h3 {
  font-size: 1.125rem;
  font-weight: 600;
}

.card-body {
  padding: 1.5rem;
}

/* Filters bar */
.filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  margin-bottom: 1.5rem;
}

/* Tables */
.table-responsive {
  overflow-x: auto;
}

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

.table th, .table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}

.table th {
  font-weight: 600;
  color: var(--text-muted);
  background-color: #f8fafc;
}

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

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 9999px;
}
.badge-success { background-color: #d1fae5; color: #065f46; }
.badge-danger { background-color: #fee2e2; color: #991b1b; }
.badge-warning { background-color: #fef3c7; color: #92400e; }
.badge-primary { background-color: #dbeafe; color: #1e40af; }
.badge-secondary { background-color: #e2e8f0; color: #475569; }

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1050;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  background-color: var(--surface);
  border-radius: var(--radius);
  width: 90%;
  max-width: 800px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  transform: scale(0.95);
  transition: transform 0.2s;
}
.modal-overlay.active .modal-content {
  transform: scale(1);
}

.modal-content.modal-lg { max-width: 1000px; }
.modal-content.modal-sm { max-width: 400px; }

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

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* Print Preview Overlay */
.print-preview-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #333;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  opacity: 0; visibility: hidden;
  transition: all 0.2s;
}
.print-preview-overlay.active {
  opacity: 1; visibility: visible;
}
.print-toolbar {
  height: 50px; background: #222;
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 2rem; color: white;
}
.print-paper-container {
  flex: 1; overflow-y: auto;
  display: flex; justify-content: center;
  padding: 2rem;
}
.print-paper {
  background: white; color: black;
  width: 210mm; /* A4 width */
  min-height: 297mm; /* A4 height */
  box-shadow: 0 0 10px rgba(0,0,0,0.5);
  padding: 20mm;
  position: relative;
}

/* Tire Position Selector SVG */
.tire-selector-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}
.tire-svg {
  width: 200px;
  height: auto;
}
.tire-part {
  fill: #e2e8f0;
  stroke: #64748b;
  stroke-width: 2;
  cursor: pointer;
  transition: fill 0.2s;
}
.tire-part:hover {
  fill: #cbd5e1;
}
.tire-part.selected {
  fill: var(--primary);
  stroke: var(--primary-hover);
}

/* Grid Layouts for Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}
.form-grid-2 { grid-template-columns: 1fr 1fr; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-grid-4 { grid-template-columns: repeat(4, 1fr); }

/* Financial Dashboards */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 1rem;
}
.stat-icon {
  width: 48px; height: 48px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem;
}
.stat-icon.primary { background: #dbeafe; color: #1e40af; }
.stat-icon.success { background: #d1fae5; color: #065f46; }
.stat-icon.warning { background: #fef3c7; color: #92400e; }
.stat-icon.danger { background: #fee2e2; color: #991b1b; }
.stat-info h4 { font-size: 0.875rem; color: var(--text-muted); font-weight: 500; }
.stat-info p { font-size: 1.5rem; font-weight: 700; color: var(--text); }

/* Tabs */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}
.tab {
  padding: 0.75rem 1.5rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-weight: 500;
  transition: all 0.2s;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Line Items Editor */
.line-items-table { margin-bottom: 1rem; }
.line-items-table th, .line-items-table td { padding: 0.5rem; }
.line-items-table input { width: 100%; min-width: 60px; }

/* Announcement Board */
.marquee-container {
  background: var(--warning);
  color: #78350f;
  padding: 0.5rem;
  overflow: hidden;
  white-space: nowrap;
  font-weight: 600;
}
.marquee-text {
  display: inline-block;
  animation: marquee 15s linear infinite;
}
@keyframes marquee {
  0% { transform: translateX(100%); }
  100% { transform: translateX(-100%); }
}

/* ==================== PRINT MEDIA ==================== */
@media print {
  body * {
    visibility: hidden;
  }
  .print-paper, .print-paper * {
    visibility: visible;
  }
  .print-paper {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    box-shadow: none;
    padding: 0;
  }
  /* Optional page break controls inside print-paper */
  .page-break { page-break-before: always; }
}

/* Utility Classes */
.hidden { display: none !important; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.mb-4 { margin-bottom: 1rem; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 0.5rem; }
.w-full { width: 100%; }

/* Login specific */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background-color: var(--background);
}
.login-box {
  background: var(--surface);
  padding: 2.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
}
.login-logo { text-align: center; margin-bottom: 2rem; color: var(--primary); }
