:root {
  /* Core */
  --ink: #20302a;
  --muted: #6b7269;
  --paper: #faf8f2;
  --card: #ffffff;
  --line: #e7e2d3;

  /* Brand green */
  --green: #146c50;
  --green-dark: #0f5540;
  --green-light: #e7f1ea;
  --accent-spark: #8fd6b4;

  /* Status */
  --amber: #9a6710;
  --amber-light: #fff5d9;
  --red: #a33831;
  --red-light: #f7e5e2;

  /* Type scale */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.375rem;
  --text-2xl: 2rem;
  --text-3xl: clamp(2rem, 4vw, 2.75rem);

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-14: 3.5rem;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 999px;

  /* Shadow */
  --shadow-sm: 0 4px 12px rgba(20, 45, 35, .05);
  --shadow-md: 0 8px 22px rgba(20, 45, 35, .08);
  --shadow-lg: 0 20px 60px rgba(20, 45, 35, .12);

  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--paper);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); }
a { color: var(--green); }
button { border: 0; border-radius: var(--radius-md); background: var(--green); color: white; padding: .78rem 1rem; font-weight: 700; cursor: pointer; min-height: 44px; }
button:hover { background: var(--green-dark); }
button:disabled { opacity: .55; cursor: not-allowed; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: var(--radius-md); padding: .8rem; margin-top: .35rem; font: inherit; background: white; }
textarea:focus, input:focus, select:focus { outline: 3px solid var(--accent-spark); border-color: var(--green); }

/* Brand mark */
.logo-mark { display: block; flex-shrink: 0; }
.logo-mark.size-lg { width: 54px; height: 54px; }
.logo-mark.size-sm { width: 34px; height: 34px; margin-right: .7rem; }
.wordmark { font-weight: 700; letter-spacing: -.01em; }

.eyebrow { color: var(--green); text-transform: uppercase; letter-spacing: .1em; font-size: var(--text-xs); font-weight: 800; }
.muted, .fine-print { color: var(--muted); }
.fine-print { font-size: var(--text-xs); margin-top: var(--space-6); }
.stack { display: grid; gap: var(--space-4); margin-top: var(--space-6); }
.alert { padding: var(--space-3); border-radius: var(--radius-md); margin: var(--space-4) 0; }
.alert.success { background: var(--green-light); color: var(--green); border: 1px solid var(--green); font-weight: 700; }
.danger { background: var(--red-light); color: var(--red); }

.login-body { min-height: 100vh; display: grid; place-items: center; padding: var(--space-6); background: radial-gradient(circle at 20% 20%, var(--green-light), transparent 38%), var(--paper); }
.login-card { width: min(440px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: var(--space-8); box-shadow: var(--shadow-lg); }

.topbar { min-height: 64px; display: flex; align-items: center; justify-content: space-between; padding: var(--space-3) var(--space-6); background: var(--card); border-bottom: 1px solid var(--line); }
.topbar > div, .identity { display: flex; align-items: center; gap: var(--space-3); }
.identity form { margin: 0; }
.role { background: var(--green-light); color: var(--green); padding: .28rem .6rem; border-radius: var(--radius-full); font-size: var(--text-xs); font-weight: 800; text-transform: uppercase; }
.link-button { background: none; color: var(--green); padding: 0; min-height: auto; }

/* Topbar Dropdown Menu */
.dropdown { position: relative; display: inline-block; }
.dropdown-trigger { background: var(--paper); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius-full); padding: 0.4rem 0.9rem; font-size: var(--text-sm); font-weight: 700; cursor: pointer; display: flex; align-items: center; gap: 0.5rem; transition: all 0.15s ease; user-select: none; }
.dropdown-trigger:hover, .dropdown.open .dropdown-trigger { background: var(--green-light); border-color: var(--green); color: var(--green); }
.dropdown-menu { display: none; position: absolute; right: 0; top: 100%; margin-top: 4px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); min-width: 240px; box-shadow: var(--shadow-md); z-index: 10000; overflow: hidden; padding: 0.4rem 0; }
.dropdown-menu::before { content: ""; position: absolute; top: -10px; left: 0; right: 0; height: 10px; }
.dropdown.open .dropdown-menu, .dropdown:hover .dropdown-menu { display: block; }
.dropdown-item { display: flex; align-items: center; gap: 0.6rem; padding: 0.7rem 1rem; color: var(--ink); text-decoration: none; font-size: var(--text-sm); font-weight: 600; transition: background 0.12s ease; }
.dropdown-item.current { font-weight: 700; color: var(--green); }
.dropdown-item:hover { background: var(--paper); color: var(--green); }
.dropdown-divider { height: 1px; background: var(--line); margin: 0.3rem 0; }
.dropdown-button { width: 100%; text-align: left; background: none; border: 0; color: var(--red); padding: 0.7rem 1rem; font-size: var(--text-sm); font-weight: 700; cursor: pointer; display: flex; align-items: center; gap: 0.6rem; border-radius: 0; min-height: auto; }
.dropdown-button:hover { background: var(--red-light); color: var(--red); }

