/* Craig Editor app shell + 3-column layout */
:root {
  --api-teal: #009999;
  --api-teal-dark: #006666;
  --api-yellow: #F2C800;
  --api-bg: #FFFFFF;
  --api-bg-soft: #F5F7F8;
  --api-border: #DCE2E5;
  --api-ink: #1A1A1A;
  --api-muted: #6B7378;
  --api-warn: #B8860B;
  --api-error: #C0392B;
  --pad: 16px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Arial, sans-serif;
  color: var(--api-ink);
  background: var(--api-bg);
}
.hidden { display: none !important; }
.primary {
  background: var(--api-teal);
  color: white;
  border: 0;
  padding: 8px 16px;
  border-radius: 4px;
  font-weight: 600;
  cursor: pointer;
}
.primary:hover { background: var(--api-teal-dark); }
.primary:disabled {
  background: var(--api-muted);
  cursor: not-allowed;
  opacity: 0.6;
}
.secondary {
  background: white;
  color: var(--api-ink);
  border: 1px solid var(--api-border);
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
}
.secondary:hover { background: var(--api-bg-soft); }
button { font-family: inherit; font-size: 14px; }

/* PIN gate */
.pin-gate-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.pin-gate-card {
  background: white; padding: 32px; border-radius: 8px;
  width: 360px; box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  display: flex; flex-direction: column; gap: 12px;
}
.pin-gate-card h2 { margin: 0; }
.pin-gate-card input { padding: 10px; font-size: 18px; letter-spacing: 4px; text-align: center; border: 1px solid var(--api-border); border-radius: 4px; }
.pin-gate-card button { background: var(--api-teal); color: white; border: 0; padding: 10px; border-radius: 4px; font-size: 16px; cursor: pointer; }
.pin-gate-error { color: var(--api-error); font-size: 13px; }

/* App shell */
.app-shell {
  display: flex; flex-direction: column;
  height: 100vh;
}
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px var(--pad);
  background: var(--api-teal);
  color: white;
  flex: 0 0 auto;
}
.app-header h1 { margin: 0; font-size: 18px; font-weight: 700; }
.header-right { display: flex; align-items: center; gap: 12px; }
.captured-status { font-size: 13px; opacity: 0.9; }
.spend-pill {
  background: white; color: var(--api-ink);
  padding: 6px 12px; border-radius: 16px;
  font-size: 13px; font-weight: 600;
}
.spend-pill.warning { background: var(--api-yellow); color: var(--api-ink); }
.spend-pill.blocked { background: var(--api-error); color: white; }

/* Empty state */
.empty-state {
  flex: 1; display: flex; align-items: center; justify-content: center;
  background: var(--api-bg-soft);
  border: 2px dashed var(--api-border);
  margin: var(--pad);
  border-radius: 8px;
  cursor: pointer;
  text-align: center;
}
.empty-state.dragover { border-color: var(--api-teal); background: #EAF7F7; }

/* Resume modal */
.resume-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 900;
}
.resume-modal-card {
  background: white; padding: 28px; border-radius: 8px;
  max-width: 460px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
.resume-modal-buttons { margin-top: 16px; display: flex; gap: 12px; justify-content: flex-end; }

/* 3-column workspace */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 240px 1fr 420px;
  gap: 12px;
  padding: 12px;
  min-height: 0;
}

/* Column 1: TOC sidebar */
.toc-sidebar {
  background: var(--api-bg-soft);
  border: 1px solid var(--api-border);
  border-radius: 6px;
  padding: 12px;
  display: flex; flex-direction: column; min-height: 0;
}
.module-label { font-weight: 700; font-size: 14px; padding-bottom: 8px; border-bottom: 1px solid var(--api-border); margin-bottom: 8px; }
.toc-list {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
}
.toc-link {
  background: transparent; border: 0;
  text-align: left; padding: 6px 8px; border-radius: 4px;
  cursor: pointer; font-size: 13px;
}
.toc-link:hover { background: white; }
.toc-link.active { background: white; font-weight: 600; color: var(--api-teal-dark); }
.sidebar-footer { display: flex; flex-direction: column; gap: 6px; padding-top: 8px; border-top: 1px solid var(--api-border); margin-top: 8px; }
.edit-count-summary { font-size: 12px; color: var(--api-muted); text-align: center; }

