:root {
  color-scheme: light;
  --bg: #f5f3ee;
  --paper: #fffdf8;
  --paper-strong: #ffffff;
  --ink: #171716;
  --muted: #6f6a60;
  --line: #ddd6c8;
  --line-strong: #c9bfae;
  --accent: #0f6f5d;
  --accent-strong: #09483f;
  --accent-soft: #dfeeea;
  --wine: #7c2e46;
  --gold: #a36f22;
  --blue: #27476a;
  --shadow: 0 22px 70px rgba(32, 29, 22, 0.16);
  font-family: "EB Garamond", "Noto Serif Hebrew", David, Georgia, serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(15, 111, 93, 0.07), transparent 34%),
    linear-gradient(315deg, rgba(124, 46, 70, 0.07), transparent 36%),
    var(--bg);
  color: var(--ink);
  font-size: 18px;
}

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

button {
  cursor: pointer;
}

button:disabled,
textarea:disabled,
select:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.68;
}

svg {
  display: block;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-shell {
  width: min(100%, 430px);
}

.auth-panel {
  background: rgba(255, 253, 248, 0.95);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: clamp(26px, 5vw, 42px);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--paper-strong);
  font-weight: 800;
  letter-spacing: 0;
  direction: ltr;
}

.brand-mark.small {
  width: 40px;
  height: 40px;
  font-size: 0.88rem;
}

.eyebrow {
  margin: 20px 0 8px;
  color: var(--accent-strong);
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0;
}

.auth-panel h1,
.empty-state h1 {
  margin: 0;
  font-size: clamp(2.5rem, 8vw, 4.6rem);
  font-weight: 800;
  line-height: 0.95;
  letter-spacing: 0;
}

.auth-form {
  display: grid;
  gap: 14px;
  margin-top: 34px;
}

.auth-form label:not(.check-row) {
  color: var(--muted);
  font-size: 1rem;
  font-weight: 700;
}

.auth-form input[type="password"] {
  min-height: 50px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-strong);
  color: var(--ink);
  outline: none;
  padding: 0 14px;
}

.auth-form input[type="password"]:focus,
.composer textarea:focus,
.model-picker select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 111, 93, 0.16);
}

.check-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  width: fit-content;
}

.check-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 52px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.form-error {
  min-height: 22px;
  margin: 0;
  color: #9b2f28;
  font-size: 0.98rem;
}

.app-shell {
  direction: ltr;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 304px minmax(0, 1fr);
}

.history-sidebar {
  direction: rtl;
  min-height: 100vh;
  border-right: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.92);
  backdrop-filter: blur(14px);
  padding: 18px;
  overflow-y: auto;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.sidebar-head .eyebrow {
  margin: 0 0 2px;
  color: var(--wine);
}

.sidebar-head h2 {
  margin: 0;
  font-size: 1.9rem;
  line-height: 1;
}

.thread-list {
  display: grid;
  gap: 8px;
}

.thread-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 68px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  padding: 10px 10px 10px 6px;
  text-align: right;
}

.thread-row:hover {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.65);
}

.thread-row.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.thread-copy {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.thread-copy strong,
.thread-copy small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-copy strong {
  font-size: 1.04rem;
}

.thread-copy small {
  color: var(--muted);
  font-size: 0.86rem;
}

.thread-remove {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--muted);
}

.thread-remove:hover {
  background: rgba(124, 46, 70, 0.12);
  color: var(--wine);
}