.layout { display: grid; grid-template-columns: 290px minmax(0, 1fr); min-height: calc(100vh - 64px); }
aside { padding: var(--space-6); border-right: 1px solid var(--line); background: #f2efe4; }
.status-row { display: flex; flex-direction: column; gap: var(--space-2); margin: var(--space-2) 0 var(--space-5); }
.status-row .status { margin: 0; }
.status { display: flex; gap: var(--space-2); align-items: center; font-weight: 700; margin: var(--space-3) 0 var(--space-5); font-size: var(--text-sm); }
.status span { width: 10px; height: 10px; border-radius: 50%; background: var(--accent-spark); box-shadow: 0 0 0 4px var(--green-light); }
.env-pill { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.7rem; font-weight: 700; padding: 0.18rem 0.55rem; border-radius: var(--radius-full); width: fit-content; text-transform: uppercase; letter-spacing: 0.04em; user-select: none; }
.env-pill.env-local { background: #e2ede5; color: var(--green-dark); border: 1px solid #c4decb; }
.env-pill.env-local .env-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); }
.env-pill.env-vm { background: #e8f0fe; color: #1a4f8b; border: 1px solid #c2d8f2; }
.env-pill.env-vm .env-dot { width: 6px; height: 6px; border-radius: 50%; background: #1d6fdc; }
dl { display: grid; grid-template-columns: 1fr; gap: .15rem; font-size: var(--text-sm); }
dt { color: var(--muted); margin-top: .6rem; }
dd { margin: 0; font-weight: 700; overflow-wrap: anywhere; }
.examples { padding-left: 1.2rem; color: var(--muted); font-size: var(--text-sm); line-height: 1.5; }
.examples li { margin-bottom: .6rem; cursor: pointer; transition: color 0.15s ease; }
.examples li:hover { color: var(--green); text-decoration: underline; }
.full { width: 100%; }
.secondary { background: white; color: var(--green); border: 1px solid var(--green); }
.workspace { padding: clamp(1.5rem, 4vw, 4rem); max-width: 1050px; width: 100%; margin: 0 auto; }
.workspace h1 { font-size: var(--text-3xl); margin: .2rem 0 var(--space-4); font-weight: 700; letter-spacing: -.01em; }

.hidden { display: none !important; }
.action-buttons-row { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; margin-bottom: var(--space-4); }
.action-buttons-row .ask-again-pill, .action-buttons-row .new-conv-pill { margin-bottom: 0; }
.ask-again-pill { background: white; color: var(--green); border: 1px solid var(--green); border-radius: var(--radius-full); padding: .7rem 1.2rem; font-weight: 700; }
.ask-again-pill:hover { background: var(--green-light); }
.new-conv-pill { border-radius: var(--radius-full); padding: .7rem 1.2rem; font-weight: 700; }

.prompt-studio { margin-bottom: var(--space-4); }
.studio-label { font-size: var(--text-sm); font-weight: 700; color: var(--muted); display: block; margin-bottom: .4rem; }
.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chip { background: white; color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius-full); padding: .5rem .9rem; font-size: var(--text-sm); font-weight: 600; cursor: pointer; transition: all .15s ease; min-height: auto; }
.chip:hover { background: var(--green-light); color: var(--green); border-color: var(--green); transform: translateY(-1px); }

.question-form { background: var(--card); padding: var(--space-4); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow-sm); }
.question-form textarea { border: 0; padding: .5rem; resize: vertical; margin-top: 0; }
.question-form textarea:focus { outline: none; }

