:root {
  --ink: #17324d;
  --ink-soft: #486177;
  --navy: #102b45;
  --navy-deep: #0a2035;
  --teal: #0a8f98;
  --teal-dark: #08747c;
  --teal-pale: #e7f5f5;
  --sky: #edf5f7;
  --line: #dbe5e9;
  --paper: #ffffff;
  --canvas: #f6f9fa;
  --shadow: 0 18px 50px rgba(14, 42, 65, .12);
  --radius: 18px;
  color-scheme: light;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; color: var(--ink); background: var(--canvas); }
button, textarea, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
.eyebrow { margin: 0; color: var(--teal); font-size: .72rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }

.brand-mark {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  overflow: hidden;
  border-radius: 16px;
  background: white;
  box-shadow: 0 8px 20px rgba(10, 32, 53, .12);
}
.brand-mark img { width: 100%; height: 100%; object-fit: contain; }
.brand-mark.small { width: 43px; height: 43px; border-radius: 12px; box-shadow: none; }

/* Login */
.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 28px;
  background:
    radial-gradient(circle at 15% 18%, rgba(22, 161, 166, .18), transparent 30%),
    radial-gradient(circle at 90% 85%, rgba(53, 111, 145, .17), transparent 32%),
    linear-gradient(145deg, #eef8f8 0%, #f8fbfc 50%, #edf3f6 100%);
}
.login-shell { width: min(100%, 470px); text-align: center; }
.login-card {
  padding: 42px;
  text-align: left;
  border: 1px solid rgba(255,255,255,.8);
  border-radius: 26px;
  background: rgba(255,255,255,.92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}
.login-brand { display: flex; align-items: center; gap: 17px; }
.login-brand h1 { margin: 3px 0 0; font-size: 2rem; letter-spacing: -.045em; }
.login-brand h1 span { color: var(--teal); }
.login-intro { margin: 27px 0 28px; color: var(--ink-soft); font-size: 1.04rem; line-height: 1.65; }
.microsoft-button {
  display: flex;
  min-height: 54px;
  align-items: center;
  justify-content: center;
  gap: 13px;
  padding: 0 20px;
  border-radius: 13px;
  color: white;
  background: var(--navy);
  font-weight: 750;
  text-decoration: none;
  transition: transform .16s ease, background .16s ease, box-shadow .16s ease;
}
.microsoft-button:hover { transform: translateY(-1px); background: var(--navy-deep); box-shadow: 0 10px 24px rgba(10,32,53,.18); }
.microsoft-grid { display: grid; grid-template-columns: repeat(2, 8px); gap: 2px; }
.microsoft-grid i { width: 8px; height: 8px; background: #f25022; }
.microsoft-grid i:nth-child(2) { background: #7fba00; }
.microsoft-grid i:nth-child(3) { background: #00a4ef; }
.microsoft-grid i:nth-child(4) { background: #ffb900; }
.login-note { margin: 19px 0 0; color: #718393; font-size: .84rem; text-align: center; }
.login-footer { margin: 19px 0 0; color: #6c8292; font-size: .78rem; }
.alert { margin: -8px 0 20px; padding: 12px 14px; border: 1px solid #efc5c5; border-radius: 11px; color: #812f2f; background: #fff2f2; font-size: .9rem; }

/* Portal shell */
.app-shell { display: grid; min-height: 100vh; grid-template-columns: 292px minmax(0, 1fr); }
.sidebar {
  position: relative;
  z-index: 30;
  display: flex;
  height: 100vh;
  flex-direction: column;
  padding: 22px 17px 17px;
  color: #e8f2f7;
  background: linear-gradient(180deg, var(--navy-deep), #102f4b 58%, #113853);
}
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 0 4px 20px; }
.sidebar-brand .eyebrow { color: #71c9cc; font-size: .62rem; }
.sidebar-brand strong { display: block; margin-top: 2px; font-size: 1.2rem; letter-spacing: -.03em; }
.sidebar-brand strong em { color: #74d0d2; font-style: normal; }
.sidebar-brand .icon-button { margin-left: auto; color: white; }
.new-conversation {
  display: flex;
  min-height: 47px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px solid rgba(120, 214, 216, .32);
  border-radius: 13px;
  color: white;
  background: rgba(15, 143, 151, .82);
  font-weight: 750;
  cursor: pointer;
  transition: background .15s ease, transform .15s ease;
}
.new-conversation:hover { background: var(--teal); transform: translateY(-1px); }
.history-heading { margin: 26px 10px 8px; color: #7f9caf; font-size: .68rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.conversation-list { min-height: 0; overflow: auto; scrollbar-width: thin; }
.conversation-link {
  display: block;
  width: 100%;
  margin: 3px 0;
  padding: 11px 12px;
  overflow: hidden;
  border: 0;
  border-radius: 10px;
  color: #cbdbe5;
  background: transparent;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.conversation-link:hover { color: white; background: rgba(255,255,255,.07); }
.conversation-link.active { color: white; background: rgba(98, 199, 203, .17); box-shadow: inset 3px 0 #61c7cb; }
.sidebar-foot { display: grid; grid-template-columns: 9px 1fr auto; align-items: center; gap: 9px; margin-top: auto; padding: 14px 10px 4px; border-top: 1px solid rgba(255,255,255,.09); color: #c0d2dc; font-size: .76rem; }
.sidebar-foot small { color: #7f9caf; }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 999px; background: #55d4a8; box-shadow: 0 0 0 4px rgba(85,212,168,.1); }
.sidebar-scrim { display: none; }

.workspace { display: grid; min-width: 0; height: 100vh; grid-template-rows: auto minmax(0, 1fr) auto; background: var(--paper); }
.topbar { display: flex; min-height: 76px; align-items: center; gap: 14px; padding: 0 30px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.95); }
.conversation-heading { min-width: 0; }
.conversation-heading h1 { margin: 0; overflow: hidden; font-size: 1.03rem; text-overflow: ellipsis; white-space: nowrap; }
.conversation-heading > span { display: flex; align-items: center; gap: 7px; margin-top: 5px; color: #718493; font-size: .72rem; }
.conversation-heading .live-dot { width: 6px; height: 6px; }
.account { position: relative; margin-left: auto; }
.account-button { display: flex; align-items: center; gap: 10px; padding: 6px 9px 6px 6px; border: 0; border-radius: 12px; background: transparent; cursor: pointer; }
.account-button:hover { background: var(--sky); }
.avatar { display: grid; width: 36px; height: 36px; place-items: center; border-radius: 11px; color: white; background: linear-gradient(145deg, var(--teal), #17647e); font-weight: 800; }
.account-copy { display: grid; max-width: 190px; text-align: left; }
.account-copy strong, .account-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-copy strong { font-size: .82rem; }
.account-copy small { margin-top: 2px; color: #788b99; font-size: .68rem; }
.account-menu { position: absolute; top: calc(100% + 8px); right: 0; z-index: 20; width: 190px; padding: 7px; border: 1px solid var(--line); border-radius: 12px; background: white; box-shadow: 0 12px 35px rgba(17,47,74,.15); }
.account-menu button { width: 100%; padding: 10px; border: 0; border-radius: 8px; background: transparent; text-align: left; cursor: pointer; }
.account-menu button:hover { background: var(--sky); }
.icon-button { display: grid; width: 38px; height: 38px; place-items: center; border: 0; border-radius: 10px; background: transparent; cursor: pointer; }
.mobile-only { display: none; }

.conversation { min-height: 0; overflow: auto; padding: 26px 7vw 34px; scroll-behavior: smooth; }
.messages { width: min(100%, 900px); margin: 0 auto; }
.empty-state { width: min(100%, 760px); margin: clamp(60px, 12vh, 135px) auto 0; text-align: center; }
.empty-state[hidden] { display: none; }
.virgile-orb { display: grid; width: 66px; height: 66px; margin: 0 auto 22px; place-items: center; border-radius: 21px; color: white; background: linear-gradient(145deg, #0aa2a5, #115675); box-shadow: 0 14px 30px rgba(9, 131, 142, .23); }
.virgile-orb span { font-family: Georgia, serif; font-size: 2.1rem; font-style: italic; }
.empty-state h2 { margin: 8px 0 10px; font-size: clamp(1.65rem, 3vw, 2.35rem); letter-spacing: -.05em; }
.empty-state > p:not(.eyebrow) { margin: 0 auto; color: var(--ink-soft); line-height: 1.6; }
.suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 28px; }
.suggestions button { padding: 11px 14px; border: 1px solid var(--line); border-radius: 999px; color: var(--ink-soft); background: white; cursor: pointer; box-shadow: 0 5px 15px rgba(18,50,77,.05); }
.suggestions button:hover { border-color: #9bcfd2; color: var(--teal-dark); background: var(--teal-pale); }

.message { display: grid; grid-template-columns: 42px minmax(0, 1fr); gap: 14px; margin: 0 0 28px; }
.message.user { grid-template-columns: minmax(0, 1fr); justify-items: end; }
.message-avatar { display: grid; width: 38px; height: 38px; place-items: center; border-radius: 12px; color: white; background: linear-gradient(145deg, var(--teal), #17647e); font-family: Georgia, serif; font-style: italic; font-weight: 700; }
.message-body { min-width: 0; }
.message-role { margin: 1px 0 8px; color: #718493; font-size: .72rem; font-weight: 750; }
.message-content { color: #263f54; font-size: .98rem; line-height: 1.7; overflow-wrap: anywhere; }
.message.user .message-content { white-space: pre-wrap; }
.message.assistant .message-content > :first-child { margin-top: 0; }
.message.assistant .message-content > :last-child { margin-bottom: 0; }
.message.assistant .message-content p { margin: 0 0 .78em; }
.message.assistant .message-content h2,
.message.assistant .message-content h3,
.message.assistant .message-content h4 { margin: 1.15em 0 .45em; color: #17384e; line-height: 1.3; }
.message.assistant .message-content h2 { font-size: 1.18rem; }
.message.assistant .message-content h3 { font-size: 1.08rem; }
.message.assistant .message-content h4 { font-size: 1rem; }
.message.assistant .message-content ul,
.message.assistant .message-content ol { margin: .35em 0 .9em; padding-left: 1.35em; }
.message.assistant .message-content li { margin: .24em 0; }
.message.assistant .message-content blockquote { margin: .7em 0; padding: .5em .85em; border-left: 3px solid #8bc8cb; color: #526c7e; background: #f4fafa; }
.message.assistant .message-content code { padding: .12em .35em; border-radius: 4px; color: #17475c; background: #eef5f6; font-size: .9em; }
.message.assistant .message-content a { color: var(--teal-dark); text-decoration-thickness: 1px; text-underline-offset: 2px; }
.message.assistant .message-content table { width: 100%; margin: .8em 0 1em; border-collapse: collapse; font-size: .9rem; }
.message.assistant .message-content th,
.message.assistant .message-content td { padding: .55em .65em; border: 1px solid var(--line); text-align: left; vertical-align: top; }
.message.assistant .message-content th { color: #17384e; background: var(--sky); }
.message.user .message-content { max-width: min(76ch, 84%); padding: 13px 17px; border-radius: 17px 17px 4px 17px; color: #19374f; background: var(--sky); }
.thinking .message-content { display: flex; align-items: center; gap: 8px; color: #6e8291; }
.typing-dots { display: inline-flex; gap: 4px; }
.typing-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--teal); animation: bounce 1.1s infinite ease-in-out; }
.typing-dots i:nth-child(2) { animation-delay: .13s; }
.typing-dots i:nth-child(3) { animation-delay: .26s; }
@keyframes bounce { 0%, 70%, 100% { transform: translateY(0); opacity: .4; } 35% { transform: translateY(-4px); opacity: 1; } }

.document-list { display: grid; gap: 9px; margin-top: 16px; }
.document-card { display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; align-items: center; gap: 12px; max-width: 660px; padding: 12px; border: 1px solid var(--line); border-radius: 13px; background: #fbfdfd; }
.file-icon { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 10px; color: var(--teal-dark); background: var(--teal-pale); font-size: .65rem; font-weight: 900; }
.file-copy { min-width: 0; }
.file-copy strong { display: block; overflow: hidden; font-size: .84rem; text-overflow: ellipsis; white-space: nowrap; }
.file-copy small { display: block; margin-top: 4px; color: #758896; font-size: .7rem; }
.file-actions { display: flex; gap: 6px; }
.file-actions a { padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: white; font-size: .72rem; font-weight: 700; text-decoration: none; }
.file-actions a.primary { border-color: var(--teal); color: white; background: var(--teal); }
.file-actions a:hover { filter: brightness(.97); }

.composer-wrap { padding: 12px 7vw 17px; background: linear-gradient(180deg, rgba(255,255,255,.7), white 30%); }
.composer { display: grid; width: min(100%, 900px); margin: 0 auto; grid-template-columns: minmax(0, 1fr) 44px; align-items: end; gap: 8px; padding: 8px 8px 8px 17px; border: 1px solid #ccdadd; border-radius: 18px; background: white; box-shadow: 0 8px 28px rgba(16,43,69,.1); }
.composer:focus-within { border-color: #82c4c7; box-shadow: 0 8px 28px rgba(16,43,69,.1), 0 0 0 3px rgba(10,143,152,.08); }
.composer textarea { width: 100%; max-height: 170px; resize: none; border: 0; outline: 0; color: var(--ink); background: transparent; line-height: 1.5; }
.composer textarea::placeholder { color: #91a0aa; }
.send-button { display: grid; width: 42px; height: 42px; place-items: center; border: 0; border-radius: 12px; color: white; background: var(--teal); font-size: 1.25rem; font-weight: 900; cursor: pointer; }
.send-button:hover { background: var(--teal-dark); }
.send-button:disabled { cursor: wait; opacity: .45; }
.composer-note { margin: 8px 0 0; color: #91a0aa; font-size: .66rem; text-align: center; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 100; max-width: min(390px, calc(100vw - 44px)); padding: 13px 16px; border-radius: 11px; color: white; background: #813737; box-shadow: var(--shadow); font-size: .85rem; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(310px, 88vw); transform: translateX(-105%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-scrim { position: fixed; inset: 0; z-index: 25; background: rgba(5,23,38,.42); }
  .sidebar-scrim.open { display: block; }
  .mobile-only { display: grid; }
  .topbar { padding: 0 17px; }
  .conversation, .composer-wrap { padding-left: 18px; padding-right: 18px; }
}

@media (max-width: 620px) {
  .login-page { padding: 16px; }
  .login-card { padding: 29px 24px; border-radius: 21px; }
  .login-brand h1 { font-size: 1.72rem; }
  .account-copy { display: none; }
  .conversation-heading h1 { max-width: 48vw; }
  .conversation { padding-top: 18px; }
  .empty-state { margin-top: 44px; }
  .suggestions { align-items: stretch; flex-direction: column; }
  .message { grid-template-columns: 35px minmax(0, 1fr); gap: 10px; }
  .message-avatar { width: 34px; height: 34px; }
  .message.user .message-content { max-width: 94%; }
  .document-card { grid-template-columns: 38px minmax(0, 1fr); }
  .file-actions { grid-column: 2; }
  .composer-wrap { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
}
