:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --panel-strong: #f0f4f2;
  --border: #d8ddd8;
  --border-strong: #b8c3bc;
  --text: #18201c;
  --muted: #667069;
  --accent: #246b55;
  --accent-strong: #184f3e;
  --warning: #a15e18;
  --danger: #a63a32;
  --shadow: 0 10px 24px rgba(24, 32, 28, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

button {
  border: 0;
  cursor: pointer;
}

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

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

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

.eyebrow,
.panel-kicker {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.1;
}

h1 {
  font-size: 32px;
}

h2 {
  font-size: 18px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  outline: none;
}

input {
  height: 42px;
  padding: 0 12px;
}

select {
  height: 34px;
  min-width: 132px;
  padding: 0 28px 0 10px;
  background: #ffffff;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

textarea {
  min-height: 60px;
  max-height: 160px;
  resize: vertical;
  padding: 10px 12px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(36, 107, 85, 0.15);
}

.login-panel button,
.composer button,
.account button {
  border-radius: 6px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
}

.login-panel button {
  height: 44px;
}

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

.workspace {
  display: grid;
  grid-template-columns: minmax(230px, 0.24fr) minmax(220px, 0.22fr) minmax(420px, 0.54fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overflow: hidden;
}

.panel {
  min-width: 0;
  border-right: 1px solid var(--border);
  background: var(--panel);
}

.file-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  position: relative;
  background: #f7f8f7;
}

.file-panel.drop-target {
  background: #eef7f1;
}

.file-panel.drop-target::after {
  position: absolute;
  inset: 8px;
  border: 2px dashed var(--accent);
  border-radius: 8px;
  box-shadow: inset 0 0 0 9999px rgba(36, 107, 85, 0.05);
  content: "";
  pointer-events: none;
}

.file-panel.uploading .file-list {
  opacity: 0.65;
}

.file-panel .panel-header {
  min-height: 48px;
  background: #f1f3f2;
  padding: 8px 10px;
}

.file-panel .panel-kicker {
  margin-bottom: 2px;
  font-size: 10px;
}

.file-panel h2 {
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.panel-header,
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
}

.toolbar,
.account {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  justify-content: flex-end;
  gap: 8px;
}

.icon-button {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-strong);
  color: var(--text);
  font-size: 13px;
  font-weight: 900;
}

.file-panel .icon-button {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
}

.file-panel .icon-button:hover {
  background: #e3e8e5;
  color: var(--text);
}

.icon-button svg,
.file-action svg,
.file-icon svg,
.tree-toggle svg,
.explorer-root-button svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.icon-button:hover,
.file-action:hover,
.chat-row:hover {
  border-color: var(--border-strong);
  background: #e8efeb;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  background: #fbfcfb;
  padding: 0 8px;
  white-space: nowrap;
}

.breadcrumb button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 5px;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  font-weight: 900;
  padding: 3px 4px;
}

.explorer-current-path {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-overflow: ellipsis;
}

.file-list,
.chat-list {
  height: calc(100vh - 116px);
  overflow: auto;
  padding: 8px;
}

.file-panel .file-list {
  height: auto;
  padding: 4px 0 8px;
}

.file-row,
.chat-row {
  display: grid;
  gap: 8px;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  padding: 10px;
  text-align: left;
}

.file-row {
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
}

.file-panel .file-row {
  grid-template-columns: 16px 18px minmax(0, 1fr) auto;
  min-height: 28px;
  gap: 4px;
  border: 0;
  border-radius: 0;
  padding: 0 6px 0 calc(6px + (var(--depth, 0) * 14px));
}

.file-panel .file-row:hover,
.file-panel .file-row.active {
  background: #e8efeb;
}

.file-panel .file-row.folder-drop-target {
  background: #dceee5;
  box-shadow: inset 3px 0 0 var(--accent);
}

.file-row[draggable="true"] {
  cursor: grab;
}

.file-row.dragging {
  opacity: 0.55;
}

.file-main,
.chat-main {
  min-width: 0;
}

.file-panel .file-main {
  display: flex;
  min-width: 0;
  align-items: center;
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
}

