/* ==========================================================================
   EQS Rental Calendar
   The interface chrome is deliberately neutral graphite and paper.
   Colour is reserved for one job only: telling you the state of a car.
   ========================================================================== */

:root {
  /* Chrome — no colour, so status colour always reads */
  --paper:      #F1F3F5;
  --surface:    #FFFFFF;
  --surface-2:  #F7F8FA;
  --line:       #DDE2E7;
  --line-soft:  #EAEDF0;
  --ink:        #131A21;
  --ink-2:      #4A5661;
  --ink-3:      #7C8993;

  /* Brand — plate blue, the colour of a UAE number plate */
  --plate:      #14417E;
  --plate-dark: #0E3160;
  --plate-tint: #E8EEF7;

  /* Status language of the fleet */
  --st-booked:      #4E6E96;
  --st-booked-bg:   #E4EBF3;
  --st-active:      #0B6E5B;
  --st-active-bg:   #DEF0EA;
  --st-overdue:     #B3282E;
  --st-overdue-bg:  #FBE3E3;
  --st-returned:    #79858F;
  --st-returned-bg: #ECEFF1;
  --st-maint:       #7A5AA6;
  --st-maint-bg:    #EDE6F6;
  --st-free:        #FFFFFF;

  --radius:    6px;
  --radius-lg: 10px;
  --shadow-sm: 0 1px 2px rgba(19,26,33,.07);
  --shadow-md: 0 4px 16px rgba(19,26,33,.10);
  --shadow-lg: 0 18px 48px rgba(19,26,33,.20);

  --font-ui:   "IBM Plex Sans Arabic", "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-data: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --cell-w: 38px;   /* one day column on the timeline */
  --row-h:  46px;
  --lane-w: 190px;  /* vehicle label column */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

body.is-locked { overflow: hidden; }

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }

a { color: var(--plate); text-decoration: none; }
a:hover { text-decoration: underline; }

.mono, .num { font-family: var(--font-data); font-variant-numeric: tabular-nums; }

:focus-visible {
  outline: 2px solid var(--plate);
  outline-offset: 2px;
  border-radius: 3px;
}

/* ---------- App bar ---------- */

.appbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--plate);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.appbar-inner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  height: 56px;
  max-width: 1600px;
  margin: 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-weight: 600;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }

.brand-mark {
  font-family: var(--font-data);
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .12em;
  background: #fff;
  color: var(--plate-dark);
  padding: 4px 7px;
  border-radius: 3px;
}

.nav {
  display: flex;
  gap: 2px;
  margin-inline-start: 10px;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }

