* { box-sizing: border-box; }

:root {
  --brand-primary: #231f20;
  --brand-accent: #8a6d3b;
  --surface: #ffffff;
  --surface-soft: #f5f4f1;
  --line: #dedbd5;
  --text: #231f20;
  --muted: #69645f;
  --danger: #a12622;
}

html { font-family: Inter, "Segoe UI", Arial, sans-serif; color: var(--text); }
body {
  margin: 0; min-height: 100vh; min-height: 100dvh; background: var(--surface-soft);
  display: flex; flex-direction: column;
}
a { color: var(--brand-primary); }
button, input { font: inherit; }
textarea, select { font: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.app-header {
  min-height: 68px; padding: 12px clamp(20px, 4vw, 56px); background: var(--surface);
  border-bottom: 1px solid var(--line); display: flex; align-items: center;
  justify-content: space-between; gap: 24px;
}
.brand { display: inline-flex; align-items: center; gap: 12px; text-decoration: none; font-weight: 700; }
.brand img { width: 38px; height: 38px; object-fit: contain; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px; color: white; background: var(--brand-primary);
  display: grid; place-items: center; font-size: 20px;
}
.app-header nav { display: flex; align-items: center; flex-wrap: wrap; gap: 18px; font-size: 14px; }
.app-header nav form { margin: 0; }
.link-button { border: 0; padding: 0; background: none; color: var(--brand-primary); text-decoration: underline; cursor: pointer; }
.app-footer {
  min-height: 32px; padding: 6px 20px; flex: 0 0 32px; display: flex;
  align-items: center; justify-content: center; gap: 8px; border-top: 1px solid #393536;
  color: #f5f2ed; background: var(--brand-primary); font-size: 11px;
  letter-spacing: .055em; text-align: center;
}
.app-footer-mark { width: 5px; height: 5px; flex: 0 0 5px; border-radius: 50%; background: var(--brand-accent); }

.page-shell { width: min(1120px, calc(100% - 40px)); margin: 48px auto; }
.hero-card, .content-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px;
  box-shadow: 0 18px 45px rgba(35, 31, 32, .07); padding: clamp(28px, 5vw, 64px);
}
.hero-card { display: grid; grid-template-columns: 1.5fr .7fr; align-items: center; gap: 48px; min-height: 360px; }
.hero-card h1, .content-card h1, .login-card h1 { font-size: clamp(32px, 5vw, 54px); letter-spacing: -.04em; margin: 6px 0 18px; }
.hero-copy { color: var(--muted); font-size: 18px; line-height: 1.65; max-width: 680px; }
.eyebrow { color: var(--brand-accent); font-size: 12px; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
.status-panel { border-left: 3px solid var(--brand-accent); padding: 18px 20px; display: flex; gap: 12px; align-items: flex-start; }
.status-panel span { color: var(--muted); }
.status-dot { width: 10px; height: 10px; margin-top: 5px; border-radius: 50%; background: #2f855a; }

.login-page {
  display: grid; grid-template-rows: minmax(0, 1fr) 32px; place-items: center;
  padding: clamp(14px, 3vh, 28px) 16px 0;
  background: linear-gradient(135deg, color-mix(in srgb, var(--surface-soft) 94%, var(--brand-primary)), var(--surface));
}
.login-page .app-footer { width: calc(100% + 32px); margin-inline: -16px; align-self: end; }
.login-card { width: min(400px, 100%); padding: clamp(22px, 4vw, 34px); border-radius: 18px; background: var(--surface); box-shadow: 0 20px 55px rgba(35, 31, 32, .12); }
.login-logo { display: block; width: min(220px, 78%); height: 78px; object-fit: contain; object-position: center; margin: 0 auto 16px; }
.login-logo-fallback { min-height: 78px; margin: 0 auto 16px; display: flex; align-items: center; justify-content: center; gap: 12px; color: var(--brand-primary); }
.login-logo-fallback span { width: 54px; height: 54px; border-radius: 14px; display: grid; place-items: center; color: var(--surface); background: var(--brand-primary); font-size: 24px; font-weight: 800; }
.login-logo-fallback strong { max-width: 210px; font-size: 25px; line-height: 1.05; }
.login-intro { text-align: center; }
.login-card .eyebrow { margin: 0 0 6px; }
.login-card h1 { margin: 0 0 8px; font-size: 30px; }
.login-card .muted { margin: 0; font-size: 14px; }
.login-card .stacked-form { gap: 7px; margin-top: 20px; }
.login-card .stacked-form label { margin-top: 5px; }
.login-card .stacked-form input { padding: 10px 12px; }
.login-card .primary-button { margin-top: 9px; padding: 11px 16px; }
.login-card .form-error { margin: 14px 0 0; font-size: 13px; text-align: center; }
.muted, .help-text { color: var(--muted); }
.narrow-card { max-width: 680px; margin: 0 auto; }

@media (max-height: 680px) {
  .login-page { padding-top: 8px; }
  .login-card { padding: 18px 24px; }
  .login-logo { width: min(180px, 68%); height: 58px; margin-bottom: 10px; }
  .login-logo-fallback { min-height: 58px; margin-bottom: 10px; }
  .login-logo-fallback span { width: 44px; height: 44px; border-radius: 12px; font-size: 19px; }
  .login-logo-fallback strong { font-size: 21px; }
  .login-card .eyebrow { margin-bottom: 3px; font-size: 10px; }
  .login-card h1 { margin-bottom: 5px; font-size: 26px; }
  .login-card .muted { font-size: 13px; }
  .login-card .stacked-form { gap: 5px; margin-top: 12px; }
  .login-card .stacked-form label { margin-top: 3px; font-size: 14px; }
  .login-card .stacked-form input { padding: 8px 10px; }
  .login-card .primary-button { margin-top: 6px; padding-block: 9px; }
}

.stacked-form { display: grid; gap: 10px; margin-top: 28px; }
.stacked-form label { font-weight: 650; margin-top: 8px; }
.stacked-form input {
  width: 100%; border: 1px solid #bbb7b1; border-radius: 9px; padding: 12px 14px;
  background: var(--surface); outline: none;
}
.stacked-form input:focus { border-color: var(--brand-accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-accent) 20%, transparent); }
.primary-button {
  border: 0; border-radius: 9px; padding: 13px 18px; margin-top: 14px;
  color: white; background: var(--brand-primary); font-weight: 750; cursor: pointer;
  text-align: center; text-decoration: none;
}
.inline-button { display: inline-block; }
.form-error, .errorlist { color: var(--danger); }
.messages { border-radius: 10px; padding: 8px 18px; margin-bottom: 20px; background: #eaf6ef; }
.chat-page .messages { position: fixed; z-index: 20; top: 76px; left: 50%; width: min(720px, calc(100% - 30px)); margin: 0; transform: translateX(-50%); box-shadow: 0 8px 30px rgba(35,31,32,.16); }

.chat-page {
  height: 100vh; height: 100dvh; min-height: 0; overflow: hidden;
  background: var(--surface-soft);
}
.chat-page .app-header { position: relative; z-index: 5; min-height: 64px; flex: 0 0 auto; }
.chat-shell {
  display: grid; grid-template-columns: 300px minmax(0, 1fr);
  flex: 1 1 auto; height: auto; min-height: 0;
}
.chat-sidebar { min-width: 0; background: color-mix(in srgb, var(--surface) 70%, var(--surface-soft)); border-right: 1px solid var(--line); display: flex; flex-direction: column; overflow: hidden; }
.sidebar-actions { padding: 20px 18px 14px; border-bottom: 1px solid var(--line); }
.sidebar-actions form { margin: 0; }
.new-chat-button { display: block; width: 100%; border: 1px solid var(--brand-primary); border-radius: 10px; padding: 11px 14px; background: var(--brand-primary); color: white; font-weight: 750; cursor: pointer; text-align: center; text-decoration: none; }
.conversation-search { display: flex; margin-top: 12px !important; }
.conversation-search input { min-width: 0; flex: 1; border: 1px solid #c9c5bf; border-right: 0; border-radius: 9px 0 0 9px; padding: 9px 11px; background: white; }
.conversation-search button { border: 1px solid #c9c5bf; border-radius: 0 9px 9px 0; padding: 0 12px; background: white; cursor: pointer; }
.conversation-list { padding: 12px 10px 28px; overflow-y: auto; }
.conversation-list section + section { margin-top: 20px; }
.conversation-list h2 { margin: 0 10px 7px; color: var(--muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.conversation-list a { display: grid; gap: 3px; padding: 10px; border-radius: 9px; color: var(--text); text-decoration: none; }
.conversation-list a:hover, .conversation-list a.active { background: color-mix(in srgb, var(--surface-soft) 86%, var(--brand-accent)); }
.conversation-list a span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.conversation-list a small { color: var(--muted); font-size: 11px; }
.empty-history { padding: 12px; color: var(--muted); font-size: 13px; }

.chat-workspace { min-width: 0; background: var(--surface); display: grid; grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden; }
.conversation-header { min-height: 76px; padding: 14px clamp(20px, 4vw, 54px); border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.conversation-header h1 { max-width: 620px; margin: 2px 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 21px; }
.conversation-header .eyebrow { margin: 0; font-size: 10px; }
.conversation-controls { display: flex; align-items: center; gap: 10px; }
.conversation-controls > label { color: var(--muted); font-size: 12px; }
.conversation-controls select { max-width: 280px; border: 1px solid #c9c5bf; border-radius: 8px; padding: 8px 10px; background: white; }
.conversation-menu { position: relative; }
.conversation-menu summary { width: 36px; height: 36px; border: 1px solid #c9c5bf; border-radius: 8px; display: grid; place-items: center; cursor: pointer; list-style: none; }
.conversation-menu summary::-webkit-details-marker { display: none; }
.conversation-menu > div { position: absolute; z-index: 8; right: 0; top: 44px; width: 300px; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: white; box-shadow: 0 16px 40px rgba(35,31,32,.15); }
.conversation-menu form { display: grid; gap: 8px; }
.conversation-menu form + form { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); }
.conversation-menu label { font-size: 12px; font-weight: 700; }
.conversation-menu input { width: 100%; border: 1px solid #c9c5bf; border-radius: 7px; padding: 8px; }
.conversation-menu textarea, .conversation-menu select { width: 100%; border: 1px solid #c9c5bf; border-radius: 7px; padding: 8px; background: white; }
.conversation-menu button { border: 0; border-radius: 7px; padding: 8px 10px; cursor: pointer; }
.danger-button { background: #f7e8e7; color: var(--danger); }

.message-list { overflow-y: auto; padding: 26px clamp(22px, 7vw, 110px) 40px; scroll-behavior: smooth; }
.message { width: min(850px, 100%); margin: 0 auto 26px; display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 14px; }
.message-avatar { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: #dedad3; font-weight: 800; }
.message-assistant .message-avatar { color: white; background: var(--brand-primary); }
.artifact-status { margin: 10px 0 0; color: var(--brand-accent); font-size: 12px; font-weight: 700; }
.artifact-status-error { color: var(--danger); }
.message-body { min-width: 0; }
.message-meta { min-height: 28px; display: flex; align-items: center; gap: 10px; font-size: 13px; }
.message-meta span { color: var(--danger); font-size: 11px; }
.message-content { color: #312d2e; font-size: 15px; line-height: 1.68; overflow-wrap: anywhere; white-space: pre-wrap; }
.message-assistant .message-content { white-space: normal; }
.message-content p { margin: 0 0 12px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content h1, .message-content h2, .message-content h3 { margin: 18px 0 8px; color: #231f20; line-height: 1.3; letter-spacing: -.015em; }
.message-content h1:first-child, .message-content h2:first-child, .message-content h3:first-child { margin-top: 0; }
.message-content h1 { font-size: 20px; }
.message-content h2 { font-size: 18px; }
.message-content h3 { font-size: 16px; }
.message-content ul, .message-content ol { margin: 6px 0 14px; padding-left: 24px; }
.message-content li { margin: 4px 0; padding-left: 3px; }
.message-content li::marker { color: var(--brand-accent); font-weight: 800; }
.message-content blockquote { margin: 12px 0; border-left: 3px solid var(--brand-accent); padding: 4px 0 4px 14px; color: #5d5658; }
.message-content hr { margin: 18px 0; border: 0; border-top: 1px solid var(--line); }
.message-content a { color: #795f22; text-decoration-thickness: 1px; text-underline-offset: 2px; }
.message-content code { padding: 2px 5px; border-radius: 5px; background: #efede8; font-family: "Cascadia Code", Consolas, monospace; font-size: .9em; }
.code-block { position: relative; margin: 12px 0; border-radius: 10px; overflow: hidden; background: #1f1d1e; }
.code-block button { position: absolute; top: 8px; right: 8px; border: 1px solid #5e595b; border-radius: 6px; padding: 5px 8px; color: #eee; background: #343031; cursor: pointer; font-size: 11px; }
.code-block pre { margin: 0; padding: 42px 16px 16px; overflow-x: auto; color: #f4f1ed; }
.code-block code { padding: 0; background: none; color: inherit; white-space: pre; }
.message-error { border-left: 3px solid var(--danger); padding-left: 12px; }
.message-error-label { color: var(--danger); font-size: 12px; }
.message-files { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 9px; }
.message-files a { border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; color: #312d2e; background: #f7f5f1; font-size: 12px; text-decoration: none; }
.message-files a:hover { border-color: var(--brand-accent); }
.message-sources { margin-top: 10px; color: #5d5658; font-size: 12px; }
.message-sources summary { cursor: pointer; font-weight: 700; color: #795f22; }
.message-sources ol { margin: 7px 0 0; padding-left: 22px; }
.message-sources li { margin: 4px 0; }
.generated-image { width: min(100%, 620px); margin: 0; }
.generated-image img { display: block; width: 100%; max-height: 620px; border-radius: 12px; object-fit: contain; background: #f3f1ed; }
.generated-image a { display: inline-block; margin-top: 7px; }
.streaming-cursor::after { content: ""; display: inline-block; width: 7px; height: 16px; margin-left: 3px; vertical-align: -2px; background: var(--brand-accent); animation: cursor-blink 1s steps(2) infinite; }
@keyframes cursor-blink { 50% { opacity: 0; } }

.conversation-welcome, .chat-empty-state { align-self: center; justify-self: center; max-width: 620px; padding: 40px; text-align: center; }
.conversation-welcome { margin-top: min(14vh, 110px); }
.conversation-welcome h2, .chat-empty-state h1 { margin: 12px 0; font-size: clamp(28px, 4vw, 42px); letter-spacing: -.035em; }
.conversation-welcome p, .chat-empty-state > p { color: var(--muted); line-height: 1.6; }
.welcome-mark, .empty-mark { width: 50px; height: 50px; margin: 0 auto; border-radius: 14px; display: grid; place-items: center; color: white; background: var(--brand-primary); font-weight: 900; font-size: 24px; }
.empty-mark { background: var(--danger); }

.composer-shell { padding: 10px clamp(22px, 7vw, 110px) 16px; background: linear-gradient(to top, white 78%, rgba(255,255,255,0)); }
.message-form { width: min(850px, 100%); margin: 0 auto; border: 1px solid #bbb7b1; border-radius: 15px; padding: 12px 12px 9px; background: white; box-shadow: 0 9px 28px rgba(35,31,32,.08); }
.message-form:focus-within { border-color: var(--brand-accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-accent) 16%, transparent); }
.message-form textarea { width: 100%; min-height: 32px; max-height: 180px; resize: none; border: 0; padding: 6px; outline: none; line-height: 1.5; }
.pending-files { display: flex; flex-wrap: wrap; gap: 6px; }
.attachment-capability { margin: 5px 6px 0; color: var(--danger); font-size: 11px; }
.attachment-capability:empty { display: none; }
.file-chip { display: inline-flex; align-items: center; gap: 7px; max-width: 100%; border-radius: 8px; padding: 5px 8px; background: #efede8; color: #403b3d; font-size: 11px; }
.file-chip-incompatible { outline: 2px solid color-mix(in srgb, var(--danger) 48%, transparent); background: #f9e9e8; }
.file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip button { border: 0; padding: 0; color: var(--danger); background: transparent; cursor: pointer; font-weight: 800; }
.attach-button { border: 0; border-radius: 8px; padding: 7px 9px; color: #4d4749; background: #efede8; cursor: pointer; }
.attach-button:disabled { opacity: .5; cursor: not-allowed; }
.composer-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.composer-actions > span { margin-right: auto; color: var(--muted); font-size: 11px; }
.send-button { width: 34px; height: 34px; border: 0; border-radius: 9px; color: white; background: var(--brand-primary); cursor: pointer; font-size: 20px; }
.send-button:disabled { opacity: .45; cursor: wait; }
.secondary-button { border: 1px solid #c9c5bf; border-radius: 8px; padding: 7px 10px; background: white; cursor: pointer; }
.composer-footnote { margin: 7px auto 0; color: var(--muted); text-align: center; font-size: 10px; }

.assistant-catalog-page { background: #eeece8; }
.assistant-catalog-main { width: 100%; flex: 1; }
.assistant-catalog { width: min(1040px, calc(100% - 32px)); margin: 32px auto; }
.assistant-catalog-heading { max-width: 760px; margin: 0 auto 28px; text-align: center; }
.assistant-catalog-heading h1 { margin: 5px 0 8px; font-size: clamp(30px, 4vw, 44px); letter-spacing: -.04em; }
.assistant-catalog-heading p { margin-inline: auto; color: var(--muted); line-height: 1.6; }
.assistant-back { display: inline-flex; align-items: center; gap: 7px; margin-bottom: 18px; color: var(--text); text-decoration: none; }
.assistant-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(245px, 308px)); justify-content: center; gap: 14px; }
.assistant-card { display: flex; flex-direction: column; min-height: 304px; padding: 19px; border: 1px solid var(--line); border-radius: 14px; background: white; box-shadow: 0 9px 24px rgba(35,31,32,.06); }
.assistant-card-heading { display: flex; align-items: center; gap: 12px; margin-bottom: 13px; min-width: 0; }
.assistant-card-heading > div:last-child { min-width: 0; }
.assistant-card-mark { width: 40px; height: 40px; flex: 0 0 40px; border-radius: 11px; display: grid; place-items: center; color: white; background: var(--brand-primary); font-size: 18px; font-weight: 900; }
.assistant-card-heading .eyebrow { margin: 0 0 3px; font-size: 10px; }
.assistant-card h2 { margin: 0; font-size: 19px; line-height: 1.2; letter-spacing: -.025em; }
.assistant-card-description { display: -webkit-box; margin: 0; overflow: hidden; color: var(--muted); font-size: 13px; line-height: 1.45; -webkit-box-orient: vertical; -webkit-line-clamp: 3; }
.assistant-capabilities { margin: 14px 0 12px; border-top: 1px solid var(--line); }
.assistant-capabilities div { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 11px; }
.assistant-capabilities dt { color: var(--muted); }
.assistant-capabilities dd { margin: 0; text-align: right; font-weight: 700; }
.assistant-card form { margin-top: auto; }
.assistant-card form .primary-button { width: 100%; min-height: 44px; margin-top: 6px; padding: 10px 12px; font-size: 13px; }
.assistant-card-disabled { opacity: .72; }
.assistant-unavailable { margin-top: auto !important; padding: 9px; border-radius: 8px; background: #f7e8e7; color: var(--danger) !important; font-size: 11px; }

@media (max-width: 760px) {
  .app-header, .app-header nav { align-items: flex-start; }
  .app-header { flex-direction: column; }
  .hero-card { grid-template-columns: 1fr; gap: 24px; }
  .chat-page { height: auto; min-height: 100vh; min-height: 100dvh; overflow: auto; }
  .chat-shell { grid-template-columns: 1fr; flex: none; height: auto; }
  .chat-sidebar { max-height: 260px; border-right: 0; border-bottom: 1px solid var(--line); }
  .chat-workspace { min-height: calc(100vh - 260px); grid-template-rows: auto minmax(420px, 1fr) auto; }
  .conversation-header { align-items: flex-start; flex-direction: column; }
  .conversation-controls { width: 100%; }
  .conversation-controls select { min-width: 0; flex: 1; }
  .message-list { padding-inline: 18px; }
  .composer-shell { padding-inline: 14px; }
  .composer-actions > span { display: none; }
  .assistant-catalog { width: calc(100% - 24px); margin: 22px auto; }
  .assistant-catalog-heading { margin-bottom: 20px; }
  .assistant-catalog-heading h1 { font-size: clamp(28px, 9vw, 36px); }
  .assistant-catalog-heading p { margin-block: 0; font-size: 14px; line-height: 1.45; }
  .assistant-back { margin-bottom: 14px; }
  .assistant-grid { gap: 11px; }
  .assistant-card { min-height: 0; padding: 16px; }
}

@media (max-width: 520px) {
  .assistant-grid { grid-template-columns: 1fr; }
  .assistant-card-description { -webkit-line-clamp: 2; }
}
