:root {
  --bg: #f3ede2;
  --panel: rgba(255, 250, 243, 0.92);
  --panel-strong: #fff8ef;
  --surface: rgba(255, 255, 255, 0.74);
  --surface-strong: #fffdf9;
  --surface-soft: rgba(255, 255, 255, 0.52);
  --ink: #1f1a17;
  --muted: #6d645d;
  --accent: #ca5a2e;
  --accent-dark: #8a3113;
  --teal: #35695b;
  --line: rgba(31, 26, 23, 0.12);
  --success: #2d6a4f;
  --danger: #9d2b1f;
  --shadow: 0 12px 28px rgba(68, 37, 20, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Avenir Next", "Segoe UI", "Trebuchet MS", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(202, 90, 46, 0.2), transparent 30%),
    radial-gradient(circle at right 20%, rgba(53, 105, 91, 0.14), transparent 24%),
    linear-gradient(135deg, #eee2d2, #f7f2ea 44%, #f3e6dc);
}

body.menu-open {
  overflow: hidden;
}

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

button {
  border: 0;
}

.app-shell {
  max-width: 1480px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 28px;
  position: relative;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}

.app-header {
  position: relative;
  z-index: 40;
  isolation: isolate;
  overflow: visible;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 28px;
  padding: 28px;
  margin-bottom: 24px;
}

.brand-block {
  min-width: 0;
}

.header-actions {
  position: relative;
  z-index: 41;
  overflow: visible;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.menu-toggle {
  display: none;
  width: 52px;
  height: 52px;
  padding: 0;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 5px;
}

.menu-toggle-line {
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.language-dropdown {
  position: relative;
  z-index: 60;
}

.language-dropdown summary {
  list-style: none;
}

.language-dropdown summary::-webkit-details-marker {
  display: none;
}

.language-summary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.language-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  display: grid;
  gap: 8px;
  min-width: 120px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface-strong);
  box-shadow: var(--shadow);
  z-index: 80;
  pointer-events: auto;
}

.language-option {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(31, 26, 23, 0.06);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  font-size: clamp(2rem, 3.4vw, 3.2rem);
  line-height: 0.96;
}

h2 {
  margin-bottom: 0;
  font-size: 1.15rem;
}

h3 {
  margin-bottom: 0;
  font-size: 0.96rem;
}

.hero-copy {
  max-width: 62ch;
  margin-bottom: 0;
}

.eyebrow,
.section-kicker {
  margin-bottom: 10px;
  font-family: "SFMono-Regular", "Consolas", "Liberation Mono", monospace;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-dark);
}

.section-kicker {
  margin-bottom: 6px;
}

.muted {
  color: var(--muted);
}

.top-nav {
  display: inline-flex;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.52);
}

.mobile-drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 89;
  background: rgba(31, 26, 23, 0.28);
  backdrop-filter: blur(4px);
}

.mobile-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(360px, 86vw);
  padding: 22px;
  display: none;
  flex-direction: column;
  gap: 22px;
  border-left: 1px solid var(--line);
  background: rgba(255, 251, 245, 0.96);
  box-shadow: 0 18px 48px rgba(31, 26, 23, 0.16);
  z-index: 90;
}

.mobile-drawer.open {
  display: flex;
}

.mobile-drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.mobile-drawer-close {
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
}

.mobile-drawer-section {
  display: grid;
  gap: 10px;
}

.mobile-drawer-link {
  width: 100%;
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(31, 26, 23, 0.06);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.mobile-drawer-link.active {
  background: rgba(202, 90, 46, 0.14);
  color: var(--accent-dark);
}

.nav-tab,
.ghost-button,
.primary-button,
.danger-button {
  border-radius: 999px;
  padding: 11px 16px;
  cursor: pointer;
  transition: transform 120ms ease, opacity 120ms ease, background 120ms ease, color 120ms ease;
}

.nav-tab:hover,
.ghost-button:hover,
.primary-button:hover,
.danger-button:hover,
.standard-item:hover {
  transform: translateY(-1px);
}

.nav-tab {
  background: transparent;
  color: var(--muted);
  font-weight: 500;
}

.nav-tab.active {
  background: var(--accent);
  color: #fffaf5;
}

.ghost-button {
  background: rgba(31, 26, 23, 0.07);
  color: var(--ink);
}

.primary-button {
  background: var(--accent);
  color: #fffaf5;
}

.danger-button {
  background: rgba(157, 43, 31, 0.12);
  color: var(--danger);
}

.view-stack {
  position: relative;
  z-index: 1;
}

.view-panel {
  display: none;
}

.view-panel.active {
  display: block;
}

.chat-layout,
.profiles-layout {
  display: grid;
  gap: 0;
  min-height: 760px;
  overflow: hidden;
}

.chat-layout {
  grid-template-columns: 340px minmax(0, 1fr);
}

.profiles-layout {
  grid-template-columns: 340px minmax(0, 1fr);
}

.history-sidebar,
.profiles-sidebar {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 24px;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 248, 239, 0.94), rgba(253, 247, 239, 0.82));
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.fill-section {
  min-height: 0;
  flex: 1;
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.compact-row {
  align-items: flex-start;
}

.note-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.7);
}

