:root {
  --gold: #D9A76A;
  --green: #51C56D;
  --mustard: #C59A00;
  --orange: #EC7016;
  --red: #E64823;
  --mauve: #9C6A6A;
  --blue: #2998E3;
  --olive: #7F723D;

  --oil: var(--green);
  --water: var(--blue);
  --gas: var(--red);

  --ink: #1d1d1f;
  --ink-2: #55565b;
  --ink-3: #8a8b90;
  --line: #e3e1dc;
  --bg: #ffffff;
  --bg-2: #f7f5f1;
  --focus: #2998E3;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: Calibri, Carlito, "Segoe UI", -apple-system, BlinkMacSystemFont, Helvetica, Arial, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: 10px 16px calc(0px) 16px;
  padding-top: max(10px, env(safe-area-inset-top));
}
.topbar-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand img { height: 40px; width: auto; }
.brand .title { font-weight: 700; font-size: 19px; letter-spacing: .2px; }
.brand .sub { font-size: 13px; color: var(--ink-3); }
.well-pick select { min-width: 220px; }
.who { display: flex; align-items: center; gap: 8px; font-size: 15px; color: var(--ink-2); }
.chip {
  display: inline-block; font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .5px; padding: 2px 8px; border-radius: 999px; background: var(--bg-2);
  color: var(--ink-2); border: 1px solid var(--line);
}
.chip.admin { background: #fbf1e3; color: #8a5a17; border-color: #ecd4ac; }
.chip.operator { background: #e8f4fc; color: #1a6aa3; border-color: #bcdcf3; }

.tabs { display: flex; gap: 2px; margin-top: 10px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tab {
  border: 0; background: none; padding: 10px 14px 12px; cursor: pointer;
  color: var(--ink-2); font-weight: 600; border-bottom: 3px solid transparent; white-space: nowrap;
}
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--gold); }

/* ---------- layout ---------- */
main { max-width: 1100px; margin: 0 auto; padding: 18px 16px 80px; }
h1 { font-size: 24px; margin: 0 0 4px; }
h2 {
  font-size: 18px; margin: 0 0 12px; padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}
.lede { color: var(--ink-2); margin: 0 0 16px; }
.card {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px; background: var(--bg);
}
.grid { display: grid; gap: 12px 14px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.grid.wide { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

label.f { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--ink-2); font-weight: 600; }
label.f .unit { font-weight: 400; color: var(--ink-3); }
input, select, textarea {
  min-height: 46px; padding: 9px 12px; border: 1px solid #cfccc5; border-radius: 8px;
  background: #fff; font-size: 18px; width: 100%;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 35%, transparent); outline-offset: 1px;
  border-color: var(--focus);
}
input[disabled], select[disabled], textarea[disabled] { background: var(--bg-2); color: var(--ink-2); }
.calc { font-size: 14px; color: var(--ink-2); margin-top: 2px; min-height: 18px; }
.calc b { color: var(--ink); }

.btn {
  min-height: 46px; padding: 10px 18px; border-radius: 8px; border: 1px solid #cfccc5;
  background: #fff; cursor: pointer; font-weight: 600;
}
.btn.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn.primary:hover { background: #1f86cd; }
.btn.danger { color: var(--red); border-color: #f0b9ab; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 15px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }

.notice { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 15px; }
.notice.info { background: #eef6fd; border: 1px solid #c6e1f6; }
.notice.warn { background: #fff6e8; border: 1px solid #f1d6a7; }
.notice.err { background: #fdeeea; border: 1px solid #f3c2b5; color: #8f2a12; }

/* tank cards */
.tank-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.tank {
  border: 1px solid var(--line); border-left: 5px solid var(--oil); border-radius: 8px; padding: 12px;
}
.tank.water { border-left-color: var(--water); }
.tank h3 { margin: 0 0 8px; font-size: 16px; display: flex; justify-content: space-between; }
.tank h3 span { font-weight: 400; color: var(--ink-3); font-size: 14px; }
.fill { height: 10px; background: var(--bg-2); border-radius: 4px; overflow: hidden; margin-top: 8px; display: flex; }
.fill > .dead { height: 100%; background: #c9c6bf; }
.fill > .lvl { height: 100%; background: var(--oil); }
.tank.water .fill > .lvl { background: var(--water); }

/* haul rows */
.haul {
  display: grid; gap: 8px; grid-template-columns: 1.2fr 1fr 1fr 1fr 0.8fr 0.8fr auto;
  align-items: end; padding: 8px 0; border-bottom: 1px dashed var(--line);
}
@media (max-width: 820px) {
  .haul { grid-template-columns: 1fr 1fr; }
}

/* tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 15px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th { background: var(--bg-2); font-weight: 700; position: sticky; top: 0; }
td.l, th.l { text-align: left; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #fbfaf7; }
.flag { color: var(--orange); font-weight: 700; }
.muted { color: var(--ink-3); }
.oil { color: #2e9a4a; } .water { color: #1f7fc2; } .gas { color: #c23716; }

/* kpis */
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); margin-bottom: 16px; }
.kpi { border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.kpi .k { font-size: 13px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .4px; }
.kpi .v { font-size: 26px; font-weight: 700; }
.kpi .v small { font-size: 14px; font-weight: 400; color: var(--ink-3); }
.kpi.oil { border-top: 4px solid var(--oil); }
.kpi.water { border-top: 4px solid var(--water); }
.kpi.gas { border-top: 4px solid var(--gas); }

.chart { width: 100%; height: 300px; }
.legend { display: flex; gap: 16px; font-size: 14px; color: var(--ink-2); margin-top: 6px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 14px; height: 3px; vertical-align: middle; margin-right: 6px; }

/* login */
.auth { max-width: 420px; margin: 8vh auto; padding: 0 16px; }
.auth .logo { display: block; margin: 0 auto 10px; height: 120px; }
.auth h1 { text-align: center; }
.auth .lede { text-align: center; }
.auth form { display: flex; flex-direction: column; gap: 12px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 8px;
  opacity: 0; transition: all .2s; pointer-events: none; max-width: 90vw; font-size: 16px;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: #a8321a; }

.stickybar {
  position: sticky; bottom: 0; background: rgba(255,255,255,.96); border-top: 1px solid var(--line);
  padding: 12px 0 max(12px, env(safe-area-inset-bottom)); margin-top: 8px;
}
.pill-ro { font-size: 13px; color: var(--ink-3); font-weight: 400; margin-left: 8px; }

td input, td select { min-width: 130px; min-height: 40px; font-size: 16px; }
td input[inputmode="decimal"] { min-width: 95px; }

.kpi.eff { border-top: 4px solid var(--olive); }