.answer { margin-top: var(--space-6); background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
.answer.blocked { border-color: #e0bdb8; }
.answer-header { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-3) var(--space-4); background: var(--paper); border-bottom: 1px solid var(--line); color: var(--green); font-weight: 700; font-size: var(--text-sm); }
.answer-meta { display: flex; flex-wrap: wrap; gap: var(--space-3); padding: var(--space-3) var(--space-4); background: var(--paper); color: var(--muted); font-size: var(--text-sm); }
.answer-meta-bottom { display: flex; flex-wrap: wrap; gap: var(--space-3); padding: var(--space-2) var(--space-4); background: var(--paper); border-top: 1px solid var(--line); color: var(--muted); font-size: var(--text-xs); }
.route { color: var(--green); font-weight: 800; }
.response-text { line-height: 1.65; padding: var(--space-5) var(--space-5) var(--space-3); font-size: var(--text-lg); }
.response-text h1, .response-text h2, .response-text h3, .response-text h4 { font-size: var(--text-xl); color: var(--ink); font-weight: 700; margin: 1.2em 0 .4em; }
.response-text h1:first-child, .response-text h2:first-child, .response-text h3:first-child, .response-text h4:first-child { margin-top: 0; }
.response-text p { margin: 0 0 .9em; }
.response-text ul, .response-text ol { margin: .6em 0 .9em; padding-left: 1.4em; }
.response-text li { margin-bottom: .8em; }
.response-text li:last-child { margin-bottom: 0; }
.response-text strong { color: var(--ink); font-weight: 700; }

/* Governance line — reassuring by default, detail behind "show why" */
.governance-line { display: flex; align-items: center; gap: .4rem; padding: 0 var(--space-5) var(--space-4); font-size: var(--text-sm); font-weight: 600; }
.governance-line.allow { color: var(--green); }
.governance-line.deny { color: var(--amber); }

/* Inline citations */
.citation-chip { display: inline-flex; align-items: center; background: var(--green-light); color: var(--green); border: 0; border-radius: var(--radius-sm); padding: 0 .35rem; font-size: .82em; font-weight: 700; cursor: pointer; min-height: auto; line-height: 1.6; }
.citation-chip:hover, .citation-chip-active { background: var(--green); color: white; }
.citation-popover { position: relative; display: block; margin: .5rem 0; padding: .8rem 1rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-md); box-shadow: var(--shadow-md); max-width: 420px; font-size: var(--text-sm); }
.citation-popover strong { display: block; font-size: var(--text-sm); }
.citation-popover small { display: block; color: var(--muted); margin-top: .15rem; }
.citation-popover p { margin: .5rem 0; color: var(--ink); line-height: 1.5; }
.citation-popover .link-button { font-weight: 700; font-size: var(--text-sm); }

/* Rules & Rails Inspector */
.rails-inspector { margin: 0 var(--space-5) var(--space-5); background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); }
.rails-inspector summary { font-size: var(--text-sm); font-weight: 700; color: var(--green); outline: none; cursor: pointer; }
.inspector-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--space-3); margin-top: var(--space-3); }
.inspector-card { background: white; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .7rem; display: flex; flex-direction: column; gap: .2rem; }
.card-label { font-size: var(--text-xs); text-transform: uppercase; font-weight: 800; color: var(--muted); letter-spacing: .05em; }
.inspector-card strong { font-size: var(--text-sm); }
.inspector-card small { font-size: var(--text-xs); color: var(--muted); }
.text-allow { color: var(--green); }
.text-deny { color: var(--red); }

