*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body, * { font-family: 'Almarai', sans-serif; }

:root {
  --bg:      #0f1117;
  --surface: #1a1d27;
  --surface2:#22263a;
  --border:  #2e3250;
  --text:    #e2e8f0;
  --muted:   #64748b;
  --green:   #22c55e;
  --red:     #ef4444;
  --blue:    #3b82f6;
  --orange:  #f97316;
  --purple:  #a855f7;
  --yellow:  #facc15;
  --radius:  12px;
  --sidebar: 240px;
  --topbar:  48px;
}

body.light {
  --bg:      #f1f5f9;
  --surface: #ffffff;
  --surface2:#e2e8f0;
  --border:  #cbd5e1;
  --text:    #0f172a;
  --muted:   #64748b;
}

/* ── Topbar ── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0 1.25rem;
  z-index: 200;
}
.topbar-logo {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text);
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}
.topbar-logo small {
  font-size: 0.62rem;
  font-weight: 400;
  color: var(--muted);
}
.topbar-date {
  color: var(--muted);
  font-size: 0.8rem;
  direction: ltr;
  margin-right: auto;
  padding-right: 1rem;
}
.topbar-theme {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.topbar-theme:hover { background: var(--border); }

body {
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  font-size: 14px;
}

/* ── Lucide icons ── */
.lucide { width: 18px; height: 18px; stroke-width: 2; flex-shrink: 0; }

/* ── Mobile toggle ── */
.menu-toggle {
  display: none;
  position: fixed;
  top: calc(var(--topbar) + 0.5rem);
  right: 1rem;
  z-index: 300;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.45rem;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 150;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar);
  background: var(--surface);
  border-left: 1px solid var(--border);
  position: fixed;
  top: var(--topbar); right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1rem;
  gap: 1.5rem;
  z-index: 200;
  transition: transform 0.25s ease;
  overflow-y: auto;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text);
  padding: 0 0.4rem;
}

.logo .lucide { color: var(--blue); width: 22px; height: 22px; }
.logo span { display: flex; flex-direction: column; line-height: 1.1; }
.logo small { font-size: 0.65rem; font-weight: 400; color: var(--muted); margin-top: 1px; }

.sidebar-nav { list-style: none; display: flex; flex-direction: column; gap: 0.2rem; flex: 1; }

.nav-group-label {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.85rem 0.85rem 0.3rem;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.88rem;
  transition: background 0.15s, color 0.15s;
}

.sidebar-nav a:hover { background: var(--surface2); color: var(--text); }
.sidebar-nav a.active { background: var(--blue); color: #fff; }
.sidebar-nav a.active .lucide { color: #fff; }

.nav-badge {
  margin-right: auto;
  background: var(--red);
  color: #fff;
  border-radius: 999px;
  font-size: 0.65rem;
  padding: 1px 6px;
  font-weight: 700;
}

/* ── Content ── */
.content {
  margin-right: var(--sidebar);
  margin-top: var(--topbar);
  flex: 1;
  padding: 1.5rem 2rem;
  min-width: 0;
}

.page-header { margin-bottom: 1.5rem; display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 0.5rem; }
.page-header h1 { font-size: 1.55rem; font-weight: 800; }
.subtitle { color: var(--muted); margin-top: 0.3rem; font-size: 0.88rem; }

/* ══════════════════════════════════════
   STAT CARDS — compact, no wasted space
══════════════════════════════════════ */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  border-top: 3px solid transparent;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.85rem;
  transition: border-color 0.2s, transform 0.15s;
  cursor: default;
  position: relative;
  overflow: hidden;
}

.card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.025) 0%, transparent 60%);
  pointer-events: none;
}

.card:hover { transform: translateY(-2px); border-color: inherit; }
.card.full-width { grid-column: 1 / -1; }

.card-green  { border-top-color: var(--green); }
.card-red    { border-top-color: var(--red); }
.card-blue   { border-top-color: var(--blue); }
.card-orange { border-top-color: var(--orange); }
.card-purple { border-top-color: var(--purple); }
.card-yellow { border-top-color: var(--yellow); }

.card-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.card-icon .lucide { width: 20px; height: 20px; }

.card-icon.green  { background: rgba(34,197,94,0.13);  color: var(--green); }
.card-icon.red    { background: rgba(239,68,68,0.13);   color: var(--red); }
.card-icon.blue   { background: rgba(59,130,246,0.13);  color: var(--blue); }
.card-icon.orange { background: rgba(249,115,22,0.13);  color: var(--orange); }
.card-icon.purple { background: rgba(168,85,247,0.13);  color: var(--purple); }
.card-icon.yellow { background: rgba(250,204,21,0.13);  color: var(--yellow); }