.nav a {
  color: rgba(255,255,255,.82);
  padding: 7px 12px;
  border-radius: var(--radius);
  font-size: .9rem;
  white-space: nowrap;
}
.nav a:hover { background: rgba(255,255,255,.12); color: #fff; text-decoration: none; }
.nav a.on { background: rgba(255,255,255,.18); color: #fff; font-weight: 600; }

.appbar-right { display: flex; align-items: center; gap: 8px; }

.who {
  font-size: .82rem;
  color: rgba(255,255,255,.85);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip-btn {
  background: rgba(255,255,255,.14);
  border: 1px solid rgba(255,255,255,.22);
  color: #fff;
  border-radius: var(--radius);
  padding: 5px 10px;
  font: inherit;
  font-size: .82rem;
  cursor: pointer;
}
.chip-btn:hover { background: rgba(255,255,255,.24); text-decoration: none; color: #fff; }

.burger { display: none; }

/* ---------- Page frame ---------- */

.page {
  max-width: 1600px;
  margin: 0 auto;
  padding: 18px 16px 80px;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 8px 14px;
  font: inherit;
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
  min-height: 40px;
  transition: background .12s ease, border-color .12s ease;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--plate);
  border-color: var(--plate);
  color: #fff;
}
.btn-primary:hover { background: var(--plate-dark); border-color: var(--plate-dark); color: #fff; }

.btn-danger { color: var(--st-overdue); border-color: #E7C3C4; background: #fff; }
.btn-danger:hover { background: var(--st-overdue-bg); }

.btn-sm { padding: 5px 10px; min-height: 32px; font-size: .84rem; }
.btn-icon { padding: 6px 9px; min-height: 34px; }

/* ---------- Cards & stats ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-inline-start: 3px solid var(--ink-3);
  border-radius: var(--radius);
  padding: 11px 13px;
}
.stat b {
  display: block;
  font-family: var(--font-data);
  font-size: 1.45rem;
  font-weight: 600;
  line-height: 1.15;
}
.stat span { font-size: .78rem; color: var(--ink-2); }
.stat.s-active  { border-inline-start-color: var(--st-active); }
.stat.s-due     { border-inline-start-color: var(--st-booked); }
.stat.s-overdue { border-inline-start-color: var(--st-overdue); }
.stat.s-free    { border-inline-start-color: var(--ink-3); }

/* ---------- Timeline: the signature view ---------- */

.tl-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.tl-scroll {
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
}

.tl {
  min-width: max-content;
  position: relative;
}

.tl-row {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--line-soft);
}
.tl-row:last-child { border-bottom: 0; }

.tl-head {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}

/* Vehicle label column, pinned while the days scroll */
.tl-lane {
  position: sticky;
  inset-inline-start: 0;
  z-index: 15;
  width: var(--lane-w);
  min-width: var(--lane-w);
  background: var(--surface);
  border-inline-end: 1px solid var(--line);
  padding: 7px 11px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.tl-head .tl-lane { background: var(--surface-2); z-index: 25; }

.tl-plate {
  font-family: var(--font-data);
  font-size: .82rem;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tl-car {
  font-size: .76rem;
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tl-days { display: flex; position: relative; flex: 1; }

.tl-day {
  width: var(--cell-w);
  min-width: var(--cell-w);
  border-inline-end: 1px solid var(--line-soft);
  text-align: center;
  padding: 5px 0;
  font-family: var(--font-data);
  font-size: .74rem;
  color: var(--ink-2);
  line-height: 1.25;
}
.tl-day .dw { display: block; font-size: .62rem; color: var(--ink-3); }
.tl-day.weekend { background: #EDF0F3; }
.tl-day.is-today { background: var(--plate); color: #fff; font-weight: 600; }
.tl-day.is-today .dw { color: rgba(255,255,255,.8); }

.tl-track {
  display: flex;
  position: relative;
  flex: 1;
  min-height: var(--row-h);
}

.tl-cell {
  width: var(--cell-w);
  min-width: var(--cell-w);
  border-inline-end: 1px solid var(--line-soft);
  cursor: pointer;
}
.tl-cell.weekend { background: #F5F7F9; }
.tl-cell.is-today { box-shadow: inset 2px 0 0 var(--plate), inset -2px 0 0 var(--plate); }
.tl-cell:hover { background: var(--plate-tint); }

/* Booking bar */
.bar {
  position: absolute;
  top: 6px;
  height: calc(var(--row-h) - 12px);
  border-radius: 4px;
  padding: 0 8px;
  display: flex;
  align-items: center;
  font-size: .76rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  border: 1px solid transparent;
  z-index: 5;
  transition: filter .12s ease;
}
.bar:hover { filter: brightness(.95); z-index: 8; }

.bar.b-booked   { background: var(--st-booked-bg);   color: var(--st-booked);   border-color: var(--st-booked); }
.bar.b-active   { background: var(--st-active-bg);   color: var(--st-active);   border-color: var(--st-active); }
.bar.b-overdue  { background: var(--st-overdue-bg);  color: var(--st-overdue);  border-color: var(--st-overdue); }
.bar.b-returned { background: var(--st-returned-bg); color: var(--st-returned); border-color: var(--st-returned); }
.bar.b-maint {
  background: repeating-linear-gradient(45deg, var(--st-maint-bg), var(--st-maint-bg) 6px, #fff 6px, #fff 12px);
  color: var(--st-maint);
  border-color: var(--st-maint);
}

.bar-ext {
  font-family: var(--font-data);
  font-size: .64rem;
  margin-inline-start: 6px;
  opacity: .85;
}

/* Legend */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  font-size: .8rem;
  color: var(--ink-2);
}
.legend i {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 3px;
  margin-inline-end: 6px;
  vertical-align: -2px;
  border: 1px solid;
}
.lg-booked  { background: var(--st-booked-bg);   border-color: var(--st-booked); }
.lg-active  { background: var(--st-active-bg);   border-color: var(--st-active); }
.lg-overdue { background: var(--st-overdue-bg);  border-color: var(--st-overdue); }
.lg-maint   { background: var(--st-maint-bg);    border-color: var(--st-maint); }

.month-nav { display: flex; align-items: center; gap: 6px; }
.month-label {
  font-weight: 600;
  min-width: 140px;
  text-align: center;
  font-size: .95rem;
}

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); }

table.tbl { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.tbl th {
  text-align: start;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  font-size: .76rem;
  font-weight: 600;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}
table.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl tbody tr:hover { background: var(--surface-2); }

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 600;
  border: 1px solid;
  white-space: nowrap;
}
.p-booked   { background: var(--st-booked-bg);   color: var(--st-booked);   border-color: var(--st-booked); }
.p-active   { background: var(--st-active-bg);   color: var(--st-active);   border-color: var(--st-active); }
.p-overdue  { background: var(--st-overdue-bg);  color: var(--st-overdue);  border-color: var(--st-overdue); }
.p-returned { background: var(--st-returned-bg); color: var(--st-returned); border-color: var(--st-returned); }
.p-cancelled{ background: var(--st-returned-bg); color: var(--st-returned); border-color: var(--st-returned); }
.p-scheduled{ background: var(--st-maint-bg);    color: var(--st-maint);    border-color: var(--st-maint); }
.p-done     { background: var(--st-returned-bg); color: var(--st-returned); border-color: var(--st-returned); }

.row-actions { display: flex; gap: 6px; }

.empty {
  padding: 44px 20px;
  text-align: center;
  color: var(--ink-2);
}
.empty p { margin: 0 0 14px; }

/* ---------- Forms ---------- */

.field { margin-bottom: 13px; }
.field > label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 5px;
}
.field .hint { font-size: .76rem; color: var(--ink-3); font-weight: 400; }

input[type=text], input[type=password], input[type=date], input[type=number],
input[type=email], input[type=search], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font: inherit;
  font-size: .92rem;
  color: var(--ink);
  min-height: 42px;
}
input[type=date], input[type=number], .num-input { font-family: var(--font-data); }
textarea { min-height: 76px; resize: vertical; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--plate);
  box-shadow: 0 0 0 3px rgba(20,65,126,.14);
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 12px; }

.check { display: flex; align-items: center; gap: 8px; }
.check input { width: 18px; height: 18px; min-height: 0; }
.check label { font-size: .88rem; font-weight: 500; }

/* ---------- Searchable combo (customer picker) ---------- */

.combo { position: relative; }

.combo-input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font: inherit;
  font-size: .92rem;
  color: var(--ink);
  min-height: 42px;
}
.combo-input:focus {
  outline: none;
  border-color: var(--plate);
  box-shadow: 0 0 0 3px rgba(20,65,126,.14);
}

select.combo-hidden-select { display: none; }

.combo-list {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  inset-inline-start: 0;
  inset-inline-end: 0;
  max-height: 260px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  z-index: 60;
}
.combo-list.open { display: block; }

.combo-item {
  padding: 9px 12px;
  font-size: .88rem;
  cursor: pointer;
  border-bottom: 1px solid var(--line-soft);
}
.combo-item:last-child { border-bottom: 0; }
.combo-item:hover, .combo-item.active { background: var(--plate-tint); }

.combo-empty {
  padding: 12px;
  font-size: .84rem;
  color: var(--ink-3);
  text-align: center;
}

/* ---------- Modal ---------- */

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(19,26,33,.5);
  display: none;
  align-items: flex-start;
  justify-content: center;
  z-index: 100;
  padding: 24px 14px;
  overflow-y: auto;
}
.modal-back.open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 620px;
  margin: auto;
  animation: pop .16s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .modal { animation: none; } }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.modal-body { padding: 18px; }
.modal-foot {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  flex-wrap: wrap;
}
.modal-foot .spacer { margin-inline-end: auto; }

.x-btn {
  border: 0;
  background: transparent;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--ink-3);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius);
}
.x-btn:hover { background: var(--surface-2); color: var(--ink); }

