/* PowerGrid — mobile-first app styles
   Palette: pale steel page, white surfaces, steel ink, enamel-blue actions, oil colours only for oil. */

:root {
  --bg: #ecefec;
  --surface: #ffffff;
  --surface-2: #f4f6f4;
  --ink: #17232a;
  --mute: #5a6a70;
  --line: #d4dbd7;
  --accent: #1f4f7a;
  --accent-ink: #ffffff;
  --accent-soft: #e2ebf3;
  --warn: #7d5200;
  --warn-bg: #fff3d6;
  --warn-line: #f0d18f;
  --err: #b42318;
  --err-bg: #fdecea;

  --tank-body: #f3f5f3;
  --tank-stroke: #93a09b;
  --oil-hfo: #3e2814;
  --oil-lube: #b9822a;
  --oil-diesel: #cfa43a;
  --oil-waste: #5c5044;
  --oil-glow: #f2b445;
  --limit-refill: #b77900;
  --limit-over: #c2321f;

  --font-ui: "Hind Siliguri", "Nirmala UI", "Noto Sans Bengali", "Segoe UI", system-ui, sans-serif;
  --font-num: "Barlow Semi Condensed", "Hind Siliguri", "Segoe UI", system-ui, sans-serif;

  --r-xl: 24px;
  --r-lg: 18px;
  --r-md: 12px;
  --r-sm: 9px;
  --shadow: 0 1px 2px rgb(23 35 42 / 6%), 0 8px 24px -12px rgb(23 35 42 / 18%);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --bar-h: 60px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1619; --surface: #172126; --surface-2: #1c282e; --ink: #e5ecea; --mute: #93a3a9; --line: #2a3940;
    --accent: #8bb9e6; --accent-ink: #0b1d2e; --accent-soft: #1a3044;
    --warn: #f2c46b; --warn-bg: #2b2310; --warn-line: #5a4517; --err: #ff9c92; --err-bg: #34191b;
    --tank-body: #10191d; --tank-stroke: #51636a; --oil-hfo: #7a4e26; --oil-waste: #7a6c5d;
    --limit-refill: #f0b440; --limit-over: #ff7a68;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 10px 28px -14px rgb(0 0 0 / 60%);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1619; --surface: #172126; --surface-2: #1c282e; --ink: #e5ecea; --mute: #93a3a9; --line: #2a3940;
  --accent: #8bb9e6; --accent-ink: #0b1d2e; --accent-soft: #1a3044;
  --warn: #f2c46b; --warn-bg: #2b2310; --warn-line: #5a4517; --err: #ff9c92; --err-bg: #34191b;
  --tank-body: #10191d; --tank-stroke: #51636a; --oil-hfo: #7a4e26; --oil-waste: #7a6c5d;
  --limit-refill: #f0b440; --limit-over: #ff7a68;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 10px 28px -14px rgb(0 0 0 / 60%);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.55 var(--font-ui);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; letter-spacing: .01em; }

/* Language: every bilingual string is rendered twice; show the one for the current language. */
html[lang="bn"] [data-l="en"], html[lang="en"] [data-l="bn"] { display: none !important; }

@view-transition { navigation: auto; }
@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
  *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; }
}

