:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --line: #d6dde5;
  --text: #18202a;
  --muted: #627080;
  --accent: #1f6feb;
  --accent-dark: #1858bd;
  --green: #16833a;
  --yellow: #c98a00;
  --red: #c92a2a;
  --shadow: 0 6px 18px rgba(24, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  color: var(--text);
  background: var(--bg);
  font-family: Arial, Helvetica, sans-serif;
  letter-spacing: 0;
}

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

button {
  min-height: 36px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  padding: 0 14px;
}

button:hover:not(:disabled) {
  background: var(--accent-dark);
}

button:disabled {
  border-color: #b9c2cc;
  background: #b9c2cc;
  cursor: not-allowed;
}

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

input,
select {
  min-height: 36px;
  padding: 0 10px;
}

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

.hidden {
  display: none !important;
}

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

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

.login-panel h1,
.topbar h1 {
  margin: 0;
  font-size: 22px;
}

.error-text {
  min-height: 20px;
  margin: 0;
  color: var(--red);
}

.app-view {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.topbar {
  min-height: 64px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.topbar-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.topbar span,
#editorMeta {
  color: var(--muted);
  font-size: 13px;
}

.workspace {
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(420px, 1fr) minmax(320px, 420px);
  gap: 14px;
  padding: 14px;
}

.sidebar,
.viewer-pane,
.chat-pane {
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.sidebar {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
  padding: 12px;
}

.upload-form {
  display: grid;
  gap: 10px;
}

.file-list-header,
.editor-toolbar,
.chat-header {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
}

.file-list-header {
  border-bottom: 0;
}

.file-list {
  min-height: 0;
  max-height: 100%;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 8px;
}

.file-row {
  display: grid;
  grid-template-columns: 16px 1fr 36px;
  align-items: center;
  gap: 8px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
  cursor: pointer;
}

.file-row.missing {
  background: #fffaf0;
}

.file-row.drag-over {
  border-color: var(--accent);
  background: #edf5ff;
}

.file-row.active {
  border-color: var(--accent);
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
}

.status-synced {
  background: var(--green);
}

.status-pending {
  background: var(--yellow);
}

.status-error {
  background: var(--red);
}

.status-missing {
  background: var(--yellow);
}

.file-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.source-description {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  white-space: normal;
}

.source-children {
  display: grid;
  gap: 6px;
  margin: -2px 0 4px 24px;
}

.source-children .file-row {
  grid-template-columns: 12px 1fr 32px;
  padding: 7px;
  box-shadow: none;
}

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

.viewer-pane {
  display: grid;
  grid-template-rows: auto 1fr;
}

.editor-toolbar {
  padding: 0 12px;
}

#fileEditor {
  min-height: 0;
  height: 100%;
  overflow: auto;
  resize: none;
  border: 0;
  border-radius: 0 0 8px 8px;
  padding: 14px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.45;
}

.chat-pane {
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.chat-header {
  padding: 0 12px;
}

.chat-log {
  min-height: 0;
  max-height: 100%;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 10px;
  padding: 12px;
}

.message {
  max-width: 92%;
  padding: 9px 11px;
  border-radius: 8px;
  line-height: 1.35;
  white-space: pre-wrap;
}

.message.user {
  justify-self: end;
  background: #dfeeff;
}

.message.model {
  justify-self: start;
  background: #eef1f4;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.icon-button {
  width: 34px;
  min-height: 34px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 6px;
  font-size: 20px;
  line-height: 1;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  color: #fff;
  background: #243447;
  box-shadow: var(--shadow);
}

@media (max-width: 1120px) {
  .workspace {
    grid-template-columns: 300px 1fr;
    grid-template-rows: minmax(0, 1fr) minmax(240px, 38vh);
  }

  .chat-pane {
    grid-column: 1 / -1;
    min-height: 0;
  }
}

@media (max-width: 760px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(150px, 24vh) minmax(220px, 1fr) minmax(190px, 28vh);
    gap: 10px;
    padding: 10px;
  }

  .sidebar,
  .viewer-pane,
  .chat-pane {
    min-height: 0;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px;
  }
}
