:root {
  --ink: #10231f;
  --forest: #064c3d;
  --forest-deep: #03352b;
  --mint: #dcebdc;
  --cream: #f4efdf;
  --paper: #fffaf0;
  --amber: #f3b834;
  --coral: #e36d4f;
  --line: rgba(16, 35, 31, .2);
  --muted: #65726d;
  --shadow: 0 24px 70px rgba(16, 35, 31, .14);
  --mono: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  --display: Georgia, "Times New Roman", serif;
  --sans: "Avenir Next", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { color: var(--ink); background: radial-gradient(circle at 85% 8%, rgba(243,184,52,.13), transparent 28rem), var(--cream); font-family: var(--sans); }
button, input, select, textarea { font: inherit; }
button { color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { min-height: 1.25rem; color: #a22d23; font-size: .86rem; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.page-grid { position: fixed; inset: 0; pointer-events: none; opacity: .45; background-image: linear-gradient(rgba(6, 76, 61, .07) 1px, transparent 1px), linear-gradient(90deg, rgba(6, 76, 61, .07) 1px, transparent 1px); background-size: 32px 32px; }
.eyebrow { margin: 0 0 .5rem; color: var(--coral); font: 700 .69rem/1.2 var(--mono); letter-spacing: .14em; text-transform: uppercase; }

/* Sign in */
.signin-overlay { position: relative; z-index: 1; min-height: 100vh; display: grid; grid-template-columns: minmax(360px, .9fr) minmax(560px, 1.35fr); }
.signin-story { min-height: 100vh; padding: clamp(2rem, 5vw, 5rem); color: var(--paper); background: linear-gradient(155deg, #075646 0%, var(--forest-deep) 78%); display: flex; flex-direction: column; justify-content: space-between; overflow: hidden; position: relative; animation: reveal-left .55s ease both; }
.signin-story::before { content: ""; position: absolute; width: 34rem; height: 34rem; right: -18rem; top: 15%; border: 1px solid rgba(243, 184, 52, .55); border-radius: 50%; box-shadow: 0 0 0 5rem rgba(243, 184, 52, .04), 0 0 0 10rem rgba(243, 184, 52, .025); }
.signin-story::after { content: "AUTHORIZED"; position: absolute; left: -1.5rem; bottom: 24%; font: 800 clamp(4rem, 9vw, 9rem)/1 var(--mono); color: rgba(255, 250, 240, .035); transform: rotate(-90deg); transform-origin: left bottom; }
.brand-lockup, .sidebar-brand { display: flex; align-items: center; gap: .9rem; position: relative; z-index: 1; }
.brand-mark { width: 3.25rem; height: 3.25rem; display: grid; place-items: center; background: var(--amber); color: var(--forest-deep); border-radius: .8rem; font: 900 1rem var(--sans); letter-spacing: -.1em; text-indent: -.1em; box-shadow: inset -8px -8px 0 rgba(255,255,255,.16), 0 12px 30px rgba(2,35,28,.22); }
.brand-mark.small { width: 2.55rem; height: 2.55rem; font-size: .82rem; }
.brand-lockup h1 { margin: 0; font: 700 clamp(2.1rem, 4vw, 3.5rem)/.9 var(--display); letter-spacing: -.055em; }
.brand-lockup .eyebrow { color: #f2d58e; }
.cursor { display: inline-block; color: var(--amber); animation: cursor-blink 1.08s step-end infinite; }
@keyframes cursor-blink { 0%, 52% { opacity: 1; } 53%, 100% { opacity: .08; } }
.story-copy { position: relative; z-index: 1; max-width: 40rem; }
.story-index { color: #f2d58e; font: 700 .72rem var(--mono); letter-spacing: .1em; }
.story-copy h2 { margin: 1rem 0 1.5rem; font: 500 clamp(3rem, 6.5vw, 6.4rem)/.88 var(--display); letter-spacing: -.06em; text-wrap: balance; }
.story-copy > p:last-child { max-width: 30rem; font-size: 1.1rem; line-height: 1.7; color: rgba(255, 250, 240, .76); }
.boundary-strip { position: relative; z-index: 1; display: flex; flex-wrap: wrap; gap: .55rem; }
.boundary-strip span { border: 1px solid rgba(255,255,255,.23); padding: .55rem .7rem; font: 700 .62rem var(--mono); letter-spacing: .07em; }
.signin-panel { min-width: 0; padding: clamp(2rem, 5vw, 5.5rem); display: flex; flex-direction: column; justify-content: center; background: rgba(244, 239, 223, .88); backdrop-filter: blur(10px); animation: reveal-right .55s .08s ease both; }
.signin-heading { max-width: 48rem; }
.signin-heading h2 { margin: .25rem 0 .7rem; font: 600 clamp(2.3rem, 4vw, 4.4rem)/1 var(--display); letter-spacing: -.04em; }
.signin-heading > p:last-child { margin: 0 0 1.8rem; font-size: 1rem; }
.organization-tabs { display: flex; gap: .55rem; margin-bottom: 1rem; overflow-x: auto; }
.organization-tab { border: 1px solid var(--line); background: rgba(255,255,255,.4); padding: .65rem .85rem; border-radius: 999px; cursor: pointer; font: 700 .72rem var(--mono); white-space: nowrap; }
.organization-tab.active { color: var(--paper); background: var(--forest); border-color: var(--forest); }
.persona-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; max-height: min(43vh, 28rem); overflow: auto; padding: .15rem .35rem .15rem .15rem; }
.persona-card { min-height: 8.5rem; padding: 1rem; text-align: left; border: 1px solid var(--line); border-radius: .85rem; background: rgba(255, 250, 240, .76); cursor: pointer; transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease; position: relative; }
.persona-card:hover { transform: translateY(-2px); border-color: var(--forest); box-shadow: 0 10px 24px rgba(16,35,31,.08); }
.persona-card.selected { color: var(--paper); background: var(--forest); border-color: var(--forest); box-shadow: 0 12px 28px rgba(6,76,61,.22); }
.persona-card .persona-team { display: block; margin-bottom: .65rem; color: var(--coral); font: 700 .64rem var(--mono); letter-spacing: .08em; text-transform: uppercase; }
.persona-card.selected .persona-team { color: #f2d58e; }
.persona-card strong { display: block; font: 600 1.18rem var(--display); }
.persona-card small { display: block; margin-top: .3rem; color: var(--muted); line-height: 1.35; }
.persona-card.selected small { color: rgba(255,255,255,.7); }
.persona-card .persona-assistant { position: absolute; right: .8rem; bottom: .75rem; font: 700 .6rem var(--mono); opacity: .72; }
.loading-card { grid-column: 1 / -1; padding: 2rem; border: 1px dashed var(--line); color: var(--muted); text-align: center; }
.persona-selected { margin: 1rem 0; padding: .85rem 1rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; border-left: 4px solid var(--amber); background: rgba(255,255,255,.52); }
.persona-selected strong, .persona-selected small { display: block; }
.persona-selected small { margin-top: .15rem; color: var(--muted); }
.persona-selection-copy { min-width: 0; }
.persona-brief { margin-top: .45rem; }
.persona-brief summary { color: var(--coral); cursor: pointer; font: 700 .65rem var(--mono); letter-spacing: .05em; text-transform: uppercase; }
.persona-selection-copy p { margin: .45rem 0 0; max-width: 62rem; color: var(--ink); font-size: .78rem; line-height: 1.45; }
.persona-selection-copy .selected-focus { color: var(--muted); }
.persona-selection-copy .selected-focus::before { content: "Current focus: "; color: var(--coral); font: 700 .62rem var(--mono); letter-spacing: .06em; text-transform: uppercase; }
.assistant-pill, .tenant-badge, .privacy-label { padding: .45rem .65rem; border: 1px solid var(--line); border-radius: 999px; font: 700 .65rem var(--mono); white-space: nowrap; }
.access-key-field { display: grid; gap: .35rem; margin: .8rem 0; color: var(--muted); font-size: .8rem; }
.access-key-field > span { font-weight: 700; }
.access-key-field input { width: 100%; }
.trust-note { margin: .8rem 0 0; color: var(--muted); font-size: .72rem; line-height: 1.5; }
.entra-card { max-width: 34rem; padding: 2rem; background: var(--paper); border: 1px solid var(--line); box-shadow: var(--shadow); }
.entra-card h3 { margin: 1rem 0 .5rem; font: 600 1.8rem var(--display); }
.entra-card p { line-height: 1.6; }
.microsoft-mark { width: 2.4rem; display: grid; grid-template-columns: 1fr 1fr; gap: 3px; }
.microsoft-mark i { display: block; aspect-ratio: 1; background: var(--forest); }
.microsoft-mark i:nth-child(2) { background: var(--coral); }.microsoft-mark i:nth-child(3) { background: var(--amber); }.microsoft-mark i:nth-child(4) { background: #4b84a6; }

/* Inputs and buttons */
input, select, textarea { border: 1px solid var(--line); border-radius: .35rem; padding: .75rem .82rem; background: var(--paper); color: var(--ink); outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--forest); box-shadow: 0 0 0 3px rgba(6,76,61,.1); }
.btn { border: 1px solid var(--forest); border-radius: .55rem; padding: .7rem 1rem; background: transparent; cursor: pointer; font-weight: 700; transition: transform .16s ease, background .16s ease, box-shadow .16s ease; }
.btn:hover { transform: translateY(-1px); }
.btn.primary { color: var(--paper); background: var(--forest); }
.btn.primary:hover { background: var(--forest-deep); box-shadow: 0 10px 24px rgba(3,53,43,.16); }
.btn:disabled { opacity: .42; cursor: not-allowed; transform: none; }
.btn.wide { width: 100%; }
.btn.ghost { border-color: var(--line); background: rgba(255,255,255,.42); }
.btn.small { padding: .45rem .7rem; font-size: .78rem; }
.btn.microsoft { color: white; background: #245aa5; border-color: #245aa5; }

/* Application shell */
.app-shell { position: relative; z-index: 1; min-height: 100vh; display: grid; grid-template-columns: 18rem minmax(0, 1fr); }
.sidebar { min-height: 100vh; padding: 1.4rem; color: var(--paper); background: var(--forest-deep); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.sidebar-brand strong, .sidebar-brand small { display: block; }
.sidebar-brand strong { font: 800 1.2rem var(--mono); letter-spacing: .04em; }
.sidebar-brand small { margin-top: .18rem; color: rgba(255,255,255,.55); font-size: .68rem; }
.side-nav { display: grid; gap: .35rem; margin: 3rem 0; }
.side-nav .tab { display: flex; gap: .9rem; align-items: center; border: 0; border-left: 2px solid transparent; padding: .8rem .65rem; color: rgba(255,255,255,.62); background: transparent; cursor: pointer; text-align: left; }
.side-nav .tab span { color: rgba(255,255,255,.32); font: 700 .65rem var(--mono); }
.side-nav .tab.active { color: var(--paper); border-left-color: var(--amber); background: rgba(255,255,255,.07); }
.identity-card { margin-top: auto; padding: 1.1rem; border: 1px solid rgba(255,255,255,.14); background: rgba(255,255,255,.05); }
.identity-card .eyebrow { color: #f2d58e; }
.avatar { width: 3rem; height: 3rem; margin: .85rem 0; display: grid; place-items: center; border-radius: 50%; color: var(--forest-deep); background: var(--amber); font: 900 .85rem var(--mono); }
.identity-card > strong, .identity-card > span { display: block; }
.identity-card > strong { font: 600 1.18rem var(--display); }
.identity-card > span { margin-top: .2rem; color: rgba(255,255,255,.58); font-size: .78rem; }
.identity-card dl { margin: 1rem 0 0; }
.identity-card dl div { padding: .65rem 0; border-top: 1px solid rgba(255,255,255,.12); }
.identity-card dt { color: rgba(255,255,255,.42); font: 700 .58rem var(--mono); text-transform: uppercase; }
.identity-card dd { margin: .2rem 0 0; font-size: .76rem; }
.sidebar-footer { display: flex; gap: .5rem; align-items: center; margin-top: 1rem; color: rgba(255,255,255,.45); font-size: .67rem; }
.live-dot { width: .55rem; height: .55rem; border-radius: 50%; background: #66d09c; box-shadow: 0 0 0 4px rgba(102,208,156,.12); }
.workspace-shell { min-width: 0; }
.topbar { min-height: 6.5rem; padding: 1.4rem clamp(1.25rem, 3vw, 3rem); display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); background: rgba(244,239,223,.83); backdrop-filter: blur(8px); }
.topbar h1 { margin: 0; font: 600 2rem var(--display); }
.topbar-actions { display: flex; align-items: center; gap: .7rem; }
.tenant-badge { background: var(--amber); border-color: #d49917; }
.who { max-width: 15rem; color: var(--muted); font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.content { padding: clamp(1rem, 2.5vw, 2.5rem); }
.context-ribbon { display: grid; grid-template-columns: 1.3fr 1fr 1fr .8fr; margin-bottom: 1rem; border: 1px solid var(--line); background: var(--paper); }
.context-ribbon > div { min-width: 0; padding: .85rem 1rem; border-right: 1px solid var(--line); }
.context-ribbon > div:last-child { border-right: 0; }
.context-ribbon span { display: block; color: var(--muted); font: 700 .58rem var(--mono); letter-spacing: .08em; }
.context-ribbon strong { display: block; margin-top: .3rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .8rem; }
.context-ribbon .context-state { display: flex; gap: .6rem; align-items: center; background: var(--mint); }
.context-state i { width: .6rem; height: .6rem; border-radius: 50%; background: #16966b; }
.chat-layout { min-height: calc(100vh - 11.5rem); display: grid; grid-template-columns: minmax(0, 1fr) 19rem; gap: 1rem; }
.conversation-panel, .access-panel, .panel { border: 1px solid var(--line); background: rgba(255,250,240,.86); box-shadow: 0 12px 32px rgba(16,35,31,.06); }
.conversation-panel { min-height: 42rem; display: grid; grid-template-rows: auto 1fr auto; }
.conversation-head { padding: 1.25rem 1.4rem; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.conversation-head h2 { margin: 0; font: 600 1.45rem var(--display); }
.privacy-label { color: var(--forest); background: var(--mint); }
.messages { min-height: 20rem; max-height: calc(100vh - 23rem); overflow-y: auto; padding: 1.4rem; display: flex; flex-direction: column; gap: 1rem; background-image: linear-gradient(rgba(6,76,61,.035) 1px, transparent 1px); background-size: 100% 2.4rem; }
.msg { max-width: min(78%, 48rem); padding: .9rem 1rem; border-radius: .65rem; line-height: 1.58; white-space: pre-wrap; animation: rise .22s ease both; }
.msg.user { margin-left: auto; color: var(--paper); background: var(--forest); border-bottom-right-radius: .1rem; }
.msg.assistant { background: white; border: 1px solid var(--line); border-bottom-left-radius: .1rem; }
.msg.system { align-self: center; padding: .55rem .85rem; color: var(--muted); background: var(--mint); font-size: .78rem; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@keyframes reveal-left { from { opacity: 0; transform: translateX(-12px); } }
@keyframes reveal-right { from { opacity: 0; transform: translateX(12px); } }
.chat-input { padding: 1rem; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .7rem; border-top: 1px solid var(--line); background: var(--paper); }
.chat-input textarea { resize: none; min-height: 3.3rem; }
.access-panel { padding: 1.3rem; align-self: stretch; }
.access-panel h3 { margin: .4rem 0 1.3rem; font: 600 1.45rem var(--display); }
.access-layers { display: grid; gap: .7rem; }
.access-layer { padding: .9rem; border-left: 3px solid var(--forest); background: rgba(220,235,220,.5); }
.access-layer:nth-child(2) { border-color: var(--amber); }.access-layer:nth-child(3) { border-color: var(--coral); }
.access-layer span, .access-layer strong, .access-layer small { display: block; }
.access-layer span { color: var(--muted); font: 700 .58rem var(--mono); letter-spacing: .08em; text-transform: uppercase; }
.access-layer strong { margin: .3rem 0; font-size: .86rem; }
.access-layer small { color: var(--muted); line-height: 1.4; }
.access-footnote { margin-top: 1.2rem; color: var(--muted); font-size: .72rem; line-height: 1.5; }
.citations { display: grid; gap: .45rem; margin-top: .8rem; }
.citation { padding: .7rem; text-align: left; border: 1px solid var(--line); background: var(--cream); cursor: pointer; }
.c-title { font-weight: 700; }.c-snippet { margin-top: .25rem; color: var(--muted); font-size: .72rem; }
.actions { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .7rem; }
.action-chip { border: 1px solid var(--forest); border-radius: 999px; padding: .35rem .6rem; color: var(--forest); background: transparent; cursor: pointer; font-size: .7rem; }

/* Workspace and governance */
.section-intro { margin: 0 0 1.5rem; max-width: 46rem; }
.section-intro h2 { margin: 0; font: 600 clamp(2rem, 4vw, 3.6rem)/1 var(--display); }
.section-intro > p:last-child { color: var(--muted); }
.workspace-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.panel { min-width: 0; padding: 1.35rem; }
.panel h3 { margin: .55rem 0; font: 600 1.35rem var(--display); }
.panel p { color: var(--muted); line-height: 1.55; }
.panel-index { color: var(--coral); font: 700 .62rem var(--mono); letter-spacing: .1em; }
.panel code { display: inline-block; margin-top: .6rem; padding: .35rem .5rem; background: var(--mint); color: var(--forest-deep); }
.assistant-settings { grid-column: 1 / -1; }
.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .8rem; }
.form-grid label { display: grid; gap: .35rem; color: var(--muted); font-size: .74rem; }
.form-actions { grid-column: 1 / -1; display: flex; align-items: center; gap: .8rem; }
.readout { display: grid; grid-template-columns: auto 1fr; gap: .45rem 1rem; }
.readout dt { color: var(--muted); }.readout dd { margin: 0; }
.saved { color: var(--forest); font-size: .82rem; }
.admin-grid { display: grid; grid-template-columns: minmax(16rem, .7fr) minmax(28rem, 1.3fr); gap: 1rem; }
.admin-grid .wide { grid-column: 1 / -1; }
.health { display: grid; gap: .55rem; margin: 1rem 0; }
.health-item { display: flex; gap: .55rem; align-items: flex-start; font-size: .82rem; }
.dot { width: .6rem; height: .6rem; margin-top: .25rem; border-radius: 50%; background: var(--muted); flex: 0 0 auto; }.dot.ok { background: #15926a; }.dot.warn { background: var(--amber); }.dot.err { background: var(--coral); }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .78rem; }
.table th { color: var(--muted); font: 700 .62rem var(--mono); letter-spacing: .06em; text-align: left; }
.table th, .table td { padding: .7rem .55rem; border-bottom: 1px solid var(--line); }
.role-select { padding: .35rem; }
.pill { padding: .25rem .45rem; border-radius: 999px; font-size: .65rem; }.pill.ok { background: var(--mint); }.pill.no { background: #f4d8d0; }
.upload-row { display: grid; grid-template-columns: 1fr 1fr 1fr 2fr auto; gap: .55rem; margin: 1rem 0; }

/* Source drawer */
.drawer { position: fixed; z-index: 30; inset: 0 0 0 auto; width: min(44rem, 94vw); padding: 1.4rem; background: var(--paper); border-left: 1px solid var(--line); box-shadow: -20px 0 60px rgba(16,35,31,.2); display: grid; grid-template-rows: auto auto 1fr; }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.drawer-head strong { font: 600 1.4rem var(--display); }
.drawer-path { margin: .8rem 0; padding: .55rem; color: var(--muted); background: var(--cream); font: .68rem var(--mono); overflow-wrap: anywhere; }
.drawer-body { overflow: auto; white-space: pre-wrap; font: .83rem/1.65 var(--mono); }

@media (max-width: 1050px) {
  .signin-overlay { grid-template-columns: 1fr; }
  .signin-story { min-height: 26rem; padding: 2rem; }
  .story-copy h2 { font-size: clamp(3rem, 10vw, 5rem); }
  .signin-panel { padding: 2rem; }
  .app-shell { grid-template-columns: 5.2rem minmax(0, 1fr); }
  .sidebar { padding: 1rem .65rem; align-items: center; }
  .sidebar-brand > div, .identity-card, .sidebar-footer span:last-child { display: none; }
  .side-nav .tab { width: 3.5rem; justify-content: center; font-size: 0; }
  .side-nav .tab span { font-size: .68rem; }
  .chat-layout { grid-template-columns: 1fr; }
  .access-panel { display: none; }
  .workspace-grid { grid-template-columns: 1fr 1fr; }
  .upload-row { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 720px) {
  .signin-story { min-height: 22rem; }
  .boundary-strip { display: none; }
  .organization-tabs { display: grid; grid-template-columns: 1fr; overflow: visible; }
  .organization-tab { width: 100%; text-align: left; white-space: normal; }
  .persona-grid { grid-template-columns: 1fr; max-height: none; }
  .app-shell { display: block; }
  .sidebar { position: fixed; z-index: 20; inset: auto 0 0; width: auto; height: 4.2rem; min-height: 0; padding: .4rem; flex-direction: row; background: var(--forest-deep); }
  .sidebar-brand, .identity-card, .sidebar-footer { display: none; }
  .side-nav { width: 100%; margin: 0; grid-template-columns: repeat(3, 1fr); }
  .side-nav .tab { width: auto; border-left: 0; border-top: 2px solid transparent; }
  .side-nav .tab.active { border-left: 0; border-top-color: var(--amber); }
  .topbar { min-height: 5.5rem; padding: 1rem; }
  .topbar .who, .tenant-badge { display: none; }
  .content { padding: .7rem .7rem 5rem; }
  .context-ribbon { grid-template-columns: 1fr 1fr; }
  .context-ribbon > div:nth-child(2) { border-right: 0; }.context-ribbon > div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .chat-layout { min-height: auto; }
  .conversation-panel { min-height: calc(100vh - 13rem); }
  .conversation-head { align-items: flex-start; }.privacy-label { display: none; }
  .messages { max-height: none; min-height: 22rem; }
  .msg { max-width: 92%; }
  .chat-input { grid-template-columns: 1fr; }
  .workspace-grid, .admin-grid { grid-template-columns: 1fr; }
  .assistant-settings, .admin-grid .wide { grid-column: auto; }
  .form-grid { grid-template-columns: 1fr; }
  .upload-row { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .cursor { animation: none !important; opacity: 1; }
}