.note-card h3 {
  margin-bottom: 8px;
}

.standard-list,
.messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.standard-list {
  min-height: 0;
  overflow: auto;
}

.standard-item,
.message {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
}

.standard-item {
  width: 100%;
  padding: 16px;
  text-align: left;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.standard-item.active {
  border-color: rgba(202, 90, 46, 0.46);
  background: rgba(202, 90, 46, 0.08);
}

.standard-item strong {
  display: block;
  margin-bottom: 5px;
}

.item-meta {
  display: block;
  font-size: 0.92rem;
  color: var(--muted);
}

.item-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  font-size: 0.8rem;
  color: var(--accent-dark);
}

.conversation-panel,
.profile-editor {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 24px;
}

.conversation-header {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.conversation-heading {
  min-width: 0;
}

.chat-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.rename-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.rename-inline.hidden {
  display: none;
}

.rename-input {
  min-width: 220px;
  max-width: 100%;
  padding: 9px 12px;
}

body[dir="rtl"] .app-header,
body[dir="rtl"] .panel-title-row,
body[dir="rtl"] .conversation-actions,
body[dir="rtl"] .chat-form-actions,
body[dir="rtl"] .form-actions,
body[dir="rtl"] .profile-inline-top,
body[dir="rtl"] .header-actions {
  direction: rtl;
}

body[dir="rtl"] .language-menu {
  right: auto;
  left: 0;
}

.mobile-history-toggle {
  display: none;
  margin-bottom: 10px;
}

.conversation-actions,
.chat-form-actions,
.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.subtle-status,
.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.9rem;
}

.subtle-status {
  background: rgba(31, 26, 23, 0.06);
  color: var(--muted);
}

.status-pill {
  background: rgba(45, 106, 79, 0.1);
  color: var(--success);
}

.chat-title {
  margin-bottom: 6px;
  font-size: 1.2rem;
}

.messages {
  flex: 1;
  min-height: 420px;
  overflow: auto;
  padding: 18px 6px 12px 0;
}

.message {
  max-width: min(780px, 92%);
  padding: 16px 18px;
  box-shadow: 0 10px 24px rgba(31, 26, 23, 0.05);
}

.message.user {
  align-self: flex-end;
  background: rgba(202, 90, 46, 0.12);
}

.message.assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.86);
}

.message.error {
  align-self: center;
  width: 100%;
  max-width: 100%;
  border-color: rgba(157, 43, 31, 0.35);
  background: rgba(157, 43, 31, 0.07);
}

.message-role {
  margin-bottom: 8px;
  font-family: "SFMono-Regular", "Consolas", "Liberation Mono", monospace;
  font-size: 0.78rem;
  text-transform: uppercase;
  color: var(--accent-dark);
}

.message-content {
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.skeleton {
  align-self: flex-start;
  width: min(720px, 88%);
  background: rgba(255, 255, 255, 0.72);
}

.skeleton-line {
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(31, 26, 23, 0.08), rgba(31, 26, 23, 0.16), rgba(31, 26, 23, 0.08));
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.2s linear infinite;
}

.skeleton-line + .skeleton-line {
  margin-top: 10px;
}

.skeleton-line.short {
  width: 38%;
}

.skeleton-line.medium {
  width: 72%;
}

.skeleton-line.long {
  width: 94%;
}

@keyframes skeleton-shimmer {
  from {
    background-position: 200% 0;
  }

  to {
    background-position: -200% 0;
  }
}

.composer-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: rgba(255, 253, 249, 0.94);
  box-shadow: 0 10px 26px rgba(31, 26, 23, 0.08);
}

