:root {
  --content: #f3f0ec;
  --panel: #ffffff;
  --surface: #ffffff;
  --subtle: #faf9f8;
  --line: #e6e1db;
  --ink: #23201e;
  --muted: #867f79;
  --accent: #ef7326;
  --accent-hover: #de6316;
  --accent-soft: #fdece1;
  --accent-softer: #fef6f1;
  --ok: #1ba85e;
  --ok-soft: #e6f6ee;
  --danger: #d8503c;
  --danger-soft: #fcece9;
  --info: #2f6fd0;
  --info-soft: #eaf2fd;
  --shadow-card: 0 1px 2px rgb(35 32 30 / 4%), 0 8px 24px -16px rgb(35 32 30 / 18%);
  --shadow-float: 0 24px 60px -20px rgb(35 32 30 / 32%);
}

* { box-sizing: border-box; }

html,
body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background: var(--content);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea { font: inherit; }

button { color: inherit; }

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.chat-app {
  display: flex;
  width: 100%;
  height: 100dvh;
  background: var(--content);
}

.sidebar {
  display: flex;
  width: 18rem;
  min-width: 18rem;
  min-height: 0;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.sidebar-head {
  border-bottom: 1px solid var(--line);
  padding: 1rem;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: .625rem;
}

.brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: .625rem;
  color: var(--ink);
  text-decoration: none;
}

.brand-logo {
  width: 2.5rem;
  height: 2.5rem;
  flex: 0 0 auto;
  object-fit: contain;
}

.brand > span {
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -.025em;
}

.connection-status {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: .35rem;
  margin-left: auto;
  color: var(--muted);
  font-size: .625rem;
  font-weight: 600;
}

.connection-copy { display: none; }

.connection-dot,
.mobile-connection {
  width: .5rem;
  height: .5rem;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgb(239 115 38 / 10%);
}

.connection-status.is-ready { color: var(--ok); }
.connection-status.is-ready .connection-dot,
.mobile-connection.is-ready {
  background: var(--ok);
  box-shadow: 0 0 0 4px rgb(27 168 94 / 10%);
}
.connection-status.is-error { color: var(--danger); }
.connection-status.is-error .connection-dot,
.mobile-connection.is-error {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgb(216 80 60 / 10%);
}

.close-sidebar { display: none !important; }

.icon-button,
.tool-button,
.modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.search-field {
  position: relative;
  display: block;
  margin-top: .75rem;
}

.search-field svg {
  position: absolute;
  top: 50%;
  left: .75rem;
  width: 1rem;
  height: 1rem;
  pointer-events: none;
  color: var(--muted);
  transform: translateY(-50%);
}

.search-field input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: .75rem;
  background: var(--subtle);
  color: var(--ink);
  padding: .625rem .75rem .625rem 2.25rem;
  font-size: .875rem;
  transition: border-color .15s ease-out, background-color .15s ease-out;
}

