@font-face {
  font-family: "Plus Jakarta Sans";
  src: url("/assets/plus-jakarta-sans.ttf") format("truetype");
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
}

:root {
  color-scheme: light;
  font-family: "Plus Jakarta Sans", ui-sans-serif, system-ui, -apple-system, sans-serif;
  color: #271813;
  background: #fff8f6;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: #fcf7f5;
}

button,
textarea {
  color: inherit;
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease,
    box-shadow 140ms ease, transform 140ms ease;
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:focus-visible,
textarea:focus-visible {
  outline: 3px solid #e67e5f;
  outline-offset: 3px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  width: 100%;
  height: 100dvh;
}

.sidebar {
  position: relative;
  z-index: 20;
  display: flex;
  min-width: 0;
  flex-direction: column;
  padding: 24px 18px 18px;
  background: #f7f3f1;
  border-right: 1px solid rgb(155 68 42 / 9%);
}

.brand-row,
.topbar-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-row strong,
.topbar-title strong {
  display: block;
  letter-spacing: -0.02em;
}

.brand-row span,
.topbar-title span {
  display: block;
  margin-top: 2px;
  color: #88726c;
  font-size: 12px;
}

.brand-mark,
.mini-avatar,
.message-avatar,
.empty-avatar {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  color: #fff8f6;
  background: linear-gradient(145deg, #e98d70, #9b442a);
  box-shadow: 0 8px 22px rgb(155 68 42 / 18%);
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: #a94a2f;
  box-shadow: none;
  font-size: 18px;
  font-weight: 800;
}

.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 13px;
  color: #55423d;
  background: transparent;
  font-size: 20px;
}

.icon-button:hover {
  background: rgb(255 255 255 / 55%);
}

.sidebar-close,
.menu-button {
  display: none;
}

.new-chat-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 46px;
  margin-top: 24px;
  border-radius: 10px;
  color: #fff;
  background: #9b442a;
  box-shadow: none;
  font-weight: 700;
}

.new-chat-button:hover {
  background: #843820;
}

.conversation-nav {
  min-height: 0;
  flex: 1;
  margin-top: 24px;
}

.section-label,
.eyebrow {
  color: #9b442a;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.section-label {
  color: #6f5d57;
  font-size: 12px;
  letter-spacing: 0;
  text-transform: none;
}

.conversation-list {
  max-height: calc(100dvh - 306px);
  margin-top: 11px;
  overflow-y: auto;
}

.conversation-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 36px;
  gap: 4px;
  margin-bottom: 4px;
  border: 1px solid transparent;
  border-radius: 9px;
}

.conversation-row.is-active {
  border-color: #e7deda;
  background: #fff;
  box-shadow: none;
}

.conversation-open,
.conversation-delete {
  min-width: 0;
  background: transparent;
}

.conversation-open {
  padding: 10px 8px 10px 12px;
  overflow: hidden;
  text-align: left;
}

.conversation-open strong,
.conversation-open span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-open strong {
  font-size: 13px;
  font-weight: 650;
}

.conversation-open span {
  margin-top: 3px;
  color: #88726c;
  font-size: 11px;
}

.conversation-delete {
  align-self: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  color: #88726c;
  opacity: 0;
}

.conversation-row:hover .conversation-delete,
.conversation-delete:focus-visible {
  opacity: 1;
}

.conversation-delete:hover {
  color: #9b442a;
  background: #fadcd3;
}

.history-link {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 8px;
  color: #55423d;
  background: transparent;
  font-weight: 650;
  text-align: left;
}

.history-link:hover,
.history-link[aria-current="page"] {
  background: rgb(255 255 255 / 62%);
}

.local-note {
  margin-top: 16px;
  padding: 14px 2px 0;
  border: 0;
  border-top: 1px solid #e7deda;
  border-radius: 0;
  color: #88726c;
  background: transparent;
  font-size: 10px;
  line-height: 1.55;
}

.local-note p {
  margin: 0;
}

.local-note strong {
  color: #55423d;
  font-size: 11px;
}

.main-shell {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-rows: 72px minmax(0, 1fr);
  background: #fcf8f6;
}

.topbar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  background: rgb(255 252 250 / 90%);
  border-bottom: 1px solid rgb(155 68 42 / 9%);
  backdrop-filter: blur(12px);
}

