:root {
  --bg-a: #0b1220;
  --bg-b: #13233d;
  --line: #2c4468;
  --panel: #10233d;
  --panel-soft: #173353;
  --text: #edf4ff;
  --muted: #9db4d3;
  --accent: #ffb703;
  --ok: #5ce1a8;
  --warn: #ffd166;
  --err: #ef476f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "Hiragino Kaku Gothic ProN", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 20% 20%, #22477a 0%, var(--bg-a) 45%),
    linear-gradient(120deg, var(--bg-a), var(--bg-b));
  display: grid;
  place-items: center;
}

.loginGate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(5, 12, 20, 0.7);
  backdrop-filter: blur(4px);
}

.loginCard {
  width: min(420px, 92vw);
  display: grid;
  gap: 10px;
  padding: 22px;
  border-radius: 16px;
  border: 1px solid #2f4f79;
  background: linear-gradient(180deg, rgba(13, 30, 52, 0.98), rgba(8, 18, 31, 0.96));
}

.loginCard h2 {
  margin: 0;
  font-size: 22px;
}

.loginField {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.loginField input {
  border-radius: 10px;
  border: 1px solid #365980;
  background: #102139;
  color: var(--text);
  padding: 10px;
}

.loginError {
  min-height: 1.3em;
  margin: 0;
  color: #ffc6d4;
  font-size: 12px;
}

.workspace.locked {
  pointer-events: none;
  user-select: none;
  filter: blur(2px);
  opacity: 0.45;
}

.authUserBadge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid #365980;
  background: #15304f;
  color: #d8e9ff;
  font-size: 12px;
  font-weight: 600;
}

.workspace {
  width: min(1440px, 96vw);
  height: min(90vh, 900px);
  display: grid;
  grid-template-columns: minmax(360px, 420px) 1fr;
  gap: 12px;
  position: relative;
  z-index: 1;
  transition: grid-template-columns 180ms ease;
}

.workspace.editorWideMode {
  grid-template-columns: minmax(560px, 660px) minmax(400px, 1fr);
}

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

.topTabs {
  display: flex;
  align-items: end;
  gap: 4px;
  padding: 0 14px;
  margin-bottom: -1px;
  z-index: 2;
}

.viewBtn {
  width: auto;
  text-align: center;
  background: #1a3759;
  color: #d8e8ff;
  border: 1px solid #365980;
  border-bottom-color: #365980;
  border-radius: 12px 12px 0 0;
  padding: 8px 14px;
}

.viewBtn.active {
  background: #10233d;
  color: #edf4ff;
  border-color: #2f4f79;
  border-bottom-color: #10233d;
  margin-bottom: -1px;
}

.browserPanel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 8px;
  padding: 14px;
  border-radius: 18px;
  border: 1px solid #2f4f79;
  background: linear-gradient(180deg, rgba(13, 30, 52, 0.96), rgba(8, 18, 31, 0.95));
  min-height: 0;
  overflow: hidden;
}
.browserHeader {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.browserActions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.gitCommitControls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: start;
}

#gitCommitMessageInput {
  border-radius: 10px;
  padding: 10px 12px;
  border: 1px solid #365980;
  color: var(--text);
  background: #102139;
  min-width: 0;
  width: 100%;
  font-size: 13px;
  resize: vertical;
  min-height: 68px;
  max-height: 160px;
  line-height: 1.45;
  font-family: inherit;
}

#gitCommitBtn {
  padding: 10px 14px;
  min-width: 86px;
  align-self: start;
}

.browserHeader h2 {
  margin: 0;
  font-size: 18px;
}