.search-field input::placeholder { color: rgb(134 127 121 / 72%); }
.search-field input:focus { border-color: var(--accent); background: #fff; outline: none; }

.new-chat-button {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  margin-top: .625rem;
  border: 0;
  border-radius: .75rem;
  background: var(--accent-soft);
  color: var(--accent);
  cursor: pointer;
  padding: .625rem;
  font-size: .875rem;
  font-weight: 600;
  transition: background-color .15s ease-out, color .15s ease-out;
}

.new-chat-button:hover { background: var(--accent); color: #fff; }

.conversation-nav {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  padding: .5rem;
}

.section-label {
  margin: 0;
  padding: .25rem .5rem;
  color: var(--muted);
  font-size: .625rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.conversation-list { display: flex; flex-direction: column; gap: .25rem; }

.conversation-item {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  border-radius: .75rem;
  padding: .625rem .75rem;
  transition: background-color .15s ease-out;
}

.conversation-item:hover { background: var(--subtle); }
.conversation-item.is-active { background: var(--accent-soft); }

.conversation-select {
  min-width: 0;
  flex: 1;
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 0;
  text-align: left;
}

.conversation-title {
  display: block;
  overflow: hidden;
  color: var(--ink);
  font-size: .875rem;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-item.is-active .conversation-title { color: var(--accent); }

.conversation-meta {
  display: block;
  overflow: hidden;
  margin-top: .125rem;
  color: var(--muted);
  font-size: .6875rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-delete,
.trash-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: .375rem;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: .25rem;
  transition: color .15s ease-out;
}

.conversation-delete { margin-top: .125rem; opacity: 0; }
.conversation-item:hover .conversation-delete,
.conversation-delete:focus-visible { opacity: 1; }
.conversation-delete:hover,
.trash-action.is-danger:hover { color: var(--danger); }
.trash-action:hover { color: var(--accent); }

.sidebar-empty {
  margin: 0;
  padding: 1.5rem .5rem;
  color: var(--muted);
  font-size: .75rem;
  text-align: center;
}

.sidebar-footer {
  border-top: 1px solid var(--line);
  padding: .5rem;
}

.footer-button,
.account-button {
  display: flex;
  width: 100%;
  align-items: center;
  gap: .75rem;
  border: 0;
  border-radius: .75rem;
  background: transparent;
  cursor: pointer;
  padding: .625rem .75rem;
  text-align: left;
  transition: background-color .15s ease-out, color .15s ease-out;
}

.footer-button { color: var(--muted); font-size: .875rem; font-weight: 500; }
.footer-button:hover,
.account-button:hover { background: var(--subtle); color: var(--ink); }
.footer-button > span:nth-of-type(1) { flex: 1; }
.trash-chevron { width: .875rem; height: .875rem; transition: transform .15s ease-out; }
.footer-button[aria-expanded="true"] .trash-chevron { transform: rotate(180deg); }

.trash-count {
  flex: 0 0 auto !important;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  padding: .125rem .5rem;
  font-size: .625rem;
  font-weight: 700;
}

.trash-list {
  max-height: 10rem;
  overflow-y: auto;
  padding: .25rem 0;
}

.trash-item { border-radius: .75rem; padding: .5rem .75rem; }
.trash-item:hover { background: var(--subtle); }
.trash-item-title { overflow: hidden; margin: 0; font-size: .75rem; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.trash-item-meta { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-top: .25rem; }
.trash-item-meta > span:first-child { color: var(--muted); font-size: .6875rem; }
.trash-actions { display: flex; gap: .25rem; }

.account-button { margin-top: .25rem; }
.account-avatar {
  display: inline-flex;
  width: 2rem;
  height: 2rem;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: .6875rem;
  font-weight: 700;
}
.account-copy { min-width: 0; flex: 1; }
.account-copy strong,
.account-copy span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-copy strong { font-size: .875rem; font-weight: 600; }
.account-copy span { margin-top: .0625rem; color: var(--muted); font-size: .6875rem; }
.account-button > svg { flex: 0 0 auto; color: var(--muted); }

.chat-main {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex: 1;
  flex-direction: column;
}

.mobile-header { display: none; }

.chat-history {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  padding: 2rem 2.5rem;
  scroll-behavior: smooth;
}

.empty-state {
  width: min(100%, 48rem);
  margin: 0 auto;
  padding-top: 2.5rem;
  text-align: center;
}
.empty-state h1 { margin: 0; font-size: 1.5rem; font-weight: 600; letter-spacing: -.025em; }
.empty-state p { margin: .5rem 0 0; color: var(--muted); font-size: .875rem; }

.message-list {
  display: flex;
  width: min(100%, 48rem);
  margin: 0 auto;
  flex-direction: column;
  gap: 1.25rem;
}

.message-row { display: flex; animation: message-in .2s cubic-bezier(.23, 1, .32, 1); }
.message-row.is-user { justify-content: flex-end; }
.message-row.is-assistant { justify-content: flex-start; }

.message-bubble {
  max-width: 85%;
  overflow: hidden;
  border-radius: 1rem;
  padding: .75rem 1rem;
  font-size: .875rem;
  line-height: 1.625;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.message-row.is-user .message-bubble { background: var(--accent); color: #fff; }
.message-row.is-assistant .message-bubble { border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow-card); }

.message-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-bottom: .5rem;
  font-size: .75rem;
  opacity: .9;
}
.message-attachment { display: inline-flex; align-items: center; gap: .375rem; }
.message-attachment svg { width: .875rem; height: .875rem; }

.thinking {
  width: min(100%, 48rem);
  margin: 1.25rem auto 0;
}
.thinking::before { display: none; }
.thinking {
  align-items: center;
  gap: .375rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: var(--surface);
  box-shadow: var(--shadow-card);
  padding: .75rem 1rem;
}
.thinking:not([hidden]) { display: flex; width: fit-content; margin-left: max(0px, calc((100% - 48rem) / 2)); }
.thinking span { width: .375rem; height: .375rem; border-radius: 999px; background: var(--accent); animation: thinking .9s infinite; }
.thinking span:nth-child(2) { animation-delay: .15s; }
.thinking span:nth-child(3) { animation-delay: .3s; }

.notice {
  width: min(100%, 48rem);
  margin: 1rem auto 0;
  border: 1px solid var(--line);
  border-radius: .75rem;
  padding: .75rem .875rem;
  font-size: .8125rem;
  line-height: 1.5;
}
.notice-progress { border-color: rgb(239 115 38 / 25%); background: var(--accent-softer); color: var(--ink); }
.notice-error { border-color: rgb(216 80 60 / 24%); background: var(--danger-soft); color: var(--danger); }

.composer-wrap { padding: 0 2.5rem max(1.5rem, env(safe-area-inset-bottom)); }
.composer {
  width: min(100%, 48rem);
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 1.25rem;
  background: var(--surface);
  box-shadow: var(--shadow-card);
  padding: 1rem;
}
.composer textarea {
  width: 100%;
  min-height: 3rem;
  max-height: 7rem;
  resize: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: .125rem .25rem;
  font-size: .875rem;
  line-height: 1.5;
}
.composer textarea:focus { outline: none; }
.composer textarea::placeholder { color: rgb(134 127 121 / 70%); }

.attachment-list { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .5rem; }
.attachment-chip {
  display: inline-flex;
  max-width: 14rem;
  align-items: center;
  gap: .5rem;
  border-radius: .5rem;
  background: var(--accent-softer);
  color: var(--accent);
  padding: .375rem .75rem;
  font-size: .75rem;
}
.attachment-chip > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-chip button { display: inline-flex; border: 0; background: transparent; color: inherit; cursor: pointer; padding: 0; }
.attachment-chip svg { width: .75rem; height: .75rem; }

.composer-tools { display: flex; align-items: center; gap: .75rem; margin-top: .5rem; border-top: 1px solid var(--line); padding-top: .5rem; }
.tool-button { border-radius: .5rem; color: var(--muted); padding: .375rem; transition: background-color .15s ease-out, color .15s ease-out; }
.tool-button:hover { background: var(--accent-soft); color: var(--accent); }
.tool-button:disabled { cursor: not-allowed; opacity: .45; }

.depth-control { display: flex; min-width: 0; flex: 1; align-items: center; gap: .5rem; }
.depth-control label { color: var(--muted); font-size: .75rem; font-weight: 500; }
.depth-control strong { overflow: hidden; font-size: .75rem; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.depth-control input {
  width: 7rem;
  height: .25rem;
  appearance: none;
  border-radius: 999px;
  background: #eae5e0;
}
.depth-control input::-webkit-slider-thumb {
  width: 1rem;
  height: 1rem;
  appearance: none;
  border: 3px solid #fff;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 1px 4px rgb(239 115 38 / 50%);
  cursor: pointer;
}
.depth-control input::-moz-range-thumb {
  width: .625rem;
  height: .625rem;
  border: 3px solid #fff;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 1px 4px rgb(239 115 38 / 50%);
  cursor: pointer;
}

.mobile-depth-button { display: none; }

.send-button {
  display: inline-flex;
  height: 2.25rem;
  flex: 0 0 auto;
  align-items: center;
  gap: .375rem;
  border: 0;
  border-radius: .5rem;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  padding: 0 .875rem;
  font-size: .75rem;
  font-weight: 600;
  transition: background-color .15s ease-out;
}
.send-button:hover:not(:disabled) { background: var(--accent-hover); }
.send-button:disabled { cursor: not-allowed; background: rgb(239 115 38 / 35%); }
.send-button svg { width: .875rem; height: .875rem; }

.composer-note {
  width: min(100%, 48rem);
  margin: .375rem auto 0;
  color: var(--muted);
  font-size: .6875rem;
  line-height: 1.4;
  text-align: center;
}

.drawer-backdrop { display: none; }

.modal {
  width: min(calc(100% - 2rem), 28rem);
  max-height: min(85dvh, 42rem);
  overflow: visible;
  border: 1px solid var(--line);
  border-radius: 1.25rem;
  background: var(--surface);
  box-shadow: var(--shadow-float);
  padding: 0;
}
.modal::backdrop { background: rgb(35 32 30 / 30%); backdrop-filter: blur(2px); }
.modal-card { position: relative; max-height: min(85dvh, 42rem); overflow-y: auto; padding: 2rem; }
.modal-card h2 { margin: 0; padding-right: 2rem; font-size: 1.25rem; font-weight: 600; letter-spacing: -.025em; }
.modal-card > p { margin: .375rem 0 0; color: var(--muted); font-size: .875rem; line-height: 1.55; }
.modal-close { position: absolute; top: 1rem; right: 1rem; border-radius: .5rem; color: var(--muted); padding: .375rem; }
.modal-close:hover { background: var(--subtle); color: var(--ink); }
.modal-actions { display: flex; gap: .75rem; margin-top: 1.5rem; }
.button { display: inline-flex; min-height: 2.75rem; flex: 1; align-items: center; justify-content: center; border-radius: .75rem; cursor: pointer; padding: .625rem 1rem; font-size: .875rem; font-weight: 600; }
.button-outline { border: 1px solid var(--line); background: #fff; color: var(--ink); }
.button-outline:hover { border-color: var(--accent); color: var(--accent); }
.button-primary { border: 0; background: var(--accent); color: #fff; }
.button-primary:hover { background: var(--accent-hover); }
.button-danger { border: 0; background: var(--danger); color: #fff; }

.depth-options { display: flex; flex-direction: column; gap: .5rem; margin-top: 1.25rem; }
.depth-option {
  display: flex;
  width: 100%;
  align-items: center;
  gap: .75rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: var(--subtle);
  cursor: pointer;
  padding: .75rem 1rem;
  text-align: left;
  transition: border-color .15s ease-out, background-color .15s ease-out;
}
.depth-option:hover { border-color: var(--accent); }
.depth-option.is-selected { border-color: var(--accent); background: var(--accent-softer); }
.depth-number { display: inline-flex; width: 2rem; height: 2rem; flex: 0 0 auto; align-items: center; justify-content: center; border-radius: .5rem; background: #fff; color: var(--muted); font-size: .75rem; font-weight: 700; }
.depth-option.is-selected .depth-number { background: var(--accent); color: #fff; }
.depth-copy { min-width: 0; flex: 1; }
.depth-copy strong,
.depth-copy span { display: block; }
.depth-copy strong { font-size: .875rem; font-weight: 600; }
.depth-copy span { margin-top: .125rem; color: var(--muted); font-size: .75rem; }
.depth-option > svg { color: var(--accent); }

@keyframes thinking { 0%, 100% { opacity: .3; } 50% { opacity: 1; } }
@keyframes message-in { from { opacity: 0; transform: translateY(.375rem); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 767px) {
  .sidebar {
    position: fixed;
    z-index: 50;
    inset: 0 auto 0 0;
    width: min(17rem, 85vw);
    min-width: 0;
    box-shadow: var(--shadow-float);
    transform: translateX(-105%);
    transition: transform .26s cubic-bezier(.23, 1, .32, 1);
  }
  .sidebar.is-open { transform: translateX(0); }
  .close-sidebar { display: inline-flex !important; margin-left: .25rem; border-radius: .5rem; color: var(--muted); padding: .5rem; }
  .connection-status { margin-left: auto; }
  .drawer-backdrop {
    position: fixed;
    z-index: 40;
    inset: 0;
    background: rgb(35 32 30 / 40%);
  }
  .drawer-backdrop:not([hidden]) { display: block; }
  .mobile-header {
    display: flex;
    align-items: center;
    gap: .625rem;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
    padding: .625rem .75rem;
  }
  .mobile-header .icon-button { width: 2.25rem; height: 2.25rem; flex: 0 0 auto; border: 1px solid var(--line); border-radius: .75rem; background: var(--content); }
  .mobile-logo { width: 2.5rem; height: 2.5rem; flex: 0 0 auto; object-fit: contain; }
  .mobile-header p { min-width: 0; flex: 1; overflow: hidden; margin: 0; font-size: .875rem; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-connection { margin-right: .25rem; }
  .chat-history { padding: 1.5rem 1rem; }
  .empty-state { padding-top: 2rem; }
  .empty-state h1 { font-size: 1.25rem; }
  .empty-state p { font-size: .8125rem; line-height: 1.5; }
  .message-list { gap: 1rem; }
  .message-bubble { max-width: 88%; }
  .conversation-delete { opacity: 1; }
  .thinking:not([hidden]) { margin-left: 0; }
  .composer-wrap { padding: 0 1rem max(1rem, env(safe-area-inset-bottom)); }
  .composer { border-radius: 1.25rem; padding: .75rem; }
  .composer-tools { gap: .5rem; }
  .depth-control { display: none; }
  .mobile-depth-button {
    display: flex;
    min-width: 0;
    flex: 1;
    align-items: center;
    gap: .5rem;
    border: 0;
    border-radius: .5rem;
    background: var(--accent-soft);
    color: var(--accent);
    cursor: pointer;
    padding: .375rem .625rem;
    text-align: left;
  }
  .mobile-depth-button span { min-width: 0; flex: 1; overflow: hidden; font-size: .6875rem; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
  .mobile-depth-button svg { width: .875rem; height: .875rem; flex: 0 0 auto; }
  .send-button { width: 2.25rem; justify-content: center; padding: 0; }
  .send-button span { display: none; }
  .modal { width: 100%; max-width: none; margin: auto 0 0; border-width: 1px 0 0; border-radius: 1.5rem 1.5rem 0 0; }
  .modal-card { padding: 1.5rem 1.25rem max(1.5rem, env(safe-area-inset-bottom)); }
  .modal-card h2 { font-size: 1.125rem; }
  .modal-actions { flex-direction: column-reverse; }
}

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