* { box-sizing: border-box; }
:root {
  --bg: #f5f7fa; --card: #ffffff; --text: #1a2233; --muted: #64748b;
  --accent: #0f766e; --accent-soft: #ccfbf1; --border: #e2e8f0;
  --danger: #b91c1c; --warn: #b45309; --ok: #15803d;
}
body { margin: 0; font-family: -apple-system, "Segoe UI", Roboto, "Noto Sans Myanmar", sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }

/* layout */
.topbar { background: #0f172a; color: #fff; display: flex; align-items: center; gap: 4px; padding: 0 12px; flex-wrap: wrap; position: sticky; top: 0; z-index: 20; }
.topbar .brand { font-weight: 700; padding: 12px 10px 12px 0; margin-right: 8px; white-space: nowrap; }
.topbar .nav { display: flex; flex: 1; min-width: 0; }
.topbar a { color: #cbd5e1; text-decoration: none; padding: 12px 10px; display: inline-block; border-bottom: 3px solid transparent; white-space: nowrap; }
.topbar a.active { color: #fff; border-bottom-color: #2dd4bf; }
.topbar .who { color: #94a3b8; padding: 12px 6px; white-space: nowrap; }
@media (max-width: 768px) {
  .topbar { flex-wrap: nowrap; }
  .topbar .nav { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .topbar .nav::-webkit-scrollbar { display: none; }
  .topbar .who { display: none; }
}
.container { max-width: 1280px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
h1 { font-size: 20px; margin: 4px 0 14px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }

/* forms */
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
input, select { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; background: #fff; color: var(--text); width: 100%; }
input:focus, select:focus { outline: 2px solid #99f6e4; border-color: var(--accent); }
.field { min-width: 140px; }
button { padding: 9px 16px; border: 0; border-radius: 8px; background: var(--accent); color: #fff; font-size: 14px; font-weight: 600; cursor: pointer; }
button:hover { filter: brightness(1.1); }
button.secondary { background: #e2e8f0; color: var(--text); }
button.danger { background: var(--danger); }
button.small { padding: 5px 10px; font-size: 12px; }

/* feeder grid */
.feeder-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin: 12px 0; }
.feeder-grid .fcode { font-weight: 600; font-size: 13px; }
.feeder-grid .flabel { font-size: 11px; color: var(--muted); min-height: 14px; margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* computed panel */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.stat { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px; }
.stat .v { font-size: 18px; font-weight: 700; }
.stat .k { font-size: 11px; color: var(--muted); }
.stat.good .v { color: var(--ok); }
.stat.bad .v { color: var(--danger); }

/* tables — .table-wrap is the scroll container in BOTH axes so sticky headers work */
.table-wrap { overflow: auto; max-height: calc(100vh - 230px); border: 1px solid var(--border); border-radius: 10px; background: #fff; }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 12.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 9px; border-bottom: 1px solid var(--border); text-align: right; }
th { background: #f1f5f9; position: sticky; top: 0; z-index: 2; height: 30px; font-size: 11.5px; color: #334155; }
td:first-child, th:first-child { text-align: left; position: sticky; left: 0; }
th:first-child { z-index: 3; background: #f1f5f9; }
td:first-child { z-index: 1; background: inherit; box-shadow: 2px 0 4px -2px rgba(0, 0, 0, 0.18); }
tr.h2 th { top: 30px; }
tbody tr { background: #fff; }
tbody tr:nth-child(even):not(.mepe):not(.empty):not(.totals) { background: #f8fafc; }
tbody tr:hover:not(.totals) { background: #f0fdfa; }
tbody tr.empty td { color: #cbd5e1; }
tbody tr.mepe { background: #fefce8; }
tr.totals { background: #f8fafc; }
tr.totals td { font-weight: 700; border-top: 2px solid #cbd5e1; }
.neg { color: var(--danger); }

/* login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-box { width: 340px; }
.login-box .card { padding: 28px; }
.login-box h1 { text-align: center; }
.login-box .field { margin-bottom: 12px; }
.login-box button { width: 100%; margin-top: 6px; }
.err { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 16px; }

/* toast */
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #0f172a; color: #fff; padding: 10px 18px; border-radius: 8px; opacity: 0; transition: opacity .25s; pointer-events: none; z-index: 50; }
#toast.show { opacity: 1; }
#toast.error { background: var(--danger); }

/* charts */
.chart-card h2 { margin-bottom: 2px; }
.chart-sub { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin: 4px 0 10px; }
.legend .li { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text); }
.legend .sw { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.chart-svg { width: 100%; height: auto; display: block; }
.chart-scroll { overflow-x: auto; }
.chart-scroll .chart-svg { min-width: 640px; }
.chart-empty { text-align: center; color: var(--muted); padding: 30px 0; }
#chart-tip { position: fixed; background: #0f172a; color: #f1f5f9; border-radius: 8px; padding: 8px 11px; font-size: 12px; pointer-events: none; opacity: 0; transition: opacity .12s; z-index: 60; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
#chart-tip .tt-title { font-weight: 700; margin-bottom: 4px; }
#chart-tip .tt-row { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
#chart-tip .sw { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
#chart-tip .tt-total { border-top: 1px solid #334155; margin-top: 5px; padding-top: 4px; font-weight: 700; }
.meters { display: grid; gap: 12px; }
.meter { display: grid; grid-template-columns: 46px 1fr 175px; gap: 10px; align-items: center; }
.meter .code { font-weight: 700; font-size: 13px; }
.meter .track { background: #f0efec; border-radius: 6px; height: 14px; overflow: hidden; }
.meter .fill { height: 100%; border-radius: 6px 4px 4px 6px; min-width: 2px; }
.meter .val { font-size: 12px; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }

/* missing-entries warning */
.warn-card { border-left: 4px solid var(--warn); background: #fffbeb; }
.missing-row { margin: 7px 0; font-size: 13px; }
.ok-note { color: var(--ok); font-size: 13px; margin: -6px 0 14px 4px; }

/* users/admin */
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; background: var(--accent-soft); color: #0f766e; margin: 1px; }
.pill.gray { background: #e2e8f0; color: #475569; }
.pill.warn { background: #fef3c7; color: #92400e; text-decoration: none; }
.pill.warn:hover { background: #fde68a; }
.checks { display: flex; gap: 10px; flex-wrap: wrap; }
.checks label { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--text); margin: 0; }
.checks input { width: auto; }
.muted { color: var(--muted); font-size: 12px; }
.bcard-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.mini-table td, .mini-table th { padding: 4px 8px; }
@media (max-width: 640px) {
  .container { padding: 10px; }
  .feeder-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  /* 16px stops iOS Safari from auto-zooming on focus */
  input, select { font-size: 16px; }
}