.browserPath {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.crumbBtn {
  border: none;
  border-radius: 8px;
  padding: 3px 8px;
  background: #1a3759;
  color: #d8e8ff;
  font-size: 12px;
  cursor: pointer;
}

.crumbSep {
  color: #89a7cc;
}

.browserPreview {
  min-height: 0;
  padding-top: 2px;
}

.previewCard {
  border: 1px solid #2c4e77;
  border-radius: 12px;
  padding: 8px;
  background: #12253f;
}

.previewCard img {
  width: 100%;
  height: 140px;
  object-fit: contain;
  background: #08192b;
  border-radius: 8px;
}

.previewMeta {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.textEditorCard {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 8px;
  min-height: 240px;
}

.textEditorHead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.textEditorHead .previewMeta {
  margin: 0;
}

.textEditor {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  border-radius: 8px;
  border: 1px solid #365980;
  background: #0b1f34;
  color: #e7f1ff;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 12px;
  line-height: 1.45;
  padding: 10px;
}

.workspace.editorWideMode .textEditor {
  min-height: 320px;
}

.browserList {
  overflow: auto;
  border-radius: 12px;
  border: 1px solid #25456d;
  background: #0c1b30;
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  min-height: 0;
}

.fileRow {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border-bottom: 1px solid rgba(79, 121, 170, 0.3);
}

.fileInfo {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.fileRow:last-child {
  border-bottom: none;
}

.fileType {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #9dc3ee;
}

.fileType svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.fileNameBtn {
  background: transparent;
  color: #ebf4ff;
  border: none;
  padding: 2px 0;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fileMeta {
  font-size: 11px;
  color: #9db4d3;
  line-height: 1.3;
}

.dangerBtn {
  background: #8b1e3f;
  color: #fff4f8;
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}

.subtleBtn {
  background: #24476f;
  color: #d9ebff;
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}

.rowActions {
  display: flex;
  gap: 6px;
}

.browserToolbarRow {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px;
  border-bottom: 1px solid rgba(79, 121, 170, 0.3);
  background: #102139;
  border-radius: 8px;
  margin-bottom: 6px;
}

.browserToolbarRow .hint {
  margin: 0;
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image: linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 24px 24px;
  opacity: 0.22;
}

.shell {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 12px;
  padding: 20px;
  border: 1px solid #2f4f79;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(16, 35, 61, 0.92), rgba(10, 22, 38, 0.92));
  backdrop-filter: blur(8px);
  min-height: 0;
  overflow: hidden;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.toggleControl {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid #365980;
  border-radius: 999px;
  background: #15304f;
  color: #d8e9ff;
  font-size: 12px;
  font-weight: 600;
}

.toggleControl input {
  margin: 0;
}

.topbar h1 {
  margin: 0;
  letter-spacing: 0.03em;
  font-size: clamp(20px, 3vw, 28px);
}

button {
  border: none;
  border-radius: 999px;
  padding: 10px 14px;
  font-weight: 600;
  background: var(--accent);
  color: #231400;
  cursor: pointer;
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 10px 14px;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.secondary {
  background: #7dd3fc;
  color: #062032;
}

.meta {
  padding: 10px 12px;
  border-radius: 12px;
  color: var(--muted);
  background: var(--panel-soft);
  font-size: 14px;
}

#historyPanel {
  grid-template-rows: auto auto auto auto;
  align-content: start;
  overflow-y: auto;
}

#toolsPanel {
  grid-template-rows: auto auto auto;
  align-content: start;
  overflow-y: auto;
}

#toolsPanel .uploadControls {
  grid-template-columns: 1fr auto;
}

#toolsPanel .importControls {
  grid-template-columns: 1fr auto;
}

#toolsPanel .importControls input[type="url"] {
  grid-column: 1 / -1;
}

.uploadDropZone {
  position: relative;
  border: 2px dashed #365980;
  border-radius: 10px;
  padding: 14px 10px;
  text-align: center;
  cursor: pointer;
  transition: background 150ms, border-color 150ms;
}

.uploadDropZone input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.uploadDropLabel {
  font-size: 12px;
  color: var(--muted);
  pointer-events: none;
}

.uploadDropZone.dragover {
  background: #1a3a5c;
  border-color: #6ab4ff;
}

.uploadDropZone.dragover .uploadDropLabel {
  color: #cde2ff;
}

.uploadCard {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid #25456d;
  background: #0f243d;
}

.importCard {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid #2f5b87;
  background: #132844;
}

.uploadCard h2 {
  margin: 0 0 8px;
  font-size: 15px;
  color: #cde2ff;
}

.importCard h2 {
  margin: 0 0 8px;
  font-size: 15px;
  color: #cde2ff;
}

.uploadControls {
  display: grid;
  grid-template-columns: 1.2fr 1fr auto;
  gap: 8px;
}

.importControls {
  display: grid;
  grid-template-columns: 1.5fr 1fr auto;
  gap: 8px;
}

.uploadControls input[type="text"],
.uploadControls input[type="file"] {
  border-radius: 10px;
  padding: 10px;
  border: 1px solid #365980;
  color: var(--text);
  background: var(--panel);
}

.importControls input[type="text"],
.importControls input[type="url"] {
  border-radius: 10px;
  padding: 10px;
  border: 1px solid #365980;
  color: var(--text);
  background: var(--panel);
}

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
}

