:root {
  --bg: #ffffff;
  --surface: #fafafa;
  --surface-strong: #f0f0f0;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --text-primary: #09090b;
  --text-secondary: #71717a;
  --text-tertiary: #a1a1aa;
  --accent: #18181b;
  --radius: 8px;
  --radius-sm: 6px;
  --copilot-width: 360px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text-primary);
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

* {
  box-sizing: border-box;
}

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

/* ========================================
   Buttons
   ======================================== */

button,
.button {
  border: 1px solid var(--border);
  background: var(--bg);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  font-size: 13px;
  transition: all var(--transition);
}

button:hover,
.button:hover {
  background: var(--surface-strong);
  border-color: var(--border-strong);
}

button:active,
.button:active {
  transform: scale(0.98);
}

button:focus-visible,
.button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button.active,
.nav-button.active,
.list-item.active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

/* ========================================
   Form Controls
   ======================================== */

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg);
  padding: 8px 12px;
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  font-size: 13px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(24, 24, 27, 0.08);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-tertiary);
}

textarea {
  min-height: 100px;
  resize: vertical;
  line-height: 1.6;
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%2371717a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 5l3 3 3-3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "SF Mono", "Cascadia Code", "Fira Code", monospace;
  font-size: 12px;
}

/* ========================================
   App Shell: 2-column layout
   ======================================== */

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 220px 1fr;
  transition: margin-right 0.25s ease;
}

.app-shell.copilot-open {
  margin-right: var(--copilot-width);
}

/* ========================================
   Nav Rail (left sidebar)
   ======================================== */

.nav-rail {
  min-height: 100vh;
  padding: 24px 16px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface);
}

.nav-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 16px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.nav-header h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.4px;
}

.nav-spacer {
  flex: 1;
}

.tag {
  display: inline-block;
  width: fit-content;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-secondary);
  background: var(--surface-strong);
  padding: 3px 8px;
  border-radius: 4px;
}

.muted,
.small {
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.5;
}

