:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #21252e;
  --muted: #5c6578;
  --border: #b5bccc;
  --accent: #1f6feb;
  --accent-dark: #1558b8;
  --danger-bg: #fdecec;
  --danger-text: #8a1f1f;
  --warn-bg: #fff8e6;
  --warn-text: #7a5b00;
  --ok: #1a7f4b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.45;
  font-size: 0.9rem;
}

main {
  padding: 0.65rem 0 1.25rem;
}

.container {
  width: min(920px, calc(100% - 1.5rem));
  margin: 0 auto;
}

.container-wide {
  width: min(1180px, calc(100% - 1rem));
}

.site-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 1.25rem 0;
}

.compact-header {
  padding: 0.55rem 0;
}

.header-brand {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  flex-wrap: wrap;
  min-width: 0;
}

.header-logo {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  line-height: 1.2;
}

.header-logo:hover {
  color: var(--accent);
}

.header-sub {
  font-size: 0.8rem;
}

.header-badge {
  flex-shrink: 0;
}

.page-head {
  margin: 0 0 0.5rem;
}

.page-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.55rem;
}

.page-nav-end {
  justify-content: flex-end;
}

.back-link,
.forward-link {
  text-decoration: none;
  white-space: nowrap;
}

.breadcrumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem 0.35rem;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.78rem;
  color: var(--muted);
}

.breadcrumbs li {
  display: inline-flex;
  align-items: center;
}

.breadcrumbs li + li::before {
  content: "/";
  margin-right: 0.35rem;
  color: #9aa3b2;
}

.breadcrumbs a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.breadcrumbs a:hover {
  text-decoration: underline;
}

.breadcrumbs [aria-current="page"] {
  color: var(--text);
  font-weight: 600;
}

.page-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.page-head .compact-note {
  margin-top: 0.15rem;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  flex-wrap: wrap;
}

.header-auth {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
}

.header-auth-status {
  font-size: 0.82rem;
  white-space: nowrap;
}

.site-nav {
  display: flex;
  gap: 0.85rem;
  flex-wrap: wrap;
  align-items: center;
  flex: 1 1 auto;
  justify-content: center;
}

.eyebrow {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

h1 {
  margin: 0.15rem 0 0;
  font-size: 1.75rem;
}

.badge {
  background: var(--warn-bg);
  color: var(--warn-text);
  border: 1px solid #e8d49a;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

.badge-sm {
  padding: 0.2rem 0.5rem;
  font-size: 0.72rem;
  white-space: nowrap;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
}

.compact-card {
  padding: 0.75rem 0.85rem;
  margin-bottom: 0.65rem;
}

.compact-card h2,
.compact-card h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
}

.compact-note {
  font-size: 0.8rem;
  margin: 0.35rem 0 0;
}

.explain-details summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--accent);
  list-style: none;
}

.explain-details summary::-webkit-details-marker {
  display: none;
}

.explain-details summary::before {
  content: "▸ ";
}

.explain-details[open] summary::before {
  content: "▾ ";
}

.explain-body {
  margin-top: 0.65rem;
}

.explain-body h4 {
  margin: 0.75rem 0 0.25rem;
  font-size: 0.85rem;
}

.explain-body h4:first-child {
  margin-top: 0.15rem;
}

.formula-block {
  margin: 0.35rem 0;
  padding: 0.45rem 0.55rem;
  font-size: 0.78rem;
  background: #f4f7fb;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow-x: auto;
}

.formula-primary {
  font-size: 0.88rem;
  background: #eef4ff;
  border-color: #b8cce8;
}

.formula-label {
  margin-bottom: 0.15rem;
}

.explain-list {
  margin: 0.35rem 0 0;
  padding-left: 1.15rem;
}

.explain-list li {
  margin: 0.25rem 0;
}

.section-head {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}

.section-head h2 {
  margin: 0;
  font-size: 0.95rem;
}

.hero {
  margin-top: 1.5rem;
}