.main-panel {
  direction: rtl;
  min-width: 0;
  overflow-x: hidden;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(16px, 4vw, 32px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.86);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.brand strong,
.brand small {
  display: block;
  line-height: 1.05;
}

.brand strong {
  font-size: 1.16rem;
  font-weight: 800;
}

.brand small {
  color: var(--muted);
  font-size: 0.88rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.mobile-only {
  display: none;
}

.icon-button.mobile-only {
  display: none;
}

.model-picker,
.search-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  color: var(--muted);
  font-size: 0.98rem;
  font-weight: 800;
  white-space: nowrap;
}

.model-picker select {
  min-height: 40px;
  max-width: min(32vw, 250px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-strong);
  color: var(--ink);
  outline: none;
  padding: 0 12px 0 34px;
}

.search-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch {
  position: relative;
  width: 44px;
  height: 24px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: #e9e5dc;
  pointer-events: none;
  transition:
    background 0.16s ease,
    border-color 0.16s ease;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--paper-strong);
  box-shadow: 0 2px 6px rgba(32, 29, 22, 0.22);
  transition: transform 0.16s ease;
}

.search-toggle input:checked + .switch {
  border-color: var(--accent);
  background: var(--accent);
}

.search-toggle input:checked + .switch::after {
  transform: translateX(20px);
}

.search-toggle:has(input:focus-visible) .switch {
  box-shadow: 0 0 0 3px rgba(15, 111, 93, 0.16);
}

.icon-button,
.mini-button,
.send-button,
.tool-button,
.mode-button,
.pro-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-strong);
  color: var(--ink);
}

.icon-button,
.mini-button,
.send-button,
.tool-button {
  width: 40px;
  padding: 0;
}

.mode-button,
.pro-button {
  padding: 0 12px;
  font-weight: 800;
  white-space: nowrap;
}

.icon-button:hover,
.mini-button:hover,
.tool-button:hover,
.mode-button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.pro-button {
  border-color: rgba(163, 111, 34, 0.45);
  background: #fff8e7;
  color: #5e3d0e;
}

.pro-button:hover,
.pro-button.active {
  border-color: var(--gold);
  background: var(--gold);
  color: #fff;
}

.mode-button.active {
  border-color: var(--wine);
  background: var(--wine);
  color: #fff;
}

.standard-button.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.image-button.active {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.chat-layout {
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr auto;
}

.messages {
  width: min(100%, 1120px);
  margin: 0 auto;
  padding: clamp(22px, 4vw, 38px) clamp(16px, 4vw, 28px) 18px;
  overflow-x: hidden;
  overflow-y: auto;
}

.empty-state {
  min-height: clamp(300px, calc(100vh - 390px), 520px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 24px;
}

.empty-state .eyebrow {
  margin: 0;
  color: var(--wine);
}

.prompt-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: min(100%, 720px);
}

.prompt-grid button {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.86);
  color: var(--ink);
  padding: 12px 16px;
  text-align: right;
}

.prompt-grid button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.message {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 12px;
  max-width: 100%;
  margin: 0 0 20px;
}

.avatar {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 900;
  direction: ltr;
}

.message.assistant .avatar {
  background: var(--accent);
}

.bubble {
  width: fit-content;
  min-width: 0;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  padding: 14px 16px;
  line-height: 1.56;
  box-shadow: 0 10px 30px rgba(32, 29, 22, 0.06);
}

.message.assistant .bubble {
  max-width: min(100%, 820px);
  border-color: #c9ded8;
  border-top: 3px solid var(--accent);
  background:
    linear-gradient(180deg, rgba(223, 238, 234, 0.34), transparent 82px),
    var(--paper);
}

.message.user .bubble {
  background: #eef3f7;
  border-color: #ccd8e1;
}

.message.assistant .pending-bubble {
  width: min(100%, 560px);
  border-color: #bfd9d2;
  background:
    linear-gradient(90deg, rgba(15, 111, 93, 0.12), transparent 70%),
    var(--paper);
}