.file-name,
.chat-title {
  overflow: hidden;
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-panel .file-name {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
}

.file-meta,
.chat-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.file-icon {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 6px;
  background: #e5eee8;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 900;
}

.file-panel .file-icon {
  width: 18px;
  height: 18px;
  border-radius: 0;
  background: transparent;
  color: #6c7370;
}

.file-panel .file-icon.folder {
  color: #a56a24;
}

.file-panel .file-icon.file {
  color: #4f6f8f;
}

.tree-toggle {
  display: grid;
  width: 16px;
  height: 24px;
  place-items: center;
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  padding: 0;
}

.tree-toggle:empty {
  cursor: default;
}

.tree-toggle:not(:empty):hover {
  background: #dfe5e2;
  color: var(--text);
}

.file-actions {
  display: flex;
  gap: 1px;
  justify-self: end;
  opacity: 0;
  pointer-events: none;
}

.file-panel .file-row:hover .file-actions,
.file-panel .file-row.active .file-actions,
.file-panel .file-row:focus-within .file-actions {
  opacity: 1;
  pointer-events: auto;
}

.file-action {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  padding: 0;
}

.file-action.danger {
  color: var(--danger);
}

.file-action:hover {
  background: #dfe5e2;
  color: var(--text);
}

.file-action.danger:hover {
  color: var(--danger);
}

.explorer-empty {
  padding: 14px 12px 14px 24px;
  font-size: 12px;
}

.chat-list {
  display: grid;
  align-content: start;
  gap: 6px;
}

.chat-row {
  border-color: var(--border);
}

.chat-row.active {
  border-color: rgba(36, 107, 85, 0.45);
  background: #e7f1ec;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
  border-right: 0;
  overflow: hidden;
}

.account {
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  flex-shrink: 0;
}

#accountName {
  min-width: 0;
  flex-shrink: 1;
}

#logoutButton {
  flex-shrink: 0;
  white-space: nowrap;
}

.engine-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.engine-picker span {
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.account span {
  overflow: hidden;
  max-width: 180px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account button,
.composer button {
  padding: 9px 14px;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow: auto;
  padding: 18px;
}

.message {
  max-width: min(760px, 86%);
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  padding: 12px 14px;
  overflow-wrap: anywhere;
}

.message .message-content {
  line-height: 1.55;
  font-size: 14px;
  word-wrap: break-word;
}

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

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

.message .markdown p {
  margin: 8px 0;
}

.message .markdown h1,
.message .markdown h2,
.message .markdown h3,
.message .markdown h4,
.message .markdown h5,
.message .markdown h6 {
  margin: 14px 0 6px;
  line-height: 1.3;
  font-weight: 700;
}

.message .markdown h1 { font-size: 1.3rem; }
.message .markdown h2 { font-size: 1.2rem; }
.message .markdown h3 { font-size: 1.1rem; }
.message .markdown h4 { font-size: 1rem; }

.message .markdown ul,
.message .markdown ol {
  margin: 8px 0;
  padding-left: 22px;
}

.message .markdown li {
  margin: 3px 0;
}

.message .markdown li > p {
  margin: 0;
}

.message .markdown a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.message .markdown a:hover {
  color: var(--accent-strong);
}

.message .markdown code {
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.92em;
}

.message .markdown pre {
  margin: 10px 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0f1413;
  color: #e8efe9;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.5;
}

.message .markdown pre code {
  background: transparent;
  border: 0;
  padding: 0;
  color: inherit;
  font-size: inherit;
  white-space: pre;
}

.message .markdown blockquote {
  margin: 10px 0;
  padding: 4px 12px;
  border-left: 3px solid var(--border-strong);
  color: var(--muted);
}

.message .markdown strong { font-weight: 700; }
.message .markdown em { font-style: italic; }

.message.streaming {
  border-color: rgba(36, 107, 85, 0.35);
  background: #fbfdfc;
}

.message.streaming .message-role::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: middle;
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

.message-content.stream-output {
  white-space: pre-wrap;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text);
  max-height: 360px;
  overflow: auto;
}

.message.user {
  align-self: flex-end;
  border-color: rgba(36, 107, 85, 0.28);
  background: #e7f1ec;
}

.message.assistant {
  align-self: flex-start;
}

.message-role {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  border-top: 1px solid var(--border);
  background: var(--panel);
  padding: 14px;
}

.empty {
  padding: 20px 12px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.editor-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(15, 22, 18, 0.45);
  padding: 24px;
  z-index: 50;
}

.editor-modal {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(100%, 1080px);
  height: min(100%, 760px);
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
}

.editor-header h2 {
  overflow: hidden;
  max-width: 560px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.editor-status {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.editor-save,
.editor-close {
  border-radius: 6px;
  padding: 9px 14px;
  font-weight: 800;
}

.editor-save {
  background: var(--accent);
  color: #ffffff;
}

.editor-close {
  border: 1px solid var(--border);
  background: var(--panel-strong);
  color: var(--text);
}

.editor-content {
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 0;
  background: #fbfcfb;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;
  font-size: 13.5px;
  line-height: 1.55;
  padding: 16px 18px;
  resize: none;
  max-height: none;
  outline: none;
}

.editor-content:focus {
  box-shadow: none;
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: 28vh 22vh 1fr;
    height: 100vh;
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
  }

  .panel {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .chat-panel {
    overflow: hidden;
  }

  .file-list,
  .chat-list {
    height: calc(100% - 116px);
  }

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

  #accountName {
    display: none;
  }
}
