/* ============================================================
   Palmer Proposal System — SM Services Branding
   Primary: #FF6210 (orange) | Dark: #0F0F0F | Card: #1E1E1E
   ============================================================ */

:root {
  --orange: #FF6210;
  --orange-dark: #e0540a;
  --orange-light: rgba(255, 98, 16, 0.12);
  --orange-glow: rgba(255, 98, 16, 0.25);
  --black: #0F0F0F;
  --dark: #1A1A1A;
  --card: #1E1E1E;
  --card-border: #2a2a2a;
  --card-light: #252525;
  --white: #ffffff;
  --text: #e8e8e8;
  --text-muted: #888;
  --text-dim: #555;
  --green: #22c55e;
  --green-bg: rgba(34, 197, 94, 0.1);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.1);
  --yellow: #f59e0b;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--black);
  color: var(--text);
  font-size: 13px;
  line-height: 1.6;
}

/* ── Layout ─────────────────────────────────────────────── */
.app-layout {
  display: grid;
  grid-template-rows: 56px 1fr;
  grid-template-columns: 380px 1fr;
  height: 100vh;
  overflow: hidden;
}

.app-header {
  grid-column: 1 / -1;
  grid-row: 1;
  background: var(--dark);
  border-bottom: 1px solid var(--card-border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  z-index: 100;
}

.sidebar {
  grid-column: 1;
  grid-row: 2;
  background: var(--dark);
  border-right: 1px solid var(--card-border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.main-panel {
  grid-column: 2;
  grid-row: 2;
  background: var(--black);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* ── Header ─────────────────────────────────────────────── */
.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.header-logo svg { width: 30px; height: 30px; }
.header-brand {
  font-size: 14px;
  font-weight: 700;
  color: var(--white);
  letter-spacing: -0.2px;
}
.header-brand span { color: var(--orange); }
.header-divider {
  width: 1px;
  height: 28px;
  background: var(--card-border);
}
.header-title {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}
.header-spacer { flex: 1; }
.header-link {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  transition: all 0.15s;
  cursor: pointer;
}
.header-link:hover { border-color: var(--orange); color: var(--orange); }
.header-link svg { width: 14px; height: 14px; }

/* ── Sidebar / Input Panel ───────────────────────────────── */
.sidebar-inner {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
}

.section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.demo-btn {
  width: 100%;
  background: var(--orange-light);
  border: 1px solid var(--orange);
  color: var(--orange);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: 'Inter', sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.demo-btn:hover { background: var(--orange); color: var(--white); }
.demo-btn svg { width: 14px; height: 14px; }

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

.form-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.3px;
}

.form-textarea {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 12.5px;
  line-height: 1.6;
  padding: 10px 12px;
  resize: vertical;
  min-height: 80px;
  transition: border-color 0.15s;
  width: 100%;
}
.form-textarea:focus {
  outline: none;
  border-color: var(--orange);
}
.form-textarea::placeholder { color: var(--text-dim); }
.form-textarea.guidance { min-height: 120px; }
.form-textarea.transcript { min-height: 160px; }

/* ── Voice Button ────────────────────────────────────────────── */
.voice-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  transition: all 0.15s;
  flex-shrink: 0;
}
.voice-btn svg { width: 13px; height: 13px; }
.voice-btn:hover { border-color: var(--orange); color: var(--orange); }
.voice-btn.recording {
  background: rgba(239, 68, 68, 0.12);
  border-color: var(--red);
  color: var(--red);
  animation: voicePulse 1.2s ease-in-out infinite;
}
@keyframes voicePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 0 0 5px rgba(239, 68, 68, 0); }
}
.voice-status {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 4px;
  min-height: 14px;
  transition: color 0.15s;
}
.voice-status.listening { color: var(--red); }

.generate-btn {
  width: 100%;
  background: var(--orange);
  border: none;
  color: var(--white);
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.generate-btn:hover:not(:disabled) { background: var(--orange-dark); transform: translateY(-1px); box-shadow: 0 4px 16px var(--orange-glow); }
.generate-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }
.generate-btn svg { width: 16px; height: 16px; }

/* ── Pipeline Status ─────────────────────────────────────── */
.pipeline-status {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 14px;
  display: none;
}
.pipeline-status.visible { display: block; }
.pipeline-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.pipeline-steps {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pipeline-step {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--card-light);
  border: 1px solid transparent;
  transition: all 0.2s;
}
.pipeline-step.active {
  border-color: var(--orange);
  background: var(--orange-light);
}
.pipeline-step.done {
  border-color: var(--card-border);
  opacity: 0.7;
}
.step-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
  color: var(--text-muted);
  border: 1px solid var(--card-border);
}
.pipeline-step.active .step-icon {
  background: var(--orange);
  color: var(--white);
  border-color: var(--orange);
  animation: pulse 1s infinite;
}
.pipeline-step.done .step-icon {
  background: var(--green-bg);
  color: var(--green);
  border-color: var(--green);
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 98, 16, 0.4); }
  50% { box-shadow: 0 0 0 6px rgba(255, 98, 16, 0); }
}
.step-info { flex: 1; }
.step-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}
.pipeline-step.active .step-name { color: var(--orange); }
.pipeline-step.done .step-name { color: var(--text-muted); }
.step-desc {
  font-size: 11px;
  color: var(--text-muted);
}
.step-check {
  font-size: 14px;
  color: var(--green);
  display: none;
}
.pipeline-step.done .step-check { display: block; }

