:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f5f7fb;
  color: #17213a;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body { margin: 0; min-height: 100vh; }

button, input, select, textarea { font: inherit; }

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(20rem, 0.9fr) minmax(28rem, 1.4fr);
}

.shell.signed-in { grid-template-columns: 1fr; }
.shell.signed-in .brand { display: none; }
.shell.signed-in .workspace { align-content: start; }

.brand {
  padding: clamp(3rem, 8vw, 7rem);
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: linear-gradient(145deg, #14213d 0%, #163754 55%, #0b6655 100%);
  color: #fff;
}

.brand-mark {
  width: 3rem;
  height: 3rem;
  display: grid;
  place-items: center;
  border-radius: 0.85rem;
  background: #53d6a8;
  color: #10243a;
  font-weight: 800;
  letter-spacing: -0.04em;
}

.brand h1 { max-width: 11ch; margin: 1rem 0; font-size: clamp(2.4rem, 5vw, 4.8rem); line-height: 1.03; letter-spacing: -0.05em; }
.brand-copy { max-width: 35rem; color: #d8e8e5; font-size: 1.05rem; line-height: 1.7; }
.security-note { margin-top: 2rem; display: flex; gap: 0.75rem; align-items: center; color: #d8e8e5; }
.security-note span { display: grid; place-items: center; width: 1.8rem; height: 1.8rem; border-radius: 50%; background: #53d6a8; color: #10243a; font-weight: 800; }
.security-note p { margin: 0; }

.workspace { min-width: 0; padding: clamp(1.5rem, 5vw, 5rem); display: grid; align-content: center; position: relative; }
.card { min-width: 0; width: min(100%, 68rem); margin-inline: auto; border: 1px solid #dfe4ec; border-radius: 1.4rem; background: #fff; box-shadow: 0 1.5rem 4rem rgba(24, 39, 75, 0.08); }
.compact { max-width: 34rem; padding: clamp(1.5rem, 4vw, 2.75rem); }
.app-card { padding: clamp(1.3rem, 3vw, 2.25rem); }
.eyebrow { margin: 0 0 0.55rem; color: #147b65; font-size: 0.75rem; font-weight: 800; letter-spacing: 0.13em; text-transform: uppercase; }
.brand .eyebrow { margin-top: 2rem; color: #79e5c1; }
h2, h3 { margin: 0; letter-spacing: -0.025em; }
h2 { font-size: 2rem; }
h3 { font-size: 1.35rem; }
.muted { color: #667085; line-height: 1.55; }

form { display: grid; gap: 0.75rem; margin-top: 1.5rem; }
label, .field-label { color: #344054; font-size: 0.86rem; font-weight: 700; }
input, select, textarea { width: 100%; border: 1px solid #cbd2dc; border-radius: 0.75rem; padding: 0.85rem 1rem; background: #fff; color: #17213a; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(20, 123, 101, 0.18); border-color: #147b65; }
button { border: 0; border-radius: 0.75rem; padding: 0.85rem 1rem; background: #147b65; color: #fff; font-weight: 750; cursor: pointer; }
button:hover { background: #0f6956; }
button:disabled { cursor: wait; opacity: 0.65; }
button.secondary { background: #edf2f7; color: #26324a; }
button.secondary:hover { background: #dfe6ee; }
button.danger { background: #fff0f0; color: #a12626; }
button.danger:hover { background: #fbdada; }

.notice { position: fixed; top: 1.5rem; left: 50%; translate: -50% 0; width: min(34rem, calc(100% - 3rem)); padding: 0.85rem 1rem; border-radius: 0.7rem; background: #fff4e5; border: 1px solid #f3c780; color: #854d0e; z-index: 2; }
.notice.error { background: #fff0f0; border-color: #f5abab; color: #a12626; }
.secret-panel { margin-top: 1rem; padding: 1rem; border-radius: 0.8rem; background: #f2f6f8; }
.secret-panel .field-label { margin: 0.7rem 0 0.3rem; }
code { display: block; color: #153d53; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.wrap { overflow-wrap: anywhere; font-size: 0.76rem; }
details { margin-top: 1.5rem; }
summary { cursor: pointer; color: #475467; font-weight: 700; }
.code-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem; padding: 0; list-style: none; }
.code-grid li { padding: 0.65rem; border-radius: 0.55rem; background: #f2f6f8; text-align: center; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.app-header, .section-heading { display: flex; justify-content: space-between; gap: 1rem; align-items: center; }
.app-header { padding-bottom: 1.5rem; border-bottom: 1px solid #e5e9f0; }
.app-header button, .section-heading button { width: auto; }
nav { display: flex; flex-wrap: wrap; gap: 0.5rem; padding: 1rem 0 1.5rem; }
nav span { padding: 0.55rem 0.8rem; border-radius: 0.65rem; background: #e7f6f1; color: #126652; font-size: 0.86rem; font-weight: 750; }
.section-heading { margin-bottom: 1rem; }
.section-heading .muted { margin: 0.45rem 0 0; }
.admin-section + .admin-section, .delivery-panel + .admin-section { margin-top: 2rem; padding-top: 2rem; border-top: 1px solid #e5e9f0; }
.form-grid { grid-template-columns: repeat(3, minmax(0, 1fr)) auto; align-items: end; padding: 1rem; margin: 0 0 1.25rem; border-radius: 0.9rem; background: #f7f9fc; }
.form-grid > div { display: grid; gap: 0.45rem; }
.form-grid > button { min-height: 3rem; }
.delivery-panel { display: grid; gap: 1rem; margin-top: 2rem; padding: 1.25rem; border: 1px solid #98d5c3; border-radius: 0.9rem; background: #effbf7; }
.delivery-panel p { margin-bottom: 0; }
.delivery-panel code { padding: 0.8rem; border-radius: 0.6rem; background: #fff; user-select: all; }
.button-row { display: flex; flex-wrap: wrap; gap: 0.55rem; }
.button-row button { width: auto; }
.compact-buttons button { padding: 0.5rem 0.65rem; font-size: 0.78rem; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { padding: 0.8rem 0.65rem; border-bottom: 1px solid #e5e9f0; text-align: left; vertical-align: top; }
th { color: #667085; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.07em; }
td select { min-width: 11rem; padding: 0.55rem 0.65rem; }
.hours-summary { border-radius: 0.75rem; padding: 1rem; background: #eff8f4; line-height: 1.6; }
.hours-help { margin: 0 0 0.5rem; font-size: 0.9rem; }
h4 { font-size: 1.1rem; margin: 0.7rem 0; }
.hours-days { display: grid; gap: 0.8rem; }
.hours-day { min-width: 0; margin: 0; padding: 1rem; border: 1px solid #dfe4ec; border-radius: 0.8rem; }
.hours-day legend { padding: 0 0.4rem; font-weight: 750; }
.closed-toggle { display: flex; align-items: center; gap: 0.55rem; }
.closed-toggle input, #handoff-sound { width: 1rem; height: 1rem; margin: 0; }
.interval-list { display: grid; gap: 0.65rem; margin: 0.8rem 0; }
.interval-row { display: grid; grid-template-columns: minmax(5rem, 1fr) minmax(5rem, 1fr) auto; gap: 0.6rem; align-items: end; }
.interval-row label { display: grid; gap: 0.3rem; }
.interval-row input { padding: 0.65rem; }
.hours-day > button { font-size: 0.85rem; padding: 0.6rem 0.8rem; }
.exceptions-heading { margin-top: 2rem; }
#exception-form { margin-bottom: 1.5rem; }
#save-business-hours { justify-self: start; }
.settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; margin-bottom: 1.5rem; }
.settings-grid label { display: grid; gap: 0.5rem; }
.settings-grid .full-width { grid-column: 1 / -1; }
.settings-grid button { align-self: end; }
.tenant-detail { margin-top: 1.5rem; padding: 1.25rem; border: 1px solid #dfe4ec; border-radius: 0.9rem; }
.tenant-detail h4 { margin-top: 1.5rem; }
.readiness-checks { padding: 0; list-style: none; display: grid; gap: 0.65rem; }
.readiness-checks li { padding: 0.85rem; border-left: 3px solid #d8a744; border-radius: 0.4rem; background: #fff9ed; }
.readiness-checks li.passed { border-color: #147b65; background: #eff8f4; }
.readiness-checks p { margin: 0.3rem 0 0; font-size: 0.88rem; }
#platform-tenants-section details { margin-bottom: 1.5rem; }
#initial-admin-panel form { margin-top: 1rem; }
textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; }

[hidden] { display: none !important; }

.conversation-layout { display: grid; grid-template-columns: minmax(16rem, 0.8fr) minmax(0, 2fr); border: 1px solid #dfe4ec; border-radius: 0.9rem; overflow: hidden; }
.conversation-sidebar { padding: 1rem; background: #f7f9fc; border-right: 1px solid #dfe4ec; }
.conversation-sidebar form { margin-top: 0; }
.search-row { display: flex; gap: 0.4rem; }
.search-row input { min-width: 0; }
.search-row button { width: auto; padding-inline: 0.75rem; }
.conversation-list { display: grid; gap: 0.5rem; max-height: 32rem; overflow-y: auto; }
.conversation-item { display: grid; gap: 0.3rem; text-align: left; background: #fff; border: 1px solid #dfe4ec; color: #17213a; overflow-wrap: anywhere; }
.conversation-item:hover, .conversation-item.selected { background: #e7f6f1; border-color: #147b65; }
.conversation-item span { font-size: 0.78rem; font-weight: 450; color: #526478; }
.conversation-item .state-label { color: #126652; font-weight: 700; }
.window-countdown { font-variant-numeric: tabular-nums; }
.window-countdown.window-warning { color: #805000; background: #fff4cf; padding: 0.3rem; }
.window-countdown.window-urgent { color: #a02020; background: #ffe8e8; padding: 0.3rem; font-weight: 700; }
.window-countdown.window-closed { color: #536070; background: #eef0f4; padding: 0.3rem; }
.thread-pane { min-width: 0; display: flex; flex-direction: column; min-height: 30rem; }
.thread-heading { padding: 1rem 1.25rem; border-bottom: 1px solid #e5e9f0; overflow-wrap: anywhere; }
.thread-heading h4 { margin: 0; }
.thread-heading p { margin-bottom: 0; font-size: 0.82rem; line-height: 1.6; }
.thread-actions { display: flex; flex-wrap: wrap; align-items: end; gap: 0.6rem; margin-top: 0.75rem; }
.thread-actions button { width: auto; }
#reply-form { padding: 1rem 1.25rem; }
.thread-messages { display: flex; flex-direction: column; gap: 0.7rem; padding: 1.25rem; max-height: 34rem; overflow-y: auto; flex: 1; }
.message-bubble { max-width: 88%; padding: 0.8rem 1rem; border-radius: 0.8rem; background: #f0f3f8; align-self: flex-start; }
.message-bubble.outbound { align-self: flex-end; background: #e7f6f1; }
.message-content { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0.35rem 0; line-height: 1.6; }
.message-label, .message-delivery { font-size: 0.73rem; color: #526478; margin: 0; }
.retrieval-toggle, .safety-toggle { width: auto; margin-top: 0.55rem; padding: 0.38rem 0.6rem; font-size: 0.72rem; }
.retrieval-inspection, .safety-inspection { margin-top: 0.55rem; padding-top: 0.6rem; border-top: 1px solid #bad8cf; font-size: 0.75rem; line-height: 1.5; overflow-wrap: anywhere; }
.retrieval-inspection p, .safety-inspection p { margin: 0.3rem 0; }
.retrieval-summary { font-weight: 700; }
.retrieval-configuration { color: #526478; }
.retrieval-hit { margin-top: 0.6rem; padding: 0.55rem; border: 1px solid #cbded8; border-radius: 0.55rem; background: #f8fcfb; }
.retrieval-hit p { color: #405466; }
.retrieval-hit .retrieval-excerpt { color: #17213a; white-space: pre-wrap; }
.retrieval-error { color: #a12626; }
.session-divider { text-align: center; font-size: 0.72rem; color: #667085; overflow-wrap: anywhere; }
.read-only-note { padding: 1rem 1.25rem; border-top: 1px solid #e5e9f0; background: #fafbfd; color: #667085; font-size: 0.8rem; line-height: 1.5; }
#thread-status { padding: 0 1.25rem; font-size: 0.8rem; }
#conversation-list-status { font-size: 0.76rem; line-height: 1.5; }
#conversation-tenant-label { display: grid; gap: 0.5rem; max-width: 30rem; margin-bottom: 1rem; }
#more-messages { align-self: center; width: auto; margin: 0.5rem; }
#more-conversations { margin-top: 0.8rem; }

.knowledge-layout { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; }
.knowledge-layout > * { min-width: 0; }
#knowledge-text { margin-top: 0.5rem; min-height: 25rem; line-height: 1.6; }
.knowledge-preview { border: 1px solid #dfe4ec; border-radius: 0.75rem; padding: 1rem; min-height: 20rem; max-height: 38rem; overflow: auto; overflow-wrap: anywhere; line-height: 1.6; }
.knowledge-preview pre { white-space: pre-wrap; overflow-wrap: anywhere; padding: 0.6rem; background: #f5f7fb; }
.knowledge-preview code { display: inline; font-size: 0.85em; }
.knowledge-preview blockquote { margin-inline: 0; border-left: 3px solid #98d5c3; padding-left: 1rem; }
.knowledge-preview :is(h1, h2, h3, h4, h5, h6) { margin-block: 0.7rem; font-size: 1.25rem; }
.knowledge-warning { padding: 1rem; border: 1px solid #f3c780; border-radius: 0.75rem; background: #fff9ed; margin-bottom: 1rem; }
#knowledge-recovery { margin-top: 1rem; }
#knowledge-recovery button { margin-top: 0.5rem; }
#knowledge-status, #knowledge-metadata { overflow-wrap: anywhere; }
.knowledge-error { color: #a12626; }
.knowledge-history, .knowledge-version-detail { margin-top: 1.25rem; border-top: 1px solid #dfe4ec; padding-top: 1rem; }
.knowledge-history-list { display: grid; gap: 0.65rem; }
.knowledge-history-item { display: flex; justify-content: space-between; gap: 1rem; align-items: center; padding: 0.8rem; border: 1px solid #dfe4ec; border-radius: 0.75rem; }
.knowledge-history-item p { margin: 0.2rem 0; overflow-wrap: anywhere; }
.knowledge-history-item button { width: auto; flex: 0 0 auto; }
#knowledge-more-history { width: auto; margin-top: 0.75rem; }
#knowledge-version-text { margin-top: 0.5rem; min-height: 18rem; }

@media (max-width: 850px) {
  .knowledge-layout { grid-template-columns: 1fr; }
  #knowledge-section .section-heading { flex-wrap: wrap; }
  .knowledge-history-item { align-items: stretch; flex-direction: column; }
  .conversation-layout { grid-template-columns: 1fr; }
  .conversation-sidebar { border-right: 0; border-bottom: 1px solid #dfe4ec; }
  .conversation-list { max-height: 15rem; }
  .shell { grid-template-columns: 1fr; }
  .brand { padding: 2rem; min-height: 20rem; }
  .brand h1 { font-size: 2.5rem; max-width: 15ch; }
  .brand-copy, .security-note { display: none; }
  .workspace { padding: 1.25rem; align-content: start; }
  .card { border-radius: 1rem; }
  .form-grid { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .section-heading { align-items: flex-start; }
}
:root .owner-offline { color: #9a3412; font-weight: 700; }
