/* ============================================================
   AgroElNavigator - tablet-first UI
   Big touch targets, high contrast, minimal text.
   ============================================================ */

:root {
  --green-900: #1b5e20;
  --green-700: #2e7d32;
  --green-500: #43a047;
  --green-100: #e8f5e9;
  --amber-600: #f9a825;
  --red-700:   #c62828;
  --red-100:   #ffebee;
  --blue-700:  #1565c0;
  --blue-900:  #1e3a5f;
  --ink:       #1c2321;
  --ink-soft:  #5b6660;
  --paper:     #f4f5f2;
  --card:      #ffffff;
  --line:      #d7dcd7;
  --radius:    14px;
  --shadow:    0 2px 8px rgba(0,0,0,.08);
}

* { box-sizing: border-box; }

/* The hidden attribute MUST always win. The browser's built-in
   [hidden]{display:none} is a weak UA rule that ANY author display
   (e.g. .btn's inline-flex, an inline style) silently overrides —
   which left "hidden" dialogs and buttons visible. Never remove. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--paper);
  color: var(--ink);
  font-size: 18px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

h1 { font-size: 1.6rem; margin: 0 0 16px; }
h2 { font-size: 1.25rem; margin: 24px 0 12px; }
a  { color: var(--green-700); }

/* ---------------- top bar ---------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  background: var(--green-900);
  color: #fff;
  padding: 10px 18px;
  flex-wrap: wrap;
}

/* ---------------- admin shell: sidebar + app bar ----------------
   The admin portal is its own installed app with a blue identity —
   the sidebar color is what tells Dimitris which app he is in.
   Desktop: fixed sidebar, collapsible to an icon rail (html.sb-mini).
   Phones (incl. Z Fold cover screen): off-canvas drawer (html.sb-open). */

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

.sidebar {
  width: 264px;
  flex: none;
  background: var(--blue-900);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 12px 10px calc(12px + env(safe-area-inset-bottom, 0px));
  padding-left: max(10px, env(safe-area-inset-left));
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  text-decoration: none;
  font-weight: 800;
  font-size: 1.08rem;
  line-height: 1.15;
  padding: 10px 12px;
  margin-bottom: 10px;
  white-space: nowrap;
  overflow: hidden;
}
.sidebar-brand small {
  display: block;
  font-size: .7rem;
  font-weight: 700;
  opacity: .7;
  letter-spacing: .09em;
  text-transform: uppercase;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
}
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #d5e2f3;
  text-decoration: none;
  font-weight: 600;
  padding: 12px;
  border-radius: 12px;
  white-space: nowrap;
  overflow: hidden;
}
.sidebar-nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar-nav a.active { background: var(--blue-700); color: #fff; }

.nav-ico { font-size: 1.25rem; width: 28px; text-align: center; flex: none; }

.sidebar-foot {
  border-top: 1px solid rgba(255,255,255,.16);
  margin-top: 10px;
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
a.sidebar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  padding: 10px 12px;
  border-radius: 10px;
  white-space: nowrap;
  overflow: hidden;
}
a.sidebar-user:hover { background: rgba(255,255,255,.08); }
.sidebar-logout {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  background: transparent;
  border: 1px solid rgba(255,255,255,.4);
  color: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
}
.sidebar-logout:hover { background: rgba(255,255,255,.08); }

.admin-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.appbar {
  position: sticky;
  top: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 8px 14px;
  padding-top: max(8px, env(safe-area-inset-top));
}
.appbar-burger {
  background: transparent;
  border: none;
  font-size: 1.45rem;
  line-height: 1;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--ink);
}
.appbar-burger:hover { background: #eceeec; }
.appbar-title {
  font-weight: 800;
  font-size: 1.05rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.appbar .sync-status { margin-left: auto; }
.admin-body > .main-page { width: 100%; }

/* Desktop: sticky full-height sidebar + collapsible icon rail. */
@media (min-width: 1024px) {
  .sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
    transition: width .15s ease;
  }
  .sidebar-backdrop { display: none !important; }
  html.sb-mini .sidebar { width: 68px; }
  html.sb-mini .sidebar .nav-label { display: none; }
}

/* Phones/tablets: off-canvas drawer over a backdrop. */
@media (max-width: 1023.98px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1300;
    width: min(300px, 84vw);
    transform: translateX(-105%);
    transition: transform .2s ease;
    box-shadow: 0 0 30px rgba(0,0,0,.35);
  }
  html.sb-open .sidebar { transform: translateX(0); }
  html.sb-open, html.sb-open body { overflow: hidden; }
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1250;
    background: rgba(0,0,0,.45);
  }
}

