:root {
  --ink: #173936;
  --ink-2: #315653;
  --paper: #f4efe3;
  --paper-deep: #e8dfcf;
  --white: #fffdf8;
  --line: #d8cfbd;
  --red: #b6402d;
  --red-soft: #f3d9d1;
  --amber: #d79b2f;
  --amber-soft: #f7e8bd;
  --green: #347760;
  --green-soft: #dbe9df;
  --blue: #3b6e78;
  --muted: #746f65;
  --sidebar: 248px;
  --shadow: 0 18px 50px rgba(40, 48, 41, 0.09);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: "Manrope", sans-serif;
  font-size: 14px;
}

button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
a { color: inherit; text-decoration: none; }

.paper-grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 20;
  opacity: .13;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.22'/%3E%3C/svg%3E");
}

.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar);
  padding: 26px 18px 20px;
  color: #f8f2e5;
  background: var(--ink);
  display: flex;
  flex-direction: column;
  z-index: 10;
  overflow-y: auto;
}

.sidebar::after {
  content: "";
  position: absolute;
  width: 230px;
  height: 230px;
  left: -90px;
  bottom: -100px;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 50%;
  box-shadow: 0 0 0 28px rgba(255,255,255,.025), 0 0 0 57px rgba(255,255,255,.02);
}