.conversation-canvas {
  position: relative;
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  padding: 18px;
  margin-top: 18px;
  border: 1px solid rgba(31, 26, 23, 0.08);
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(255, 252, 247, 0.82), rgba(255, 248, 240, 0.72));
  overflow: hidden;
}

.conversation-glow {
  position: absolute;
  inset: 0 auto auto 0;
  width: 280px;
  height: 280px;
  background: radial-gradient(circle, rgba(202, 90, 46, 0.12), transparent 66%);
  pointer-events: none;
}

.composer-label {
  font-size: 0.92rem;
  font-weight: 500;
}

.profile-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding-top: 18px;
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.profile-form label {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

input,
textarea,
select {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid rgba(31, 26, 23, 0.14);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.84);
  color: var(--ink);
}

textarea {
  resize: vertical;
}

.model-select-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.notes-list {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.6;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 100%;
  padding: 32px;
  border: 1px dashed var(--line);
  border-radius: 22px;
  text-align: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.4);
}

.empty-state p {
  margin-bottom: 8px;
}

.toast-stack {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  min-width: 240px;
  max-width: min(360px, calc(100vw - 32px));
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 252, 247, 0.96);
  box-shadow: 0 10px 24px rgba(31, 26, 23, 0.12);
  color: var(--ink);
  transform: translateY(8px);
  opacity: 0;
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: auto;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.success {
  border-color: rgba(45, 106, 79, 0.22);
}

.toast.error {
  border-color: rgba(157, 43, 31, 0.24);
}

.toast-title {
  margin: 0 0 4px;
  font-size: 0.95rem;
  font-weight: 700;
}

.toast-message {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.toast-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

.toast-action {
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(202, 90, 46, 0.12);
  color: var(--accent-dark);
  font-size: 0.84rem;
  font-weight: 700;
}

.chat-profile-bar {
  display: flex;
  align-items: stretch;
  justify-content: center;
  min-height: 100%;
}

.profile-inline-card {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.82);
}

.profile-inline-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.profile-inline-card strong {
  display: block;
  margin-bottom: 6px;
}

.profile-inline-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(31, 26, 23, 0.06);
  color: var(--muted);
  font-size: 0.84rem;
}

.tiny-button {
  padding: 8px 12px;
  font-size: 0.85rem;
}

@media (max-width: 1180px) {
  .app-header,
  .chat-form-actions,
  .form-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .conversation-header {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .chat-layout,
  .profiles-layout {
    grid-template-columns: 1fr;
  }

  .history-sidebar,
  .profiles-sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .chat-layout {
    position: relative;
  }

  .history-sidebar {
    display: none;
  }

  .chat-layout.history-open .history-sidebar {
    display: flex;
  }

  .mobile-history-toggle {
    display: inline-flex;
    align-self: flex-start;
  }

  .top-nav {
    display: none;
  }

  .menu-toggle {
    display: inline-flex;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 16px;
  }

  .app-header,
  .history-sidebar,
  .profiles-sidebar,
  .conversation-panel,
  .profile-editor {
    padding: 18px;
  }

  .profile-grid,
  .model-select-row {
    grid-template-columns: 1fr;
  }

  .conversation-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .chat-title-row,
  .rename-inline {
    flex-direction: column;
    align-items: stretch;
  }

  .rename-input {
    min-width: 0;
  }

  .conversation-actions .subtle-status,
  .conversation-actions .ghost-button {
    width: 100%;
    justify-content: center;
  }

  .toolbar-actions {
    width: 100%;
    justify-content: stretch;
    flex-wrap: wrap;
  }

  .editor-toolbar {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
  }

  .toolbar-actions .ghost-button {
    flex: 1;
  }

  .editor-toolbar .status-pill {
    grid-column: 1 / -1;
    justify-content: center;
  }

  .editor-toolbar .ghost-button {
    justify-content: center;
    width: 100%;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .language-dropdown,
  .language-summary {
    width: auto;
  }

  .language-menu {
    left: 0;
    right: auto;
    min-width: 140px;
  }

  .mobile-drawer {
    width: min(340px, 100vw);
  }

  .conversation-canvas {
    padding: 14px;
    border-radius: 22px;
  }

  .composer-panel {
    border-radius: 22px;
  }

  .nav-tab {
    flex: 1;
  }

  .message {
    max-width: 100%;
  }

  .toast-stack {
    right: 12px;
    bottom: 12px;
    left: 12px;
  }

  .toast {
    max-width: 100%;
  }
}
