:root {
  --bg: #0a0a0c; --panel: #141417; --panel2: #1d1d21; --line: #2a2a30;
  --text: #f5f5f7; --muted: #8c8c94; --accent: #4aa8ff; --accent2: #2f8fff;
  --ok: #22c55e; --off: #6b6b73; --warn: #f59e0b; --bad: #ef4444;
  /* chrome surfaces that vary by theme */
  --bg-grad: #16161b; --nav-bg: rgba(12,12,14,.72); --card-hover-bg: #17171b;
}
:root[data-theme="light"] {
  --bg: #f4f6f9; --panel: #ffffff; --panel2: #eef1f5; --line: #d9dde3;
  --text: #16181d; --muted: #5f656e; --accent: #1f7ae0; --accent2: #2f8fff;
  --ok: #16a34a; --off: #94a3b8; --warn: #d97706; --bad: #dc2626;
  --bg-grad: #e7ecf3; --nav-bg: rgba(255,255,255,.78); --card-hover-bg: #f5f7fb;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: radial-gradient(1200px 600px at 50% -10%, var(--bg-grad) 0%, var(--bg) 60%);
  background-attachment: fixed; color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "SF Pro Display", Segoe UI, Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased; letter-spacing: -.01em;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topnav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; background: var(--nav-bg); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
  flex-wrap: wrap; gap: 10px;
}
.brand { font-weight: 600; color: var(--text); letter-spacing: -.02em; }
.navlinks { display: flex; align-items: center; gap: 22px; font-size: 14px; }
.navlinks a { color: var(--muted); }
.navlinks a:hover { color: var(--text); text-decoration: none; }
.navlinks .who { color: var(--muted); }
.theme-toggle {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 999px; width: 34px; height: 34px; padding: 0; font-size: 15px;
  line-height: 1; cursor: pointer; display: inline-flex; align-items: center;
  justify-content: center; transition: background .2s, border-color .2s;
}
.theme-toggle:hover { background: var(--line); }
/* show the icon for the theme you'll switch TO */
.theme-toggle .icon-dark { display: none; }
:root[data-theme="light"] .theme-toggle .icon-dark { display: inline; }
:root[data-theme="light"] .theme-toggle .icon-light { display: none; }

.container { max-width: 1040px; margin: 0 auto; padding: 32px 24px 48px; }
h1 { font-size: 30px; font-weight: 600; letter-spacing: -.025em; margin: 0 0 24px; }
h2 { font-size: 19px; font-weight: 600; letter-spacing: -.02em; margin: 30px 0 14px; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 22px; margin-bottom: 18px;
}
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }

/* Fleet summary strip */
.stat-strip {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px; margin-bottom: 28px;
}
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px;
}
.stat-num { font-size: 32px; font-weight: 600; letter-spacing: -.03em; }
.stat-of { font-size: 15px; font-weight: 500; color: var(--muted); }
.stat-lbl { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; margin-top: 4px; }
.stat-alert { border-color: rgba(239,68,68,.4); }
.stat-alert .stat-num { color: var(--bad); }

.live-note { display: flex; align-items: center; gap: 8px; font-size: 13px; margin: 18px 2px 0; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 rgba(34,197,94,.5); animation: live-pulse 2s infinite; }
@keyframes live-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(34,197,94,.5); }
  70%  { box-shadow: 0 0 0 7px rgba(34,197,94,0); }
  100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}
@media (prefers-reduced-motion: reduce) { .live-dot { animation: none; } }

a.device-card {
  display: flex; flex-direction: column; align-items: stretch;
  color: var(--text); text-decoration: none; padding: 24px 22px 20px;
  background: var(--panel); border-radius: 22px;
  transition: border-color .2s, transform .2s, box-shadow .2s, background .2s;
}
a.device-card:hover {
  text-decoration: none; border-color: #3a3a42; transform: translateY(-4px);
  background: var(--card-hover-bg); box-shadow: 0 16px 40px rgba(0,0,0,.5);
}
.device-card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.device-card h3 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: -.01em; }
.device-card .tanksvg { margin-top: 18px; margin-bottom: 14px; }
.device-card .tank-caption { margin-top: auto; }
.tank-caption { text-align: center; font-size: 13px; line-height: 1.5; margin-top: 6px; }
.tank-caption .link { color: var(--accent); }
.metrics { display: flex; flex-wrap: wrap; gap: 18px; margin: 10px 0; }
.metric .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.metric .value { font-size: 20px; font-weight: 600; }
.metric .unit { color: var(--muted); font-size: 13px; font-weight: 400; }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px;
  padding: 2px 10px; border-radius: 999px; font-weight: 600; }