.topbar-brand {
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.15rem;
  white-space: nowrap;
}

.topbar-nav { display: flex; gap: 6px; flex-wrap: wrap; }

.topbar-nav a {
  color: #dcefdd;
  text-decoration: none;
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 600;
}

.topbar-nav a.active,
.topbar-nav a:hover { background: var(--green-700); color: #fff; }

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 14px;
}

.topbar-user { opacity: .9; font-size: .95rem; }
/* the name links to «Αλλαγή κωδικού» — keep it white, hint with dots */
a.topbar-user {
  color: #fff;
  text-decoration: underline dotted rgba(255,255,255,.55);
  text-underline-offset: 3px;
}
a.topbar-user:hover { text-decoration-style: solid; }

.logout-form { display: inline; margin: 0; }

.topbar-logout {
  color: #fff;
  background: transparent;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid rgba(255,255,255,.5);
  padding: 8px 14px;
  border-radius: 10px;
  font-weight: 600;
}

/* sync status pill */
.sync-status {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: .85rem;
  font-weight: 700;
  white-space: nowrap;
}
.sync-ok      { background: var(--green-500); color: #fff; }
.sync-pending { background: var(--amber-600); color: #fff; }
.sync-offline { background: var(--red-700);   color: #fff; }

/* ---------------- layout ---------------- */

.main-page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

/* Full-screen map pages: the body is a flex column (topbar + map area),
   so the layout stays correct no matter how many rows the topbar wraps
   into on narrow phones — no hardcoded topbar height anywhere. */
body.fullbleed {
  height: 100vh;
  /* svh = small viewport: guarantees the bottom action bar is visible
     even in a browser tab where the URL bar eats viewport height. */
  height: 100svh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
body.fullbleed .topbar { flex: none; }

.main-fullbleed {
  padding: 0;
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 760px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.muted { color: var(--ink-soft); }
.center { text-align: center; }

/* ---------------- buttons (big, for gloves) ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 52px;
  padding: 12px 22px;
  border: none;
  border-radius: var(--radius);
  background: #e4e7e4;
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}

.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary { background: var(--green-700); color: #fff; }
.btn-danger  { background: var(--red-700);   color: #fff; }
.btn-warn    { background: var(--amber-600); color: #fff; }
.btn-blue    { background: var(--blue-700);  color: #fff; }
.btn-ghost   { background: transparent; border: 2px solid var(--line); }

/* Huge buttons for the driver tablet */
.btn-big {
  width: 100%;
  min-height: 76px;
  font-size: 1.35rem;
  border-radius: 18px;
}

.btn-stack { display: flex; flex-direction: column; gap: 14px; }

/* ---------------- forms ---------------- */

label { display: block; font-weight: 600; margin: 12px 0 6px; }

input[type=text], input[type=password], input[type=number],
input[type=date], input[type=email], input[type=tel],
select, textarea {
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: #fff;
  font-size: 1.05rem;
  color: var(--ink);
}

textarea { min-height: 90px; resize: vertical; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--green-500);
}

.form-actions { margin-top: 20px; display: flex; gap: 12px; flex-wrap: wrap; }

/* stepper: [-] value [+] for width/overlap/shift adjustments */
.stepper {
  display: flex;
  align-items: stretch;
  gap: 8px;
}
.stepper button {
  min-width: 64px;
  min-height: 60px;
  font-size: 1.5rem;
  font-weight: 800;
  border: none;
  border-radius: 12px;
  background: var(--green-100);
  color: var(--green-900);
  cursor: pointer;
}
.stepper .stepper-value {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 800;
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 12px;
  min-width: 110px;
}

/* ---------------- tables (admin) ---------------- */

.table-wrap { overflow-x: auto; }

table.list {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

table.list th, table.list td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  font-size: .98rem;
}

table.list th {
  background: var(--green-100);
  color: var(--green-900);
  font-size: .9rem;
  text-transform: uppercase;
  letter-spacing: .03em;
}

table.list tr:last-child td { border-bottom: none; }

/* suspended users in the admin list */
table.list tr.row-inactive td { color: var(--ink-soft); }

/* report tables: per-customer subtotals + grand total */
table.list tr.subtotal-row td { font-weight: 700; background: #f4f8f1; }
table.list tr.total-row td {
  font-weight: 800;
  background: var(--green-100);
  border-top: 2px solid var(--green-700);
}

/* ---------------- badges ---------------- */

.badge {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: .85rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge-assigned    { background: #e3f2fd; color: var(--blue-700); }
.badge-in_progress { background: #fff8e1; color: #b26a00; }
.badge-paused      { background: #ede7f6; color: #5e35b1; }
.badge-completed   { background: var(--green-100); color: var(--green-900); }
.badge-cancelled   { background: #eceff1; color: #546e7a; }
.badge-active      { background: var(--green-100); color: var(--green-900); }
.badge-maintenance { background: #fff8e1; color: #b26a00; }
.badge-inactive    { background: #eceff1; color: #546e7a; }

/* ---------------- flash & toast ---------------- */

.flash {
  padding: 14px 18px;
  border-radius: var(--radius);
  margin-bottom: 14px;
  font-weight: 600;
}
.flash-success { background: var(--green-100); color: var(--green-900); }
.flash-error   { background: var(--red-100);   color: var(--red-700); }

#toast-container {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.toast {
  background: var(--ink);
  color: #fff;
  padding: 14px 22px;
  border-radius: 12px;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,.3);
  max-width: 90vw;
}
.toast-error   { background: var(--red-700); }
.toast-success { background: var(--green-700); }

/* ---------------- maps ---------------- */

.map-box {
  width: 100%;
  height: 380px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
}

/* The map fills whatever vertical space the action bar leaves. */
.map-full {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  z-index: 1;
}

.map-overlay {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* Info panels float over the TOP of the map only. The container is
   click-transparent — a full-width strip at z-index 1000 would swallow
   taps meant for the map and Leaflet's own controls underneath; only
   the visible panels themselves are interactive. */
.map-overlay.top {
  position: absolute;
  z-index: 1000;
  top: 12px;
  left: 12px;
  right: 12px;
  pointer-events: none;
}
.map-overlay.top > * { pointer-events: auto; }

/* Solid bar ABOVE the map (normal flow, like the bottom action bar):
   GPS accuracy pill + basemap toggle. These used to float on the map,
   covering it and blocking the controls. */
.map-topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 10px;
  padding: 8px 12px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
  position: relative;
  z-index: 2;
}
.map-topbar .gps-pill { box-shadow: none; padding: 8px 12px; }

/* Action buttons live in a SOLID bar below the map — normal page flow,
   so they can never be clipped by viewport quirks, URL bars or gesture
   zones on any screen size. */
.map-overlay.bottom {
  position: static;
  z-index: 2;
  background: var(--paper);
  border-top: 1px solid var(--line);
  box-shadow: 0 -2px 8px rgba(0,0,0,.06);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  /* the bar may never squeeze the map away entirely; if a screen is
     extremely short the bar scrolls internally instead */
  max-height: 62vh;
  overflow-y: auto;
  flex: none;
}
.map-overlay.bottom .btn-stack { flex: 1 1 100%; }

.map-panel {
  background: rgba(255,255,255,.96);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 16px;
}

/* GPS accuracy pill */
.gps-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 1.05rem;
  background: #fff;
  box-shadow: var(--shadow);
}
.gps-pill::before {
  content: "";
  width: 14px; height: 14px;
  border-radius: 50%;
  background: currentColor;
}
.gps-good { color: var(--green-700); }
.gps-med  { color: #b26a00; }
.gps-bad  { color: var(--red-700); }

/* Current-position marker: blue dot; the triangle appears and the dot
   rotates when the device reports a valid heading (map.js). */
.pos-marker { background: none; border: none; }
.pos-dot {
  position: relative;
  box-sizing: border-box;
  width: 20px;
  height: 20px;
  margin: 3px;
  border-radius: 50%;
  background: #1565c0;
  border: 3px solid #fff;
  box-shadow: 0 0 4px rgba(0,0,0,.45);
  transform-origin: 50% 50%;
}
.pos-arrow {
  position: absolute;
  left: 50%;
  top: -10px;
  margin-left: -6px;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 9px solid #1565c0;
  filter: drop-shadow(0 0 1px #fff);
}

/* «Δορυφόρος / Χάρτης» base-layer toggle (Leaflet control, map.js) */
.basemap-toggle {
  background: #fff;
  border: 2px solid rgba(0,0,0,.2);
  border-radius: 8px;
  padding: 8px 12px;
  font: inherit;
  font-size: .95rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
}

/* big stat tiles during work */
.stat-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
}
.stat-tile {
  background: rgba(255,255,255,.96);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 10px 14px;
  text-align: center;
}
.stat-tile .stat-label { font-size: .8rem; color: var(--ink-soft); font-weight: 700; text-transform: uppercase; }
.stat-tile .stat-value { font-size: 1.5rem; font-weight: 800; }

/* ---------------- AB guidance display ---------------- */

.guidance-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px;
  border-radius: 18px;
  background: rgba(255,255,255,.97);
  box-shadow: var(--shadow);
  min-width: 260px;
}

.guidance-deviation {
  font-size: 3.2rem;
  font-weight: 900;
  line-height: 1.05;
}

.guidance-instruction {
  font-size: 1.5rem;
  font-weight: 800;
}

.guidance-ok    { color: var(--green-700); }
.guidance-left  { color: var(--red-700); }
.guidance-right { color: var(--blue-700); }

.guidance-arrow { font-size: 2.6rem; line-height: 1; }

/* ---------------- misc ---------------- */

.job-card { display: block; text-decoration: none; color: inherit; }
.job-card:active { background: var(--green-100); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; }
.kv dt { font-weight: 700; color: var(--ink-soft); }
.kv dd { margin: 0; font-weight: 600; }

.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(160deg, var(--green-900), var(--green-700));
}

.login-card {
  background: #fff;
  border-radius: 20px;
  padding: 34px 30px;
  width: 100%;
  max-width: 430px;
  box-shadow: 0 10px 40px rgba(0,0,0,.35);
}

.warn-box {
  background: var(--red-100);
  color: var(--red-700);
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 700;
}

/* ---------------- phones (narrow screens) ---------------- */

/* Compact topbar so it fits one or two short rows on a phone. */
@media (max-width: 640px) {
  .topbar { padding: 6px 10px; gap: 8px; }
  .topbar-brand { font-size: 1rem; }
  .topbar-nav { gap: 4px; }
  .topbar-nav a { padding: 7px 10px; font-size: .92rem; }
  .topbar-right { gap: 8px; }
  .topbar-user { display: none; } /* the name is not worth a row on a phone */
  .topbar-logout { padding: 6px 10px; font-size: .92rem; }
  .sync-status { font-size: .72rem; padding: 4px 9px; }
}

/* Slightly smaller controls over the map so start/back stay visible
   even on short phone screens. */
@media (max-width: 480px) {
  .map-overlay .btn-big { min-height: 58px; font-size: 1.1rem; }
  .map-overlay .btn-stack { gap: 10px; }
  .map-panel { padding: 8px 12px; font-size: .95rem; }
  .stat-tile .stat-value { font-size: 1.2rem; }
  .gps-pill { font-size: .92rem; padding: 8px 12px; }
}

/* ---------------- admin on phones (Z Fold cover ≈ 344px) ----------------
   The 18px tablet-glove base is too coarse for a narrow phone: tighten
   type, cards, tables and buttons so the admin pages read as a proper
   compact dashboard instead of zoomed-in tablet UI. */

/* Dashboard stat cards: 2-up compact tiles instead of a tall single
   column (six full-width cards would fill two cover-screen heights). */
@media (max-width: 760px) {
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-grid .stat-card { padding: 12px 8px; }
  .stat-grid .stat-card .stat-num { font-size: 1.6rem; }
  .stat-grid .stat-card .muted { font-size: .82rem; }
}

@media (max-width: 640px) {
  /* Tables: tighter cells, no mid-word wrapping — .table-wrap provides
     the horizontal scroll, momentum included. */
  table.list th, table.list td { padding: 9px 10px; font-size: .9rem; white-space: nowrap; }
  .table-wrap { -webkit-overflow-scrolling: touch; }
  .card { padding: 14px 12px; }
}

@media (max-width: 480px) {
  body { font-size: 16px; }
  h1 { font-size: 1.3rem; margin-bottom: 12px; }
  h2 { font-size: 1.12rem; }
  .main-page { padding: 14px 10px 48px; }
  .btn { min-height: 46px; padding: 10px 16px; font-size: .98rem; border-radius: 12px; }
  input[type=text], input[type=password], input[type=number],
  input[type=date], input[type=email], input[type=tel],
  select, textarea { min-height: 48px; font-size: 1rem; }
  .form-actions .btn { flex: 1 1 auto; }
  /* Key-value sheets (job details): stack instead of two columns. */
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dt { margin-top: 10px; font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; }
  .kv dt:first-child { margin-top: 0; }
  .appbar { padding-left: 8px; padding-right: 10px; }
  .appbar-title { font-size: .98rem; }
  .badge { padding: 4px 10px; font-size: .78rem; }
}