.nav-stack {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-button {
  text-align: left;
  font-weight: 500;
  font-size: 13px;
  padding: 8px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
}

.nav-button:hover {
  background: var(--surface-strong);
  border: none;
}

.nav-button.active {
  background: var(--accent);
  color: #ffffff;
  border: none;
}

.copilot-toggle {
  font-weight: 600;
  font-size: 13px;
  padding: 8px 12px;
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

/* ========================================
   Main Content: list + editor side by side
   ======================================== */

.main-content {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.library-panel {
  padding: 24px 20px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.editor-panel {
  padding: 24px 32px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 860px;
}

/* ========================================
   Copilot Drawer (right, slides in/out)
   ======================================== */

#copilot-root {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--copilot-width);
  z-index: 50;
  border-left: 1px solid var(--border);
  background: var(--bg);
  transform: translateX(100%);
  transition: transform 0.25s ease;
}

#copilot-root.open {
  transform: translateX(0);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.06);
}

.prefi-copilot-frame {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.prefi-copilot-status {
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  padding: 14px 16px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-thread {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.chat-viewport {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.chat-empty {
  color: var(--text-tertiary);
  font-size: 13px;
  padding: 20px 0;
}

.chat-composer {
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  flex-shrink: 0;
}

.chat-composer-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chat-input {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 10px 12px;
  resize: none;
  min-height: 40px;
  max-height: 120px;
  font-size: 13px;
  line-height: 1.4;
  border-radius: var(--radius-sm);
}

.chat-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(24, 24, 27, 0.08);
}

.chat-send {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--bg);
  padding: 10px 16px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  border-radius: var(--radius-sm);
}

.chat-send:hover {
  opacity: 0.85;
}

.chat-send:disabled {
  opacity: 0.4;
  cursor: default;
}

.chat-tool-status {
  font-size: 12px;
  color: var(--text-tertiary);
  font-style: italic;
  padding: 4px 0;
}

[data-aui-role="user"] {
  margin-bottom: 12px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.5;
}

[data-aui-role="assistant"] {
  margin-bottom: 12px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.5;
}

/* ========================================
   Panels, Cards, Status
   ======================================== */

.panel-header {
  margin-bottom: 4px;
}

.panel-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.panel-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.panel-header p {
  margin: 4px 0 0;
}

.section-title {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-secondary);
}

.panel,
.status-box,
.run-card,
.result-card,
.composer-box {
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: var(--radius);
}

.panel,
.status-box,
.composer-box,
.run-card,
.result-card {
  padding: 16px;
}

.status-box {
  background: var(--surface);
}

.status-box.error {
  background: var(--surface-strong);
}

.panel-stack,
.field-stack,
.run-list,
.result-list,
.assistant-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ========================================
   List Items
   ======================================== */

.list-item {
  text-align: left;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.list-item:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

.list-item.active {
  border-color: var(--accent);
}

/* ========================================
   Pills & Tags
   ======================================== */

.pill {
  border: 1px solid var(--border);
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  background: var(--surface);
  border-radius: 4px;
}

.pill.running {
  background: var(--surface-strong);
}

.pill.completed {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

.pill.failed,
.pill.blocked {
  background: var(--surface-strong);
}

/* ========================================
   Field Grid (Editor Forms)
   ======================================== */

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field > .small {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-tertiary);
}

.field.full {
  grid-column: 1 / -1;
}

.check-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-row input {
  width: auto;
  accent-color: var(--accent);
}

.split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

/* ========================================
   Transcript & Messages (Runs)
   ======================================== */

.transcript {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
}

.message {
  border: 1px solid var(--border);
  padding: 10px 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.6;
}

.message.user {
  background: var(--surface);
}

.message-role {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-tertiary);
  margin-bottom: 4px;
}

/* ========================================
   Dimension Options Editor
   ======================================== */

.dimension-options-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.dimension-option-row {
  display: grid;
  grid-template-columns: 1fr 2fr auto;
  gap: 6px;
  align-items: center;
}

.dimension-option-name,
.dimension-option-desc {
  padding: 8px 10px;
  font-size: 13px;
}

.dimension-option-remove {
  padding: 6px 10px;
  font-size: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  line-height: 1;
  border-radius: 4px;
}

.dimension-option-remove:hover {
  background: var(--surface-strong);
}

/* ========================================
   YAML Toggle (replaces raw-rail)
   ======================================== */

.yaml-toggle {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.yaml-toggle summary {
  cursor: pointer;
  padding: 10px 14px;
  background: var(--surface);
  font-weight: 500;
  font-size: 12px;
  user-select: none;
}

.yaml-toggle summary:hover {
  background: var(--surface-strong);
}

.yaml-preview {
  padding: 16px;
  background: var(--bg);
  max-height: 400px;
  overflow: auto;
  font-size: 12px;
  border-top: 1px solid var(--border);
}

/* ========================================
   Assistant Panel (in editor)
   ======================================== */

.assistant-summary {
  border: 1px solid var(--border);
  padding: 14px;
  background: var(--surface);
  border-radius: var(--radius-sm);
}

.assistant-action-list,
.assistant-example-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

.assistant-example-item {
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.5;
  border-radius: var(--radius-sm);
}

.assistant-action-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 13px;
  border-radius: var(--radius-sm);
}

.assistant-action-item strong {
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.6px;
}

/* ========================================
   Save/Action Buttons (bottom of editors)
   ======================================== */

.editor-panel button[data-action="save-spec"],
.editor-panel button[data-action="create-run"] {
  margin-top: 8px;
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  font-weight: 600;
}

.editor-panel button[data-action="save-spec"]:hover,
.editor-panel button[data-action="create-run"]:hover {
  opacity: 0.9;
}

.editor-panel button[data-action="delete-spec"] {
  margin-top: 8px;
  color: var(--text-secondary);
  border-color: var(--border);
}

/* ========================================
   Inline Create Form
   ======================================== */

.inline-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.inline-form input {
  background: var(--bg);
}

.inline-form-actions {
  display: flex;
  gap: 6px;
}

.inline-form-actions button {
  flex: 1;
  font-size: 12px;
  padding: 6px 10px;
}

/* ========================================
   Inline Delete Confirmation
   ======================================== */

.confirm-delete {
  padding: 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.danger-button {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  font-weight: 600;
}

.danger-button:hover {
  opacity: 0.9;
}

/* ========================================
   Copilot Open Tab (right edge)
   ======================================== */

#copilot-open-tab {
  position: fixed;
  top: 50%;
  right: 0;
  transform: translateY(-50%) rotate(-90deg) translateX(50%);
  transform-origin: right center;
  z-index: 40;
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: 6px 6px 0 0;
  padding: 6px 16px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.3px;
  transition: opacity var(--transition);
}

#copilot-open-tab:hover {
  opacity: 0.85;
}

body.copilot-visible #copilot-open-tab {
  display: none;
}

/* ========================================
   Copilot Close Button
   ======================================== */

.copilot-close {
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  padding: 4px 8px;
  cursor: pointer;
  color: var(--text-secondary);
  border-radius: 4px;
}

.copilot-close:hover {
  background: var(--surface-strong);
  color: var(--text-primary);
}

/* ========================================
   Copilot Welcome
   ======================================== */

.chat-welcome {
  padding: 8px 0;
}

.chat-welcome-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 6px;
}

.chat-welcome-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 0 12px;
  line-height: 1.5;
}

.chat-welcome-examples {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat-welcome-example {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--surface);
  line-height: 1.4;
  cursor: default;
}

/* ========================================
   Responsive
   ======================================== */

@media (max-width: 900px) {
  .main-content {
    grid-template-columns: 1fr;
  }

  .library-panel {
    display: none;
  }

  .editor-panel {
    padding: 20px 16px;
  }
}