.approval { margin: 0 var(--space-5) var(--space-5); padding: var(--space-4); border: 1px solid #e0c785; background: var(--amber-light); border-radius: var(--radius-md); display: grid; gap: .5rem; }
.approval button { justify-self: start; background: var(--amber); }
.sources { margin-top: var(--space-8); }
.sources h2 { font-size: var(--text-base); }
.conversation-thread { display: flex; flex-direction: column; gap: var(--space-6); margin-top: var(--space-6); }
.turn-question { font-weight: 700; color: var(--muted); margin-bottom: var(--space-2); }
.turn .answer { margin-top: 0; }
.thread-controls { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); border-top: 1px solid var(--line); padding-top: var(--space-4); }
.thread-note { color: var(--muted); font-size: var(--text-sm); margin: 0; max-width: 640px; }
details { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .8rem 1rem; margin-bottom: .6rem; }
summary { cursor: pointer; font-weight: 700; }
.source-ref { color: var(--muted); font-weight: 400; font-size: var(--text-sm); margin-left: .4rem; }
.source-content { margin: .5rem 0; white-space: pre-line; line-height: 1.5; font-size: var(--text-sm); }
.source-meta { color: var(--muted); font-size: var(--text-xs); display: block; margin-top: .4rem; }

/* Audit filters, toolbar, pagination */
.audit-filters { display: flex; flex-wrap: wrap; gap: var(--space-4); align-items: end; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--space-4); margin-bottom: var(--space-4); }
.audit-filter-field { display: flex; flex-direction: column; gap: .2rem; font-size: var(--text-sm); }
.audit-filter-field label { color: var(--muted); font-weight: 700; }
.audit-filter-field input, .audit-filter-field select { margin-top: 0; min-width: 160px; }
.audit-filter-actions { display: flex; gap: var(--space-2); }
.audit-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-3); flex-wrap: wrap; gap: var(--space-3); }
.sort-link { color: var(--ink); text-decoration: none; font-weight: 700; white-space: nowrap; }
.sort-link:hover { color: var(--green); }
.audit-pagination { display: flex; align-items: center; justify-content: space-between; margin-top: var(--space-4); flex-wrap: wrap; gap: var(--space-3); }
.audit-pagination-links { display: flex; align-items: center; gap: var(--space-3); }
.audit-pagination-links a { font-weight: 700; text-decoration: none; }