.pending-state {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.pending-spinner {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border: 3px solid rgba(15, 111, 93, 0.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: pending-spin 0.85s linear infinite;
}

.pending-copy {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.pending-copy strong,
.pending-copy small {
  min-width: 0;
  overflow-wrap: anywhere;
}

.pending-copy strong {
  color: var(--accent-strong);
  font-size: 1.06rem;
  line-height: 1.25;
}

.pending-copy small {
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.3;
}

@keyframes pending-spin {
  to {
    transform: rotate(360deg);
  }
}

.message-media {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.media-item {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-strong);
}

.media-item img {
  display: block;
  width: 100%;
  max-height: 520px;
  object-fit: contain;
  background: #eee9dd;
}

.media-item.audio,
.media-item.file {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 12px;
  color: var(--muted);
}

.media-icon {
  display: inline-flex;
  flex: 0 0 auto;
  color: var(--accent-strong);
}

.media-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.speak-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  padding: 0 10px;
  font-weight: 800;
}

.speak-button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.speak-button svg {
  width: 17px;
  height: 17px;
}

.rich-content {
  min-width: 0;
  font-size: 1.05rem;
}

.rich-content > :first-child {
  margin-top: 0;
}

.rich-content > :last-child {
  margin-bottom: 0;
}

.rich-content p {
  margin: 0 0 0.82em;
}

.rich-content h2,
.rich-content h3,
.rich-content h4,
.rich-content h5 {
  margin: 1.1em 0 0.45em;
  color: var(--ink);
  font-weight: 800;
  line-height: 1.05;
}

.rich-content h2 {
  font-size: 1.72rem;
}

.rich-content h3 {
  font-size: 1.48rem;
}

.rich-content h4,
.rich-content h5 {
  font-size: 1.24rem;
}

.rich-content ul,
.rich-content ol {
  margin: 0 1.15em 0.92em 0;
  padding: 0;
}

.rich-content li {
  margin: 0.22em 0;
  padding-inline-start: 0.18em;
}

.rich-content li::marker {
  color: var(--accent);
  font-weight: 800;
}

.rich-content blockquote {
  margin: 1em 0;
  border-inline-start: 4px solid var(--wine);
  background: rgba(124, 46, 70, 0.07);
  border-radius: 8px;
  padding: 12px 16px;
  color: #45383d;
}

.rich-content a {
  color: var(--accent-strong);
  font-weight: 800;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.rich-content a:hover {
  color: var(--wine);
}

.rich-content code {
  direction: ltr;
  unicode-bidi: isolate;
  border: 1px solid #d8d1c4;
  border-radius: 6px;
  background: #f3efe6;
  color: #442f14;
  padding: 0.06em 0.34em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78em;
}

.code-block {
  margin: 1em 0;
  max-width: 100%;
  overflow: hidden;
  border: 1px solid #2b3835;
  border-radius: 8px;
  background: #111816;
  box-shadow: 0 14px 36px rgba(17, 24, 22, 0.16);
}

.code-label {
  display: flex;
  align-items: center;
  min-height: 34px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: #18231f;
  color: #d8e9e4;
  padding: 0 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
}

.code-block pre {
  margin: 0;
  overflow-x: auto;
  padding: 14px 16px;
}

.code-block code {
  display: block;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #f1f7f4;
  padding: 0;
  font-size: 0.86rem;
  line-height: 1.55;
  white-space: pre;
}

.table-wrap {
  margin: 1em 0;
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-strong);
}

.rich-content table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: 0.98rem;
}

.rich-content th,
.rich-content td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: start;
  vertical-align: top;
}

.rich-content th {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 800;
}

.rich-content tr:last-child td {
  border-bottom: 0;
}

.rich-content hr {
  height: 1px;
  border: 0;
  background: var(--line);
  margin: 1.2em 0;
}

.user-content {
  font-size: 1rem;
}

.composer {
  width: min(100%, 1120px);
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 28px) 24px;
}

.composer-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.96);
  box-shadow: var(--shadow);
  padding: 14px;
}

.composer-side {
  display: grid;
  grid-auto-flow: column;
  align-items: end;
  gap: 8px;
}

.composer textarea {
  width: 100%;
  max-height: 260px;
  min-height: 96px;
  resize: none;
  border: 0;
  border-radius: 8px;
  outline: none;
  background: transparent;
  color: var(--ink);
  font-size: 1.16rem;
  line-height: 1.5;
  padding: 6px 8px;
}

