:root {
  --teal: #0d5f6e;
  --teal-dark: #0a4a56;
  --orange: #f2994a;
  --orange-dark: #e08838;
  --bg: #f4f6f8;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-faint: #94a3b8;
  --danger: #dc2626;
  --success: #16a34a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15,23,42,0.06), 0 1px 6px rgba(15,23,42,0.05);
  --shadow-hover: 0 4px 14px rgba(15,23,42,0.10);
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Login page ---------- */
body.loginBody {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--teal-dark), var(--teal));
  padding: 16px;
}
.card {
  background: var(--card); border-radius: 16px; padding: 36px 32px; width: 100%; max-width: 340px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.card h1 { font-size: 20px; margin: 0 0 2px; color: var(--teal-dark); font-weight: 700; }
.card p.sub { font-size: 13px; color: var(--text-muted); margin: 0 0 24px; }
.card label { font-size: 13px; color: var(--text); font-weight: 500; display: block; margin-bottom: 6px; }
.card input {
  width: 100%; padding: 11px 12px; margin-bottom: 16px; border: 1.5px solid var(--border);
  border-radius: 8px; font-size: 14px; transition: border-color 0.15s;
}
.card input:focus { outline: none; border-color: var(--teal); }
.card button {
  width: 100%; padding: 12px; background: var(--teal); color: #fff; border: none;
  border-radius: 8px; font-size: 14px; cursor: pointer; font-weight: 600; transition: background 0.15s;
}
.card button:hover { background: var(--teal-dark); }
.card button:disabled { opacity: 0.6; cursor: not-allowed; }
.error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 16px; }

/* ---------- Header ---------- */
header {
  background: linear-gradient(135deg, var(--teal-dark), var(--teal));
  color: #fff; padding: 16px 24px;
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}
header h1 { font-size: 17px; margin: 0; font-weight: 600; letter-spacing: 0.01em; }
.headerActions { display: flex; gap: 8px; flex-wrap: wrap; }
.headerActions button, .headerActions a {
  background: var(--orange); color: #fff; border: none; padding: 8px 16px;
  border-radius: 7px; font-size: 13px; cursor: pointer; font-weight: 600;
  text-decoration: none; display: inline-block; transition: background 0.15s, transform 0.1s;
}
.headerActions button:hover, .headerActions a:hover { background: var(--orange-dark); }
.headerActions button:active, .headerActions a:active { transform: scale(0.97); }

/* ---------- Page layout ---------- */
main { padding: 24px; max-width: 1100px; margin: 0 auto; }
.backLink {
  display: inline-flex; align-items: center; gap: 4px; margin-bottom: 16px;
  color: var(--teal); font-size: 13px; text-decoration: none; font-weight: 600;
}
.backLink:hover { text-decoration: underline; }

/* ---------- Card-grid dashboard ---------- */
.sectionTitle {
  font-size: 12px; color: var(--text-muted); font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; margin: 28px 0 12px;
}
.sectionTitle:first-child { margin-top: 0; }
.cardGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.dashCard {
  background: var(--card); border-radius: var(--radius); padding: 26px 16px; text-align: center;
  box-shadow: var(--shadow); cursor: pointer; text-decoration: none;
  color: var(--teal-dark); font-weight: 600; font-size: 14px; border: 1px solid var(--border);
  transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s;
}
.dashCard:hover { transform: translateY(-3px); box-shadow: var(--shadow-hover); border-color: var(--teal); }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; align-items: center; flex-wrap: wrap; }
.toolbar input, .toolbar select {
  padding: 9px 11px; border: 1.5px solid var(--border); border-radius: 8px; font-size: 13px;
}
.toolbar button {
  padding: 9px 16px; border: none; background: var(--teal); color: #fff; border-radius: 8px;
  font-size: 13px; cursor: pointer; font-weight: 600;
}
.toolbar button:hover { background: var(--teal-dark); }

