/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue:       #1e40af;
  --blue-light: #3b82f6;
  --blue-pale:  #eff6ff;
  --gray-50:    #f9fafb;
  --gray-100:   #f3f4f6;
  --gray-200:   #e5e7eb;
  --gray-400:   #9ca3af;
  --gray-600:   #4b5563;
  --gray-800:   #1f2937;
  --green:      #059669;
  --green-pale: #d1fae5;
  --red:        #dc2626;
  --red-pale:   #fee2e2;
  --orange:     #d97706;
  --orange-pale:#fef3c7;
  --radius:     8px;
  --shadow:     0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:  0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--gray-800);
  background: var(--gray-50);
  height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius);
  border: 1px solid transparent; cursor: pointer;
  font-size: 13px; font-weight: 500;
  transition: background .15s, transform .1s;
}
.btn:active { transform: scale(.98); }
.btn svg { width: 16px; height: 16px; }

.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-secondary { background: #fff; color: var(--gray-800); border-color: var(--gray-200); }
.btn-secondary:hover { background: var(--gray-50); }
.btn-full { width: 100%; justify-content: center; padding: 10px 16px; font-size: 14px; }
.btn-link { background: none; border: none; color: var(--blue-light); cursor: pointer; font-size: 12px; padding: 2px; }
.btn-link:hover { text-decoration: underline; }
.btn-back {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: none; cursor: pointer;
  color: var(--gray-600); font-size: 13px; padding: 4px 0;
}
.btn-back:hover { color: var(--blue); }
.btn-back svg { width: 16px; height: 16px; }
.btn-icon { background: none; border: none; cursor: pointer; padding: 4px; color: var(--gray-600); border-radius: 4px; }
.btn-icon:hover { background: var(--gray-100); }
.btn-icon svg { width: 16px; height: 16px; display: block; }

/* ── Login ── */
.login-screen {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; background: linear-gradient(135deg, #1e3a8a 0%, #1e40af 50%, #1d4ed8 100%);
}
.login-card {
  background: #fff; border-radius: 16px; padding: 40px 36px;
  width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-logo { display: flex; justify-content: center; margin-bottom: 20px; }
.login-logo svg { width: 52px; height: 52px; }
.login-card h1 { text-align: center; font-size: 22px; font-weight: 700; color: var(--gray-800); margin-bottom: 6px; }
.login-sub { text-align: center; color: var(--gray-400); font-size: 13px; margin-bottom: 28px; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--gray-600); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }
.form-group input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--gray-200);
  border-radius: var(--radius); font-size: 14px;
  transition: border-color .15s, box-shadow .15s;
}
.form-group input:focus { outline: none; border-color: var(--blue-light); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }

.error-msg { color: var(--red); font-size: 13px; margin-bottom: 12px; padding: 8px 12px; background: var(--red-pale); border-radius: var(--radius); }

/* ── App Layout ── */
.app { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ── */
.sidebar {
  width: 260px; flex-shrink: 0; background: #fff;
  border-right: 1px solid var(--gray-200);
  display: flex; flex-direction: column; overflow: hidden;
}
.sidebar-header {
  padding: 16px; border-bottom: 1px solid var(--gray-200);
}
.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 15px; color: var(--blue); margin-bottom: 12px;
}
.sidebar-logo svg { width: 28px; height: 28px; flex-shrink: 0; }
.user-info { display: flex; align-items: center; justify-content: space-between; }
#user-email-display { font-size: 11px; color: var(--gray-400); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

.sidebar-nav { padding: 8px; border-bottom: 1px solid var(--gray-200); }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 12px; border: none; border-radius: var(--radius);
  background: none; cursor: pointer; color: var(--gray-600); font-size: 13px; font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: var(--gray-100); color: var(--gray-800); }
.nav-item.active { background: var(--blue-pale); color: var(--blue); }

.company-list { flex: 1; overflow-y: auto; padding: 8px; }
.company-list-item {
  padding: 10px 12px; border-radius: var(--radius); cursor: pointer;
  transition: background .15s;
}
.company-list-item:hover { background: var(--gray-100); }
.company-list-item.active { background: var(--blue-pale); }
.company-list-item .cli-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.company-list-item .cli-meta { font-size: 11px; color: var(--gray-400); margin-top: 2px; }

/* ── Main Content ── */
.main-content { flex: 1; overflow-y: auto; display: flex; flex-direction: column; min-width: 0; }

.view { display: none; flex-direction: column; flex: 1; padding: 24px; }
.view.active { display: flex; }

.view-header {
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 20px; flex-wrap: wrap;
}
.view-header h2 { font-size: 20px; font-weight: 700; flex: 1; }
.view-actions { display: flex; gap: 10px; align-items: center; }

.search-input {
  padding: 8px 12px; border: 1px solid var(--gray-200); border-radius: var(--radius);
  font-size: 13px; width: 220px;
}
.search-input:focus { outline: none; border-color: var(--blue-light); box-shadow: 0 0 0 3px rgba(59,130,246,.15); }

/* ── Companies Grid ── */
.companies-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.company-card {
  background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius);
  padding: 20px; cursor: pointer; transition: box-shadow .15s, border-color .15s;
}
.company-card:hover { box-shadow: var(--shadow-md); border-color: var(--blue-light); }
.company-card-name { font-weight: 700; font-size: 15px; margin-bottom: 8px; color: var(--gray-800); }
.company-card-id { font-size: 10px; color: var(--gray-400); font-family: monospace; margin-bottom: 12px; }
.company-card-stats { display: flex; gap: 16px; }
.stat { display: flex; align-items: center; gap: 6px; color: var(--gray-600); font-size: 12px; }
.stat svg { width: 14px; height: 14px; color: var(--blue-light); }