/* Audit, Admin, Dashboard, Compare pages */
.audit-page, .admin-page, .dashboard-page, .compare-page { padding: var(--space-8); max-width: 1250px; margin: 0 auto; }
.page-header { margin-bottom: var(--space-8); }
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); }
table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
th, td { padding: var(--space-3); text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--paper); }
.cell-time { white-space: nowrap; font-size: var(--text-xs); color: var(--muted); }
.cell-query { max-width: 340px; font-weight: 600; }
.cell-rule { font-size: var(--text-xs); color: var(--muted); }
.cell-rule small { display: block; margin-top: .2rem; }
.role-badge-sm { font-size: var(--text-xs); padding: 0.15rem 0.45rem; display: inline-block; margin-top: 0.2rem; }
.outcome-tag { display: inline-block; padding: 0.35rem 0.65rem; border-radius: var(--radius-sm); font-weight: 700; font-size: var(--text-sm); background: var(--paper); color: var(--ink); }
.outcome-tag.denied { background: var(--red-light); color: var(--red); }
.outcome-tag.calendar { background: #e2f0d9; color: #2e75b6; }
.outcome-tag.sharepoint { background: #deebf7; color: #1f4e78; }
.outcome-tag.academic { background: var(--amber-light); color: var(--amber); }
.outcome-tag.brief { background: var(--green-light); color: var(--green); }
.decision { font-weight: 800; text-transform: uppercase; }
.decision.allow { color: var(--green); }
.decision.deny { color: var(--red); }

/* Admin page */
.admin-panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--space-6); margin-bottom: var(--space-8); box-shadow: var(--shadow-sm); }
.admin-panel h2, .metrics-section h2 { margin-top: 0; font-size: var(--text-xl); }
.panel-row { display: flex; flex-wrap: wrap; gap: var(--space-8); align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); padding-bottom: var(--space-5); margin-bottom: var(--space-5); }
.panel-stats { display: flex; gap: var(--space-6); flex-wrap: wrap; }
.panel-stat-label { color: var(--muted); font-size: var(--text-sm); font-weight: 700; display: block; }
.panel-stat-value { color: var(--green); font-weight: 800; }
.panel-actions { display: flex; gap: var(--space-3); }
.panel-note { background: var(--paper); padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm); font-size: var(--text-sm); color: var(--muted); }
.metrics-section { margin-bottom: var(--space-10); }
.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--space-4); }
.metric-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-md); padding: var(--space-4); }
.metric-card .metric-label { color: var(--muted); font-size: var(--text-xs); font-weight: 800; text-transform: uppercase; }
.metric-card .metric-value { font-size: var(--text-2xl); margin: .3rem 0; color: var(--green); }
.metric-card small { color: var(--muted); }
.telemetry-section { display: grid; grid-template-columns: repeat(auto-fit, minmax(350px, 1fr)); gap: var(--space-6); }
.telemetry-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--space-5); }
.telemetry-card h3 { margin-top: 0; }
.telemetry-card ul { padding-left: 1.2rem; margin-bottom: 0; line-height: 1.6; font-size: var(--text-sm); }

/* Dashboard */
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(450px, 1fr)); gap: var(--space-6); }
.chart-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--space-5); }
.chart-card h3 { margin-top: 0; }

/* Compare page */
.compare-header form.question-form { margin-top: var(--space-6); }
.compare-actions { display: flex; gap: var(--space-2); margin-top: .6rem; flex-wrap: wrap; }
.compare-grid { margin-top: var(--space-8); display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: var(--space-5); }
.persona-card { background: var(--card); border: 2px solid var(--line); border-radius: var(--radius-lg); padding: var(--space-5); display: flex; flex-direction: column; gap: var(--space-3); }
.persona-card.allow-card { border-color: var(--green); }
.persona-card.deny-card { border-color: var(--red); }
.persona-card-head { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); padding-bottom: var(--space-3); }
.persona-card-head small { display: block; color: var(--muted); margin-top: .2rem; }
.outcome-pill { padding: 0.3rem 0.7rem; border-radius: var(--radius-full); font-weight: 800; font-size: var(--text-xs); }
.outcome-pill.allow { background: var(--green-light); color: var(--green); }
.outcome-pill.deny { background: var(--red-light); color: var(--red); }
.persona-rule { font-size: var(--text-sm); }
.persona-rule .persona-label { color: var(--muted); font-weight: 700; display: block; }
.persona-rls { font-size: var(--text-sm); background: var(--paper); padding: var(--space-3); border-radius: var(--radius-sm); border: 1px solid var(--line); }
.persona-response-label { color: var(--muted); font-weight: 700; display: block; margin-bottom: .3rem; }
.persona-response { font-size: var(--text-sm); line-height: 1.5; background: var(--paper); padding: var(--space-3); border-radius: var(--radius-sm); border: 1px solid var(--line); }
.persona-response p { margin: 0 0 .6em; }
.persona-response p:last-child { margin-bottom: 0; }
.persona-response ul { margin: .3em 0; padding-left: 1.3em; }
.persona-response li { margin-bottom: .3em; }

@media (max-width: 780px) {
  .layout { grid-template-columns: 1fr; }
  aside { border-right: 0; border-bottom: 1px solid var(--line); }
  .identity > span:first-child { display: none; }
}