/* Column 2: Preview */
.preview-column {
  display: flex; flex-direction: column;
  background: white;
  border: 1px solid var(--api-border);
  border-radius: 6px;
  min-height: 0;
}
.preview-toolbar {
  padding: 8px 12px; border-bottom: 1px solid var(--api-border);
  background: var(--api-bg-soft);
  font-size: 13px;
}
.capture-hint { color: var(--api-muted); }
.preview-iframe {
  flex: 1; width: 100%; border: 0; background: white;
}

/* Column 3: Edit panel */
.edit-column {
  display: flex; flex-direction: column;
  background: white;
  border: 1px solid var(--api-border);
  border-radius: 6px;
  min-height: 0;
}
.edit-panel-empty { padding: var(--pad); display: flex; flex-direction: column; gap: 8px; }
.recent-edits-heading { font-weight: 600; font-size: 13px; color: var(--api-muted); padding-top: 8px; border-top: 1px solid var(--api-border); }
.recent-edits-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.recent-edits-list li { padding: 4px 6px; border-radius: 4px; background: var(--api-bg-soft); font-size: 12px; }
.recent-edits-empty { color: var(--api-muted); font-style: italic; }

.edit-panel-active { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.target-meta { padding: 10px 12px; background: var(--api-bg-soft); font-size: 12px; border-bottom: 1px solid var(--api-border); }

.tab-bar { display: flex; gap: 0; background: var(--api-bg-soft); padding: 0 8px; border-bottom: 1px solid var(--api-border); }
.tab { background: transparent; border: 0; padding: 8px 12px; cursor: pointer; font-size: 13px; border-bottom: 2px solid transparent; }
.tab.active { font-weight: 700; color: var(--api-teal-dark); border-bottom-color: var(--api-teal); }

.tab-panels { flex: 1; min-height: 0; position: relative; }
.tab-panel { display: none; height: 100%; }
.tab-panel.active { display: block; }
.output-iframe { width: 100%; height: 100%; border: 0; background: white; }
.output-source {
  width: 100%; height: 100%; margin: 0;
  padding: 12px; box-sizing: border-box;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px; line-height: 1.5;
  background: var(--api-bg-soft);
  white-space: pre-wrap; overflow: auto;
}
.message-list { padding: 12px; overflow-y: auto; height: 100%; display: flex; flex-direction: column; gap: 8px; }
.history-empty { color: var(--api-muted); font-style: italic; font-size: 13px; }
.message { padding: 8px 10px; border-radius: 6px; font-size: 13px; }
.message.user { background: #E8F4F4; }
.message.assistant { background: var(--api-bg-soft); font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; white-space: pre-wrap; }
.message-role { font-weight: 700; font-size: 11px; color: var(--api-muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; }

.chat-input { padding: 12px; border-top: 1px solid var(--api-border); display: flex; flex-direction: column; gap: 8px; }
.instruction-input {
  width: 100%; min-height: 80px;
  resize: vertical;
  padding: 8px; font-family: inherit; font-size: 13px;
  border: 1px solid var(--api-border); border-radius: 4px;
}
.chat-buttons { display: flex; gap: 8px; }

/* Toast */
.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 800; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--api-ink); color: white;
  padding: 10px 14px; border-radius: 6px;
  font-size: 13px; max-width: 320px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.3);
  animation: toast-slide 0.2s ease-out;
}
.toast.warn { background: var(--api-warn); }
.toast.error { background: var(--api-error); }
@keyframes toast-slide {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