.mini-avatar,
.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
}

.topbar-title span.is-online::before {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 4px;
  border-radius: 50%;
  background: #62a879;
  content: "";
}

.private-badge {
  padding: 7px 11px;
  border-radius: 999px;
  color: #9b442a;
  background: #fadcd3;
  font-size: 11px;
  font-weight: 750;
}

.main-content,
.chat-view {
  min-width: 0;
  min-height: 0;
}

.chat-view {
  display: grid;
  height: 100%;
  grid-template-rows: minmax(0, 1fr) auto;
}

.messages {
  min-height: 0;
  padding: 36px max(24px, calc((100% - 820px) / 2)) 28px;
  overflow-x: hidden;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.empty-state {
  display: grid;
  min-height: 100%;
  place-items: center;
  align-content: center;
  padding-bottom: 5vh;
  text-align: center;
}

.empty-avatar {
  width: 78px;
  height: 78px;
  border: 7px solid #ffe2d9;
  border-radius: 50% 50% 46% 54%;
  font-size: 28px;
  transform: rotate(-3deg);
}

.empty-state h1 {
  margin: 20px 0 7px;
  font-size: clamp(24px, 3vw, 30px);
  letter-spacing: -0.04em;
}

.empty-state p {
  max-width: 440px;
  margin: 0;
  color: #88726c;
  font-size: 14px;
  line-height: 1.65;
}

.message {
  display: flex;
  width: 100%;
  margin-bottom: 20px;
}

.message--user {
  justify-content: flex-end;
}

.message--assistant {
  align-items: flex-start;
  gap: 10px;
  justify-content: flex-start;
}

.message__body {
  max-width: min(74%, 620px);
}

.message__meta {
  display: block;
  margin: 0 6px 6px;
  color: #88726c;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.message--user .message__meta {
  text-align: right;
}

.message__text {
  margin: 0;
  padding: 13px 16px;
  border: 1px solid transparent;
  border-radius: 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.65;
}

.message--user .message__text {
  border-bottom-right-radius: 4px;
  background: #f3a88f;
  box-shadow: 0 5px 14px rgb(155 68 42 / 10%);
}

.message--assistant .message__text {
  border-color: rgb(155 68 42 / 10%);
  border-bottom-left-radius: 4px;
  background: #fff;
  box-shadow: 0 5px 18px rgb(95 46 31 / 5%);
}

.copy-button {
  margin: 7px 0 0 4px;
  padding: 5px 8px;
  border-radius: 8px;
  color: #88726c;
  background: transparent;
  font-size: 11px;
}

.copy-button:hover {
  color: #9b442a;
  background: #ffe9e3;
}

.thinking {
  display: flex;
  align-items: center;
  gap: 9px;
  width: fit-content;
  margin: 0 0 20px 46px;
  padding: 11px 15px;
  border-radius: 16px 16px 16px 5px;
  color: #55423d;
  background: #ffe2d9;
  font-size: 12px;
}

.thinking-dots {
  display: flex;
  gap: 3px;
}

.thinking-dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #9b442a;
  animation: thinking 1s infinite alternate;
}

.thinking-dots i:nth-child(2) {
  animation-delay: 0.2s;
}

.thinking-dots i:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes thinking {
  to {
    opacity: 0.3;
    transform: translateY(-3px);
  }
}

.chat-error {
  max-width: 620px;
  margin: 0 0 20px 46px;
  padding: 14px 16px;
  border: 1px solid rgb(155 68 42 / 22%);
  border-radius: 14px;
  color: #843820;
  background: #fff1ed;
  font-size: 13px;
}

.chat-error p {
  margin: 0 0 10px;
}

.retry-button {
  padding: 7px 11px;
  border-radius: 9px;
  color: #fff;
  background: #9b442a;
  font-size: 12px;
  font-weight: 700;
}