/* ---------- Tables ---------- */
.tableScroll { overflow-x: auto; border-radius: var(--radius); box-shadow: var(--shadow); }
table {
  width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow);
}
th, td { text-align: left; padding: 11px 14px; font-size: 13px; border-bottom: 1px solid var(--bg); white-space: nowrap; }
td { white-space: normal; }
th { background: #f8fafc; color: var(--text-muted); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; }
tbody tr:hover { background: #f8fafc; }
tr.alarmRow { background: #fef2f2; }
tr.alarmRow:hover { background: #fee2e2; }
.badge { padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge.ok { background: #dcfce7; color: #166534; }
.badge.bad { background: #fee2e2; color: #991b1b; }

/* ---------- Forms ---------- */
.formCard {
  background: var(--card); border-radius: var(--radius); padding: 24px; max-width: 480px;
  box-shadow: var(--shadow); border: 1px solid var(--border);
}
.formCard label { font-size: 13px; color: var(--text); font-weight: 500; display: block; margin-top: 14px; margin-bottom: 5px; }
.formCard input, .formCard select, .formCard textarea {
  width: 100%; padding: 10px 11px; border: 1.5px solid var(--border); border-radius: 8px; font-size: 14px;
  font-family: inherit; transition: border-color 0.15s;
}
.formCard input:focus, .formCard select:focus, .formCard textarea:focus { outline: none; border-color: var(--teal); }
.formCard button.submitBtn {
  margin-top: 22px; width: 100%; padding: 12px; background: var(--teal); color: #fff;
  border: none; border-radius: 8px; font-size: 14px; cursor: pointer; font-weight: 600; transition: background 0.15s;
}
.formCard button.submitBtn:hover { background: var(--teal-dark); }
.formMsg { font-size: 13px; margin-top: 12px; min-height: 18px; font-weight: 500; }
.formMsg.success { color: var(--success); }
.formMsg.error { color: var(--danger); }
.choicePrompt {
  background: #fffbeb; border: 1.5px solid #fbbf24; border-radius: 10px; padding: 14px; margin-top: 14px; font-size: 13px;
}
.choicePrompt button {
  margin-top: 10px; margin-right: 8px; padding: 8px 15px; border: none; border-radius: 7px;
  cursor: pointer; font-size: 13px; font-weight: 600;
}
.choiceOverwrite { background: #e2e8f0; color: var(--text); }
.choiceOverwrite:hover { background: #cbd5e1; }
.choiceBatch { background: var(--teal); color: #fff; }
.choiceBatch:hover { background: var(--teal-dark); }

/* ---------- Operator CM entry page ---------- */
.dateBar { background: var(--card); border-radius: var(--radius); padding: 14px; margin: 16px; display: flex; gap: 12px; align-items: center; box-shadow: var(--shadow); flex-wrap: wrap; }
.dateBar label { font-size: 13px; color: var(--text); font-weight: 500; }
.dateBar input[type=date] { padding: 8px; border: 1.5px solid var(--border); border-radius: 7px; }
#progress { font-size: 12px; color: var(--text-muted); margin-left: auto; font-weight: 600; }

.viewTabs { display: flex; gap: 6px; overflow-x: auto; padding: 0 16px 8px; margin-bottom: 4px; }
.viewTab {
  flex-shrink: 0; padding: 7px 16px; font-size: 13px; border-radius: 999px; border: 1.5px solid var(--border);
  background: var(--card); color: var(--text); cursor: pointer; font-weight: 500; transition: all 0.15s;
}
.viewTab.active { background: var(--teal); color: #fff; border-color: var(--teal); }

.yard { background: var(--card); border-radius: var(--radius); padding: 18px; min-height: 200px; margin: 0 16px 16px; box-shadow: var(--shadow); }
.grid { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; justify-content: flex-start; }
.unitBtn { background: none; border: none; padding: 0; cursor: pointer; transition: transform 0.1s; }
.unitBtn:hover { transform: translateY(-2px); }

/* Fixed row/column layout per view, built with flexbox — same structure
   on every screen size, cell size scales via flex-basis percentage
   instead of the layout reflowing based on available width. */
.fixedFlex { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.unitCell { aspect-ratio: var(--aspect, 0.7); cursor: pointer; }
.unitCell svg { width: 100%; height: 100%; display: block; }

.saveAllBar { margin: 16px; text-align: center; }
#saveAllBtn {
  background: var(--teal); color: #fff; border: none; padding: 13px 36px; border-radius: 9px;
  font-size: 14px; cursor: pointer; font-weight: 600; box-shadow: var(--shadow);
}

/* ---------- Tank-style visual report ---------- */
.gaugeGrid { display: flex; flex-wrap: wrap; gap: 22px; padding: 22px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.gaugeUnit { display: flex; flex-direction: column; align-items: center; cursor: pointer; width: 96px; transition: transform 0.1s; }
.gaugeUnit:hover { transform: translateY(-2px); }
.gaugeCode { font-size: 13px; font-weight: 700; color: var(--text); margin-top: 8px; }
.gaugeInfo { font-size: 11px; color: var(--text-muted); text-align: center; line-height: 1.4; margin-top: 2px; }
.gaugeInfo b { color: var(--teal); }

/* ---------- Modal ---------- */
.modalWrap {
  display: none; position: fixed; inset: 0; background: rgba(15,23,42,0.5);
  align-items: center; justify-content: center; z-index: 100; padding: 16px; backdrop-filter: blur(2px);
}
.modalWrap.open { display: flex; }
.modalCard {
  background: var(--card); border-radius: 14px; padding: 24px; width: 320px; max-width: 100%;
  max-height: 85vh; overflow-y: auto; box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.modalCard h2 { font-size: 17px; margin: 0 0 2px; color: var(--text); }
.modalCard .sub { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; }
.modalCard label { font-size: 13px; color: var(--text); font-weight: 500; display: block; margin-top: 12px; margin-bottom: 4px; }
.modalCard input, .modalCard select, .modalCard textarea {
  width: 100%; padding: 10px; margin-top: 4px; border: 1.5px solid var(--border); border-radius: 8px; font-size: 14px;
}
.modalCard table { box-shadow: none; margin-top: 8px; }
.lastReading { font-size: 12px; color: var(--text-faint); margin-top: 8px; }
.modalBtns { display: flex; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.modalBtns button { flex: 1; min-width: 80px; padding: 10px; border-radius: 8px; border: none; font-size: 13px; cursor: pointer; font-weight: 600; }
.btnCancel { background: #e2e8f0; color: var(--text); }
.btnCancel:hover { background: #cbd5e1; }
.btnSave { background: var(--teal); color: #fff; }
.btnSave:hover { background: var(--teal-dark); }

/* ==================== RESPONSIVE ==================== */
@media (max-width: 640px) {
  header { padding: 12px 16px; }
  header h1 { font-size: 15px; }
  .headerActions button, .headerActions a { padding: 7px 12px; font-size: 12px; }
  main { padding: 14px; }
  .cardGrid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
  .dashCard { padding: 20px 10px; font-size: 13px; }
  .formCard { padding: 18px; max-width: 100%; }
  .toolbar { gap: 8px; }
  .toolbar input, .toolbar select, .toolbar button { flex: 1; min-width: 100px; }
  table { font-size: 12px; }
  th, td { padding: 8px 10px; }
  .gaugeGrid { gap: 14px; padding: 14px; justify-content: center; }
  .gaugeUnit { width: 76px; }
  .dateBar { margin: 10px; padding: 10px; }
  .yard { margin: 0 10px 10px; padding: 12px; }
  .modalCard { width: 100%; padding: 18px; }
}