/* ── Main Panel ──────────────────────────────────────────── */
.main-inner {
  padding: 24px;
  flex: 1;
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 400px;
  gap: 16px;
  text-align: center;
}
.empty-state svg { width: 64px; height: 64px; opacity: 0.2; }
.empty-state h2 { font-size: 18px; font-weight: 700; color: var(--text-muted); }
.empty-state p { font-size: 13px; color: var(--text-dim); max-width: 320px; }

/* Proposal output frame */
.proposal-frame-wrapper {
  background: var(--white);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
}
.proposal-frame-toolbar {
  background: #2a2a2a;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.frame-dots { display: flex; gap: 6px; }
.frame-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
}
.frame-dot:nth-child(1) { background: #ff5f57; }
.frame-dot:nth-child(2) { background: #febc2e; }
.frame-dot:nth-child(3) { background: #28c840; }
.frame-url {
  flex: 1;
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  font-family: monospace;
}
.print-proposal-btn {
  background: var(--orange);
  color: var(--white);
  border: none;
  padding: 5px 12px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: background 0.15s;
}
.print-proposal-btn:hover { background: var(--orange-dark); }
.proposal-frame-content {
  background: var(--white);
  max-height: calc(100vh - 280px);
  overflow-y: auto;
}

/* Internal notes */
.notes-box {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 20px;
}
.notes-box h3 {
  font-size: 13px;
  font-weight: 700;
  color: var(--yellow);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.notes-content {
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--text);
}
.notes-content h2, .notes-content h3 { color: var(--orange); margin: 14px 0 6px; font-size: 13px; }
.notes-content ul, .notes-content ol { padding-left: 18px; margin-bottom: 8px; }
.notes-content li { margin-bottom: 3px; }
.notes-content p { margin-bottom: 8px; }

/* Pipeline data */
.pipeline-data {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.data-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  overflow: hidden;
}
.data-card-header {
  background: var(--card-light);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}
.data-card-header h3 { font-size: 12px; font-weight: 700; color: var(--orange); }
.data-card-header span { font-size: 11px; color: var(--text-muted); }
.data-card-body {
  padding: 14px 16px;
  display: none;
}
.data-card-body.open { display: block; }
.data-card-body pre {
  font-size: 11px;
  font-family: 'Consolas', 'Monaco', monospace;
  color: #a8d8a8;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
}

/* GHL status badge */
.ghl-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--orange);
}
.ghl-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  background: var(--orange);
  border-radius: 50%;
}