/* ---------- App bar ---------- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  min-height: calc(var(--bar-h) + var(--safe-top));
  /* line the bar up with the 1080px content column on wide screens */
  --gutter: max(12px, calc((100vw - 1080px) / 2 + 6px));
  padding: var(--safe-top) max(var(--gutter), env(safe-area-inset-right)) 0 max(var(--gutter), env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid transparent;
  transition: border-color .2s;
  view-transition-name: appbar;
}
.appbar.is-scrolled { border-bottom-color: var(--line); }
.appbar-title { flex: 1; min-width: 0; line-height: 1.2; }
.appbar-title strong { display: block; font-size: 18px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar-title small { display: block; font-size: 12.5px; color: var(--mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-mark { width: 38px; height: 38px; flex: none; border-radius: 11px; display: block; }
.icon-btn {
  width: 42px; height: 42px; flex: none;
  display: inline-grid; place-items: center;
  border: 0; border-radius: 50%; background: transparent; color: var(--ink);
  cursor: pointer; text-decoration: none;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { background: var(--line); }
.icon-btn svg { width: 22px; height: 22px; }
.appbar-actions { display: flex; align-items: center; gap: 4px; }
.lang-switch {
  display: inline-flex; padding: 3px; gap: 2px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
}
.lang-switch button {
  border: 0; background: none; border-radius: 999px; cursor: pointer;
  padding: 3px 10px; font-size: 13px; font-weight: 600; color: var(--mute); line-height: 1.5;
}
.lang-switch button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

/* ---------- Page ---------- */
.page {
  width: 100%; max-width: 1080px; margin: 0 auto;
  padding: 8px max(16px, env(safe-area-inset-right)) calc(32px + var(--safe-bottom)) max(16px, env(safe-area-inset-left));
}

/* ---------- Home ---------- */
.plant { margin: 14px 2px 26px; }
.plant h1 { margin: 0; font-size: clamp(26px, 6.4vw, 38px); line-height: 1.15; font-weight: 700; letter-spacing: -.01em; max-width: 18ch; }
.plant p { margin: 8px 0 0; color: var(--mute); font-size: 15px; }
.tiles { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.tile {
  position: relative; display: grid; grid-template-columns: 76px 1fr; gap: 16px; align-items: center;
  padding: 18px 18px 18px 16px; min-height: 132px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl);
  color: inherit; text-decoration: none; box-shadow: var(--shadow);
  transition: transform .12s ease, border-color .15s;
}
.tile:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.tile:active { transform: scale(.985); }
.tile-art { width: 76px; height: 100px; view-transition-name: tank-art; }
.tile h2 { margin: 0 0 4px; font-size: 20px; line-height: 1.25; font-weight: 700; }
.tile p { margin: 0; color: var(--mute); font-size: 14.5px; line-height: 1.45; }
.tile-meta { display: inline-block; margin-top: 10px; font-size: 13px; font-weight: 600; color: var(--accent); }
.home-foot { margin: 28px 2px 0; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; color: var(--mute); font-size: 13.5px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 999px; cursor: pointer;
  font-weight: 600; font-size: 15px; text-decoration: none;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn svg { width: 18px; height: 18px; }
[hidden] { display: none !important; }

/* ---------- Calculator layout ---------- */
.calc {
  display: grid; gap: 14px;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "pick" "reading" "entry" "details";
}
.calc-pick { grid-area: pick; }
.calc-reading { grid-area: reading; scroll-margin-top: calc(var(--bar-h) + var(--safe-top) + 8px); }
.calc-entry { grid-area: entry; }
.calc-details { grid-area: details; }
@media (min-width: 900px) {
  .calc {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
    grid-template-areas: "pick reading" "entry reading" "details details";
    align-items: start; column-gap: 22px;
  }
  .calc-reading { position: sticky; top: calc(var(--bar-h) + var(--safe-top) + 10px); }
}

/* Tank picker */
.picker { position: relative; display: block; }
.picker-label { display: block; font-size: 13.5px; font-weight: 600; color: var(--mute); margin: 0 0 6px 4px; }
.picker select {
  min-width: 0; text-overflow: ellipsis;
  appearance: none; -webkit-appearance: none; width: 100%;
  min-height: 56px; padding: 0 48px 0 16px;
  font-size: 17px; font-weight: 600;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  cursor: pointer;
}
.picker::after {
  content: ""; position: absolute; right: 18px; bottom: 23px; width: 9px; height: 9px;
  border-right: 2px solid var(--mute); border-bottom: 2px solid var(--mute); transform: rotate(45deg);
  pointer-events: none;
}
.picker select:focus-visible { outline: 2.5px solid var(--accent); outline-offset: 1px; }

/* Mode switch */
.segmented {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin-top: 12px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px;
}
.segmented button {
  min-height: 44px; border: 0; border-radius: 10px; background: none; cursor: pointer;
  font-weight: 600; font-size: 15px; color: var(--mute);
  transition: background-color .15s, color .15s;
}
.segmented button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgb(23 35 42 / 14%); }

/* Reading panel — the hero */
.reading {
  display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 16px;
  padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl);
  box-shadow: var(--shadow);
}
.gauge { width: 92px; height: 100%; min-height: 236px; display: block; view-transition-name: tank-art; }
.gauge .oil, .gauge .level { transition: transform .5s cubic-bezier(.2, .8, .2, 1); }
.gauge text { font-family: var(--font-num); }
.reading-main { min-width: 0; display: flex; flex-direction: column; }
.reading-cap { margin: 0; font-size: 14px; color: var(--mute); font-weight: 500; }
.reading-big {
  margin: 0; font-family: var(--font-num); font-weight: 600; font-variant-numeric: tabular-nums;
  font-size: clamp(42px, 13vw, 62px); line-height: 1.02; letter-spacing: -.01em; word-break: break-word;
}
.reading-big small { font-family: var(--font-ui); font-size: 17px; font-weight: 600; color: var(--mute); margin-left: 6px; letter-spacing: 0; }
.reading-big.is-empty { color: var(--line); }
.reading-sub { margin: 2px 0 0; font-size: 14px; color: var(--mute); min-height: 1.4em; }
.rows { list-style: none; margin: 14px 0 0; padding: 0; }
.rows li { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 7px 0; border-top: 1px solid var(--line); font-size: 15px; }
.rows li span:first-child { color: var(--mute); }
.rows li span:last-child { font-family: var(--font-num); font-weight: 600; font-size: 17px; font-variant-numeric: tabular-nums; text-align: right; }
.reading-actions { margin-top: auto; padding-top: 12px; display: flex; justify-content: flex-end; }
.copy-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface-2); cursor: pointer;
  font-size: 13.5px; font-weight: 600; color: var(--ink);
}
.copy-btn svg { width: 16px; height: 16px; }
.alerts { grid-column: 1 / -1; display: grid; gap: 8px; }
.alerts:empty { display: none; }
.alert {
  display: grid; grid-template-columns: 20px 1fr; gap: 10px; align-items: start;
  padding: 10px 12px; border-radius: var(--r-md); font-size: 14px; line-height: 1.45;
  background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn-line);
}
.alert svg { width: 20px; height: 20px; margin-top: 1px; }