.card-body { flex: 1; min-width: 0; }
.card-label { color: var(--muted); font-size: 0.73rem; font-weight: 600; letter-spacing: 0.04em; margin-bottom: 0.2rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-value { font-size: 1.6rem; font-weight: 800; line-height: 1.1; }
.card-sub   { font-size: 0.72rem; color: var(--muted); margin-top: 0.2rem; }
.card-value.positive { color: var(--green); }
.card-value.negative { color: var(--red); }

/* ── Charts ── */
.charts-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.chart-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  min-width: 0;
}

.chart-box h3 { font-size: 0.82rem; color: var(--muted); margin-bottom: 1rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }

/* ── Recent ── */
.recent-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.recent-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.recent-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1rem;
}
.recent-header h3 { font-size: 0.95rem; font-weight: 700; }

.recent-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.55rem 0; border-bottom: 1px solid var(--border); gap: 0.5rem;
}
.recent-item:last-child { border-bottom: none; }
.item-title  { font-weight: 600; font-size: 0.85rem; }
.item-meta   { color: var(--muted); font-size: 0.72rem; margin-top: 0.1rem; }

/* ── Filter bar ── */
.filter-bar {
  display: flex; align-items: center; gap: 0.6rem; margin-bottom: 1rem; flex-wrap: wrap;
}

.filter-bar input,
.filter-bar select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  font-family: 'Almarai', sans-serif;
  outline: none;
  transition: border-color 0.15s;
  min-width: 0;
}
.filter-bar input:focus,
.filter-bar select:focus { border-color: var(--blue); }
.filter-bar input { width: 200px; }
.filter-bar select { width: 150px; }

/* ── Table ── */
.table-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table { width: 100%; border-collapse: collapse; min-width: 500px; }
thead tr { background: var(--surface2); }
th {
  padding: 0.7rem 0.85rem; text-align: right;
  font-size: 0.7rem; text-transform: uppercase;
  color: var(--muted); letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border); white-space: nowrap;
  font-weight: 700;
}
td {
  padding: 0.65rem 0.85rem; border-bottom: 1px solid var(--border);
  font-size: 0.85rem; text-align: right;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,0.025); }

/* ── Form ── */
.form-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem; margin-bottom: 1.5rem;
}
.form-box h3 { margin-bottom: 1rem; font-size: 1rem; font-weight: 700; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-group { display: flex; flex-direction: column; gap: 0.4rem; }
.form-group.full-col { grid-column: 1 / -1; }
label { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
input, select, textarea {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); padding: 0.65rem 0.85rem;
  font-size: 0.9rem; font-family: 'Almarai', sans-serif;
  transition: border-color 0.15s; outline: none; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--blue); }
