/* ============================================================================
   NDIS 2026 Amendments — Legislation Comparison Tool
   Stylesheet — interactive side-rail + live-iframe NDIS Act

   Left pane is a clickable index of the bill's 96 items (rendered from
   data/bill.json). Right pane is the live NDIS Act 2013 from the Federal
   Register (epub document HTML, anchored), tabbed Original / Proposed.
   Clicking a rail item navigates the active right-pane iframe to that
   section via a #_Toc<id> deep-link.

   1. Design tokens (light + dark)      5. Tabs
   2. Reset & base                      6. Side-rail (left)
   3. App shell & header                7. Iframe frames (right)
   4. Split panes                       8. Theme toggle, utilities, responsive
   ========================================================================== */

/* 1. DESIGN TOKENS ========================================================== */
:root {
  /* surfaces */
  --bg:            #f5f5f7;
  --surface:       #ffffff;
  --surface-2:     #fbfbfd;
  --surface-3:     #f0f0f3;
  --surface-sunk:  #ececef;

  /* text */
  --text:          #1d1d1f;
  --text-2:        #515154;
  --text-3:        #86868b;

  /* lines */
  --border:        #e6e6e9;
  --border-strong: #d2d2d7;

  /* accent — indigo */
  --accent:        #4f46e5;
  --accent-hover:  #4338ca;
  --accent-text:   #ffffff;
  --accent-soft:   #eef2ff;
  --accent-ring:   rgba(79, 70, 229, 0.35);

  /* amendment-kind coding (rail dots + legend) */
  --kind-amend:      #2563eb;
  --kind-insert:     #059669;
  --kind-structural: #8e8e93;
  --kind-provision:  #7c3aed;

  /* elevation */
  --shadow-sm: 0 1px 2px rgba(0,0,0,.04), 0 1px 3px rgba(0,0,0,.06);
  --shadow-md: 0 4px 14px rgba(0,0,0,.08), 0 1px 3px rgba(0,0,0,.05);
  --shadow-lg: 0 16px 40px rgba(0,0,0,.16), 0 4px 12px rgba(0,0,0,.08);

  /* type */
  --sans:  'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --mono:  ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, monospace;

  /* geometry */
  --r-sm: 6px;  --r-md: 10px;  --r-lg: 16px;  --r-pill: 999px;
  --header-h: 60px;
  --rail-w: 360px;
  --ease: cubic-bezier(.22, .61, .36, 1);
}

[data-theme="dark"] {
  --bg:            #161617;
  --surface:       #1d1d1f;
  --surface-2:     #1f1f21;
  --surface-3:     #2a2a2c;
  --surface-sunk:  #121213;

  --text:          #f5f5f7;
  --text-2:        #a1a1a6;
  --text-3:        #6e6e73;

  --border:        #2e2e30;
  --border-strong: #424245;

  --accent:        #818cf8;
  --accent-hover:  #a5b4fc;
  --accent-text:   #16161a;
  --accent-soft:   #20203a;
  --accent-ring:   rgba(129, 140, 248, 0.4);

  --kind-amend:      #60a5fa;
  --kind-insert:     #34d399;
  --kind-structural: #98989d;
  --kind-provision:  #a78bfa;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 4px 14px rgba(0,0,0,.45);
  --shadow-lg: 0 16px 40px rgba(0,0,0,.6), 0 4px 12px rgba(0,0,0,.4);
}

/* 2. RESET & BASE =========================================================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

.theme-ready,
.theme-ready .pane,
.theme-ready .app-header,
.theme-ready .tab,
.theme-ready .rail-item,
.theme-ready .frame-wrap {
  transition: background-color .25s var(--ease), border-color .25s var(--ease),
              color .25s var(--ease), box-shadow .25s var(--ease);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font-family: inherit; font-size: inherit; color: inherit;
  background: none; border: none; cursor: pointer;
}

::selection { background: var(--accent-soft); color: var(--text); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* 3. APP SHELL & HEADER ===================================================== */
.app {
  display: grid;
  grid-template-rows: var(--header-h) 1fr;
  height: 100vh;
}

.app-header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 30;
}

.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand-mark {
  font-weight: 700; font-size: 16px; letter-spacing: -0.02em;
  color: var(--text); white-space: nowrap;
}
.brand-mark .accent { color: var(--accent); }
.brand-sub {
  font-size: 12px; color: var(--text-3); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}

.header-spacer { flex: 1; }

.legend { display: flex; gap: 14px; align-items: center; }
.legend-item {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; color: var(--text-2); white-space: nowrap;
}
.legend-dot {
  width: 8px; height: 8px; border-radius: var(--r-pill);
  background: var(--dot, var(--text-3));
}
.legend-item[data-kind="amend"]      { --dot: var(--kind-amend); }
.legend-item[data-kind="insert"]     { --dot: var(--kind-insert); }
.legend-item[data-kind="structural"] { --dot: var(--kind-structural); }
.legend-item[data-kind="provision"]  { --dot: var(--kind-provision); }

/* 4. SPLIT PANES ============================================================ */
.panes {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  gap: 14px;
  padding: 14px;
  min-height: 0;
  background: var(--bg);
}

.pane {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.pane--rail { grid-template-rows: auto 1fr auto; }

.pane-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  min-height: 52px;
  z-index: 10;
}

.pane-label {
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-3);
}
.pane-title {
  font-size: 13.5px; font-weight: 600; color: var(--text);
  letter-spacing: -0.01em;
}
.pane-meta { font-size: 11.5px; color: var(--text-3); white-space: nowrap; }
.pane-head .spacer { flex: 1; }