/* Entry card */
.entry { padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl); }
.field-label { display: block; font-weight: 600; font-size: 15px; margin: 0 0 7px; }
.field {
  display: flex; align-items: center; min-height: 64px;
  border: 1.5px solid var(--line); border-radius: var(--r-lg); background: var(--surface-2);
  transition: border-color .15s, background-color .15s;
}
.field:focus-within { border-color: var(--accent); background: var(--surface); }
.field.is-invalid { border-color: var(--err); background: var(--err-bg); }
.field input {
  flex: 1; min-width: 0; border: 0; background: none; outline: 0;
  padding: 10px 6px 10px 16px;
  font-family: var(--font-num); font-weight: 600; font-size: 30px; font-variant-numeric: tabular-nums;
}
.field input::placeholder { color: var(--mute); opacity: .55; font-weight: 500; }
.field-unit { padding: 0 16px 0 4px; color: var(--mute); font-weight: 600; font-size: 15px; white-space: nowrap; }
.field-clear { width: 40px; height: 40px; margin-right: -6px; border: 0; background: none; border-radius: 50%; color: var(--mute); cursor: pointer; display: grid; place-items: center; }
.field-clear svg { width: 18px; height: 18px; }
.field-small { min-height: 52px; }
.field-small input { font-size: 22px; }
.hint { margin: 7px 2px 0; font-size: 13.5px; color: var(--mute); }
.hint.is-error { color: var(--err); font-weight: 600; }
.entry .field-label + .field + .hint { margin-bottom: 18px; }

/* Tank details */
.details { margin-top: 6px; }
.details h2 { margin: 6px 4px 10px; font-size: 16px; font-weight: 700; }
.facts { margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr)); column-gap: 28px; }
.facts div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--line); font-size: 14.5px; }
.facts dt { color: var(--mute); display: flex; align-items: center; }
.facts dt svg { flex: none; }
.facts dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.notes { margin: 16px 0 0; padding: 0 0 0 14px; border-left: 3px solid var(--line); color: var(--mute); font-size: 13.5px; line-height: 1.55; }
.notes p { margin: 0 0 8px; }
.notes p:last-child { margin-bottom: 0; }

/* Loading + toast */
.loading { padding: 40px 0; text-align: center; color: var(--mute); }
.toast {
  position: fixed; left: 50%; bottom: calc(20px + var(--safe-bottom)); z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); padding: 11px 18px; border-radius: 999px;
  background: var(--ink); color: var(--bg); font-size: 14.5px; font-weight: 500;
  transition: opacity .2s, transform .2s;
}
.toast.is-shown { opacity: 1; transform: translate(-50%, 0); }

/* Offline / error pages */
.message-page { text-align: center; padding: 56px 12px; max-width: 46ch; margin: 0 auto; }
.message-page h1 { font-size: 24px; margin: 18px 0 8px; }
.message-page p { color: var(--mute); margin: 0 0 22px; }

/* ---------- Wide screens: bigger gauge ---------- */
@media (min-width: 900px) {
  .reading { grid-template-columns: 124px minmax(0, 1fr); gap: 22px; padding: 24px; }
  .gauge { width: 124px; min-height: 330px; }
}

/* ---------- Small phones ---------- */
@media (max-width: 380px) {
  .reading { grid-template-columns: 72px minmax(0, 1fr); gap: 12px; padding: 14px; }
  .gauge { width: 72px; min-height: 210px; }
  .lang-switch button { padding: 3px 8px; }
  .appbar-title small { display: none; }
}