.brand { display: flex; align-items: center; gap: 12px; position: relative; z-index: 1; }
.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  color: var(--ink);
  background: var(--amber-soft);
  border-radius: 50% 50% 50% 13px;
  font: 700 20px "Fraunces", serif;
  transform: rotate(-7deg);
}
.brand strong { display: block; font: 600 18px "Fraunces", serif; letter-spacing: .01em; }
.brand small { display: block; color: #afc3bc; font: 500 10px "DM Mono", monospace; letter-spacing: .12em; text-transform: uppercase; margin-top: 3px; }

.nav-stack { display: grid; gap: 4px; margin-top: 42px; position: relative; z-index: 1; }
.nav-label { margin: 20px 12px 7px; color: #8facaa; font: 500 10px "DM Mono", monospace; letter-spacing: .15em; text-transform: uppercase; }
.nav-link {
  display: flex;
  gap: 11px;
  align-items: center;
  min-height: 42px;
  padding: 9px 12px;
  border-radius: 10px;
  color: #cfe0da;
  transition: .18s ease;
}
.nav-link:hover { background: rgba(255,255,255,.07); color: white; transform: translateX(2px); }
.nav-link.active { color: var(--ink); background: var(--paper); box-shadow: 0 8px 20px rgba(0,0,0,.14); }
.nav-icon { width: 18px; text-align: center; font-family: "DM Mono", monospace; }
.nav-count { margin-left: auto; min-width: 25px; padding: 2px 6px; border-radius: 99px; background: rgba(255,255,255,.12); text-align: center; font: 500 10px "DM Mono", monospace; }
.nav-link.active .nav-count { background: var(--paper-deep); }
.sidebar-foot { margin-top: auto; display: flex; gap: 8px; align-items: center; color: #9cb7b0; font: 10px "DM Mono", monospace; position: relative; z-index: 1; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #83c79f; box-shadow: 0 0 0 4px rgba(131,199,159,.12); }

.main-stage { min-height: 100vh; margin-left: var(--sidebar); }
.page { padding: 34px clamp(24px, 4vw, 68px) 70px; max-width: 1700px; margin: 0 auto; animation: page-in .32s ease both; }
.mobile-header { display: none; }
@keyframes page-in { from { opacity: 0; transform: translateY(7px); } }

.eyebrow { margin: 0 0 8px; color: var(--red); font: 500 11px "DM Mono", monospace; letter-spacing: .16em; text-transform: uppercase; }
h1, h2, h3 { font-family: "Fraunces", serif; }
h1 { margin: 0; font-size: clamp(34px, 4vw, 55px); line-height: .98; letter-spacing: -.035em; font-weight: 600; }
h2 { margin: 0; font-size: 26px; letter-spacing: -.02em; }
h3 { margin: 0; font-size: 18px; }
p { line-height: 1.65; }
.lede { max-width: 690px; color: var(--muted); margin: 15px 0 0; font-size: 15px; }
.page-head { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 28px; }
.page-actions { display: flex; flex-wrap: wrap; gap: 9px; justify-content: flex-end; }

.button {
  min-height: 40px;
  padding: 9px 15px;
  border: 1px solid var(--ink);
  border-radius: 10px;
  color: var(--white);
  background: var(--ink);
  font-weight: 700;
  transition: .16s ease;
}
.button:hover { transform: translateY(-1px); box-shadow: 0 6px 14px rgba(23,57,54,.18); }
.button.secondary { color: var(--ink); background: transparent; border-color: var(--line); }
.button.secondary:hover { background: var(--white); }
.button.danger { color: var(--red); border-color: #d9a99f; background: transparent; }
.button.amber { color: #382b12; background: var(--amber-soft); border-color: #ddbc72; }
.button.small { min-height: 32px; padding: 6px 10px; font-size: 12px; }
.icon-button { width: 40px; height: 40px; border: 1px solid var(--line); background: transparent; border-radius: 9px; }

.card {
  background: rgba(255,253,248,.82);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-head { padding: 21px 23px 17px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 18px; align-items: center; }
.card-body { padding: 22px 23px; }
.card-subtitle { margin: 5px 0 0; color: var(--muted); font-size: 12px; }

.field { display: grid; gap: 7px; }
.field > span, .field label { color: var(--ink-2); font-size: 11px; font-weight: 700; letter-spacing: .035em; }
.field em { color: var(--red); font-style: normal; }
.input, .select, .textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  color: var(--ink);
  background: var(--white);
  border: 1px solid #cec4b0;
  border-radius: 9px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.textarea { min-height: 84px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(59,110,120,.12); }
.input.mono { font-family: "DM Mono", monospace; font-size: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 17px; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: 1 / -1; }

.assessment-layout { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(340px, .72fr); gap: 22px; align-items: start; }
.assessment-main { display: grid; gap: 20px; min-width: 0; }
.results-rail { display: grid; gap: 16px; position: sticky; top: 24px; max-height: calc(100vh - 48px); overflow-y: auto; padding-right: 3px; }
.assessment-switcher { min-width: min(360px, 100%); }

.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.search-wrap { position: relative; flex: 1; min-width: 190px; }
.search-wrap .input { padding-left: 34px; }
.search-wrap::before { content: "⌕"; position: absolute; left: 12px; top: 9px; font: 20px "DM Mono", monospace; color: var(--muted); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: transparent; color: var(--ink-2); padding: 7px 10px; border-radius: 99px; font-size: 11px; font-weight: 700; }
.chip.active { background: var(--ink); color: white; border-color: var(--ink); }

.attribute-groups { display: grid; gap: 18px; }
.attribute-group-title { display: flex; align-items: center; gap: 10px; margin: 2px 0 10px; }
.attribute-group-title::after { content: ""; height: 1px; background: var(--line); flex: 1; }
.attribute-group-title span { color: var(--muted); font: 500 10px "DM Mono", monospace; }
.attribute-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.attribute-row { padding: 13px 14px; border: 1px solid var(--line); background: rgba(255,253,248,.54); border-radius: 12px; display: grid; grid-template-columns: minmax(120px, .85fr) minmax(150px, 1.15fr); gap: 11px; align-items: center; transition: .15s; }
.attribute-row:hover { background: var(--white); border-color: #bcb09b; }
.attribute-row.flag-red { border-left: 4px solid var(--red); }
.attribute-row.flag-yellow { border-left: 4px solid var(--amber); }
.attribute-name { font-weight: 700; font-size: 12px; }
.attribute-key { display: block; color: var(--muted); font: 10px "DM Mono", monospace; margin-top: 3px; }
.attribute-row.hidden { display: none; }
.empty-state { padding: 50px 24px; text-align: center; color: var(--muted); }

.alert-panel { padding: 17px 18px; border-radius: 14px; border: 1px solid; }
.alert-panel.red { background: var(--red-soft); border-color: #dfa79b; color: #6f2117; }
.alert-panel.yellow { background: var(--amber-soft); border-color: #e3c46f; color: #654510; }
.alert-title { display: flex; justify-content: space-between; align-items: center; font-weight: 800; margin-bottom: 9px; }
.alert-list { display: grid; gap: 7px; }
.alert-item { display: flex; justify-content: space-between; gap: 15px; font-size: 12px; }
.alert-item strong { font-family: "DM Mono", monospace; }

.result-summary { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--line); }
.summary-number { padding: 16px 9px; text-align: center; border-right: 1px solid var(--line); }
.summary-number:last-child { border-right: 0; }
.summary-number strong { display: block; font: 600 22px "Fraunces", serif; }
.summary-number span { color: var(--muted); font: 9px "DM Mono", monospace; text-transform: uppercase; letter-spacing: .08em; }
.result-list { display: grid; gap: 9px; padding: 15px; }
.result-card { padding: 13px; border: 1px solid var(--line); border-radius: 12px; background: var(--white); }
.result-card-top { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: start; }
.result-name { font-weight: 800; font-size: 12px; }
.result-head { color: var(--muted); font-size: 10px; margin-top: 2px; }
.score { font: 600 27px "Fraunces", serif; line-height: 1; }
.score small { font: 9px "DM Mono", monospace; color: var(--muted); }
.meter { height: 5px; background: var(--paper-deep); border-radius: 99px; margin-top: 12px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--green); border-radius: inherit; }
.result-meta { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 9px; color: var(--muted); font-size: 10px; }
.status-pill { padding: 3px 7px; border-radius: 99px; background: var(--green-soft); color: #265b49; font: 500 9px "DM Mono", monospace; }
.status-pill.incomplete { background: var(--amber-soft); color: #705018; }
.status-pill.error { background: var(--red-soft); color: #812c20; }
.adjustment { font-family: "DM Mono", monospace; font-weight: 700; }
.adjustment.positive { color: var(--green); }
.adjustment.negative { color: var(--red); }
.calculation-breakdown { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; padding-top: 9px; border-top: 1px dashed var(--line); }
.calculation-breakdown span { padding: 4px 7px; border-radius: 6px; color: var(--ink-2); background: var(--paper); font-size: 9px; }

.rule-guide { display: grid; grid-template-columns: minmax(230px, 1fr) auto minmax(230px, 1fr) minmax(230px, .9fr); gap: 12px; align-items: stretch; margin-bottom: 18px; }
.rule-guide article, .formula-result { padding: 17px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,253,248,.74); display: flex; align-items: center; gap: 13px; }
.rule-guide article p { margin: 3px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.mode-mark { flex: 0 0 42px; width: 42px; height: 42px; display: grid; place-items: center; border-radius: 50%; font: 700 11px "DM Mono", monospace; }
.mode-mark.average { color: #214f5a; background: #d8e8e8; }
.mode-mark.absolute { color: #7a4b0d; background: var(--amber-soft); font-size: 20px; }
.formula-arrow { align-self: center; color: var(--muted); font: 500 10px "DM Mono", monospace; text-transform: uppercase; }
.formula-result { color: var(--white); background: var(--ink); border-color: var(--ink); font: 600 18px "Fraunces", serif; line-height: 1.2; }
.quick-rule-card { margin-bottom: 18px; overflow: hidden; }
.quick-rule-card .card-head { background: linear-gradient(100deg, rgba(247,232,189,.65), transparent 58%); }
.quick-rule-grid { display: grid; grid-template-columns: 1.1fr 1.1fr 1.1fr .9fr .55fr auto; gap: 12px; align-items: end; }
.rule-add-button { min-height: 42px; white-space: nowrap; }
.rule-filters { min-width: min(480px, 100%); }
.managed-rules-note { margin-bottom: 18px; padding: 14px 18px; border: 1px solid #bfd1ce; border-left: 4px solid var(--teal); border-radius: 12px; background: linear-gradient(100deg, rgba(224,240,236,.82), rgba(255,253,248,.72)); display: flex; align-items: center; gap: 18px; }
.managed-rules-note > span { flex: 0 0 auto; color: var(--teal); font: 700 10px "DM Mono", monospace; letter-spacing: .08em; text-transform: uppercase; }
.managed-rules-note p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.managed-rules-note a { color: var(--ink); font-weight: 700; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.rule-table { min-width: 880px; }
.table-kicker { display: block; margin-top: 3px; color: var(--muted); font: 9px "DM Mono", monospace; }
.method-select.average { color: #245866; background: #edf6f6; border-color: #b8d3d5; }
.method-select.absolute { color: #77500e; background: #fff8e4; border-color: #dfc579; }
.score-field { position: relative; width: 118px; }
.score-field > span { position: absolute; left: 10px; top: 50%; z-index: 1; color: var(--muted); font: 600 11px "DM Mono", monospace; line-height: 1; pointer-events: none; transform: translateY(-50%); }
.score-field .input { width: 118px; padding-left: 27px; }
.score-field.absolute > span { color: #9a6817; }

.admin-layout { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 20px; align-items: start; }
.admin-list { position: sticky; top: 24px; max-height: calc(100vh - 50px); overflow: hidden; display: grid; grid-template-rows: auto auto minmax(0, 1fr); }
.admin-list-scroll { overflow-y: auto; padding: 8px; }
.list-item { width: 100%; text-align: left; padding: 11px 12px; border: 0; border-radius: 9px; background: transparent; color: var(--ink); display: flex; justify-content: space-between; gap: 8px; }
.list-item:hover { background: var(--paper); }
.list-item.active { color: white; background: var(--ink); }
.list-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item small { color: inherit; opacity: .65; font: 10px "DM Mono", monospace; }
.admin-editor { min-width: 0; }
.section-stack { display: grid; gap: 20px; }
.section-note { padding: 12px 14px; background: var(--green-soft); border: 1px solid #bbd4c4; border-radius: 10px; color: #2b5a49; font-size: 12px; }

.table-wrap { width: 100%; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; min-width: 620px; }
.data-table th { text-align: left; padding: 10px 11px; color: var(--muted); border-bottom: 1px solid var(--line); font: 500 10px "DM Mono", monospace; letter-spacing: .06em; text-transform: uppercase; }
.data-table td { padding: 9px 11px; border-bottom: 1px solid #e6dfd1; vertical-align: middle; }
.data-table tbody tr:hover { background: rgba(244,239,227,.55); }
.data-table .input, .data-table .select { min-height: 35px; padding: 6px 8px; }
.data-table .score-field .input { padding-left: 28px; }
.table-actions { display: flex; gap: 7px; }
.grade-input { width: 100px; }
.drag-handle { color: #aaa18e; font-family: "DM Mono", monospace; }

.health-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 13px; }
.health-card { padding: 18px; border: 1px solid var(--line); border-radius: 13px; background: var(--white); }
.health-card strong { display: block; font: 600 28px "Fraunces", serif; }
.health-card span { color: var(--muted); font-size: 11px; }
.health-card.bad { border-color: #dfaaa0; background: #fff6f3; }
.warning-list { max-height: 260px; overflow-y: auto; margin: 0; padding-left: 20px; color: var(--muted); }
.warning-list li { padding: 4px 0; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(10,29,27,.55); z-index: 30; display: grid; place-items: center; padding: 20px; }
.modal { width: min(520px, 100%); background: var(--paper); border-radius: 20px; box-shadow: 0 30px 90px rgba(0,0,0,.32); padding: 25px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 22px; }
.toast-region { position: fixed; right: 22px; bottom: 22px; z-index: 50; display: grid; gap: 9px; }
.toast { width: min(360px, calc(100vw - 44px)); padding: 13px 15px; color: white; background: var(--ink); border-radius: 11px; box-shadow: 0 15px 40px rgba(0,0,0,.25); animation: toast-in .24s ease both; }
.toast.error { background: #8c2c21; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.muted { color: var(--muted); }
.mono { font-family: "DM Mono", monospace; }
.no-margin { margin: 0; }
.divider { height: 1px; background: var(--line); margin: 4px 0; }
.hide { display: none !important; }

@media (max-width: 1160px) {
  .assessment-layout { grid-template-columns: 1fr; }
  .results-rail { position: static; max-height: none; grid-template-columns: repeat(2, minmax(0,1fr)); }
  .results-rail .results-card { grid-column: 1 / -1; }
  .attribute-grid { grid-template-columns: 1fr; }
  .rule-guide { grid-template-columns: 1fr 1fr; }
  .formula-arrow { display: none; }
  .quick-rule-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); transition: transform .22s; box-shadow: 20px 0 60px rgba(0,0,0,.2); }
  body.menu-open .sidebar { transform: translateX(0); }
  .main-stage { margin-left: 0; }
  .mobile-header { height: 64px; padding: 10px 18px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: rgba(244,239,227,.94); position: sticky; top: 0; z-index: 8; backdrop-filter: blur(10px); }
  .mobile-header .brand-mark { width: 36px; height: 36px; font-size: 16px; }
  .page { padding: 27px 18px 55px; }
  .page-head { align-items: flex-start; flex-direction: column; }
  .page-actions { justify-content: flex-start; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2, .span-3 { grid-column: auto; }
  .admin-layout { grid-template-columns: 1fr; }
  .admin-list { position: static; max-height: 340px; }
  .health-grid { grid-template-columns: 1fr; }
  .rule-guide { grid-template-columns: 1fr; }
  .quick-rule-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 540px) {
  h1 { font-size: 38px; }
  .card-head { align-items: stretch; flex-direction: column; }
  .assessment-switcher { width: 100%; min-width: 0; }
  .results-rail { grid-template-columns: 1fr; }
  .attribute-row { grid-template-columns: 1fr; }
  .result-summary { grid-template-columns: repeat(2, 1fr); }
  .summary-number:nth-child(2) { border-right: 0; }
  .summary-number:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .quick-rule-grid { grid-template-columns: 1fr; }
  .managed-rules-note { align-items: flex-start; flex-direction: column; gap: 6px; }
}