/* Status bar at bottom */
.status-bar {
  background: var(--card);
  border-top: 1px solid var(--card-border);
  padding: 6px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
}
.status-dot.error { background: var(--red); }
.status-dot.working { background: var(--orange); animation: pulse 1s infinite; }

/* Error banner */
.error-banner {
  background: var(--red-bg);
  border: 1px solid var(--red);
  border-radius: 8px;
  padding: 12px 16px;
  color: var(--red);
  font-size: 12.5px;
  display: none;
  margin-bottom: 16px;
}
.error-banner.visible { display: flex; gap: 10px; align-items: flex-start; }

/* QA badge */
.qa-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.qa-badge.pass { background: var(--green-bg); color: var(--green); border: 1px solid var(--green); }
.qa-badge.fail { background: var(--red-bg); color: var(--red); border: 1px solid var(--red); }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--card-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* Proposal HTML content rendered inside dark app */
.proposal-frame-content .proposal-wrapper { margin: 0; padding: 0; }

/* ── History Panel ───────────────────────────────────────────── */
.history-section {
  border-top: 1px solid var(--card-border);
  padding-top: 12px;
  margin-top: 4px;
}
.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding: 2px 0 8px;
  user-select: none;
}
.history-header:hover .section-label { color: var(--orange); }
.history-chevron { font-size: 12px; color: var(--text-muted); }
.archive-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  color: var(--text-dim);
  cursor: pointer;
  font-weight: 500;
}
.archive-toggle input { cursor: pointer; accent-color: var(--orange); }
.history-list { display: flex; flex-direction: column; gap: 4px; max-height: 280px; overflow-y: auto; }
.history-empty { font-size: 11px; color: var(--text-dim); text-align: center; padding: 12px 0; }
.history-view-more {
  width: 100%;
  background: none;
  border: 1px dashed var(--card-border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 11px;
  padding: 7px;
  cursor: pointer;
  margin-top: 2px;
  transition: border-color 0.15s, color 0.15s;
}
.history-view-more:hover { border-color: var(--orange); color: var(--orange); }
.history-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 6px;
  overflow: hidden;
  transition: border-color 0.15s;
}
.history-item:hover { border-color: var(--orange); }
.history-item.archived { opacity: 0.55; }
.history-item-main {
  flex: 1;
  padding: 8px 10px;
  cursor: pointer;
  min-width: 0;
}
.history-item-title {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-item-meta {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 2px;
}
.history-item-actions {
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--card-border);
}
.history-action-btn {
  background: none;
  border: none;
  padding: 6px 8px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
  transition: background 0.15s;
  line-height: 1;
}
.history-action-btn:hover { background: var(--card-light); }
.history-action-btn.danger:hover { background: var(--red-bg); }
.history-action-btn:first-child { border-bottom: 1px solid var(--card-border); }