#gitStatusHint.ok {
  color: #8ff0c7;
}

#gitStatusHint.warn {
  color: #ffd166;
}

#gitStatusHint.err {
  color: #ffc6d4;
}

.gitHistoryPanel {
  border: 1px solid #2f5b87;
  border-radius: 12px;
  padding: 10px;
  background: #10233d;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  max-height: 280px;
  overflow: hidden;
}

.gitHistoryHeader {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.gitHistoryHeader h3 {
  margin: 0;
  font-size: 14px;
  color: #cde2ff;
}

.gitHistoryList {
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.gitCommitRow {
  border: 1px solid #274a71;
  border-radius: 10px;
  padding: 8px;
  background: #0f2239;
  display: grid;
  gap: 6px;
}

.gitCommitSummary {
  font-size: 12px;
  font-weight: 600;
  color: #e7f1ff;
  overflow-wrap: anywhere;
}

.gitCommitMeta {
  font-size: 11px;
  color: #9db4d3;
}

.gitHistoryDetail {
  margin: 0;
  white-space: pre-wrap;
  border-top: 1px solid #274a71;
  padding-top: 8px;
  overflow: auto;
  max-height: 130px;
}

.publishCard {
  border: 1px solid #2f5b87;
  border-radius: 12px;
  padding: 10px;
  background: #10233d;
  display: grid;
  gap: 8px;
}

.publishCard h3 {
  margin: 0;
  font-size: 14px;
  color: #cde2ff;
}

.publishResult {
  margin: 0;
  border-radius: 8px;
  border: 1px solid #274a71;
  background: #0f2239;
  color: #d9ebff;
  padding: 8px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  white-space: pre-wrap;
}

.hidden {
  display: none !important;
}

.log {
  overflow: auto;
  border-radius: 12px;
  padding: 12px;
  background: #0c1b30;
  border: 1px solid #25456d;
  min-height: 0;
}

.row {
  margin: 0 0 10px;
  padding: 10px 12px;
  border-radius: 10px;
  line-height: 1.45;
  white-space: pre-wrap;
  animation: rise 180ms ease-out;
}

.user {
  background: #19395e;
}

.assistant {
  background: #12314f;
}

.tool {
  background: #2d2b1e;
  color: var(--warn);
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px;
}

.error {
  background: #402130;
  color: #ffc6d4;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.composerSide {
  display: grid;
  grid-template-rows: auto auto auto;
  gap: 8px;
  align-content: start;
}

.runStatus {
  margin: 0;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  width: 96px;
  box-sizing: border-box;
  overflow: hidden;
  white-space: nowrap;
}

.runStatus.idle {
  background: #1d3557;
  color: #b8d3f6;
}

@keyframes pulse-badge {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 231, 155, 0.5); }
  50%       { box-shadow: 0 0 0 7px rgba(255, 231, 155, 0); }
}

.runStatus.running {
  background: #4a3c12;
  color: #ffe79b;
  animation: pulse-badge 1.4s ease-in-out infinite;
}

#sendBtn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  filter: grayscale(0.4);
}

.dangerBtn,
.subtleBtn,
.crumbBtn {
  border-radius: 999px;
}

textarea {
  resize: vertical;
  min-height: 68px;
  max-height: 220px;
  border-radius: 10px;
  padding: 12px;
  border: 1px solid #365980;
  color: var(--text);
  background: var(--panel);
}

@keyframes rise {
  from {
    transform: translateY(6px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@media (max-width: 680px) {
  .workspace {
    grid-template-columns: 1fr;
    height: min(92vh, 900px);
    min-height: 0;
  }

  .workspace.editorWideMode {
    grid-template-columns: 1fr;
  }

  .topTabs {
    padding: 0 10px;
  }

  .viewBtn {
    text-align: center;
    padding: 8px 10px;
  }

  .browserPanel {
    min-height: 0;
  }

  .shell {
    width: 100%;
    height: min(70vh, 760px);
    padding: 12px;
  }

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

  .composerSide {
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: auto;
  }

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

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

  #gitCommitMessageInput {
    min-width: 0;
    width: 100%;
  }

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

  #gitCommitBtn {
    width: 100%;
  }
}