.muted {
  color: var(--muted);
  font-size: 0.85rem;
}

.compact-card h3 {
  margin: 0 0 0.4rem;
  font-size: 0.92rem;
  font-weight: 700;
}

.compact-card > p.compact-note:first-child {
  margin-top: 0;
}

.steps {
  display: grid;
  gap: 1rem;
  margin: 1.5rem 0 2rem;
}

.step-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

h2 {
  margin: 0;
  font-size: 1.15rem;
}

.btn {
  display: inline-block;
  border: none;
  border-radius: 6px;
  padding: 0.65rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.btn-sm {
  padding: 0.4rem 0.7rem;
  font-size: 0.82rem;
}

.btn-xs {
  padding: 0.2rem 0.45rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 4px;
  background: #eef2f8;
  color: var(--text);
  border: 1px solid var(--border);
  cursor: pointer;
  text-decoration: none;
}

.btn-icon {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.1rem 0.35rem;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-dark);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-secondary {
  background: #eef2f8;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-link {
  background: none;
  color: var(--accent);
  padding: 0;
  border: none;
  text-decoration: underline;
  cursor: pointer;
  font-size: inherit;
}

.btn-link-sm {
  font-size: 0.8rem;
  margin-top: 0.25rem;
}

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 6px;
  padding: 2rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  margin-bottom: 0.65rem;
}

.drop-zone-compact {
  padding: 1rem 0.75rem;
  margin-bottom: 0.5rem;
}

.drop-zone-compact .drop-title {
  font-size: 0.9rem;
}

.drop-zone.dragover {
  border-color: var(--accent);
  background: #eef4ff;
}

.drop-title {
  margin: 0;
  font-weight: 600;
}

.file-name {
  margin: 0.35rem 0 0;
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--accent-dark);
}

.error-box {
  margin-top: 0.5rem;
  padding: 0.55rem 0.7rem;
  background: var(--danger-bg);
  color: var(--danger-text);
  border: 1px solid #f0b4b4;
  border-radius: 4px;
  font-size: 0.82rem;
}

.form-row {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.form-row input,
.form-row select {
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  max-width: 12rem;
}

#schema-panel {
  margin-top: 0.45rem;
}

#schema-panel.hidden {
  display: none !important;
}

.hidden {
  display: none !important;
}

.loading {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.spinner {
  width: 1.1rem;
  height: 1.1rem;
  border: 2px solid #ccd4e0;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.warnings {
  margin-bottom: 0.5rem;
}

.warning-item {
  background: var(--warn-bg);
  color: var(--warn-text);
  border: 1px solid #e8d49a;
  border-radius: 4px;
  padding: 0.45rem 0.65rem;
  margin-top: 0.45rem;
  font-size: 0.8rem;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.metrics-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.65rem;
  align-items: center;
  margin-bottom: 0.35rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #f8fafc;
  font-size: 0.78rem;
}

.metric-item {
  display: inline-flex;
  align-items: baseline;
  gap: 0.25rem;
  white-space: nowrap;
}

.metric-k {
  color: var(--muted);
  font-weight: 600;
}

.metric-v {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.metric-v.ok {
  color: var(--ok);
}

.metric-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem;
  background: #fafbfc;
}

.metric-label {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.metric-value {
  font-size: 1.35rem;
  font-weight: 700;
}

.metric-value.ok {
  color: var(--ok);
}

.model-info {
  margin-bottom: 0.35rem;
  font-size: 0.74rem;
  color: var(--muted);
  line-height: 1.35;
}

#preview-table {
  width: 100%;
}

.table-wrap {
  overflow-x: auto;
}

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--card);
  padding: 1rem 0 2rem;
  margin-top: 1rem;
}

.footer-inner {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.9rem;
  color: var(--muted);
}

.footer-inner a {
  color: var(--accent);
}


.site-nav a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.85rem;
}

.site-nav a.active,
.site-nav a:hover {
  color: var(--accent);
}

