:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #64707d;
  --line: #d8dde3;
  --accent: #0b6bcb;
  --accent-dark: #084f96;
  --success: #157347;
  --warn: #9a5b00;
  --danger: #b3261e;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

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

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

button:hover {
  border-color: #aeb8c2;
}

button[type="submit"],
#newProjectButton {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button[type="submit"]:hover,
#newProjectButton:hover {
  background: var(--accent-dark);
}

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

textarea {
  resize: vertical;
}

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

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: 56px minmax(0, 1fr);
}

.topbar {
  display: grid;
  grid-template-columns: minmax(190px, 260px) minmax(260px, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  background: #222f3e;
  color: #fff;
  border-radius: 6px;
  font-size: 12px;
}

.project-tools,
.account-tools,
.button-row,
.upload-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.project-tools select {
  max-width: 360px;
}

.account-tools {
  justify-content: end;
  white-space: nowrap;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(320px, 38vw) 1fr;
}

.chat-pane,
.right-pane {
  min-width: 0;
  min-height: 0;
}

.chat-pane {
  border-right: 1px solid var(--line);
  background: #fff;
  display: grid;
}

.auth-panel {
  max-width: 460px;
  width: 100%;
  align-self: center;
  justify-self: center;
  display: grid;
  gap: 18px;
  padding: 26px;
}

.auth-panel h1 {
  margin: 0;
  font-size: 24px;
}

.auth-panel p {
  margin: 0;
  color: var(--muted);
}

#authForm,
.publish-form,
#newProjectForm {
  display: grid;
  gap: 14px;
}

.status-text {
  min-height: 22px;
  color: var(--warn);
}

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

.live-status {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 10px 14px;
  border-bottom: 1px solid #f0d79d;
  background: #fff8e8;
  color: #684000;
  font-size: 13px;
}

.working-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--warn);
  box-shadow: 0 0 0 0 rgba(154, 91, 0, 0.35);
  animation: pulse 1.4s ease-out infinite;
  flex: 0 0 auto;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(154, 91, 0, 0.35);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(154, 91, 0, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(154, 91, 0, 0);
  }
}

.messages {
  overflow: auto;
  padding: 18px;
  display: grid;
  align-content: start;
  gap: 12px;
}

.message {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.message.user {
  border-color: #b7d6f6;
  background: #f3f8ff;
}

.message.assistant {
  border-color: #c8ded1;
  background: #f4fbf6;
}

.run-progress-message {
  border-color: #f0d79d;
  background: #fff8e8;
  color: #684000;
}

.run-progress-content {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  line-height: 1.45;
}

.message .meta {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.composer {
  border-top: 1px solid var(--line);
  padding: 12px;
  display: flex;
  align-items: end;
  gap: 8px;
}

.composer textarea {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 132px;
  max-height: 280px;
}

.composer button {
  flex: 0 0 auto;
  min-width: 72px;
}

.composer-actions {
  display: grid;
  gap: 8px;
  flex: 0 0 auto;
}

.right-pane {
  display: grid;
  grid-template-rows: 45px minmax(0, 1fr);
}

.tabs {
  display: flex;
  align-items: end;
  gap: 4px;
  padding: 8px 10px 0;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.tab {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-bottom-color: transparent;
}

.tab.active {
  background: var(--bg);
  border-color: var(--line);
  border-bottom-color: var(--bg);
}

.tab-panel {
  min-height: 0;
  display: none;
  padding: 14px;
  overflow: auto;
}

.tab-panel.active {
  display: block;
}

#previewTab.active {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
}

.preview-toolbar {
  display: flex;
  justify-content: end;
  align-items: center;
}

.preview-toolbar a {
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}

.preview-toolbar a:hover {
  text-decoration: underline;
}

#previewFrame {
  width: 100%;
  height: 100%;
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.empty-state {
  place-self: center;
  color: var(--muted);
}

.list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.row {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 6px;
}

.row-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.row-title {
  font-weight: 700;
  overflow-wrap: anywhere;
}

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

.run-status {
  width: fit-content;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  background: #edf1f5;
}

.run-status.ready {
  background: #e7f6ed;
  color: var(--success);
}

.run-status.error {
  background: #fdeceb;
  color: var(--danger);
}

.run-status.running,
.run-status.queued {
  background: #fff5df;
  color: var(--warn);
}

dialog {
  width: min(680px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
}

.dialog-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

@media (max-width: 860px) {
  .topbar {
    grid-template-columns: 1fr;
    height: auto;
  }

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

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(420px, 52vh) minmax(420px, 1fr);
  }

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

  .project-tools,
  .account-tools {
    flex-wrap: wrap;
    justify-content: start;
  }
}