/* ── Toolbar Actions ─────────────────────────────────────────── */
.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.toolbar-btn {
  background: var(--card);
  color: var(--text-muted);
  border: 1px solid var(--card-border);
  padding: 5px 10px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
  white-space: nowrap;
}
.toolbar-btn:hover { border-color: var(--orange); color: var(--orange); }
.toolbar-btn.active { background: var(--orange); color: var(--white); border-color: var(--orange); }
.toolbar-btn.revise-btn:hover { border-color: #7c6af5; color: #7c6af5; }
.toolbar-btn.save-btn { border-color: var(--green); color: var(--green); }
.toolbar-btn.save-btn:hover { background: var(--green-bg); }
.toolbar-btn.new-proposal-btn { border-color: #7c6af5; color: #7c6af5; }
.toolbar-btn.new-proposal-btn:hover { background: rgba(124,106,245,0.12); }

/* ── Revision Panel ──────────────────────────────────────────── */
.revision-panel {
  background: var(--card);
  border: 1px solid var(--orange);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
  display: none;
}
.revision-panel.visible { display: block; }
.revision-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.revision-header span {
  font-size: 12px;
  font-weight: 700;
  color: var(--orange);
  display: flex;
  align-items: center;
  gap: 4px;
}
.revision-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  padding: 3px 8px;
  border-radius: 4px;
  transition: all 0.15s;
}
.revision-close:hover { background: var(--red-bg); color: var(--red); }
.revision-textarea {
  width: 100%;
  background: var(--dark);
  border: 1px solid var(--card-border);
  border-radius: 6px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 12.5px;
  line-height: 1.6;
  padding: 10px 12px;
  resize: vertical;
  min-height: 80px;
  display: block;
  margin-bottom: 10px;
  transition: border-color 0.15s;
}
.revision-textarea:focus { outline: none; border-color: var(--orange); }
.revision-textarea::placeholder { color: var(--text-dim); }
.revision-run-btn {
  background: var(--orange);
  color: var(--white);
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s;
}
.revision-run-btn:hover:not(:disabled) { background: var(--orange-dark); }
.revision-run-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Edit Mode Textarea ──────────────────────────────────────── */
.proposal-edit-textarea {
  width: 100%;
  height: calc(100vh - 280px);
  background: #111;
  color: #a8d8a8;
  border: none;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 12px;
  line-height: 1.6;
  padding: 20px;
  resize: none;
  display: block;
}
.proposal-edit-textarea:focus { outline: none; }

/* ── Mobile Responsive ───────────────────────────────────────── */
@media (max-width: 768px) {
  html, body {
    height: auto;
    overflow: auto;
  }

  .app-layout {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .app-header {
    grid-column: unset;
    grid-row: unset;
    position: sticky;
    top: 0;
    z-index: 200;
    padding: 0 12px;
    gap: 10px;
  }

  .header-divider,
  .header-title { display: none; }

  .header-brand { font-size: 13px; }

  .sidebar {
    grid-column: unset;
    grid-row: unset;
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--card-border);
    overflow-y: visible;
  }

  .sidebar-inner {
    padding: 14px;
    gap: 12px;
  }

  .main-panel {
    grid-column: unset;
    grid-row: unset;
    width: 100%;
    overflow-y: visible;
    flex: 1;
  }

  .main-inner { padding: 14px; }

  .proposal-frame-content {
    max-height: none;
    overflow-y: visible;
  }

  .proposal-edit-textarea {
    height: 60vh;
  }

  .form-textarea.guidance { min-height: 100px; }
  .form-textarea.transcript { min-height: 120px; }

  .generate-btn {
    font-size: 14px;
    padding: 14px 20px;
  }

  .proposal-frame-toolbar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 10px;
  }

  .frame-url { display: none; }

  .toolbar-actions {
    flex-wrap: wrap;
    gap: 4px;
  }

  .toolbar-btn {
    padding: 6px 10px;
    font-size: 11px;
  }

  .print-proposal-btn {
    padding: 6px 10px;
  }

  .history-list {
    max-height: none;
    overflow-y: visible;
    gap: 6px;
  }

  .history-item {
    border-radius: 8px;
  }

  .history-item-main {
    padding: 10px 12px;
  }

  .history-item-title {
    font-size: 13px;
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
    line-height: 1.35;
  }

  .history-item-meta {
    font-size: 11px;
    margin-top: 4px;
  }

  .history-item-actions {
    flex-direction: row;
    border-left: none;
    border-top: 1px solid var(--card-border);
    align-self: stretch;
    align-items: flex-end;
    padding: 4px 6px;
    gap: 2px;
  }

  .history-action-btn {
    padding: 8px 10px;
    font-size: 16px;
  }

  .history-action-btn:first-child {
    border-bottom: none;
    border-right: 1px solid var(--card-border);
  }

  .history-item {
    flex-direction: column;
    align-items: stretch;
  }

  .status-bar {
    padding: 6px 12px;
  }

  .status-bar span:last-child {
    display: none;
  }

  .pipeline-step {
    padding: 6px 8px;
  }

  .step-desc { display: none; }
}