.login-card {
  max-width: 420px;
  margin: 1rem auto;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  align-items: flex-end;
}

.inline-form.stack-sm {
  flex-direction: column;
  align-items: stretch;
}

.inline-form label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}

.inline-form input,
.inline-form select {
  padding: 0.35rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.85rem;
  min-width: 6rem;
}

.login-form,
.stack-form {
  display: grid;
  gap: 0.85rem;
}

.login-form label,
.stack-form label {
  display: grid;
  gap: 0.35rem;
  font-weight: 600;
}

.login-form input,
.stack-form input {
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
}

.small {
  font-size: 0.85rem;
}

.library-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
}

.split-panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.65rem;
  margin-bottom: 0.65rem;
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.dataset-list {
  margin-top: 0.35rem;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.data-table th,
.data-table td {
  border: 1px solid var(--border);
  padding: 0.3rem 0.45rem;
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  background: #eef2f8;
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
}

.compact-table tbody tr:hover {
  background: #f8fafc;
}

.num,
input.num {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

td.num {
  text-align: right;
  font-weight: 600;
}

.nowrap {
  white-space: nowrap;
}

.row-note {
  font-size: 0.74rem;
  color: var(--muted);
}

.dataset-link {
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
}

.dataset-link:hover {
  color: var(--accent);
}

.col-actions {
  width: 1%;
  white-space: nowrap;
  text-align: right;
}

.btn-danger {
  background: #fff5f5;
  color: var(--danger-text);
  border: 1px solid #f0b4b4;
}

.danger-text {
  color: var(--danger-text);
}

.editor-toolbar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  margin: 0.5rem 0;
}

.editor-wrap {
  max-height: 420px;
  overflow: auto;
}

.editor-table {
  width: max-content;
  min-width: 100%;
  table-layout: auto;
}

.editor-table .col-Gender {
  width: 5.5rem;
  min-width: 5.5rem;
}

.editor-table th.col-Gender {
  text-align: left;
}

.editor-table td.col-Gender {
  padding: 0.15rem;
}
.editor-table .col-K1,
.editor-table .col-K2,
.editor-table .col-ACD,
.editor-table .col-AL,
.editor-table .col-pACD,
.editor-table .col-LT,
.editor-table .col-TargetRx,
.editor-table .col-IOL_target { width: 4.2rem; }
.editor-table input,
.editor-table select {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #d5dbe6;
  border-radius: 3px;
  padding: 0.2rem 0.3rem;
  font-size: 0.8rem;
  color: var(--text);
  background: #fff;
}

.editor-table input:focus,
.editor-table select:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 1px rgba(31, 111, 235, 0.15);
}

.editor-table input.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.editor-table input::placeholder {
  color: #9aa3b2;
  font-size: 0.72rem;
}

.model-info {
  margin: 0.65rem 0;
}

.model-info-details {
  padding: 0.65rem 0.75rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.model-info h4 {
  margin: 0 0 0.35rem;
  font-size: 0.88rem;
}

.replication-steps {
  margin: 0.35rem 0 0.5rem;
}

.model-coeff-table {
  margin-top: 0.45rem;
}

.compact-metrics {
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.45rem;
}

.compact-metrics .metric-card {
  padding: 0.5rem 0.6rem;
}

.compact-metrics .metric-value {
  font-size: 1.05rem;
}

.demo-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
  margin: 0 0 0.75rem;
}

.demo-bar .btn-xs.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.tab-bar {
  display: flex;
  gap: 0.35rem;
}

.tab-btn.active {
  background: var(--accent, #2563eb);
  color: #fff;
  border-color: transparent;
}

.single-eye-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 0.55rem 0.75rem;
  margin-bottom: 0.75rem;
}

.single-eye-form label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.82rem;
}

@media (max-width: 640px) {
  h1 { font-size: 1.4rem; }
  .drop-zone { padding: 1.25rem 0.75rem; }
}