.pane-source {
  font-size: 11.5px; color: var(--text-3);
  display: inline-flex; align-items: center; gap: 4px;
  white-space: nowrap;
}
.pane-source:hover { color: var(--accent); }

/* 5. TABS =================================================================== */
.tabs {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  background: var(--surface-sunk);
  border-radius: var(--r-md);
}
.tab {
  padding: 6px 14px;
  font-size: 12.5px; font-weight: 550;
  color: var(--text-2);
  border-radius: 7px;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
[data-theme="dark"] .tab.is-active { background: var(--surface-3); }

/* 6. SIDE-RAIL (left) ======================================================= */
.rail-body {
  overflow-y: auto;
  padding: 4px 6px 12px;
  scroll-behavior: smooth;
}
.rail-loading, .rail-error {
  padding: 24px 18px;
  font-size: 13px; color: var(--text-3);
  text-align: center;
}
.rail-error { color: var(--kind-amend); }

/* Schedule heading — bold separator */
.rail-schedule {
  margin: 18px 12px 4px;
  padding: 16px 0 4px;
  border-top: 2px solid var(--text);
  font-size: 14px; font-weight: 700; letter-spacing: -0.01em;
  color: var(--text);
}
.rail-schedule:first-child { margin-top: 4px; border-top: 0; padding-top: 8px; }
.rail-schedule-num { color: var(--accent); margin-right: 4px; }

/* Part / Division — sub-headings */
.rail-part {
  margin: 12px 12px 2px;
  padding: 4px 0;
  font-size: 12px; font-weight: 650; color: var(--text);
}
.rail-division {
  margin: 6px 16px 2px;
  font-size: 11.5px; font-weight: 600; color: var(--text-2);
}

/* the amending Act's own sections 1-3 */
.rail-bill-section {
  display: flex; align-items: baseline; gap: 8px;
  margin: 4px 12px;
  padding: 5px 10px;
  font-size: 12px; color: var(--text-2);
  background: var(--surface-2);
  border-radius: var(--r-sm);
}
.rail-bill-section-num { font-family: var(--mono); color: var(--text-3); font-size: 11px; }
.rail-bill-section-head { color: var(--text-2); font-style: italic; }

/* the clickable item — the meat of the rail */
.rail-item {
  display: grid;
  grid-template-columns: 14px 36px 1fr auto;
  align-items: baseline;
  gap: 8px;
  width: calc(100% - 8px);
  margin: 2px 4px;
  padding: 7px 10px;
  text-align: left;
  border-radius: var(--r-sm);
  cursor: pointer;
  color: var(--text-2);
}
.rail-item:hover {
  background: var(--surface-3);
  color: var(--text);
}
.rail-item.is-active {
  background: var(--accent-soft);
  color: var(--text);
  box-shadow: inset 3px 0 0 var(--accent);
}

.rail-item-dot {
  width: 8px; height: 8px; border-radius: var(--r-pill);
  background: var(--kind-amend);
  align-self: center;
}
.rail-item[data-kind="insert"]     .rail-item-dot { background: var(--kind-insert); }
.rail-item[data-kind="structural"] .rail-item-dot { background: var(--kind-structural); }
.rail-item[data-kind="provision"]  .rail-item-dot { background: var(--kind-provision); }

.rail-item-num {
  font-family: var(--mono); font-size: 11.5px; font-weight: 600;
  color: var(--text-3);
  text-align: right;
}
.rail-item.is-active .rail-item-num { color: var(--accent); }

.rail-item-desc {
  font-family: var(--mono); font-size: 12px;
  letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 0;
}

.rail-item-arrow {
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
}
.rail-item:hover .rail-item-arrow,
.rail-item.is-active .rail-item-arrow { color: var(--accent); }
.rail-item[data-new="1"] .rail-item-arrow { color: var(--kind-insert); }

/* rail foot — small status strip */
.rail-foot {
  padding: 10px 14px;
  font-size: 11.5px; color: var(--text-2);
  background: var(--surface-2);
  border-top: 1px solid var(--border);
}
.rail-foot strong { color: var(--text); font-weight: 600; }

/* rail-body scrollbar */
.rail-body { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
.rail-body::-webkit-scrollbar { width: 10px; }
.rail-body::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--r-pill);
  border: 3px solid var(--surface);
}
.rail-body::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* 7. IFRAME FRAMES (right) ================================================== */
.frame-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
}
.tab-panel { display: none; }
.tab-panel.is-active { display: flex; }

.frame {
  flex: 1;
  width: 100%;
  border: 0;
  background: var(--surface);
}

.frame-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  font-size: 13px; color: var(--text-3);
  background: var(--surface);
  z-index: 5;
}
.frame-loading.is-hidden {
  opacity: 0; pointer-events: none;
  transition: opacity .35s var(--ease);
}

/* 8. THEME TOGGLE, UTILITIES, RESPONSIVE ==================================== */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
}
.theme-toggle:hover { background: var(--surface-3); color: var(--text); }
.theme-toggle svg { width: 17px; height: 17px; }
.theme-toggle .icon-sun  { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun  { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

@media (max-width: 1024px) {
  :root { --rail-w: 320px; }
  .legend { display: none; }
}

@media (max-width: 860px) {
  body { overflow: auto; }
  .app { height: auto; min-height: 100vh; }
  .panes { grid-template-columns: 1fr; gap: 12px; }
  .pane { height: auto; }
  .pane--rail { max-height: 50vh; }
  .pane--act  { height: 70vh; }
  .brand-sub { display: none; }
}

@media (max-width: 560px) {
  .app-header { gap: 10px; padding: 0 14px; }
  .pane-title { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .rail-body { scroll-behavior: auto; }
}
