:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #193443;
  background: #f5f7f6;
  --navy: #102d40;
  --teal: #087f80;
  --mint: #dff3ed;
  --ink: #193443;
  --muted: #526970;
  --line: #dce6e2;
  --canvas: #f5f7f6;
  --conversation: 780px;
  --composer-width: 1120px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font-size: 1rem; }
button, input, textarea, select { font: inherit; }
button, summary { cursor: pointer; }
button, select {
  min-height: 36px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}
button:hover:not(:disabled), summary:hover { background: #edf5f1; }
button:disabled, select:disabled { opacity: .58; cursor: not-allowed; }
:where(button, input, select, textarea, a, summary):focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 3px;
}
input[type="checkbox"], input[type="range"] { accent-color: var(--teal); }
a { color: #086d6f; }
h1, h2, p { margin-block-start: 0; }

.workspace-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}
.workspace-layout[data-nav-open="false"] { grid-template-columns: minmax(0, 1fr); }
.workspace-layout[data-nav-open="false"] .sidebar { display: none; }
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  min-height: 0;
  padding: 20px 16px 14px;
  overflow: auto;
  background: #eef2f0;
  border-right: 1px solid var(--line);
}
.sidebar-heading-row, .sidebar-brand, .sidebar-footer { display: flex; align-items: center; }
.sidebar-heading-row { justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.sidebar-brand { gap: 10px; color: var(--navy); font-size: 23px; font-weight: 800; letter-spacing: .13em; }
.ship-mark {
  display: inline-block;
  flex: 0 0 auto;
  width: 31px;
  height: 31px;
  background: var(--teal);
  -webkit-mask: url("ship.svg") center / contain no-repeat;
  mask: url("ship.svg") center / contain no-repeat;
}
.workspace-topbar > .ship-mark { display: none; }
.workspace-layout[data-nav-open="false"] .workspace-topbar > .ship-mark { display: inline-block; }
.brand-mark > .ship-mark { background: #bdece0; }
.brand-mark {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--navy);
  color: #bdece0;
  font-size: 18px;
  font-weight: 760;
  letter-spacing: 0;
}
.icon-button {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}
.nav-icon { display: block; width: 17px; height: 14px; border: 1.5px solid currentColor; border-radius: 3px; position: relative; }
.nav-icon::after { content: ""; position: absolute; inset: 0 auto 0 5px; border-left: 1.5px solid currentColor; }
.sidebar-workspace {
  display: grid;
  gap: 7px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #ffffffb3;
}
.sidebar label, .sidebar-heading { font-size: 14px; font-weight: 650; color: var(--muted); }
#workspace-select { font-weight: 650; }
.workspace-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.workspace-actions button, #new-workspace-button { font-size: 14px; }
#new-workspace-button { align-self: stretch; text-align: left; }
.workspace-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.workspace-tabs button { font-weight: 650; background: transparent; border-color: transparent; }
.workspace-tabs .active { background: #deede6; border-color: #cddfd6; color: #075f61; }
#new-chat-button, #empty-chat-action, #send-button { background: var(--teal); border-color: var(--teal); color: #fff; font-weight: 700; }
#new-chat-button:hover:not(:disabled), #empty-chat-action:hover:not(:disabled), #send-button:hover:not(:disabled) { background: #066a6b; }
#new-chat-button { min-height: 42px; text-align: left; }
.sidebar-chats {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 9px;
  min-height: 152px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fafbf9;
}
.sidebar-heading { padding-inline: 4px; }
#chat-list { display: flex; flex-direction: column; gap: 4px; flex: 1; min-height: 0; overflow: auto; }
.chat-entry { position: relative; display: flex; gap: 2px; align-items: stretch; border-radius: 8px; }
.chat-entry:has(.chat-open.active) { background: #e6eeea; }
#chat-list button { background: transparent; border-color: transparent; font-size: 14px; }
#chat-list button:hover { background: #e1ece6; }
#chat-list .chat-open { flex: 1; min-width: 0; text-align: left; padding: 9px 8px; }
#chat-list .chat-open.active { font-weight: 700; color: #075f61; }
.chat-name { display: block; overflow-wrap: anywhere; }
#chat-list .chat-actions-button { align-self: flex-start; flex: 0 0 auto; width: 34px; padding-inline: 4px; font-size: 18px; }
.chat-action-menu {
  position: absolute;
  inset: 100% 2px auto auto;
  z-index: 2;
  min-width: 148px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  box-shadow: 0 8px 24px #102d401c;
}
#chat-list .chat-action-menu button { display: block; width: 100%; text-align: left; }
#chat-list .chat-action-menu button[data-chat-action="delete"] { color: #923741; }
.sidebar-footer { justify-content: space-between; gap: 8px; padding-top: 10px; margin-top: auto; border-top: 1px solid var(--line); }
#user-email { min-width: 0; font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
#logout-button { flex: 0 0 auto; font-size: 14px; }

.workspace-main { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: #fff; }
.workspace-topbar { display: flex; align-items: center; gap: 12px; min-height: 69px; padding: 9px clamp(14px, 3vw, 36px); border-bottom: 1px solid var(--line); }
.workspace-context { display: grid; min-width: 0; gap: 2px; }
.workspace-context span { color: var(--muted); font-size: 13px; }
#active-workspace-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }
.workspace-files-view { flex: 1; min-height: 0; min-width: 0; }
.workspace-files-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; }

.chat-area { display: flex; flex: 1; flex-direction: column; min-width: 0; min-height: 0; }
.chat-header {
  position: relative;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 64px;
  padding: 8px clamp(14px, 3vw, 36px);
  border-bottom: 1px solid var(--line);
}
.chat-header h1 { margin: 0; min-width: 0; color: var(--navy); font-size: clamp(18px, 2vw, 22px); line-height: 1.25; overflow-wrap: anywhere; }
.conversation { position: relative; display: flex; flex: 1; min-height: 0; min-width: 0; }
.messages {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: clamp(16px, 3vw, 32px) max(16px, calc((100% - var(--conversation)) / 2));
  overscroll-behavior: contain;
}
.chat-message { position: relative; margin: 0 0 24px; min-width: 0; line-height: 1.68; }
.chat-message.assistant { padding-left: 43px; }
.chat-message.assistant::before {
  content: "П";
  position: absolute;
  inset: 0 auto auto 0;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--navy);
  color: #bdece0;
  font-weight: 750;
}
.chat-message.user {
  width: fit-content;
  max-width: min(85%, 650px);
  margin-left: auto;
  padding: 13px 17px;
  border: 1px solid #dfeae4;
  border-radius: 12px 3px 12px 12px;
  background: #f0f4f1;
}
.message-role { margin: 0 0 5px; color: #31535a; font-size: 14px; font-weight: 700; overflow-wrap: anywhere; }
.message-content { white-space: pre-wrap; overflow-wrap: anywhere; }
.thinking-indicator { color: var(--muted); font-style: italic; }
.chat-empty { position: absolute; inset: 0; display: grid; align-content: center; justify-items: center; text-align: center; gap: 10px; padding: 16px; pointer-events: none; }
#empty-chat-action { pointer-events: auto; min-height: 44px; margin-top: 4px; padding-inline: 18px; }
.chat-empty .brand-mark { width: 46px; height: 46px; font-size: 22px; margin-bottom: 3px; }
.chat-empty h2 { margin: 0; font-size: clamp(19px, 3vw, 25px); color: var(--navy); }
.chat-empty p { margin: 0; max-width: 360px; color: var(--muted); line-height: 1.5; }
.messages:not(:empty) + .chat-empty, .chat-empty-opened { display: none; }
.chat-area[data-chat-open="true"] .chat-empty-unopened { display: none; }
.chat-area[data-chat-open="true"] .chat-empty-opened { display: block; }

@media (max-width: 760px) {
  .workspace-layout, .workspace-layout[data-nav-open="false"] { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 12; width: min(300px, 90vw); padding: 14px; box-shadow: 10px 0 30px #102d4026; }
  #sidebar-scrim { position: fixed; inset: 0; z-index: 11; width: 100%; height: 100%; border: 0; border-radius: 0; background: #102d4060; }
  .workspace-topbar { min-height: 55px; padding-block: 5px; }
  .chat-header { min-height: 52px; padding-block: 6px; }
  .icon-button, .sidebar button, .sidebar select, #send-button { min-height: 44px; }
  .icon-button { width: 44px; height: 44px; }
  #chat-list .chat-actions-button { width: 44px; }
  .chat-message.assistant { padding-left: 34px; }
  .chat-message.assistant::before { width: 27px; height: 27px; border-radius: 7px; }
  .chat-message.user { max-width: 90%; }
  .chat-message { margin-bottom: 20px; }
}
@media (max-height: 500px) {
  .chat-empty .brand-mark { display: none; }
  .chat-empty { align-content: start; overflow: hidden; }
}

.sidebar-empty { color: var(--muted); font-size: 14px; line-height: 1.5; padding: 7px 8px; }
.chat-header h1 { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.library-file-format { max-width: 86px; overflow-wrap: anywhere; }
.job-actions { display: flex; flex-wrap: wrap; }
.job-title, .job-status { margin: 0 0 8px; }
.job-status { white-space: pre-wrap; }
.rag-sources { display: flex; flex-direction: column; align-items: flex-start; }
.rag-source-detail { width: 100%; }
