:root {
  color-scheme: light;
  --ink: #16251f;
  --muted: #64736d;
  --surface: #ffffff;
  --canvas: #f3f6f4;
  --line: #dce5e0;
  --brand: #006b5b;
  --brand-dark: #004f43;
  --brand-soft: #e3f2ed;
  --signal: #e85d26;
  --danger: #b42318;
  --shadow: 0 18px 48px rgba(22, 37, 31, 0.12);
  font-family: Inter, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--canvas); color: var(--ink); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); line-height: 1.55; }
.compact { font-size: .9rem; margin: .35rem 0 1rem; }
.eyebrow { margin: 0 0 .25rem; color: var(--brand); font-size: .72rem; font-weight: 750; letter-spacing: .12em; text-transform: uppercase; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 2rem; background: radial-gradient(circle at 15% 20%, #d8efe8 0, transparent 36%), radial-gradient(circle at 85% 80%, #f9dfd2 0, transparent 34%), #f4f7f5; }
.login-card { width: min(430px, 100%); padding: 3rem; background: rgba(255,255,255,.94); border: 1px solid rgba(255,255,255,.8); border-radius: 28px; box-shadow: var(--shadow); backdrop-filter: blur(18px); }
.login-card h1 { margin: 0; font-size: 2.4rem; letter-spacing: -.04em; }
.brand-mark { width: 54px; height: 54px; display: grid; place-items: center; margin-bottom: 1.5rem; border-radius: 16px; background: var(--brand); color: white; font-weight: 800; letter-spacing: -.06em; }
.brand-mark.small { width: 42px; height: 42px; margin: 0; border-radius: 12px; }
label { font-weight: 650; }
input, textarea { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: .85rem 1rem; background: white; color: var(--ink); outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(0,107,91,.12); }
.login-card form { display: grid; gap: .8rem; margin-top: 1.75rem; }
.form-error { min-height: 1.25rem; margin: 0; color: var(--danger); font-size: .9rem; }

.primary, .secondary, .ghost, .icon-button, .upload-button { border: 0; border-radius: 11px; padding: .72rem 1rem; font-weight: 700; transition: transform .15s, background .15s; }
.primary { background: var(--brand); color: white; }
.primary:hover { background: var(--brand-dark); transform: translateY(-1px); }
.primary:disabled { opacity: .55; cursor: wait; transform: none; }
.secondary { background: var(--brand-soft); color: var(--brand-dark); }
.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.wide { width: 100%; }

.app-shell { min-height: 100vh; }
.topbar { height: 76px; padding: 0 2rem; display: flex; align-items: center; justify-content: space-between; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand-row, .topbar-actions { display: flex; align-items: center; gap: .85rem; }
.brand-row h1 { margin: 0; font-size: 1.15rem; }
.connection { display: flex; align-items: center; gap: .45rem; padding: .45rem .7rem; border-radius: 999px; background: #f0f3f1; color: var(--muted); font-size: .82rem; font-weight: 650; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #98a49f; }
.connection.online { color: #087443; background: #e8f6ee; }
.connection.online .status-dot { background: #12a05c; box-shadow: 0 0 0 4px rgba(18,160,92,.13); }
.connection.connecting .status-dot { background: #db8b18; animation: pulse 1.1s infinite; }

.workspace { display: grid; grid-template-columns: 300px minmax(0, 1fr); min-height: calc(100vh - 76px); }
.sidebar { padding: 1.3rem; background: #edf2ef; border-right: 1px solid var(--line); }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: .35rem; padding: .3rem; background: rgba(255,255,255,.7); border-radius: 13px; }
.tab { border: 0; padding: .65rem; border-radius: 9px; color: var(--muted); background: transparent; font-weight: 700; }
.tab.active { background: white; color: var(--brand-dark); box-shadow: 0 3px 12px rgba(22,37,31,.08); }
.context-panel { margin-top: 1rem; padding: 1.2rem; border: 1px solid var(--line); border-radius: 17px; background: rgba(255,255,255,.72); }
.section-title-row { display: flex; justify-content: space-between; align-items: center; }
.section-title-row h2 { margin: 0; font-size: 1.05rem; }
.count { min-width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; background: var(--brand); color: white; font-size: .75rem; font-weight: 800; }
.inline-form { display: grid; grid-template-columns: 1fr 38px; gap: .4rem; }
.inline-form input { min-width: 0; padding: .65rem .75rem; }
.icon-button { padding: 0; background: var(--brand); color: white; }
.selected-products, .product-results { display: grid; gap: .45rem; margin-top: .75rem; }
.product-chip, .product-result { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .65rem .7rem; border: 1px solid var(--line); border-radius: 11px; background: white; font-size: .8rem; }
.product-chip button, .product-result button { flex: 0 0 auto; border: 0; color: var(--brand); background: transparent; font-weight: 800; }
.product-meta { display: block; margin-top: .15rem; color: var(--muted); font-size: .7rem; }

.content { min-width: 0; padding: 1.6rem; }
.panel { display: none; max-width: 1120px; min-height: calc(100vh - 125px); margin: 0 auto; background: var(--surface); border: 1px solid var(--line); border-radius: 22px; box-shadow: 0 8px 32px rgba(22,37,31,.05); overflow: hidden; }
.panel.active { display: flex; flex-direction: column; }
.panel-header { display: flex; align-items: center; justify-content: space-between; padding: 1.4rem 1.6rem; border-bottom: 1px solid var(--line); }
.panel-header h2 { margin: 0; font-size: 1.45rem; letter-spacing: -.025em; }
.agent-status { display: flex; align-items: center; gap: .65rem; margin: .8rem 1.6rem 0; padding: .72rem .9rem; border-radius: 11px; background: var(--brand-soft); color: var(--brand-dark); font-size: .86rem; font-weight: 650; }
.agent-status-copy { display: flex; align-items: baseline; gap: .45rem; min-width: 0; }
.agent-status-copy strong { flex: 0 0 auto; }
.agent-status-copy span { color: #42645d; font-weight: 500; }
.request-elapsed { margin-left: auto; flex-shrink: 0; font-variant-numeric: tabular-nums; font-size: .78rem; }
.message-timing { margin-top: .75rem; color: var(--muted); font-size: .76rem; font-variant-numeric: tabular-nums; white-space: normal; }
.spinner { width: 15px; height: 15px; border: 2px solid rgba(0,107,91,.25); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
.messages { flex: 1; min-height: 340px; padding: 1.6rem; overflow-y: auto; }
.empty-state { max-width: 480px; margin: 10vh auto 0; text-align: center; color: var(--muted); }
.empty-state h3 { margin: .75rem 0 .3rem; color: var(--ink); font-size: 1.4rem; }
.empty-icon { width: 54px; height: 54px; display: grid; place-items: center; margin: auto; border-radius: 17px; background: var(--brand-soft); color: var(--brand); font-size: 1.4rem; }
.message { max-width: 78%; margin-bottom: 1rem; padding: .9rem 1.05rem; border-radius: 16px; line-height: 1.55; white-space: pre-wrap; }
.message.user { margin-left: auto; background: var(--brand); color: white; border-bottom-right-radius: 4px; }
.message.assistant { background: #f0f4f2; border-bottom-left-radius: 4px; }
.message-text.markdown { white-space: normal; }
.message-text > :first-child { margin-top: 0; }
.message-text > :last-child { margin-bottom: 0; }
.message-text h2, .message-text h3, .message-text h4 { margin: 1rem 0 .4rem; line-height: 1.3; }
.message-text h2 { font-size: 1.2rem; }
.message-text h3 { font-size: 1.08rem; }
.message-text h4 { font-size: 1rem; }
.message-text p { margin: .45rem 0; }
.message-text ul, .message-text ol { margin: .5rem 0; padding-left: 1.35rem; }
.message-text li { margin: .3rem 0; }
.message-text a { color: var(--brand-dark); font-weight: 700; text-decoration-thickness: 1px; text-underline-offset: 2px; }
.message-text blockquote { margin: .65rem 0; padding: .6rem .8rem; border-left: 3px solid var(--brand); background: rgba(255,255,255,.58); }
.message-text hr { margin: 1rem 0; border: 0; border-top: 1px solid var(--line); }
.message img, .message video { display: block; max-width: 100%; max-height: 380px; margin-top: .75rem; border-radius: 12px; }
.message iframe { display: block; width: min(100%, 720px); aspect-ratio: 16 / 9; margin-top: .75rem; border: 0; border-radius: 12px; background: #111; }
.agent-request { margin: 0 1.6rem 1rem; padding: 1rem; border: 1px solid #f0c8b5; border-radius: 14px; background: #fff8f4; }
.agent-request h3 { margin: 0 0 .35rem; }
.choice-list { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; }
.choice { padding: .55rem .75rem; border: 1px solid #db9c7f; border-radius: 999px; background: white; color: #713315; font-weight: 650; }
.composer { margin: 0 1.6rem 1.5rem; padding: .8rem; border: 1px solid var(--line); border-radius: 16px; background: white; box-shadow: 0 8px 26px rgba(22,37,31,.08); }
.composer textarea { border: 0; padding: .4rem; resize: vertical; box-shadow: none; }
.composer-actions { display: flex; justify-content: space-between; align-items: center; margin-top: .5rem; }
.upload-button { display: inline-block; background: #eef2f0; color: var(--ink); font-size: .84rem; }
.image-preview { display: flex; align-items: center; gap: .7rem; padding: .5rem; border-radius: 10px; background: #f2f5f3; font-size: .82rem; }
.image-preview img { width: 50px; height: 50px; border-radius: 8px; object-fit: cover; }
.image-preview button { margin-left: auto; border: 0; background: transparent; color: var(--danger); }

.search-form { padding: 1.4rem 1.6rem .5rem; }
.segmented { display: inline-flex; padding: .25rem; border-radius: 10px; background: #edf2ef; }
.segmented input { position: absolute; opacity: 0; width: 1px; }
.segmented span { display: block; padding: .5rem .8rem; border-radius: 8px; color: var(--muted); font-size: .84rem; }
.segmented input:checked + span { background: white; color: var(--brand-dark); box-shadow: 0 2px 8px rgba(22,37,31,.08); }
.search-box { display: grid; grid-template-columns: 1fr auto; gap: .6rem; margin-top: .8rem; }
.spell-correction { margin: .7rem 1.6rem; padding: .8rem 1rem; border-radius: 11px; background: #fff2dc; color: #704a0a; }
.spell-correction button { margin-left: .4rem; border: 0; background: transparent; color: #7c4c00; font-weight: 800; text-decoration: underline; }
.search-summary { padding: .8rem 1.6rem 0; color: var(--muted); }
.search-results { display: grid; gap: .75rem; padding: 1rem 1.6rem 1.6rem; }
.search-hit { padding: 1rem 1.1rem; border: 1px solid var(--line); border-radius: 14px; background: #fcfdfc; }
.search-hit h3 { margin: 0 0 .4rem; font-size: 1rem; }
.search-hit p { margin: .45rem 0; color: #41504a; line-height: 1.5; }
.search-hit .meta { color: var(--muted); font-size: .76rem; }
.search-hit a { color: var(--brand); font-weight: 700; }
.search-hit img { max-width: 220px; max-height: 140px; margin-top: .6rem; border-radius: 9px; object-fit: contain; }
.toast { position: fixed; right: 1.5rem; bottom: 1.5rem; max-width: 390px; padding: .9rem 1.1rem; border-radius: 12px; background: #202b27; color: white; box-shadow: var(--shadow); }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .35; } }
@media (max-width: 850px) {
  .workspace { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .context-panel { display: none; }
  .content { padding: .7rem; }
  .panel { min-height: calc(100vh - 170px); border-radius: 16px; }
  .topbar { padding: 0 1rem; }
  .connection span:last-child { display: none; }
  .message { max-width: 92%; }
  .agent-status { flex-wrap: wrap; }
  .agent-status-copy { align-items: flex-start; flex-direction: column; gap: .1rem; }
}