.composer-box .send-button {
  width: 52px;
  height: 52px;
}

.tool-button {
  align-self: end;
  width: 44px;
  height: 44px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
}

.tool-button.recording {
  border-color: var(--wine);
  background: var(--wine);
  color: #fff;
}

.attachment-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  max-width: min(100%, 290px);
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.94);
  color: var(--ink);
  padding: 6px 8px;
  box-shadow: 0 8px 22px rgba(32, 29, 22, 0.08);
}

.attachment-chip img {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  object-fit: cover;
}

.attachment-chip span:not(.media-icon) {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-chip button {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.attachment-chip button:hover {
  background: rgba(124, 46, 70, 0.12);
  color: var(--wine);
}

.attachment-chip button svg {
  width: 16px;
  height: 16px;
}

.composer-modes {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  margin-top: 10px;
}

.send-button {
  border-color: transparent;
  background: var(--accent);
  color: #fff;
}

.send-button:hover {
  background: var(--accent-strong);
}

.status-line {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  font-size: 0.98rem;
}

body.request-pending .status-line {
  width: fit-content;
  max-width: 100%;
  margin-top: 8px;
  border: 1px solid #bfd9d2;
  border-radius: 8px;
  background: rgba(223, 238, 234, 0.72);
  color: var(--accent-strong);
  padding: 6px 10px;
  font-weight: 800;
}

.hidden {
  display: none;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 276px minmax(0, 1fr);
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar-actions {
    flex-wrap: wrap;
  }

  .model-picker {
    width: 100%;
    justify-content: flex-end;
  }

  .model-picker select {
    max-width: min(100%, 260px);
  }
}

@media (max-width: 820px) {
  body {
    font-size: 17px;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .history-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    width: min(82vw, 304px);
    transform: translateX(-100%);
    transition: transform 0.18s ease;
    box-shadow: 18px 0 50px rgba(32, 29, 22, 0.18);
  }

  body.sidebar-open .history-sidebar {
    transform: translateX(0);
  }

  .mobile-only {
    display: inline-flex;
  }

  .icon-button.mobile-only {
    display: inline-flex;
  }

  .topbar {
    padding: 12px 16px;
  }

  .brand {
    gap: 8px;
  }

  .brand strong {
    font-size: 1.04rem;
  }

  .topbar-actions {
    gap: 8px;
  }

  .mode-button,
  .pro-button {
    height: 38px;
    padding: 0 10px;
  }

  .search-toggle {
    order: 5;
  }

  .model-picker {
    order: 6;
  }

  .model-picker select {
    width: 210px;
  }

  .prompt-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .prompt-grid button {
    min-height: 46px;
    padding: 9px 12px;
  }

  .empty-state {
    justify-content: flex-start;
    min-height: clamp(240px, calc(100vh - 430px), 410px);
    gap: 14px;
    padding-top: 14px;
  }

  .empty-state h1 {
    font-size: clamp(2.4rem, 13vw, 3.45rem);
  }

  .message {
    grid-template-columns: 36px minmax(0, 1fr);
  }

  .avatar {
    width: 36px;
    height: 36px;
  }

  .composer-box {
    grid-template-columns: 1fr;
  }

  .composer-side {
    grid-auto-flow: column;
    justify-content: start;
  }
}

@media (max-width: 460px) {
  .brand small {
    display: none;
  }

  .model-picker {
    justify-content: stretch;
  }

  .model-picker select {
    width: 100%;
    max-width: 100%;
  }

  .composer-side {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-auto-flow: row;
  }

  .composer-side .send-button,
  .composer-side .tool-button {
    width: 100%;
  }

  .composer-modes {
    flex-wrap: nowrap;
  }

  .composer-modes .mode-button,
  .composer-modes .pro-button {
    flex: 1 1 0;
    min-width: 0;
    padding: 0 6px;
    font-size: 0.92rem;
  }

  .composer-modes svg {
    width: 17px;
    height: 17px;
  }
}