.composer-area {
  padding: 14px max(24px, calc((100% - 820px) / 2)) max(14px, env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, rgb(252 248 246 / 20%), #fcf8f6 22%);
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  min-height: 56px;
  padding: 8px 8px 8px 17px;
  border: 1px solid rgb(155 68 42 / 18%);
  border-radius: 17px;
  background: #fff;
  box-shadow: 0 10px 28px rgb(95 46 31 / 8%);
}

.composer:focus-within {
  border-color: #e67e5f;
  box-shadow: 0 10px 28px rgb(95 46 31 / 8%), 0 0 0 3px rgb(230 126 95 / 12%);
}

.composer textarea {
  min-width: 0;
  min-height: 34px;
  max-height: 160px;
  flex: 1;
  resize: none;
  overflow-y: auto;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 14px;
  line-height: 1.55;
}

.composer textarea::placeholder {
  color: #a9958f;
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.send-button,
.cancel-button {
  display: flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 14px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 750;
}

.send-button {
  color: #fff;
  background: #9b442a;
}

.send-button:hover:not(:disabled) {
  background: #843820;
  box-shadow: 0 5px 14px rgb(155 68 42 / 18%);
}

.cancel-button {
  color: #9b442a;
  background: #fadcd3;
}

.composer-area > p {
  margin: 8px 0 0;
  color: #a08b85;
  font-size: 9px;
  text-align: center;
}

.history-view {
  height: 100%;
  padding: 40px clamp(24px, 5vw, 64px);
  overflow-y: auto;
}

.history-header {
  display: flex;
  max-width: 900px;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin: 0 auto 28px;
}

.history-header h1 {
  margin: 7px 0 7px;
  font-size: clamp(28px, 4vw, 36px);
  letter-spacing: -0.05em;
}

.history-header p {
  margin: 0;
  color: #88726c;
  font-size: 13px;
}

.clear-history-button {
  flex: 0 0 auto;
  min-height: 42px;
  padding: 0 15px;
  border: 1px solid rgb(155 68 42 / 22%);
  border-radius: 12px;
  color: #9b442a;
  background: transparent;
  font-size: 12px;
  font-weight: 700;
}

.clear-history-button:hover {
  background: #ffe9e3;
}

.history-grid {
  display: grid;
  max-width: 900px;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  margin: 0 auto;
}

.history-card {
  position: relative;
  min-width: 0;
  border: 1px solid rgb(155 68 42 / 12%);
  border-radius: 15px;
  background: #fff;
  box-shadow: 0 5px 18px rgb(95 46 31 / 4%);
  overflow: hidden;
}

.history-open {
  display: grid;
  width: 100%;
  min-height: 96px;
  grid-template-areas: "date title count";
  grid-template-columns: 118px minmax(0, 1fr) auto;
  align-items: center;
  gap: 20px;
  padding: 17px 70px 17px 20px;
  background: transparent;
  text-align: left;
}

.history-open:hover {
  background: #fffaf8;
}

.history-date,
.history-count {
  display: block;
  color: #88726c;
  font-size: 11px;
}

.history-date {
  grid-area: date;
}

.history-count {
  grid-area: count;
  padding: 6px 9px;
  border-radius: 999px;
  background: #fff0eb;
  white-space: nowrap;
}

.history-title {
  display: -webkit-box;
  grid-area: title;
  margin: 0;
  overflow: hidden;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.4;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.history-delete {
  position: absolute;
  top: 50%;
  right: 16px;
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 10px;
  color: #9b442a;
  background: #ffe9e3;
  font-size: 0;
  transform: translateY(-50%);
}

.history-delete::before,
.history-delete::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 12px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  content: "";
}

.history-delete::before {
  transform: translate(-50%, -50%) rotate(45deg);
}

.history-delete::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

.history-delete:hover {
  color: #fff;
  background: #9b442a;
}

.history-delete:active:not(:disabled) {
  transform: translateY(calc(-50% + 1px));
}

.storage-warning {
  position: fixed;
  z-index: 50;
  right: 18px;
  bottom: max(18px, env(safe-area-inset-bottom));
  max-width: min(390px, calc(100vw - 36px));
  padding: 13px 16px;
  border: 1px solid rgb(155 68 42 / 24%);
  border-radius: 13px;
  color: #68301e;
  background: #fff0eb;
  box-shadow: 0 12px 35px rgb(95 46 31 / 15%);
  font-size: 12px;
  line-height: 1.5;
  pointer-events: none;
}

.confirm-dialog {
  width: min(430px, calc(100vw - 36px));
  padding: 28px;
  border: 0;
  border-radius: 20px;
  color: #271813;
  background: #fff8f6;
  box-shadow: 0 28px 90px rgb(53 25 17 / 28%);
  text-align: center;
}

.confirm-dialog::backdrop {
  background: rgb(39 24 19 / 48%);
  backdrop-filter: blur(3px);
}

.dialog-symbol {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  margin: 0 auto;
  border-radius: 50%;
  color: #9b442a;
  background: #fadcd3;
  font-size: 21px;
  font-weight: 800;
}

.confirm-dialog h2 {
  margin: 17px 0 8px;
  font-size: 20px;
}

.confirm-dialog p {
  margin: 0;
  color: #88726c;
  font-size: 13px;
  line-height: 1.6;
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 24px;
}

.dialog-actions button {
  min-height: 42px;
  border-radius: 12px;
  background: #ffe9e3;
  font-weight: 700;
}

.dialog-actions .danger-button {
  color: #fff;
  background: #9b442a;
}

.drawer-backdrop {
  position: fixed;
  z-index: 15;
  inset: 0;
  background: rgb(39 24 19 / 45%);
}

@media (max-width: 899px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(288px, calc(100vw - 32px));
    transform: translateX(-105%);
    transition: transform 180ms ease;
    box-shadow: 16px 0 50px rgb(53 25 17 / 20%);
  }

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

  .sidebar-close {
    display: grid;
    margin-left: auto;
  }

  .main-shell {
    height: 100dvh;
    grid-template-rows: 64px minmax(0, 1fr);
  }

  .topbar {
    display: flex;
    justify-content: flex-start;
    gap: 4px;
    padding: 0 12px;
    padding-inline: max(12px, env(safe-area-inset-left), env(safe-area-inset-right));
  }

  .menu-button {
    display: grid;
  }

  .topbar-title {
    min-width: 0;
  }

  .private-badge {
    display: none;
  }

  .conversation-delete {
    opacity: 1;
  }

  .icon-button {
    width: 44px;
    height: 44px;
  }

  .messages {
    padding: 22px 16px 18px;
    padding-right: max(16px, env(safe-area-inset-right));
    padding-left: max(16px, env(safe-area-inset-left));
  }

  .message__body {
    max-width: calc(100% - 42px);
  }

  .message--user .message__body {
    max-width: 86%;
  }

  .message__text {
    padding: 12px 14px;
    font-size: 14px;
  }

  .message__meta {
    font-size: 11px;
  }

  .message-avatar {
    width: 32px;
    height: 32px;
    font-size: 12px;
  }

  .composer-area {
    padding: 10px 16px max(10px, env(safe-area-inset-bottom));
    padding-right: max(16px, env(safe-area-inset-right));
    padding-left: max(16px, env(safe-area-inset-left));
  }

  .composer {
    gap: 7px;
    min-height: 56px;
    padding-left: 13px;
    border-radius: 16px;
  }

  .composer textarea {
    font-size: 16px;
  }

  .send-button,
  .cancel-button {
    width: 44px;
    min-height: 44px;
    padding: 0;
  }

  .copy-button {
    min-width: 44px;
    min-height: 36px;
    font-size: 12px;
  }

  .composer-area > p {
    margin-top: 6px;
    font-size: 10px;
    line-height: 1.4;
  }

  .send-button span:first-child {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .history-view {
    padding: 26px 16px;
    padding-right: max(16px, env(safe-area-inset-right));
    padding-left: max(16px, env(safe-area-inset-left));
  }

  .history-header {
    align-items: stretch;
    flex-direction: column;
    gap: 18px;
    margin-bottom: 22px;
  }

  .clear-history-button {
    align-self: flex-start;
    min-height: 44px;
  }

  .history-grid {
    grid-template-columns: 1fr;
  }

  .history-open {
    min-height: 104px;
    grid-template-areas:
      "title title"
      "date count";
    grid-template-columns: auto minmax(0, 1fr);
    gap: 9px 12px;
    padding: 16px 72px 16px 16px;
  }

  .history-delete {
    width: 44px;
    height: 44px;
  }

  .history-title {
    font-size: 15px;
  }

  .history-count {
    padding: 0;
    background: transparent;
  }
}

@media (hover: none), (pointer: coarse) {
  .conversation-delete {
    opacity: 1;
  }
}

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