:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #111827;
  --muted: #667085;
  --line: #d8e0ea;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --danger-dark: #b91c1c;
  --console: #0f172a;
  --soft: #eff6ff;
  --soft-strong: #dbeafe;
  --success: #0f766e;
  --warning: #b45309;
  --shadow: 0 14px 40px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.12), transparent 32rem),
    linear-gradient(180deg, #ffffff 0%, var(--bg) 28rem);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button,
.button-link {
  border: 0;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  padding: 9px 14px;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, opacity 0.15s ease, transform 0.15s ease;
}

button:hover,
.button-link:hover {
  background: var(--primary-dark);
}

button:not(:disabled):active,
.button-link:active {
  transform: translateY(1px);
}

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

button.secondary {
  background: #475569;
}

button.secondary:hover {
  background: #334155;
}

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

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

button.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}

button.ghost:hover {
  background: #f8fafc;
}

button.small,
.button-link.small {
  padding: 6px 10px;
  font-size: 14px;
}

.hidden {
  display: none !important;
}

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

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

.login-box h1 {
  margin: 0;
  font-size: 34px;
  letter-spacing: 0;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
}

.login-subtitle {
  margin: -8px 0 6px;
  color: var(--muted);
}

.login-notice {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid rgba(37, 99, 235, 0.18);
  border-radius: 6px;
  background: rgba(37, 99, 235, 0.06);
  color: #1e3a8a;
  font-size: 14px;
  line-height: 1.55;
}

.login-status {
  min-height: 20px;
  margin: -2px 0 0;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.login-status::before {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid rgba(37, 99, 235, 0.22);
  border-top-color: var(--primary);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
  flex: 0 0 auto;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
}

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

input:focus,
select:focus {
  outline: 3px solid rgba(37, 99, 235, 0.16);
  border-color: var(--primary);
}

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

.main-view {
  width: min(1360px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.topbar,
.panel,
.console-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  box-shadow: var(--shadow);
}

.topbar h1,
.panel h2,
.console-panel h2 {
  margin: 0;
}

.topbar h1 {
  font-size: 28px;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
}

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

.model-badge {
  display: inline-block;
  max-width: min(48vw, 520px);
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.console-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.usage-badge {
  padding: 6px 11px;
  border-radius: 999px;
  background: #f1f5f9;
  color: #475569;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
}

.redo {
  display: flex;
  gap: 8px;
  min-width: min(100%, 420px);
}

.status {
  padding: 6px 11px;
  border-radius: 999px;
  background: #e2e8f0;
  color: #334155;
  font-size: 14px;
  font-weight: 700;
  text-transform: capitalize;
}

.status[data-status="running"],
.status[data-status="starting"] {
  background: #dbeafe;
  color: var(--primary-dark);
}

.status[data-status="stopping"] {
  background: #fef3c7;
  color: var(--warning);
}

.status[data-status="succeeded"] {
  background: #ccfbf1;
  color: var(--success);
}

.status[data-status="failed"],
.status[data-status="cancelled"] {
  background: #fee2e2;
  color: var(--danger-dark);
}

.workspace-layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.65fr) minmax(560px, 1.35fr);
  gap: 14px;
  margin-top: 14px;
  align-items: stretch;
}

.action-column,
.files-column {
  display: grid;
  gap: 14px;
  min-height: 0;
}

.action-column {
  grid-template-rows: 1fr;
}

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

.panel,
.console-panel {
  padding: 16px;
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.045);
}

.hero-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: linear-gradient(180deg, #ffffff 0%, var(--soft) 100%);
  min-height: 100%;
}

.eyebrow {
  display: inline-flex;
  margin-bottom: 8px;
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hero-panel p,
.panel-head p,
.console-panel p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 15px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.upload-row,
.file-actions,
.run-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.upload-row input {
  flex: 1 1 100%;
  min-width: 0;
}

.upload-row button {
  width: 100%;
}

.run-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.run-actions button {
  width: 100%;
  padding: 8px 10px;
}

.start-hint {
  margin: -4px 0 0;
  padding: 8px 10px;
  border: 1px solid #fed7aa;
  border-radius: 6px;
  background: #fff7ed;
  color: #9a3412;
  font-size: 15px;
  line-height: 1.45;
}

.redo-block {
  color: var(--muted);
  padding: 12px;
  border: 1px solid rgba(37, 99, 235, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.notice {
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  background: #eff6ff;
  color: #1e40af;
  padding: 9px 10px;
  font-size: 15px;
}

.redo-block h3 {
  margin: 0;
  color: var(--text);
  font-size: 16px;
}

.redo-block p {
  margin: 5px 0 0;
  font-size: 15px;
}

.redo-block .redo {
  margin-top: 10px;
}

.file-actions {
  margin-bottom: 10px;
}

.file-list,
.tree {
  min-height: 130px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: #fbfdff;
}

.data-list {
  max-height: 180px;
}

.workspace-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.workspace-tree {
  flex: 1;
  height: 420px;
  max-height: 52vh;
  min-height: 260px;
  overflow: auto;
}

.file-item,
.tree-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border-bottom: 1px solid #edf0f5;
  font-size: 15px;
}

.file-item:hover,
.tree-item:hover {
  background: #f8fafc;
}

.file-item:last-child,
.tree-item:last-child {
  border-bottom: 0;
}

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

.file-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace-path {
  font-family: "SFMono-Regular", Consolas, monospace;
}

.file-date {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.tree-children {
  margin-left: 18px;
}

.console-panel {
  margin-top: 14px;
}

.console {
  height: 460px;
  overflow: auto;
  margin: 0;
  padding: 12px;
  border-radius: 6px;
  background: var(--console);
  color: #dbeafe;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.run-locked .file-actions .danger,
.run-locked .upload-row,
.run-locked .redo-block {
  filter: saturate(0.85);
}

@media (max-width: 900px) {
  .main-view {
    padding: 14px;
  }

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

  .hero-panel {
    min-height: auto;
  }

  .redo {
    width: 100%;
    flex-direction: column;
  }

  .file-date {
    display: none;
  }

  .topbar,
  .topbar-actions {
    align-items: flex-start;
  }

  .topbar {
    flex-direction: column;
    gap: 12px;
  }
}
