:root {
  --ink: #1c1917;
  --ink-soft: #44403c;
  --paper: #f6f1e8;
  --card: #fffcf7;
  --line: #e7e0d4;
  --amber: #c2410c;
  --amber-2: #ea580c;
  --teal: #0f766e;
  --ok: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
  --muted: #78716c;
  --shadow: 0 10px 30px rgba(28, 25, 23, 0.08);
  --nav: 64px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Sora", "Segoe UI", sans-serif;
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
}

a { color: var(--teal); text-decoration: none; }
a:hover { color: var(--amber); }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 248px;
  background: var(--ink);
  color: #f5f0e8;
  padding: 1.2rem 0.9rem 5rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  flex-shrink: 0;
}
.brand {
  display: flex;
  gap: 0.7rem;
  align-items: center;
  padding: 0.3rem 0.5rem 1.2rem;
  color: inherit;
  text-decoration: none;
}
a.brand:hover { color: #fff; }
.brand-mark {
  width: 40px; height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--amber-2), #9a3412);
  display: grid; place-items: center;
  font-weight: 700;
  overflow: hidden;
  padding: 0;
}
.brand-mark img { width: 100%; height: 100%; display: block; object-fit: cover; }
.brand small { display: block; color: #a8a29a; font-size: 0.72rem; }
.nav-link {
  display: flex; align-items: center; gap: 0.65rem;
  color: #d6d3d1; padding: 0.62rem 0.75rem; border-radius: 10px;
  margin-bottom: 0.2rem; font-size: 0.92rem;
}
.nav-link.active, .nav-link:hover { background: #292524; color: #fff; }
.nav-sec { color: #78716c; font-size: 0.7rem; letter-spacing: .08em; text-transform: uppercase; padding: 0.9rem 0.75rem 0.3rem; }

.main { flex: 1; padding: 1.1rem 1.1rem 5.5rem; min-width: 0; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 1rem; margin-bottom: 1.1rem;
}
.page-title { margin: 0; font-size: 1.35rem; letter-spacing: -0.03em; }
.page-sub { margin: 0.15rem 0 0; color: var(--muted); font-size: 0.9rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem;
  border: 0; border-radius: 10px; padding: 0.55rem 0.9rem;
  font-weight: 600; cursor: pointer; font-size: 0.9rem;
}
.btn-primary { background: var(--amber); color: #fff; }
.btn-primary:hover { background: #9a3412; color: #fff; }
.btn-ghost { background: #fff; border: 1px solid var(--line); color: var(--ink); }
.btn-teal { background: var(--teal); color: #fff; }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.8rem; }
.btn-block { width: 100%; }
.field-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; margin-bottom: 0.25rem; }
.field-head label { margin-bottom: 0; }
.modal[hidden] { display: none; }
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 1rem;
}
.modal-backdrop { position: absolute; inset: 0; background: rgba(28, 25, 23, 0.45); }
.modal-card {
  position: relative; width: min(560px, 100%); max-height: 90vh; overflow: auto;
  background: var(--card); border-radius: 16px; padding: 1.15rem 1.2rem 1.2rem;
  box-shadow: var(--shadow);
}
.modal-card-wide { width: min(780px, 100%); }
.location-block {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.9rem 0.95rem 1rem;
  margin-bottom: 0.85rem;
  background: #fff;
}
.location-block h3 { margin: 0 0 0.35rem; font-size: 1rem; }
.location-block .loc-hint { margin: 0 0 0.75rem; }
.location-block .loc-field[hidden],
.location-block [hidden] { display: none !important; }
.modal-card h3 { margin: 0 0 0.9rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }
body.modal-open { overflow: hidden; }

.grid { display: grid; gap: 0.85rem; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem;
  box-shadow: var(--shadow);
}
.stat h3 { margin: 0; font-size: 1.45rem; }
.stat p { margin: 0.2rem 0 0; color: var(--muted); font-size: 0.82rem; }
.stat.ok h3 { color: var(--ok); }
.stat.warn h3 { color: var(--warn); }
.stat.bad h3 { color: var(--bad); }

.table-wrap { overflow: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.data th { text-align: left; font-size: 0.75rem; color: var(--muted); padding: 0.55rem; border-bottom: 1px solid var(--line); }
table.data td { padding: 0.7rem 0.55rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tr:hover td { background: #faf6ef; }

.badge {
  display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px;
  font-size: 0.72rem; font-weight: 600; background: #e7e5e4; color: #44403c;
}
.badge.available, .badge.completed, .badge.closed, .badge.paid { background: #dcfce7; color: #166534; }
.badge.booked, .badge.confirmed, .badge.assigned, .badge.invoiced, .badge.quoted { background: #dbeafe; color: #1e40af; }
.badge.enquiry { background: #f3e8ff; color: #6b21a8; }
.badge.website { background: #ccfbf1; color: #0f766e; }
.badge.on_trip, .badge.in_transit, .badge.departed, .badge.loading { background: #ffedd5; color: #9a3412; }
.badge.maintenance, .badge.delayed, .badge.draft { background: #fef3c7; color: #92400e; }
.badge.off_road, .badge.cancelled, .badge.no_show { background: #fee2e2; color: #991b1b; }

.search { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.9rem; }
.search input, .search select, .form-control, .form-select, textarea.form-control {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  padding: 0.55rem 0.7rem; background: #fff; font: inherit;
}
.search input, .search select { width: auto; min-width: 160px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.85rem; }
.form-grid .full { grid-column: 1 / -1; }
.form-sec { margin: 1.2rem 0 0.35rem; font-size: 1rem; }
input[readonly], select:disabled, input:disabled {
  background: #f3eee4; color: var(--ink-soft); cursor: not-allowed;
}
.datetime-parts { display: grid; grid-template-columns: 1.25fr 0.9fr; gap: 0.5rem; }
.datetime-sub { display: block; font-size: 0.72rem; color: var(--muted); margin-bottom: 0.2rem; }
label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.25rem; }
.help { color: var(--bad); font-size: 0.8rem; }
.field { margin-bottom: 0.95rem; }
.field label { margin-bottom: 0.4rem; }
.hint { margin: 0.35rem 0 0; color: var(--muted); font-size: 0.78rem; line-height: 1.4; }
.status-form .btn { margin-top: 0.15rem; }
.status-form h3 + form { margin-top: 0.4rem; }

.bottom-nav {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0;
  background: #fff; border-top: 1px solid var(--line);
  padding: 0.35rem 0.4rem calc(0.35rem + env(safe-area-inset-bottom));
  z-index: 20;
}
.bottom-nav a {
  flex: 1; text-align: center; color: var(--muted); font-size: 0.68rem; padding: 0.25rem;
}
.bottom-nav a.active { color: var(--amber); font-weight: 700; }
.bottom-nav svg { display: block; margin: 0 auto 0.1rem; }

.login-wrap {
  min-height: 100vh; display: grid; place-items: center;
  background:
    radial-gradient(1200px 400px at 10% -10%, #fdba74, transparent),
    linear-gradient(180deg, #1c1917 0%, #292524 40%, #f6f1e8 40%);
}
.login-card { width: min(420px, 92vw); }
.login-card .lang-switch { margin: 0.85rem 0 0; }
.alert { padding: 0.7rem 0.9rem; border-radius: 10px; margin-bottom: 0.8rem; }
.alert-success { background: #dcfce7; }
.alert-error, .alert-danger { background: #fee2e2; }
.alert-warning { background: #fef3c7; }
.muted { color: var(--muted); }
.money { font-variant-numeric: tabular-nums; font-weight: 650; }
.money-input { font-variant-numeric: tabular-nums; }
.split { display: flex; justify-content: space-between; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 0.45rem 0 0.45rem 0.9rem; border-left: 2px solid var(--line); }
.user-chip { font-size: 0.82rem; color: var(--muted); }
.perm-groups { display: grid; gap: 1.1rem; margin-top: 0.75rem; }
.perm-group h4 { margin: 0 0 0.5rem; font-size: 0.92rem; }
.perm-items { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.45rem 1rem; }
.perm-item { display: flex; align-items: center; gap: 0.5rem; margin: 0; color: var(--ink); font-size: 0.88rem; cursor: pointer; }
.perm-item input { width: 16px; height: 16px; accent-color: var(--teal); flex-shrink: 0; }
@media (max-width: 720px) {
  .perm-items { grid-template-columns: 1fr; }
}

.lang-switch {
  display: flex;
  gap: 0.2rem;
  padding: 0.2rem;
  background: #292524;
  border-radius: 10px;
}
.lang-switch button {
  flex: 1;
  border: 0;
  background: transparent;
  color: #a8a29a;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 0.42rem 0.45rem;
  border-radius: 8px;
  cursor: pointer;
}
.lang-switch button:hover { color: #fff; }
.lang-switch button.active {
  background: var(--amber);
  color: #fff;
}
.lang-switch-sidebar { margin: 0 0.35rem 0.85rem; }
.lang-switch-light {
  background: #f3eee4;
  border: 1px solid var(--line);
}
.lang-switch-light button { color: var(--muted); }
.lang-switch-light button:hover { color: var(--ink); }
.lang-switch-light button.active {
  background: var(--amber);
  color: #fff;
}
.lang-switch-mobile {
  display: none;
  margin: 0 0 0.9rem auto;
  max-width: 220px;
}

.period-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem 1rem;
  align-items: flex-end;
  justify-content: space-between;
  margin: -0.25rem 0 1rem;
}
.period-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}
.period-pills a, .period-pills-label {
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 600;
}
.period-pills a:hover { color: var(--amber); border-color: var(--amber); }
.period-pills a.active, .period-pills-label.active {
  background: var(--amber);
  border-color: var(--amber);
  color: #fff;
}
.period-custom {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-end;
}
.period-custom label { margin-bottom: 0.2rem; }
.period-custom input[type="date"] {
  width: auto;
  min-width: 150px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.45rem 0.65rem;
  background: #fff;
  font: inherit;
}

@media (max-width: 980px) {
  .sidebar { display: none; }
  .bottom-nav { display: flex; }
  .lang-switch-mobile { display: flex; }
  .grid-4, .grid-3 { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .main { padding: 0.9rem 0.8rem 6rem; }
}
@media (max-width: 640px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
}
@media print {
  .sidebar, .bottom-nav, .no-print, .topbar .btn, .lang-switch { display: none !important; }
  .main { padding: 0; }
  body { background: #fff; }
}
