/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-input: #232633;
  --bg-hover: #272b3a;
  --border: #2e3347;
  --text: #e4e6f0;
  --text-muted: #8b8fa3;
  --text-dim: #5c6078;
  --accent: #6c8cff;
  --accent-hover: #8aa4ff;
  --green: #4ade80;
  --green-dim: #16653a;
  --yellow: #facc15;
  --yellow-dim: #6b5c10;
  --red: #f87171;
  --red-dim: #7f1d1d;
  --orange: #fb923c;
  --purple: #a78bfa;
  --sidebar-w: 280px;
  --radius: 8px;
  --radius-sm: 5px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 14px;
  overflow: hidden;
  height: 100vh;
}

#app {
  display: flex;
  height: 100vh;
}

/* === Sidebar === */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 12px;
  overflow-y: auto;
}

.sidebar-header h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--accent);
}
.sidebar-header .subtitle {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.sidebar-filters {
  display: flex;
  gap: 6px;
}
.sidebar-filters select {
  flex: 1;
  padding: 6px 8px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
}

.deal-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.deal-card {
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
}
.deal-card:hover {
  background: var(--bg-hover);
}
.deal-card.active {
  background: var(--bg-hover);
  border-color: var(--accent);
}
.deal-card-name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.deal-card-company {
  font-size: 11px;
  color: var(--text-muted);
}
.deal-card-meta {
  display: flex;
  gap: 6px;
  margin-top: 4px;
  align-items: center;
}
.deal-card-meta .badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 600;
  text-transform: uppercase;
}
.badge-early { background: var(--yellow-dim); color: var(--yellow); }
.badge-mid { background: rgba(108,140,255,0.15); color: var(--accent); }
.badge-late { background: var(--green-dim); color: var(--green); }
.badge-won { background: var(--green-dim); color: var(--green); }
.badge-lost { background: var(--red-dim); color: var(--red); }
.badge-active { background: rgba(108,140,255,0.15); color: var(--accent); }

.deal-card-score {
  display: flex;
  gap: 2px;
  margin-left: auto;
}
.deal-card-score .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--border);
}
.deal-card-score .dot.confirmed { background: var(--green); }
.deal-card-score .dot.in-progress { background: var(--yellow); }

/* === Sidebar Save === */
.sidebar-save {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.btn-save {
  background: var(--green);
  color: #0f1117;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 1px;
  padding: 10px 14px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}
.btn-save:hover {
  background: #6ee7a0;
  transform: scale(1.02);
}
.btn-save.pulse {
  animation: savePulse 0.4s ease;
}
@keyframes savePulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}
.save-status {
  font-size: 10px;
  color: var(--text-dim);
  text-align: center;
}
.save-status.recent {
  color: var(--green);
}
.btn-import {
  text-align: center;
  cursor: pointer;
  font-size: 12px;
}

/* === Main Content === */
#main-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px 28px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 60vh;
  color: var(--text-muted);
  text-align: center;
}
.empty-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.3; }
.empty-state h2 { font-size: 18px; margin-bottom: 8px; }

.hidden { display: none !important; }

