/* ==========================================================================
   Fleet manager - contemporary, mobile first.
   Palette follows the company cars: white body, Inter Cars red, charcoal.
   ========================================================================== */
:root {
  --bg: #f2f3f5;
  --surface: #ffffff;
  --ink: #1d2025;
  --muted: #6b7280;
  --line: #e3e5e9;
  --charcoal: #2c3036;
  --charcoal-2: #3b4047;
  --red: #d71920;
  --red-dark: #b3141a;
  --red-soft: #fdecec;
  --amber: #b45309;
  --amber-soft: #fff4e0;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 24, 30, .06), 0 6px 18px rgba(20, 24, 30, .07);
  --max: 1080px;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Roboto, system-ui, -apple-system, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

#root { min-height: 100vh; }

h1, h2, h3, h4, h5, h6 { margin: 0; line-height: 1.2; }
h4 { font-size: 1.35rem; }
h5 { font-size: 1.05rem; }
h6 { font-size: 1.05rem; font-weight: 600; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }

.muted { color: var(--muted); }
.small-text { font-size: .85rem; }
.red { color: var(--red); }
.warn-text { color: var(--amber); }

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 4px solid var(--red);
  box-shadow: 0 2px 10px rgba(20, 24, 30, .06);
}

.logo {
  display: block;
  height: 44px;
  width: auto;
  max-width: 55vw;
  object-fit: contain;
}

.header-user { display: flex; align-items: center; gap: 10px; min-width: 0; }

.name {
  font-size: .9rem;
  font-weight: 600;
  color: var(--charcoal);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 38vw;
}

.nav button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--charcoal);
  font: inherit;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
}
.nav button:hover { background: var(--bg); }

/* ---------- Page frame ---------- */
.site-wrapper {
  width: 100%;
  max-width: var(--max);
  margin: 0 auto;
  padding: 16px 16px 96px;
}

.wrapper { width: 100%; display: flex; flex-direction: column; align-items: center; }

/* Login: fleet photo behind the card */
.login-page {
  max-width: none;
  min-height: calc(100vh - 62px);
  padding: 32px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(180deg, rgba(29, 32, 37, .55), rgba(29, 32, 37, .78)),
    url("img/fleet.jpg") center / cover no-repeat;
}
.login-page > .wrapper { max-width: 420px; }

/* ---------- Buttons & forms ---------- */
button,
.menu-button,
.admin a,
.inquiry-menu a,
.card-wrapper > a {
  font-family: inherit;
}

.my-form button:not(.secondary):not(.danger),
.menu-button,
.card-wrapper > a,
.user button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 12px;
  background: var(--red);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .05s;
}
.my-form button:not(.secondary):not(.danger):hover,
.menu-button:hover,
.card-wrapper > a:hover,
.user button:hover { background: var(--red-dark); }
.my-form button:active, .menu-button:active { transform: translateY(1px); }

button.secondary {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--charcoal);
  font-weight: 600;
  cursor: pointer;
}
button.secondary:hover { background: var(--bg); }

button.danger {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid #f3c1c3;
  border-radius: 12px;
  background: var(--red-soft);
  color: var(--red-dark);
  font-weight: 600;
  cursor: pointer;
}

button.disabled, button:disabled { opacity: .55; cursor: not-allowed; }

.my-form {
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 24px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.my-form h4 { margin-bottom: 8px; color: var(--charcoal); }
.my-form label { font-size: .85rem; font-weight: 600; color: var(--charcoal-2); margin-top: 6px; }
.my-form button { margin-top: 14px; }

.my-form input,
.my-form select,
select {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfbfc;
  color: var(--ink);
  font: inherit;
}
.my-form input:focus,
.my-form select:focus,
select:focus {
  outline: 3px solid rgba(215, 25, 32, .18);
  border-color: var(--red);
  background: #fff;
}

.admin-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}
.admin-panel label { margin: 0 !important; }
.admin-panel input[type="checkbox"],
.my-form input[type="checkbox"] {
  width: 22px;
  min-height: 22px;
  height: 22px;
  accent-color: var(--red);
}

.form-section {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--charcoal);
}

.row-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.row-buttons button { margin-top: 0 !important; }