.pill.online { background: rgba(34,197,94,.15); color: var(--ok); }
.pill.offline { background: rgba(100,116,139,.2); color: var(--off); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }

label { display: block; margin: 12px 0 4px; color: var(--muted); font-size: 13px; }
input, select, button {
  font: inherit; color: var(--text); background: var(--panel2);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px;
}
input, select { width: 100%; }
button, .btn {
  background: var(--accent2); color: #04293b; border: none; font-weight: 600;
  cursor: pointer; padding: 9px 16px; display: inline-block;
}
button:hover, .btn:hover { background: var(--accent); text-decoration: none; }
.btn-muted { background: var(--panel2); color: var(--text); border: 1px solid var(--line); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.inline { display: inline; }

.auth-wrap { max-width: 380px; margin: 60px auto; }
.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; }
.flash.error { background: rgba(239,68,68,.12); color: #fca5a5; border: 1px solid rgba(239,68,68,.3); }
.flash.ok { background: rgba(34,197,94,.12); color: #86efac; border: 1px solid rgba(34,197,94,.3); }
.muted { color: var(--muted); }
.token-box { font-family: ui-monospace, Menlo, monospace; background: var(--bg);
  border: 1px dashed var(--line); padding: 12px; border-radius: 8px; word-break: break-all; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.big-reading { font-size: 40px; font-weight: 700; }
.controls { display: flex; gap: 8px; margin: 8px 0 16px; }
.controls a { padding: 6px 12px; border: 1px solid var(--line); border-radius: 8px; color: var(--text); }
.controls a.active { background: var(--accent2); color: #04293b; border-color: var(--accent2); }
.ack { color: var(--ok); }

.flash.info { background: rgba(56,189,248,.1); color: #bae6fd; border: 1px solid rgba(56,189,248,.3); }

/* Diesel tank — a CSS-drawn vessel filled with "diesel" to the fuel level */
.tank { display: flex; flex-direction: column; align-items: center; margin: 6px auto 2px; }
.tank-sm { width: 128px; }
.tank-lg { width: 150px; }
.tank-glass {
  position: relative; width: 100%; aspect-ratio: 3 / 4;
  background: linear-gradient(135deg, #0b1220 0%, #16233a 100%);
  border: 2px solid var(--line); border-radius: 16px / 14px;
  overflow: hidden;
  box-shadow: inset 0 3px 12px rgba(0,0,0,.55), inset 0 -2px 6px rgba(0,0,0,.4);
}
/* glass sheen */
.tank-glass::after {
  content: ""; position: absolute; top: 0; left: 8%; width: 22%; height: 100%;
  background: linear-gradient(90deg, rgba(255,255,255,.10), rgba(255,255,255,0));
  pointer-events: none;
}
.tank-liquid {
  position: absolute; left: 0; right: 0; bottom: 0; height: 0;
  background: linear-gradient(180deg, #fbbf24 0%, #d97706 70%, #b45309 100%);
  box-shadow: 0 -2px 14px rgba(251,191,36,.45);
  transition: height .6s cubic-bezier(.4,.6,.3,1), background .4s ease, box-shadow .4s ease;
}
.level-mid .tank-liquid {
  background: linear-gradient(180deg, #fcd34d 0%, #f59e0b 70%, #d97706 100%);
}
.level-low .tank-liquid {
  background: linear-gradient(180deg, #f87171 0%, #dc2626 70%, #991b1b 100%);
  box-shadow: 0 -2px 14px rgba(248,113,113,.5);
}
.level-empty .tank-liquid { box-shadow: none; }
/* fuel surface band + gentle bob so it reads as liquid */
.tank-surface {
  position: absolute; top: -3px; left: 0; right: 0; height: 6px;
  background: rgba(255,255,255,.35); border-radius: 50%;
  animation: tank-bob 3.2s ease-in-out infinite;
}
@keyframes tank-bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(2px); } }
@media (prefers-reduced-motion: reduce) { .tank-surface { animation: none; } }
.tank-ticks { position: absolute; inset: 0; pointer-events: none; }
.tank-ticks i { position: absolute; left: 0; width: 9px; height: 1px; background: var(--muted); opacity: .45; }
.tank-ticks i:nth-child(1) { bottom: 75%; } .tank-ticks i:nth-child(2) { bottom: 50%; } .tank-ticks i:nth-child(3) { bottom: 25%; }
.tank-readout {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1px;
  text-shadow: 0 1px 4px rgba(0,0,0,.7); pointer-events: none;
}
.tank-lg .tank-pct { font-size: 30px; }
.tank-pct { font-size: 24px; font-weight: 800; line-height: 1; }
.tank-litres { font-size: 12.5px; font-weight: 600; }

/* ---- Hero tank: big 3D cylinder vessel for the dashboard ---- */
.grid-hero { grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 18px; }

/* Dashboard zone grouping — each zone is a clearly-bounded box of tank tiles:
   a filled header strip naming the zone, a bordered/shadowed body holding the
   tiles. overflow:hidden clips the header strip to the rounded corners. */
.zone-group {
  margin: 0 0 26px;
  background: var(--bg-grad); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .06);
  overflow: hidden;
}
.zone-head {
  display: flex; align-items: baseline; gap: 12px;
  margin: 0; padding: 13px 20px;
  background: var(--panel2); border-bottom: 1px solid var(--line);
}
.zone-title { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -.02em; color: var(--text); }
.zone-title::before { content: "📍 "; font-size: .9em; }
.zone-title-none { color: var(--muted); }
.zone-title-none::before { content: ""; }
.zone-count { color: var(--muted); font-size: 13px; }
/* The tiles sit inside the box body; padding here, not on the tiles. */
.zone-group .grid-hero { padding: 18px 20px 20px; }
.zone-group .grid-hero .card { margin-bottom: 0; }
.tank-hero { width: 80%; max-width: 210px; }
.tank-hero .tank-glass {
  aspect-ratio: 1 / 1.5;
  border-radius: 50% / 9%;
  /* cylinder shading: dark edges → lit centre → dark edges */
  background: linear-gradient(90deg, #070c14 0%, #142136 20%, #20304a 50%, #142136 80%, #070c14 100%);
  border: 1px solid #0a0f1a;
  box-shadow: 0 16px 34px rgba(0,0,0,.45), inset 0 2px 6px rgba(255,255,255,.05);
}
.tank-hero .tank-glass::after { display: none; }   /* cylinder gradient replaces the flat sheen */
.tank-hero .tank-liquid {
  border-radius: 0;
  /* curved-surface shading overlaid on the diesel colour */
  background: linear-gradient(90deg, rgba(0,0,0,.32) 0%, rgba(0,0,0,0) 22%, rgba(255,255,255,.14) 50%, rgba(0,0,0,0) 78%, rgba(0,0,0,.32) 100%),
              linear-gradient(180deg, #fcd34d 0%, #f59e0b 70%, #c2700a 100%);
}
.tank-hero.level-mid .tank-liquid {
  background: linear-gradient(90deg, rgba(0,0,0,.32) 0%, rgba(0,0,0,0) 22%, rgba(255,255,255,.14) 50%, rgba(0,0,0,0) 78%, rgba(0,0,0,.32) 100%),
              linear-gradient(180deg, #fbbf24 0%, #ea8c0a 70%, #b45309 100%);
}
.tank-hero.level-low .tank-liquid {
  background: linear-gradient(90deg, rgba(0,0,0,.32) 0%, rgba(0,0,0,0) 22%, rgba(255,255,255,.14) 50%, rgba(0,0,0,0) 78%, rgba(0,0,0,.32) 100%),
              linear-gradient(180deg, #f87171 0%, #dc2626 70%, #991b1b 100%);
}
/* moving sheen so the fuel looks alive */
.tank-hero .tank-liquid::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 38%, rgba(255,255,255,.10) 50%, transparent 62%);
  background-size: 220% 100%; animation: tank-sheen 7s linear infinite;
}
@keyframes tank-sheen { from { background-position: 220% 0; } to { background-position: -220% 0; } }
/* elliptical liquid surface (meniscus) */
.tank-hero .tank-surface {
  height: 16px; top: -8px; border-radius: 50%;
  background: linear-gradient(180deg, rgba(255,255,255,.6), rgba(255,255,255,.05));
  animation: tank-bob 3.6s ease-in-out infinite;
}
.tank-hero .tank-readout { gap: 2px; text-shadow: 0 2px 6px rgba(0,0,0,.85); }
.tank-hero .tank-pct { font-size: 46px; }
.tank-hero .tank-litres { font-size: 15px; }
.tank-hero .tank-ticks i { width: 11px; opacity: .35; }
@media (prefers-reduced-motion: reduce) { .tank-hero .tank-liquid::before { animation: none; } }

/* ---- Drawn SVG tank (Tesla-style) ---- */
.tanksvg { position: relative; width: 100%; margin: 0 auto; }
.tanksvg-hero { max-width: 184px; }
.tanksvg-lg   { max-width: 168px; }
.tanksvg svg { width: 100%; height: auto; display: block; overflow: visible; }

.tank-body { fill: none; stroke: #43434b; stroke-width: 2.5; }
.tank-rim  { fill: rgba(255,255,255,.025); stroke: #43434b; stroke-width: 2.5; }
.tank-leg  { fill: none; stroke: #43434b; stroke-width: 4; stroke-linecap: round; }
.tank-cappipe { fill: #1b1b1f; stroke: #43434b; stroke-width: 2; }
.tank-tick { stroke: rgba(255,255,255,.18); stroke-width: 1.5; }

.tank-fuel { transition: y .7s cubic-bezier(.33,.7,.27,1); }
.tank-surface-svg { transition: cy .7s cubic-bezier(.33,.7,.27,1), opacity .3s; transform-box: fill-box; transform-origin: center; animation: tank-bob 3.4s ease-in-out infinite; }
.level-ok  .tank-fuel { fill: #f0a92e; }
.level-mid .tank-fuel { fill: #f0a92e; }
.level-low .tank-fuel { fill: #e2554b; }
.level-empty .tank-fuel { fill: transparent; }
.tank-fuel  { fill: #f0a92e; }
.tank-surface-svg { fill: rgba(255,255,255,.45); }
.level-low .tank-surface-svg { fill: rgba(255,225,225,.5); }
.tanksvg.level-ok  { filter: drop-shadow(0 0 26px rgba(240,169,46,.18)); }
.tanksvg.level-mid { filter: drop-shadow(0 0 26px rgba(240,169,46,.16)); }
.tanksvg.level-low { filter: drop-shadow(0 0 26px rgba(226,85,75,.22)); }

.tanksvg-readout {
  position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  pointer-events: none; text-shadow: 0 2px 10px rgba(0,0,0,.8);
}
.tanksvg-pct { font-weight: 600; letter-spacing: -.04em; line-height: 1; display: flex; align-items: baseline; }
.tanksvg-hero .tanksvg-pct { font-size: 44px; }
.tanksvg-lg   .tanksvg-pct { font-size: 40px; }
.tanksvg-pct .pctsign { font-size: .5em; font-weight: 500; color: var(--muted); margin-left: 2px; }
.tanksvg-lit { font-size: 14px; color: var(--text); font-weight: 700; }
@media (prefers-reduced-motion: reduce) { .tank-surface-svg { animation: none; } }

/* Fuel-activity log */
.fuel-log td.amt { font-weight: 700; white-space: nowrap; }
.fuel-log .refill .amt { color: var(--ok); }
.fuel-log .consumption .amt { color: var(--warn); }
.fuel-log td.margin { color: var(--muted); white-space: nowrap; font-size: 13px; }
.fuel-log .evt { white-space: nowrap; }
.fuel-log .evt .ico { margin-right: 6px; }
.tag-ongoing { font-size: 11px; color: var(--accent); border: 1px solid var(--line);
  border-radius: 999px; padding: 1px 7px; margin-left: 6px; }

/* Diesel tank fuel-level gauge (legacy bar, still used as a fallback) */
.gauge { margin: 6px 0 4px; }
.gauge-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.gauge-pct { font-size: 22px; font-weight: 700; }
.gauge-bar { height: 14px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 999px; overflow: hidden; }
.gauge-fill { height: 100%; border-radius: 999px; transition: width .4s ease, background .3s ease; }
.gauge-fill.ok  { background: var(--ok); }
.gauge-fill.mid { background: var(--warn); }
.gauge-fill.low { background: var(--bad); }

/* --- Language toggle + RTL (Arabic) ------------------------------------- */
/* Nav language button — shares the theme-toggle look but sizes to its label. */
.lang-toggle {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 999px; height: 34px; min-width: 34px; padding: 0 10px;
  font-size: 13px; font-weight: 600; line-height: 1; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .2s, border-color .2s;
}
.lang-toggle:hover { background: var(--line); }
/* Language switch on the (nav-less) auth pages: top corner of the card column. */
.auth-lang { display: flex; justify-content: flex-end; margin-bottom: 8px; }

/* Right-to-left layout for Arabic. The app is mostly flexbox + gap, which
   mirrors automatically under dir="rtl"; these rules fix the exceptions and
   swap in an Arabic-capable font stack. Numbers stay Western digits. */
[dir="rtl"] body {
  font-family: "Segoe UI", Tahoma, "Noto Naskh Arabic", "Noto Sans Arabic",
    -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  letter-spacing: 0;
}
[dir="rtl"] th, [dir="rtl"] td { text-align: right; }
/* Directional spacing → logical side under RTL. */
[dir="rtl"] .tanksvg-pct .pctsign { margin-left: 0; margin-right: 2px; }
[dir="rtl"] .fuel-log .evt .ico { margin-right: 0; margin-left: 6px; }
[dir="rtl"] .tag-ongoing { margin-left: 0; margin-right: 6px; }
/* The device header status pill uses an inline margin-left:10px; neutralise it. */
[dir="rtl"] #status-pill { margin-left: 0 !important; margin-right: 10px; }
/* Zone pin marker sits before the label — keep it hugging the text in RTL. */
[dir="rtl"] .zone-title::before { content: "📍"; margin-left: 4px; }

/* --- Overview (aggregate) views ----------------------------------------- */
/* Scope switcher reuses the .controls pill row; allow wrapping for many zones. */
.scope-switch { flex-wrap: wrap; }
/* "View totals" link in each dashboard zone header, pushed to the far end
   (logical, so it flips correctly under RTL). */
.zone-link { margin-inline-start: auto; font-size: 13px; color: var(--accent); white-space: nowrap; }

/* --- Responsive / mobile ------------------------------------------------- */
/* Wide tables (fuel-activity log, etc.) scroll horizontally INSIDE their card
   on narrow screens instead of spilling past the rounded border. */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Guard: never let a stray wide child scroll the whole page sideways.
   Applied to <html> only (not <body>) so the sticky top nav keeps working. */
html { overflow-x: hidden; }

@media (max-width: 640px) {
  .container { padding: 20px 14px 40px; }
  h1 { font-size: 24px; margin-bottom: 18px; }
  h2 { font-size: 17px; margin: 24px 0 12px; }
  .card { padding: 16px; border-radius: 14px; }
  /* Tank detail header: stack the tank drawing above its readings. */
  .big-reading { font-size: 32px; }
  .metrics { gap: 20px; }
  /* Compact the activity-log cells so more fits before it needs to scroll. */
  .fuel-log th, .fuel-log td { padding: 8px 8px; font-size: 13px; }
  .fuel-log td.margin { font-size: 12px; }
  /* Nav wraps to two rows on small screens; tighten its spacing. */
  .topnav { padding: 12px 14px; }
  .navlinks { gap: 14px; }
}