textarea { resize: vertical; }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.55rem 1.1rem; border-radius: 8px; border: none; cursor: pointer;
  font-size: 0.875rem; font-weight: 700; font-family: 'Almarai', sans-serif;
  text-decoration: none; transition: opacity 0.15s; white-space: nowrap;
}
.btn:hover:not(:disabled) { opacity: 0.85; }
.btn:disabled {
  background: #2e3250 !important;
  color: #6b7280 !important;
  border: 1px solid #3a3f5c !important;
  cursor: not-allowed !important;
  opacity: 1 !important;
  filter: none !important;
}
.btn-green  { background: var(--green);    color: #fff; }
.btn-red    { background: var(--red);      color: #fff; }
.btn-blue   { background: var(--blue);     color: #fff; }
.btn-orange { background: var(--orange);   color: #fff; }
.btn-gray   { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-yellow { background: var(--yellow);   color: #000; }

.btn-sm {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.28rem 0.6rem; border-radius: 6px; border: none; cursor: pointer;
  font-size: 0.72rem; font-weight: 700; font-family: 'Almarai', sans-serif;
  text-decoration: none; transition: opacity 0.15s; white-space: nowrap;
}
.btn-sm:hover:not(:disabled) { opacity: 0.85; }
.btn-sm:disabled {
  background: #2e3250 !important;
  color: #6b7280 !important;
  border: 1px solid #3a3f5c !important;
  cursor: not-allowed !important;
  opacity: 1 !important;
  filter: none !important;
}
.btn-sm.btn-green  { background: var(--green);    color: #fff; }
.btn-sm.btn-red    { background: var(--red);       color: #fff; }
.btn-sm.btn-blue   { background: var(--blue);      color: #fff; }
.btn-sm.btn-orange { background: var(--orange);    color: #fff; }
.btn-sm.btn-gray   { background: var(--surface2);  color: var(--text); border: 1px solid var(--border); }
.btn-sm.btn-yellow { background: var(--yellow);    color: #000; }

.btn-link { font-size: 0.8rem; color: var(--blue); text-decoration: none; font-weight: 700; }
.btn-link:hover { text-decoration: underline; }

/* ── Badges ── */
.badge {
  display: inline-block; padding: 0.18rem 0.6rem;
  border-radius: 20px; font-size: 0.7rem; font-weight: 700;
}
.badge-green   { background: rgba(34,197,94,0.15);   color: var(--green); }
.badge-red     { background: rgba(239,68,68,0.15);    color: var(--red); }
.badge-yellow  { background: rgba(250,204,21,0.15);   color: var(--yellow); }
.badge-blue    { background: rgba(59,130,246,0.15);   color: var(--blue); }
.badge-orange  { background: rgba(249,115,22,0.15);   color: var(--orange); }
.badge-gray    { background: rgba(100,116,139,0.15);  color: var(--muted); }
.badge-purple  { background: rgba(168,85,247,0.15);   color: var(--purple); }

/* ── Utilities ── */
.muted    { color: var(--muted); }
.bold     { font-weight: 700; }
.green    { color: var(--green); }
.red      { color: var(--red); }
.blue     { color: var(--blue); }
.orange   { color: var(--orange); }
.center   { text-align: center; }
.hidden   { display: none !important; }
.actions  { display: flex; gap: 0.35rem; align-items: center; flex-wrap: nowrap; justify-content: flex-end; }
td.actions { vertical-align: middle; white-space: nowrap; }
th:last-child, td:last-child { text-align: center; }
.empty    { color: var(--muted); padding: 2rem; display: block; text-align: center; }

.alert { padding: 0.85rem 1.25rem; border-radius: 10px; margin-bottom: 1.25rem; font-weight: 600; font-size: 0.9rem; }
.alert-error   { background: rgba(239,68,68,0.12);  color: var(--red);   border: 1px solid rgba(239,68,68,0.25); }
.alert-success { background: rgba(34,197,94,0.12);  color: var(--green); border: 1px solid rgba(34,197,94,0.25); }

/* ── Sidebar footer ── */
.sidebar-footer {
  margin-top: auto; display: flex; flex-direction: column; gap: 0.5rem;
  border-top: 1px solid var(--border); padding-top: 1rem;
}
.sidebar-user {
  display: flex; align-items: center; gap: 0.6rem;
  font-size: 0.82rem; color: var(--muted); padding: 0 0.4rem;
}
.btn-logout {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.6rem 0.85rem; border-radius: 10px;
  background: none; border: 1px solid var(--border); color: var(--muted);
  cursor: pointer; font-size: 0.88rem; font-weight: 600; font-family: 'Almarai', sans-serif;
  width: 100%; transition: background 0.15s, color 0.15s;
}
.btn-logout:hover { background: rgba(239,68,68,0.1); color: var(--red); border-color: var(--red); }

/* ── Detail page ── */
.detail-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; align-items: start;
}
.detail-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem;
}
.detail-box h3 { font-size: 0.82rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 1rem; }
.detail-row { display: flex; justify-content: space-between; padding: 0.55rem 0; border-bottom: 1px solid var(--border); font-size: 0.85rem; gap: 1rem; }
.detail-row:last-child { border-bottom: none; }
.detail-key { color: var(--muted); font-weight: 600; flex-shrink: 0; }
.detail-val { font-weight: 700; text-align: left; word-break: break-word; }

.doc-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.6rem; margin-top: 0.5rem; }
.doc-card {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; padding: 0.75rem; display: flex; flex-direction: column; gap: 0.4rem;
}
.doc-card img { width: 100%; border-radius: 8px; object-fit: cover; max-height: 130px; cursor: zoom-in; }
.doc-type { font-size: 0.72rem; color: var(--muted); font-weight: 700; text-transform: uppercase; }

/* ── Modal ── */
.modal-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.65); backdrop-filter: blur(4px);
  z-index: 500; align-items: center; justify-content: center; padding: 1rem;
}
.modal-backdrop.open { display: flex; animation: fadeIn 0.15s ease; }
.modal-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 1.75rem; width: 100%; max-width: 420px;
  display: flex; flex-direction: column; align-items: center; gap: 0.85rem;
  text-align: center; animation: slideUp 0.2s ease; box-shadow: 0 24px 60px rgba(0,0,0,0.5);
}
.modal-icon { width: 48px; height: 48px; background: rgba(239,68,68,0.12); border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--red); }
.modal-icon .lucide { width: 22px; height: 22px; }
.modal-icon.green-icon { background: rgba(34,197,94,0.12); color: var(--green); }
.modal-title { font-size: 1.05rem; font-weight: 800; }
.modal-msg   { color: var(--muted); font-size: 0.88rem; line-height: 1.7; width: 100%; }
.modal-actions { display: flex; gap: 0.75rem; margin-top: 0.5rem; width: 100%; }
.modal-actions .btn { flex: 1; justify-content: center; }

@keyframes fadeIn  { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideUp { from { transform: translateY(14px); opacity: 0 } to { transform: translateY(0); opacity: 1 } }

/* ── Login ── */
.login-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; width: 100%; background: var(--bg);
}
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 2.5rem 2rem; width: 100%; max-width: 420px;
}
.login-logo { display: flex; align-items: center; justify-content: center; gap: 0.6rem; margin-bottom: 1.75rem; }
.login-logo .lucide { width: 28px; height: 28px; color: var(--blue); }
.login-logo span { font-size: 1.4rem; font-weight: 800; }

/* ── Fare rates ── */
.rate-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem;
}
.rate-card h3 { font-weight: 700; margin-bottom: 1.1rem; display: flex; align-items: center; gap: 0.5rem; }

/* ════════════════════════════════════════
   RESPONSIVE
════════════════════════════════════════ */

/* Large desktop — 5 columns if room */
@media (min-width: 1400px) {
  .cards-grid { grid-template-columns: repeat(4, 1fr); }
}

/* Medium desktop */
@media (max-width: 1200px) {
  .cards-grid { grid-template-columns: repeat(2, 1fr); }
  .content { padding: 1.25rem 1.5rem; }
}

/* Tablet landscape */
@media (max-width: 1024px) {
  :root { --sidebar: 220px; }
  .charts-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .recent-split { grid-template-columns: 1fr !important; }
}

/* Tablet portrait */
@media (max-width: 768px) {
  :root { --sidebar: 240px; }

  /* Sidebar slides off-screen */
  .sidebar { transform: translateX(100%); box-shadow: -4px 0 30px rgba(0,0,0,0.5); }
  .sidebar.open { transform: translateX(0); }
  .overlay.open { display: block; }
  .menu-toggle { display: flex; }

  /* Content fills full width */
  .content {
    margin-right: 0;
    padding: 1rem;
    padding-top: calc(var(--topbar) + 0.25rem);
  }

  .cards-grid { grid-template-columns: repeat(2, 1fr); gap: 0.6rem; }
  .card { padding: 0.85rem; gap: 0.65rem; }
  .card-value { font-size: 1.35rem; }
  .card-icon { width: 38px; height: 38px; border-radius: 10px; }

  .charts-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .recent-split { grid-template-columns: 1fr !important; }

  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-bar input,
  .filter-bar select { width: 100%; }

  .form-grid { grid-template-columns: 1fr; }
  .doc-grid { grid-template-columns: repeat(2, 1fr); }

  .page-header { flex-direction: column; gap: 0.75rem; }
  .page-header > div:last-child { flex-wrap: wrap; }

  th, td { padding: 0.55rem 0.65rem; font-size: 0.8rem; }

  table { min-width: 480px; }
}

/* Phone */
@media (max-width: 480px) {
  .cards-grid { grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
  .card { padding: 0.75rem 0.7rem; gap: 0.5rem; }
  .card-value { font-size: 1.2rem; }
  .card-icon { width: 34px; height: 34px; border-radius: 8px; }
  .card-icon .lucide { width: 16px; height: 16px; }
  .card-label { font-size: 0.67rem; }
  .card-sub { font-size: 0.67rem; }

  .page-header h1 { font-size: 1.25rem; }
  .doc-grid { grid-template-columns: 1fr; }
  .detail-box { padding: 1rem; }

  .btn { padding: 0.5rem 0.85rem; font-size: 0.82rem; }
  .btn-sm { padding: 0.25rem 0.5rem; font-size: 0.68rem; }
}

/* Very small phones */
@media (max-width: 360px) {
  .cards-grid { grid-template-columns: 1fr; }
}
