:root {
  color-scheme: dark;
  --bg: #0c1014;
  --panel: #151a20;
  --panel-soft: #1d242c;
  --text: #edf2f1;
  --muted: #9aa7ad;
  --line: #2a333c;
  --accent: #46d3b0;
  --accent-strong: #71e8ca;
  --accent-soft: #183a35;
  --accent-text: #061411;
  --danger: #ff7165;
  --danger-soft: #3b1e20;
  --code-bg: #242d36;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.34);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

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

button {
  cursor: pointer;
}

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

.app-shell {
  min-height: 100vh;
}

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

.login-panel {
  width: min(100%, 380px);
  display: grid;
  gap: 20px;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.15;
}

.field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
}

.field input,
.title-input,
.composer textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  outline: none;
}

.field input {
  height: 44px;
  padding: 0 12px;
}

.field input:focus,
.title-input:focus,
.composer textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.primary-button,
.send-button,
.ghost-button,
.attach-button,
.icon-button,
.tab-button,
.role-option {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 40px;
}

.primary-button,
.send-button {
  padding: 0 16px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 750;
}

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

.ghost-button {
  padding: 0 14px;
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
}

.ghost-button:hover {
  background: var(--panel-soft);
  color: var(--text);
}

.attach-button {
  height: 44px;
  padding: 0 14px;
  background: var(--panel);
  border-color: var(--line);
  color: var(--text);
  font-weight: 750;
}

.attach-button:hover {
  background: var(--panel-soft);
}

.icon-button {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  display: inline-grid;
  place-items: center;
  background: var(--panel);
  border-color: var(--line);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
}

.icon-button:hover {
  background: var(--panel-soft);
}

.icon-button.danger {
  color: var(--danger);
}

.icon-button.danger:hover {
  background: var(--danger-soft);
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 14px;
}

.chat-view {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
}

.sidebar {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 14px;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.sidebar-head,
.conversation-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-head {
  justify-content: space-between;
}

.sidebar-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.tab-button {
  height: 38px;
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
  font-weight: 750;
}

.tab-button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.sidebar h1 {
  font-size: 22px;
}

.chat-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 8px;
  padding-right: 2px;
}

.chat-row {
  min-height: 58px;
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.chat-row:hover {
  background: var(--panel-soft);
  border-color: var(--line);
}

.chat-row.active {
  background: var(--accent-soft);
  border-color: #2a6d62;
}

.chat-row-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 750;
}

.chat-row-meta {
  color: var(--muted);
  font-size: 12px;
}

.conversation,
.files-panel {
  min-width: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.conversation-head {
  min-height: 73px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 19, 24, 0.92);
}

.title-input {
  height: 40px;
  padding: 0 12px;
  font-size: 18px;
  font-weight: 800;
}

.messages {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 24px max(24px, calc((100vw - 1120px) / 2));
}

.empty-state {
  align-self: center;
  justify-self: center;
  max-width: 360px;
  color: var(--muted);
  text-align: center;
}

.message {
  width: min(760px, 100%);
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
}

.message.user {
  justify-self: end;
}

.message.assistant {
  justify-self: start;
}

.avatar {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 13px;
  font-weight: 800;
}

.assistant .avatar {
  background: #7a8da3;
  color: #071018;
}

.message-body {
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
}

.user .message-body {
  background: var(--accent-soft);
  border-color: #2a6d62;
}

.file-card {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(12, 16, 20, 0.46);
}

.file-card-title {
  overflow-wrap: anywhere;
  font-weight: 800;
}

.file-card-meta {
  color: var(--muted);
  font-size: 12px;
}

.file-card a,
.file-link {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent-strong);
  font-weight: 750;
  text-decoration: none;
}

.file-card a:hover,
.file-link:hover {
  text-decoration: underline;
}

.markdown {
  line-height: 1.55;
  overflow-wrap: anywhere;
}

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

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

.markdown h1,
.markdown h2,
.markdown h3 {
  margin: 14px 0 8px;
  line-height: 1.25;
}

.markdown h1 {
  font-size: 22px;
}

.markdown h2 {
  font-size: 18px;
}

.markdown h3 {
  font-size: 16px;
}

.markdown p,
.markdown ul,
.markdown ol,
.markdown blockquote,
.markdown pre {
  margin: 10px 0;
}

.markdown ul,
.markdown ol {
  padding-left: 24px;
}

.markdown blockquote {
  padding: 2px 0 2px 12px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}

.markdown a {
  color: var(--accent-strong);
  font-weight: 650;
}

.markdown code {
  padding: 2px 5px;
  border-radius: 5px;
  background: var(--code-bg);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.92em;
}

.markdown pre {
  overflow: auto;
  padding: 12px;
  border-radius: 8px;
  background: #070a0e;
  color: #f5f7f3;
}

.markdown pre code {
  padding: 0;
  background: transparent;
  color: inherit;
}

.composer {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
  padding: 16px 20px 18px;
  border-top: 1px solid var(--line);
  background: rgba(15, 19, 24, 0.94);
}

.role-switch {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  width: 96px;
}

.role-option {
  height: 36px;
  padding: 0 10px;
  background: var(--panel);
  border-color: var(--line);
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.role-option.active {
  background: var(--accent);
  color: var(--accent-text);
}

.composer-main {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.pending-files {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pending-file {
  min-width: 0;
  max-width: 260px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.pending-file-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 750;
}

.pending-file-meta {
  color: var(--muted);
  font-size: 12px;
}

.remove-pending-file,
.delete-file-button {
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--danger);
  font-weight: 850;
}

.remove-pending-file:hover,
.delete-file-button:hover {
  background: var(--danger-soft);
}

.messages.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -12px;
  background: rgba(70, 211, 176, 0.08);
}

.composer textarea {
  min-height: 72px;
  max-height: 220px;
  resize: vertical;
  padding: 12px;
  line-height: 1.45;
}

.send-button {
  height: 44px;
}

.files-panel {
  grid-template-rows: auto minmax(0, 1fr);
}

.files-head {
  min-height: 73px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 19, 24, 0.92);
}

.sort-controls {
  display: flex;
  align-items: end;
  gap: 8px;
}

.sort-field {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.sort-field select {
  height: 40px;
  min-width: 150px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  outline: none;
}

.file-table {
  min-height: 0;
  overflow: auto;
  padding: 18px 20px;
}

.file-table-grid {
  min-width: 760px;
  display: grid;
  gap: 8px;
}

.file-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) 110px minmax(160px, 1fr) 150px 120px 86px;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.file-row.header {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.file-name,
.file-chat {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-meta {
  color: var(--muted);
  font-size: 13px;
}

[hidden] {
  display: none !important;
}

@media (max-width: 780px) {
  .chat-view {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .sidebar {
    min-height: auto;
    grid-template-rows: auto auto auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .chat-list {
    display: flex;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .chat-row {
    width: 180px;
    flex: 0 0 180px;
  }

  .sidebar .ghost-button {
    display: none;
  }

  .conversation,
  .files-panel {
    height: calc(100vh - 151px);
  }

  .messages {
    padding: 18px 14px;
  }

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

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

  .composer {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 12px;
  }

  .role-switch {
    width: 100%;
    grid-template-columns: 1fr 1fr;
  }

  .send-button {
    width: 100%;
  }

  .attach-button {
    width: 100%;
  }

  .files-head {
    align-items: start;
    flex-direction: column;
  }

  .sort-controls {
    width: 100%;
  }

  .sort-field {
    flex: 1;
  }

  .sort-field select {
    width: 100%;
  }
}