/* === Deal Header === */
.deal-header {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.deal-header-left { flex: 1; min-width: 200px; }
.deal-name-input {
  font-size: 22px;
  font-weight: 700;
  background: none;
  border: none;
  color: var(--text);
  width: 100%;
  padding: 2px 0;
  border-bottom: 2px solid transparent;
}
.deal-name-input:focus { border-bottom-color: var(--accent); outline: none; }
.deal-company-input {
  font-size: 14px;
  color: var(--text-muted);
  background: none;
  border: none;
  width: 100%;
  padding: 2px 0;
  border-bottom: 1px solid transparent;
}
.deal-company-input:focus { border-bottom-color: var(--border); outline: none; }

.deal-header-right { display: flex; flex-direction: column; gap: 8px; }
.deal-header-fields {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.deal-header-fields label {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.deal-header-fields input,
.deal-header-fields select {
  padding: 5px 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: 13px;
  width: 110px;
}
.deal-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* === Buttons === */
.btn {
  padding: 7px 14px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-input); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg-hover); }
.btn-accent { background: var(--purple); color: #fff; }
.btn-accent:hover { opacity: 0.9; }
.btn-danger { background: transparent; color: var(--red); border: 1px solid var(--red-dim); }
.btn-danger:hover { background: var(--red-dim); }
.btn-block { width: 100%; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* === Stage Guidance === */
.stage-guidance {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 13px;
  line-height: 1.6;
}
.stage-guidance strong { color: var(--accent); }
.stage-guidance .stage-focus {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.stage-focus .focus-tag {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}
.focus-tag.critical { background: var(--red-dim); color: var(--red); }
.focus-tag.important { background: var(--yellow-dim); color: var(--yellow); }
.focus-tag.monitor { background: rgba(108,140,255,0.15); color: var(--accent); }

/* === Score Bar === */
.score-bar {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.score-item {
  flex: 1;
  min-width: 80px;
  padding: 8px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
}
.score-item:hover {
  border-color: var(--accent);
}
.score-item .score-letter {
  font-size: 15px;
  font-weight: 700;
}
.score-item .score-label {
  font-size: 9px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.score-item .score-status {
  font-size: 10px;
  margin-top: 2px;
  font-weight: 600;
}
.score-item.status-confirmed { border-color: var(--green); }
.score-item.status-confirmed .score-letter { color: var(--green); }
.score-item.status-in-progress { border-color: var(--yellow); }
.score-item.status-in-progress .score-letter { color: var(--yellow); }
.score-item.status-not-started .score-letter { color: var(--text-dim); }

/* === Tabs === */
.tab-nav {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.tab-btn {
  padding: 10px 18px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* === MEDDPICC Sections === */
.meddpicc-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
}
.meddpicc-section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}
.meddpicc-section-header:hover { background: var(--bg-hover); }
.meddpicc-section-header .section-letter {
  font-size: 18px;
  font-weight: 800;
  width: 28px;
  text-align: center;
}
.meddpicc-section-header .section-title {
  font-weight: 600;
  font-size: 14px;
  flex: 1;
}
.meddpicc-section-header .section-status-badge {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
}
.meddpicc-section-header .section-chevron {
  color: var(--text-muted);
  transition: transform 0.2s;
  font-size: 12px;
}
.meddpicc-section.open .section-chevron { transform: rotate(90deg); }

.meddpicc-section-body {
  display: none;
  padding: 0 16px 16px 16px;
}
.meddpicc-section.open .meddpicc-section-body { display: block; }

.section-description {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
  line-height: 1.5;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}

.meddpicc-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg);
}
.meddpicc-item-status {
  margin-top: 2px;
}
.meddpicc-item-status select {
  padding: 3px 4px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: 11px;
  width: 38px;
  cursor: pointer;
}
.meddpicc-item-body {
  flex: 1;
}
.meddpicc-item-label {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 3px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.meddpicc-item-label .help-icon {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--bg-input);
  color: var(--text-muted);
  font-size: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: help;
  position: relative;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.help-icon .tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: #2a2e3f;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 400;
  color: var(--text);
  width: 300px;
  z-index: 100;
  line-height: 1.5;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  white-space: normal;
}
.help-icon .tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #2a2e3f;
}
.help-icon:hover .tooltip { display: block; }

.meddpicc-item textarea {
  width: 100%;
  padding: 6px 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  min-height: 32px;
  line-height: 1.4;
}
.meddpicc-item textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.section-overall-status {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}
.section-overall-status label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
}
.section-overall-status select {
  padding: 4px 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: 12px;
}

/* === Contacts === */
.contacts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.contact-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.contact-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}
.contact-card-name { font-weight: 600; font-size: 14px; }
.contact-card-title { font-size: 12px; color: var(--text-muted); }
.contact-card-role {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  text-transform: uppercase;
}
.role-champion { background: var(--green-dim); color: var(--green); }
.role-economic_buyer { background: var(--yellow-dim); color: var(--yellow); }
.role-technical_buyer { background: rgba(167,139,250,0.15); color: var(--purple); }
.role-coach { background: rgba(108,140,255,0.15); color: var(--accent); }
.role-user { background: rgba(139,143,163,0.15); color: var(--text-muted); }
.role-procurement { background: rgba(251,146,60,0.15); color: var(--orange); }
.role-legal { background: rgba(251,146,60,0.15); color: var(--orange); }
.role-blocker { background: var(--red-dim); color: var(--red); }
.role-unknown { background: var(--bg-input); color: var(--text-dim); }

.contact-card-details {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
}
.contact-card-details .detail-label {
  color: var(--text-dim);
  font-size: 10px;
  text-transform: uppercase;
}
.contact-card-actions {
  margin-top: 10px;
  display: flex;
  gap: 6px;
}

/* === Timeline === */
.timeline {
  margin-top: 12px;
  position: relative;
  padding-left: 20px;
}
.timeline::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
}
.timeline-entry {
  position: relative;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.timeline-entry::before {
  content: '';
  position: absolute;
  left: -16px;
  top: 16px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
}
.timeline-entry.type-in-person::before { background: var(--green); }
.timeline-entry.type-call::before,
.timeline-entry.type-phone::before { background: var(--accent); }
.timeline-entry.type-email::before { background: var(--yellow); }
.timeline-entry.type-internal::before { background: var(--purple); }

.timeline-meta {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.timeline-date { font-size: 11px; color: var(--text-muted); }
.timeline-type-badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 600;
  text-transform: uppercase;
  background: var(--bg-input);
  color: var(--text-muted);
}
.timeline-summary { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.timeline-details { font-size: 12px; color: var(--text-muted); white-space: pre-wrap; }
.timeline-next-step {
  margin-top: 6px;
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
}
.timeline-elements {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.timeline-element-tag {
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 8px;
  background: rgba(108,140,255,0.1);
  color: var(--accent);
  font-weight: 600;
}
.timeline-actions {
  margin-top: 8px;
  display: flex;
  gap: 6px;
}

/* === Emails === */
.emails-list { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.email-entry {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.email-entry-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.email-subject { font-weight: 600; font-size: 13px; }
.email-date { font-size: 11px; color: var(--text-muted); }
.email-content {
  font-size: 12px;
  color: var(--text-muted);
  white-space: pre-wrap;
  max-height: 120px;
  overflow: hidden;
  transition: max-height 0.3s;
  line-height: 1.5;
}
.email-content.expanded { max-height: none; }
.email-takeaways {
  margin-top: 8px;
  padding: 8px 10px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-size: 12px;
}
.email-takeaways strong { color: var(--accent); font-size: 10px; text-transform: uppercase; }
.email-actions { margin-top: 8px; display: flex; gap: 6px; }

/* === Notes === */
.notes-area {
  width: 100%;
  min-height: 200px;
  padding: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  line-height: 1.6;
}
.notes-area:focus { outline: none; border-color: var(--accent); }
.closed-notes-section { margin-top: 20px; }
.closed-notes-section h3 { margin-bottom: 8px; }

/* === Modals === */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal-small { width: 400px; }
.modal-medium { width: 540px; }
.modal-large { width: 680px; }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 16px; }
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
}
.modal-body {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.modal-body label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.modal-body input,
.modal-body select,
.modal-body textarea {
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
}
.modal-body textarea { resize: vertical; min-height: 60px; }
.modal-body input:focus,
.modal-body select:focus,
.modal-body textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.modal-hint {
  font-size: 12px;
  color: var(--text-muted);
  padding: 6px 10px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}
.form-row {
  display: flex;
  gap: 10px;
}
.form-row > label { flex: 1; }

.checkbox-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 4px 0;
}
.checkbox-row label {
  flex-direction: row !important;
  align-items: center;
  gap: 4px !important;
  font-size: 12px;
}
.checkbox-row input[type="checkbox"] {
  width: auto;
}

/* === Print === */
@media print {
  body { background: #fff; color: #000; overflow: visible; }
  #app { display: none; }
  .print-only {
    display: block !important;
    padding: 20px;
    font-size: 12px;
    line-height: 1.6;
  }
  .print-only h1 { font-size: 22px; margin-bottom: 4px; }
  .print-only h2 { font-size: 16px; margin-top: 16px; margin-bottom: 6px; border-bottom: 1px solid #ccc; padding-bottom: 4px; }
  .print-only h3 { font-size: 13px; margin-top: 10px; margin-bottom: 4px; }
  .print-only .print-meta { color: #666; font-size: 11px; margin-bottom: 12px; }
  .print-only .print-section { margin-bottom: 12px; }
  .print-only .print-item { margin-left: 12px; margin-bottom: 4px; }
  .print-only .print-status { font-weight: bold; }
  .print-only .print-confirmed { color: #16653a; }
  .print-only .print-gap { color: #b91c1c; }
  .print-only .print-timeline-entry { margin-left: 12px; margin-bottom: 8px; padding-bottom: 8px; border-bottom: 1px solid #eee; }
}
.print-only { display: none; }

/* === Mobile === */
@media (max-width: 768px) {
  #app { flex-direction: column; }
  #sidebar {
    width: 100%;
    min-width: 100%;
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  #main-content { padding: 16px; }
  .deal-header { flex-direction: column; }
  .deal-header-fields { flex-wrap: wrap; }
  .score-bar { gap: 3px; }
  .score-item { min-width: 60px; padding: 6px; }
  .form-row { flex-direction: column; }
  .contacts-grid { grid-template-columns: 1fr; }
  .modal-content { width: 100% !important; max-width: 100%; margin: 10px; }
  .help-icon .tooltip { width: 220px; left: auto; right: -10px; transform: none; }
}