/* ── Tabs ── */
.tabs {
  display: flex; gap: 4px; border-bottom: 2px solid var(--gray-200);
  margin-bottom: 20px;
}
.tab {
  padding: 10px 20px; border: none; background: none; cursor: pointer;
  font-size: 13px; font-weight: 600; color: var(--gray-400);
  border-bottom: 2px solid transparent; margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--gray-800); }
.tab.active { color: var(--blue); border-bottom-color: var(--blue); }

.tab-content { display: none; }
.tab-content.active { display: block; }
.tab-content.hidden { display: none; }

/* ── Tables ── */
.data-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.data-table th { padding: 10px 16px; text-align: left; font-size: 11px; font-weight: 700; color: var(--gray-400); text-transform: uppercase; letter-spacing: .05em; background: var(--gray-50); border-bottom: 1px solid var(--gray-200); }
.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--gray-50); }

/* ── Report Generation ── */
.report-wizard { max-width: 680px; }
.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-bottom: 20px; }
.template-card {
  border: 2px solid var(--gray-200); border-radius: var(--radius); padding: 14px;
  cursor: pointer; transition: border-color .15s, background .15s;
}
.template-card:hover { border-color: var(--blue-light); background: var(--blue-pale); }
.template-card.selected { border-color: var(--blue); background: var(--blue-pale); }
.template-card-title { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.template-card-desc { font-size: 11px; color: var(--gray-400); }
.template-badge {
  display: inline-flex; padding: 2px 8px; border-radius: 20px; font-size: 10px; font-weight: 700; text-transform: uppercase;
  margin-top: 8px;
}
.badge-pdf { background: #fee2e2; color: #991b1b; }
.badge-xls { background: #d1fae5; color: #065f46; }
.badge-csv { background: #dbeafe; color: #1e40af; }

.step-section { margin-bottom: 24px; }
.step-title { font-size: 13px; font-weight: 700; color: var(--gray-600); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 12px; }

.driver-check-list { display: flex; flex-direction: column; gap: 6px; max-height: 280px; overflow-y: auto; }
.driver-check-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  border: 1px solid var(--gray-200); border-radius: var(--radius); cursor: pointer;
}
.driver-check-item:hover { background: var(--gray-50); }
.driver-check-item input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; }
.driver-name { font-weight: 500; }
.driver-card { font-size: 11px; color: var(--gray-400); font-family: monospace; }

.date-inputs { display: flex; gap: 12px; flex-wrap: wrap; }
.date-field { flex: 1; min-width: 140px; }
.date-field label { display: block; font-size: 11px; font-weight: 600; color: var(--gray-600); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .04em; }
.date-field input { width: 100%; padding: 8px 10px; border: 1px solid var(--gray-200); border-radius: var(--radius); font-size: 13px; }
.date-field input:focus { outline: none; border-color: var(--blue-light); }

.select-field { flex: 1; min-width: 140px; }
.select-field label { display: block; font-size: 11px; font-weight: 600; color: var(--gray-600); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .04em; }
.select-field select { width: 100%; padding: 8px 10px; border: 1px solid var(--gray-200); border-radius: var(--radius); font-size: 13px; background: #fff; }

/* ── Reports List ── */
.reports-list { display: flex; flex-direction: column; gap: 10px; }
.report-item {
  background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius);
  padding: 16px 20px; display: flex; align-items: center; gap: 16px;
}
.report-item-icon { color: var(--red); flex-shrink: 0; }
.report-item-icon svg { width: 28px; height: 28px; display: block; }
.report-item-info { flex: 1; min-width: 0; }
.report-item-name { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.report-item-meta { font-size: 12px; color: var(--gray-400); }
.report-item-actions { display: flex; gap: 8px; flex-shrink: 0; }
.status-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 700;
}
.status-completed { background: var(--green-pale); color: var(--green); }
.status-pending { background: var(--orange-pale); color: var(--orange); }
.status-error { background: var(--red-pale); color: var(--red); }

/* ── Modal ── */
.modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,.4); }
.modal-dialog {
  position: relative; background: #fff; border-radius: 12px;
  width: 90%; max-width: 600px; max-height: 85vh; overflow: hidden;
  display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal-header { padding: 20px 24px 16px; border-bottom: 1px solid var(--gray-200); display: flex; align-items: center; }
.modal-header h3 { flex: 1; font-size: 16px; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--gray-400); line-height: 1; padding: 0 4px; }
.modal-close:hover { color: var(--gray-800); }
.modal-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--gray-200); display: flex; justify-content: flex-end; gap: 10px; }

/* ── Loading ── */
.loading { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; background: rgba(255,255,255,.8); z-index: 500; gap: 16px; }
.spinner {
  width: 36px; height: 36px; border: 3px solid var(--gray-200);
  border-top-color: var(--blue); border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Badges & Pills ── */
.pill {
  display: inline-flex; padding: 1px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
}
.pill-blue { background: var(--blue-pale); color: var(--blue); }

/* ── Empty State ── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--gray-400); }
.empty-state svg { width: 48px; height: 48px; margin: 0 auto 16px; display: block; }
.empty-state p { font-size: 14px; }

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-thumb { background: var(--gray-200); border-radius: 3px; }
