:root {
  --bg: #f3f5f7;
  --panel: #ffffff;
  --ink: #17212b;
  --muted: #68737d;
  --line: #dce2e7;
  --accent: #223b53;
  --accent-hover: #182c40;
  --soft: #eaf0f5;
  --warn: #fff7e8;
  --warn-ink: #7a4c00;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --ok: #067647;
  --ok-bg: #ecfdf3;
}

* { box-sizing: border-box; }
html { height: 100%; overflow-y: scroll; overflow-x: hidden; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.app { max-width: 1500px; margin: auto; padding: 14px 18px 72px; }
.top, .panel, .account-bar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(20, 35, 50, .06);
}

/* Account & cloud sync bar */
.account-bar {
  padding: 10px 14px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.account-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.account-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: var(--soft);
  color: var(--accent);
}
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn); color: var(--warn-ink); }
.pill.danger { background: var(--danger-bg); color: var(--danger); }

.top {
  padding: 16px;
  display: grid;
  grid-template-columns: 1fr 120px 210px 240px;
  gap: 14px;
  align-items: end;
}
.top h1 { margin: 0; font-size: 22px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.top p { margin: 3px 0 0; color: var(--muted); }
.beta-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .07em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fcd34d;
}

/* Collapsible Common AMT Drivers accordion on Page 1 */
details.accordion {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #f9fbfc;
  overflow: hidden;
}
details.accordion summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 12px;
  font-weight: 800;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  user-select: none;
  background: var(--soft);
  color: var(--accent);
}
details.accordion summary::-webkit-details-marker { display: none; }
details.accordion summary::after {
  content: '▸';
  font-size: 12px;
  transition: transform .15s ease;
}
details.accordion[open] summary::after { transform: rotate(90deg); }
.accordion-body { padding: 12px; }
.accordion-body .field { margin-bottom: 9px; }
.accordion-body .field:last-child { margin-bottom: 0; }
.field-hint { font-size: 11px; color: var(--muted); margin-top: 2px; line-height: 1.3; }

/* Province quick-switch pill bar */
.prov-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.prov-pills button {
  border: 1px solid #cbd4dc;
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}
.prov-pills button:hover { background: #f3f6f9; }
.prov-pills button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Highlighted current bracket row */
tr.bracket-active {
  background: #eef6ff;
  font-weight: 700;
}
.toggle-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #f9fbfc;
  margin-bottom: 10px;
}
.toggle-row label {
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
  color: var(--ink);
  margin: 0;
  cursor: pointer;
}
.section-subhead {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--accent);
  margin: 14px 0 8px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.kpi-jump-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.tabs { display: flex; gap: 7px; flex-wrap: wrap; margin: 14px 0; }
.tabs button, .toggles button, .btn {
  border: 1px solid #cbd4dc;
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.tabs button:hover, .toggles button:hover, .btn:hover { background: #f6f8fa; }
.tabs button.active, .toggles button.active, .btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); border-color: #fecdca; background: var(--danger-bg); }
.btn.danger:hover { background: #fee4e2; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.page { display: none; }
.page.active { display: block; }

label {
  display: block;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: 5px;
}
select, input[type=number], input[type=text], input[type=email], input[type=password], input[type=date], textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #cbd4dc;
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}
input:read-only { background: #f3f6f8; color: var(--muted); }
input[type=checkbox] { transform: translateY(1px); }

.layout { display: grid; grid-template-columns: 330px 1fr; gap: 14px; }
.panel { padding: 14px; }
.panel h2 { font-size: 15px; margin: 0 0 12px; }
.panel h3 { font-size: 13px; margin: 18px 0 9px; }

.row { margin: 0 0 15px; }
.rowgrid { display: grid; grid-template-columns: 1fr 110px; gap: 8px; align-items: center; }
.rowgrid input[type=range] { grid-column: 1 / 3; width: 100%; }

.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.field { margin-bottom: 10px; }
.toggles { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

#plot { height: 650px; min-height: 520px; touch-action: pan-y; }
.status { font-size: 12px; color: var(--muted); margin-top: 8px; }

.cards { display: grid; grid-template-columns: repeat(4, minmax(140px, 1fr)); gap: 10px; margin-top: 14px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 11px; padding: 10px; }
.card .k { font-size: 10px; color: var(--muted); text-transform: uppercase; font-weight: 800; }
.card .v { font-size: 19px; font-weight: 800; margin-top: 3px; }

.note { margin-top: 12px; background: var(--soft); border-radius: 10px; padding: 11px; font-size: 12px; color: #43515c; }
.note.warn { background: var(--warn); color: var(--warn-ink); }
.note.danger { background: var(--danger-bg); color: var(--danger); }
.note.ok { background: var(--ok-bg); color: var(--ok); }

table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { text-align: left; border-bottom: 1px solid var(--line); padding: 8px 7px; vertical-align: middle; }
th { font-size: 10px; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; }

.vintage { display: grid; grid-template-columns: 80px 1fr 1fr; gap: 8px; align-items: center; margin: 6px 0; }
.vintage strong { font-size: 12px; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline .btn { margin-top: 4px; }
.subtle { font-size: 12px; color: var(--muted); }
.footer { font-size: 11px; color: var(--muted); margin-top: 14px; padding-bottom: 8px; }

/* Auth & Admin layouts */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 26px;
  box-shadow: 0 12px 32px rgba(20, 35, 50, .09);
}
.auth-card h1 { margin: 0 0 6px; font-size: 22px; }
.auth-card .lead { margin: 0 0 18px; color: var(--muted); font-size: 13px; }
.auth-card .btn.primary { width: 100%; padding: 10px 14px; font-size: 14px; border-radius: 10px; margin-top: 6px; }
.auth-footer { margin-top: 16px; font-size: 12px; color: var(--muted); text-align: center; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .58);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 9999;
}
.modal-backdrop.open { display: flex; }
.modal-card {
  width: 100%;
  max-width: 460px;
  background: #fff;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .25);
}
.modal-card h2 { margin: 0 0 8px; font-size: 18px; }

.link-box {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}
.link-box input {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}
.table-scroll { overflow-x: auto; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }

@media (max-width: 1000px) {
  .top { grid-template-columns: 1fr; }
  .layout { grid-template-columns: 1fr; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .grid2, .grid3 { grid-template-columns: 1fr; }
}