/* ---------- Hero (menu) ---------- */
.hero {
  display: flex;
  align-items: flex-end;
  min-height: 150px;
  margin-bottom: 18px;
  padding: 18px 20px;
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, rgba(29, 32, 37, .78), rgba(29, 32, 37, .1)),
    url("img/sandero-side.jpg") center 62% / cover no-repeat;
  box-shadow: var(--shadow);
}
.hero span { color: #fff; font-size: 1.6rem; font-weight: 700; letter-spacing: .02em; }

/* ---------- Menu ---------- */
.menu { display: grid; gap: 16px; align-items: start; }
.menu.solo { max-width: 460px; margin: 0 auto; }

.admin {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.admin a,
.inquiry-menu a {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 72px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--charcoal);
  font-weight: 600;
  text-align: center;
  box-shadow: var(--shadow);
  border-left: 5px solid var(--red);
  transition: transform .1s, box-shadow .15s;
}
.admin a:hover, .inquiry-menu a:hover { transform: translateY(-2px); }

.user {
  padding: 20px;
  border-radius: var(--radius);
  background: var(--charcoal);
  color: #fff;
}
.user form { display: flex; flex-direction: column; gap: 12px; }
.user select { background: #fff; }
.car-loading { display: flex; align-items: center; gap: 10px; color: #fff; }

.car-menu { display: flex; flex-direction: column; gap: 14px; max-width: 460px; width: 100%; }
.car-actions { grid-template-columns: 1fr !important; }
.car-menu h4, .car-menu h5, .car-menu h3 { color: var(--charcoal); text-align: center; }

.inquiry-menu {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.inquiry-menu h4 { margin-bottom: 4px; color: var(--charcoal); }

/* ---------- Lists (drivers, cars) ---------- */
.table { display: grid; grid-template-columns: 1fr; gap: 10px; align-items: stretch; }

.driver {
  position: relative;
  display: flex;
  align-items: stretch;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.driver > a {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 52px 14px 16px;
  min-width: 0;
}
.driver.special { border-left: 5px solid var(--charcoal); }
.driver-name { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.driver.special .driver-name h6:last-child { font-size: .75rem; font-weight: 600; color: var(--muted); text-transform: uppercase; }

.driver-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.car-row .driver-stats { grid-template-columns: 1fr 1fr; }
.driver-stats > span {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: .75rem;
  color: var(--muted);
}
.driver-stats > span > strong { font-size: 1.05rem; color: var(--ink); }
.consumption-line { display: block; font-size: .85rem; font-weight: 600; }

.delete {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg);
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
}
.delete:hover { background: var(--red-soft); color: var(--red); }
.driver .loader-container { position: absolute; top: 10px; right: 10px; }

/* ---------- Details ---------- */
.details-wrapper { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.card-wrapper {
  width: 100%;
  max-width: 720px;
  padding: 18px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-name { padding-bottom: 12px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
.card-name h4 { color: var(--charcoal); }
.card-data {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.card-data p:first-child { color: var(--muted); }
.card-data p:last-child { text-align: right; font-weight: 600; }
.card-wrapper > a { margin-top: 16px; width: 100%; }

summary { cursor: pointer; font-weight: 600; min-height: 32px; display: flex; align-items: center; }
.history-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.history-item { padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: #fbfbfc; }
.history-item > summary { font-weight: 600; }
.history-details { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; font-size: .92rem; }
.log-head { display: flex; justify-content: space-between; gap: 8px; }
.log-head span { color: var(--muted); font-size: .85rem; }
.log-edit { box-shadow: none; padding: 0; margin-top: 6px; max-width: none; background: transparent; }

/* ---------- Dashboard ---------- */
.dashboard { display: flex; flex-direction: column; gap: 16px; }
.dashboard h4 { color: var(--charcoal); }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border-top: 4px solid var(--red);
}
.tile span { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tile strong { font-size: 1.35rem; color: var(--charcoal); }
.panel { padding: 16px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel h5 { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; color: var(--charcoal); }
.badge {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: .78rem;
}
.alert-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.alert-list li {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg);
  border-left: 4px solid var(--charcoal-2);
  font-size: .92rem;
}
.alert-list li a { font-weight: 700; }
.alert-list li.warn { background: var(--amber-soft); border-left-color: var(--amber); }
.alert-list li.danger { background: var(--red-soft); border-left-color: var(--red); }

/* ---------- Modals (entry forms, errors, loaders) ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  background: rgba(20, 24, 30, .6);
  backdrop-filter: blur(2px);
  overflow-y: auto;
}
.car-modal .my-form { max-width: 460px; }
.close-div { width: 100%; max-width: 460px; display: flex; justify-content: flex-end; }
.close {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #fff;
  color: var(--charcoal);
  font-weight: 700;
  cursor: pointer;
}
.modal-content {
  width: 100%;
  max-width: 420px;
  padding: 18px 20px 24px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}
.modal-content .close-div { margin-bottom: 4px; }
.modal-logo { display: block; height: 44px; margin: 0 auto 12px; object-fit: contain; }
.modal-message { font-size: 1.02rem; color: var(--ink); }

.time-stamp { display: flex; gap: 8px; margin: 0 0 6px; padding: 0; border: 0; }
.time-stamp > div { flex: 1; }
.select { position: absolute; opacity: 0; pointer-events: none; }
.time-stamp label {
  display: flex !important;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  margin: 0 !important;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfbfc;
  text-align: center;
  cursor: pointer;
}
.time-stamp label.checked { background: var(--charcoal); border-color: var(--charcoal); color: #fff; }
.refuel { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.refuel label { margin: 0; }
.refuel input { max-width: 150px; }
.km { max-width: none; }
.calendar { width: 100%; }

/* ---------- Loaders ---------- */
.loader {
  width: 48px;
  height: 48px;
  border: 5px solid rgba(255, 255, 255, .35);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
.loader.small { width: 22px; height: 22px; border-width: 3px; border-color: var(--line); border-top-color: var(--red); }
.loader-container { display: grid; place-items: center; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Back button ---------- */
.buttons-wrapper { position: fixed; left: 16px; bottom: 16px; z-index: 30; display: flex; gap: 8px; }
.back-button {
  width: 52px;
  height: 52px;
  border: 0;
  border-radius: 50%;
  background: var(--charcoal);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(20, 24, 30, .3);
}
.back-button:hover { background: var(--red); }

/* ---------- Wider screens ---------- */
@media (min-width: 720px) {
  .site-wrapper { padding: 28px 24px 100px; }
  .logo { height: 52px; }
  .app-header { padding: 10px 28px; }
  .name { max-width: none; font-size: 1rem; }
  .hero { min-height: 200px; }
  .hero span { font-size: 2.1rem; }
  .menu { grid-template-columns: 1.4fr 1fr; gap: 24px; }
  .menu.solo { grid-template-columns: 1fr; }
  .admin { grid-template-columns: repeat(2, 1fr); }
  .table { grid-template-columns: 1fr 1fr; }
  .tiles { grid-template-columns: repeat(4, 1fr); }
  .dashboard { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
  .dashboard > h4, .dashboard > .tiles { grid-column: 1 / -1; }
  .buttons-wrapper { left: max(24px, calc((100vw - var(--max)) / 2)); bottom: 24px; }
}

@media (min-width: 1000px) {
  .table { grid-template-columns: 1fr 1fr 1fr; }
}

@media (max-width: 380px) {
  .driver-stats { grid-template-columns: 1fr 1fr; }
  .admin { grid-template-columns: 1fr; }
}

/* Edit icon on the refuel / end-km lists */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; margin-left: auto; padding: 0;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--charcoal); cursor: pointer;
}
.icon-btn:hover { background: var(--bg); color: var(--red); }
.history-item { position: relative; }
.item-actions { position: absolute; top: 8px; right: 8px; }
.edit-fields { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.edit-fields:disabled { opacity: .6; }


/* ---- v4 tweaks ---- */
.driver-stats > span { justify-content: flex-end; }
.driver-stats > span > strong { line-height: 1.15; }
.tile { justify-content: space-between; }
.fuel-lines { display: flex; flex-direction: column; gap: 4px; }
.fuel-lines strong { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: 1.05rem; }
.fuel-lines em { font-style: normal; font-weight: 500; font-size: .85rem; color: var(--muted); text-transform: capitalize; }
.admin a.small-link {
  grid-column: 1 / -1;
  justify-self: center;
  width: auto;
  min-height: 40px;
  padding: 6px 18px;
  font-size: .85rem;
  font-weight: 500;
  color: var(--muted);
  box-shadow: none;
  border: 1px solid var(--line);
  border-left: 1px solid var(--line);
  background: transparent;
}

/* Date field that always shows dd/mm/yy */
.date-field {
  position: relative; display: flex; align-items: center; gap: 8px;
  min-height: 48px; padding: 0 14px; border: 1px solid var(--line);
  border-radius: 12px; background: #fbfbfc; color: var(--ink);
}
.date-field:focus-within { outline: 3px solid rgba(215, 25, 32, .18); border-color: var(--red); background: #fff; }
.date-field .placeholder { color: var(--muted); }
.date-field span { flex: 1; }
.date-icon { color: var(--muted); flex: none; }
.date-field input[type="date"] {
  position: absolute; inset: 0; width: 100%; height: 100%; min-height: 0;
  opacity: 0; cursor: pointer; border: 0; padding: 0;
}
.date-clear {
  position: relative; z-index: 2; width: 28px; height: 28px; padding: 0;
  border: 0; border-radius: 50%; background: var(--bg); color: var(--charcoal);
  font-size: 1.1rem; line-height: 1; cursor: pointer;
}
.current-km {
  display: flex; justify-content: space-between; gap: 12px; padding: 10px 14px;
  border-radius: 12px; background: var(--bg); font-size: .95rem;
}
.current-km strong { color: var(--charcoal); }

/* "Меню" shortcut next to the back arrow */
.menu-button-link {
  height: 52px; padding: 0 20px; border: 0; border-radius: 26px;
  background: var(--red); color: #fff; font: inherit; font-weight: 700;
  cursor: pointer; box-shadow: 0 6px 18px rgba(20, 24, 30, .3);
}
.menu-button-link:hover { background: var(--red-dark); }