/* Detail rows inside the booking sheet */
.dl { display: grid; grid-template-columns: 130px 1fr; gap: 7px 14px; font-size: .88rem; }
.dl dt { color: var(--ink-3); font-size: .8rem; }
.dl dd { margin: 0; font-weight: 500; }

.sub-list { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.sub-list h3 { margin-bottom: 8px; font-size: .84rem; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; }
.sub-list li { font-size: .84rem; margin-bottom: 5px; }

/* ---------- Alerts ---------- */

.alert {
  padding: 11px 14px;
  border-radius: var(--radius);
  margin-bottom: 14px;
  font-size: .88rem;
  border: 1px solid;
}
.alert-error { background: var(--st-overdue-bg); color: #7A1A1F; border-color: #E9BFC1; }
.alert-ok    { background: var(--st-active-bg);  color: #08503F; border-color: #B7DDD2; }
.alert-info  { background: var(--plate-tint);    color: var(--plate-dark); border-color: #C6D6EA; }

/* ---------- Toast ---------- */

#toast {
  position: fixed;
  bottom: 22px;
  inset-inline-start: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 11px 18px;
  border-radius: var(--radius);
  font-size: .88rem;
  box-shadow: var(--shadow-md);
  z-index: 200;
  display: none;
}
[dir=rtl] #toast { transform: translateX(50%); }
#toast.show { display: block; }

/* ---------- Sign-in ---------- */

.auth-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: var(--plate-dark);
  background-image: linear-gradient(160deg, var(--plate-dark) 0%, #0A2547 62%, #071B33 100%);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 30px 26px 26px;
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}
.auth-brand .brand-mark { background: var(--plate); color: #fff; }
.auth-title { font-size: 1.12rem; font-weight: 600; }
.auth-sub { color: var(--ink-2); font-size: .88rem; margin: 6px 0 20px; }
.auth-foot { margin-top: 18px; text-align: center; font-size: .82rem; }

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  :root { --lane-w: 132px; --cell-w: 34px; }
}

@media (max-width: 680px) {
  body { font-size: 14.5px; }
  .page { padding: 14px 11px 90px; }

  .burger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px; height: 38px;
    border: 0;
    background: rgba(255,255,255,.14);
    color: #fff;
    border-radius: var(--radius);
    cursor: pointer;
  }

  .nav {
    position: absolute;
    top: 56px;
    inset-inline-start: 0;
    inset-inline-end: 0;
    flex-direction: column;
    background: var(--plate-dark);
    padding: 6px;
    gap: 2px;
    margin: 0;
    display: none;
    box-shadow: var(--shadow-md);
    overflow: visible;
  }
  .nav.open { display: flex; }
  .nav a { padding: 11px 14px; font-size: .95rem; }

  .who { display: none; }

  .grid-2, .grid-3 { grid-template-columns: 1fr; }

  .month-label { min-width: 104px; font-size: .88rem; }

  .dl { grid-template-columns: 1fr; gap: 2px; }
  .dl dd { margin-bottom: 8px; }

  .modal-back { padding: 0; align-items: stretch; }
  .modal { max-width: none; border-radius: 0; min-height: 100%; }
  .modal-foot { border-radius: 0; position: sticky; bottom: 0; }

  /* Tables collapse into stacked cards */
  table.tbl thead { display: none; }
  table.tbl, table.tbl tbody, table.tbl tr, table.tbl td { display: block; width: 100%; }
  table.tbl tr {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    margin-bottom: 9px;
    padding: 4px 0;
    background: var(--surface);
  }
  table.tbl td { border: 0; padding: 6px 12px; display: flex; justify-content: space-between; gap: 12px; }
  table.tbl td::before {
    content: attr(data-label);
    font-size: .74rem;
    font-weight: 600;
    color: var(--ink-3);
    text-transform: uppercase;
    letter-spacing: .03em;
    flex-shrink: 0;
  }
  table.tbl td[data-label=""]::before { content: none; }
  .table-wrap { border: 0; background: transparent; }
  .row-actions { justify-content: flex-end; }
}

@media print {
  .appbar, .toolbar, .legend, .row-actions { display: none; }
  body { background: #fff; }
}