/* TradeMail PWA Dashboard - Full Screen Workbench */
:root {
  --bg: #f5f7fa;
  --surface: #fff;
  --border: #e8ecf1;
  --text: #1a1a2e;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --primary: #667eea;
  --primary-light: #eef0ff;
  --success: #52c41a;
  --warning: #fa8c16;
  --danger: #ff4d4f;
  --info: #1890ff;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.06);
  --shadow-hover: 0 4px 12px rgba(0,0,0,.08);
  --sidebar-w: 300px;
  --detail-w: 380px;
}

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

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

/* ── Header ── */
.app-header {
  height: 48px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-shrink: 0;
}
.app-header .logo {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.5px;
}
.app-header .spacer { flex: 1; }
.app-header .status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success);
  margin-right: 4px;
}
.app-header .status-text { font-size: 11px; color: var(--text-secondary); }
.app-header .btn {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  font-size: 11px;
  cursor: pointer;
  color: var(--text-secondary);
}
.app-header .btn:hover { background: var(--bg); }
.app-header .btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.app-header .btn-primary:hover { opacity: .9; }

/* ── Dashboard Layout ── */
.dashboard {
  display: flex;
  height: calc(100% - 48px);
  overflow: hidden;
}

/* ── Sidebar Columns ── */
.column {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
}
.column-right { border-right: none; border-left: 1px solid var(--border); }
.column-left { width: var(--sidebar-w); min-width: 260px; }
.column-right { width: var(--detail-w); min-width: 320px; }
.column-main { flex: 1; min-width: 0; border-right: none; background: var(--bg); padding: 16px; overflow-y: auto; }

/* ── Column Header ── */
.col-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 8px;
}
.col-header h3 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}
.col-header .count {
  font-size: 10px;
  color: var(--text-muted);
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 10px;
}

/* ── Search ── */
.search-box {
  padding: 8px 12px;
  flex-shrink: 0;
}
.search-box input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  outline: none;
}
.search-box input:focus { border-color: var(--primary); }

/* ── Sort ── */
.sort-row {
  display: flex;
  gap: 4px;
  padding: 0 12px 8px;
  flex-shrink: 0;
}
.sort-btn {
  flex: 1;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  font-size: 10px;
  cursor: pointer;
  color: var(--text-secondary);
  text-align: center;
}
.sort-btn.active { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }

/* ── Scroll Area ── */
.scroll-area {
  flex: 1;
  overflow-y: auto;
  padding: 0 6px 8px;
}

/* ── Customer Card ── */
.customer-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .15s;
  margin: 2px 0;
}
.customer-card:hover { background: var(--bg); }
.customer-card.selected { background: var(--primary-light); border-left: 3px solid var(--primary); padding-left: 7px; }
.customer-card .avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: bold; color: #fff; flex-shrink: 0;
}
.customer-card .info { flex: 1; min-width: 0; }
.customer-card .name {
  font-size: 12px; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.customer-card .email { font-size: 10px; color: var(--text-muted); }
.customer-card .meta {
  display: flex; gap: 4px; font-size: 10px; color: var(--text-secondary);
  margin-top: 2px;
}
.customer-card .meta span { font-size: 10px; }
.customer-card .stars { font-size: 10px; flex-shrink: 0; }

/* ── Tags ── */
.tags { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 3px; }
.tag {
  display: inline-block;
  padding: 1px 5px; border-radius: 8px; font-size: 9px;
  background: var(--bg); color: var(--text-secondary);
}
.tag.active-tag { background: #f6ffed; color: #52c41a; }
.tag.hot-tag { background: #fff7e6; color: #fa8c16; }
.tag.new-tag { background: #e6f7ff; color: #1890ff; }
.tag.cold-tag { background: #f0f0f0; color: #999; }

/* ── Pipeline ── */
.pipeline-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.pipeline-stage {
  flex: 1 1 0;
  min-width: 80px;
  text-align: center;
  padding: 14px 6px;
  border-radius: var(--radius);
  background: #f0f0f0;
  color: var(--text-muted);
  transition: transform .15s;
}
.pipeline-stage.has-count { color: #fff; }
.pipeline-stage .stage-num { font-size: 24px; font-weight: 700; }
.pipeline-stage .stage-name { font-size: 11px; margin-top: 4px; }
.pipeline-arrow { display: flex; align-items: center; color: #ccc; flex-shrink: 0; font-size: 14px; }

/* ── Panel Card ── */
.panel {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 16px;
  margin-bottom: 16px;
}
.panel h4 {
  font-size: 13px; font-weight: 600;
  margin-bottom: 12px;
  color: var(--text);
}

/* ── Todo Items ── */
.todo-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px; background: #f8f9fa;
  border-radius: 6px; margin-bottom: 6px;
}
.todo-bullet {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--primary); margin-top: 2px; flex-shrink: 0;
}
.todo-bullet.urgent { border-color: var(--danger); }
.todo-body { flex: 1; min-width: 0; }
.todo-text { font-size: 12px; color: var(--text); line-height: 1.5; }
.todo-meta { font-size: 10px; color: var(--text-muted); margin-top: 2px; }
.todo-meta .urgent-label { color: var(--danger); font-weight: 600; }

/* ── Detail Panel ── */
.customer-detail { padding: 12px; }
.detail-header {
  display: flex; align-items: center; gap: 12px;
  padding-bottom: 12px; border-bottom: 1px solid var(--border);
}
.detail-header .avatar { width: 40px; height: 40px; font-size: 18px; }
.detail-header h3 { font-size: 15px; color: var(--text); }
.detail-header .email { font-size: 11px; color: var(--text-muted); }
.detail-stats {
  display: flex; gap: 8px; padding: 12px 0;
}
.stat-box {
  flex: 1; text-align: center;
  padding: 8px; background: var(--bg);
  border-radius: 6px;
}
.stat-box .val { font-size: 16px; font-weight: 700; color: var(--primary); }
.stat-box .lbl { font-size: 10px; color: var(--text-muted); margin-top: 2px; }

/* ── Email Timeline ── */
.email-row {
  padding: 8px 10px;
  border-left: 2px solid var(--border);
  margin-left: 8px;
  font-size: 11px;
  cursor: pointer;
}
.email-row:hover { border-left-color: var(--primary); background: var(--bg); }
.email-row .subj { font-weight: 600; color: var(--text); margin-bottom: 2px; }
.email-row .meta-row { color: var(--text-muted); font-size: 10px; }

/* ── Settings ── */
.settings-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.3);
  z-index: 100;
  align-items: center; justify-content: center;
}
.settings-overlay.show { display: flex; }
.settings-panel {
  background: var(--surface);
  border-radius: 12px;
  padding: 24px;
  width: 440px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 40px rgba(0,0,0,.15);
}
.settings-panel h3 { margin-bottom: 16px; font-size: 16px; }
.settings-panel label {
  display: block; font-size: 11px; color: var(--text-secondary);
  margin-bottom: 4px; margin-top: 12px;
}
.settings-panel input, .settings-panel select {
  width: 100%; padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px; font-size: 13px;
}
.settings-panel .btn-row {
  display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px;
}

/* ── Empty States ── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 12px;
}
.empty-state .icon { font-size: 36px; margin-bottom: 8px; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  padding: 8px 20px; border-radius: 20px;
  background: #1a1a2e; color: #fff; font-size: 12px;
  z-index: 200; opacity: 0; transition: opacity .2s;
  pointer-events: none;
}
.toast.show { opacity: 1; }

/* ── Tab Navigation ── */
.tab-nav { display: flex; gap: 4px; padding: 0 8px; }
.tab-btn { padding: 6px 16px; border: none; border-radius: 6px; background: transparent; color: var(--text-secondary); font-size: 13px; cursor: pointer; transition: all .2s; }
.tab-btn:hover { background: rgba(102,126,234,.1); color: var(--primary); }
.tab-btn.active { background: var(--primary); color: #fff; }

/* ── Tab Content ── */
.tab-content { display: none; }
.tab-content.active { display: flex; gap: 16px; flex: 1; overflow: hidden; }

/* ── Data Table ── */
.data-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.data-table th { text-align: left; padding: 8px 10px; background: #f5f7fa; border-bottom: 2px solid var(--border); color: var(--text-secondary); font-weight: 600; position: sticky; top: 0; z-index: 1; }
.data-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); color: var(--text); }
.data-table tr:hover td { background: rgba(102,126,234,.04); }
.table-wrap { overflow-y: auto; max-height: calc(100vh - 180px); border: 1px solid var(--border); border-radius: 8px; }

/* ── Modal ── */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 300; align-items: center; justify-content: center; }
.modal-overlay.show { display: flex; }
.modal-panel { background: var(--surface); border-radius: 12px; width: 520px; max-height: 85vh; overflow: hidden; box-shadow: 0 8px 40px rgba(0,0,0,.15); display: flex; flex-direction: column; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 16px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.modal-body label { font-size: 11px; color: var(--text-secondary); font-weight: 600; }
.modal-body input, .modal-body select, .modal-body textarea { padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; font-family: inherit; }
.modal-body textarea { resize: vertical; min-height: 60px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); }

/* ── Badges ── */
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 10px; font-weight: 600; }
.badge-buyer { background: #e6f7ff; color: #1890ff; }
.badge-supplier { background: #fff7e6; color: #fa8c16; }
.badge-high { background: #f6ffed; color: #52c41a; }
.badge-medium { background: #fffbe6; color: #faad14; }
.badge-low { background: #f0f0f0; color: #999; }

/* ── Tag Row ── */
.tag-row { display: flex; flex-wrap: wrap; gap: 4px; }
.tag-item { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 10px; font-weight: 500; }

/* ── Panel Toolbar ── */
.panel-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.panel-toolbar h4 { margin: 0; }

/* ── Additional Tag Colors ── */
.tag.problem { background: #fff1f0; color: #ff4d4f; }
.tag.vip { background: #fff0f6; color: #eb2f96; }
.tag.loyal { background: #f6ffed; color: #52c41a; }

/* ── Follow-up Area ── */
.followup-area {
  padding: 0 12px 4px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.followup-area.collapsed .followup-list,
.followup-area.collapsed .followup-toggle { display: none; }
.followup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  color: var(--warning);
}
.followup-toggle { font-size: 9px; color: var(--text-muted); }
.followup-list { max-height: 160px; overflow-y: auto; }
.followup-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  margin: 2px 0;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  border-left: 3px solid var(--warning);
  background: #fffbe6;
}
.followup-item:hover { background: #fff7cc; }
.followup-item.overdue {
  border-left-color: var(--danger);
  background: #fff1f0;
}
.followup-item .fw-name { font-weight: 600; color: var(--text); flex: 1; }
.followup-item .fw-days { font-size: 10px; color: var(--text-muted); white-space: nowrap; }
.followup-item .fw-desc { font-size: 10px; color: var(--text-secondary); }

/* ── Customer Card Overdue ── */
.customer-card.overdue {
  border-left: 3px solid var(--warning);
  background: #fffbe6;
}
.customer-card.overdue.selected {
  border-left: 3px solid var(--primary);
  background: var(--primary-light);
}

/* ── Editable Fields ── */
.editable-field {
  margin-bottom: 8px;
}
.editable-field label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 3px;
}
.editable-field input,
.editable-field textarea {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 11px;
  font-family: inherit;
  outline: none;
}
.editable-field input:focus,
.editable-field textarea:focus { border-color: var(--primary); }
.editable-field textarea { resize: vertical; min-height: 50px; }

/* ── Review Panel ── */
.review-panel { }
.review-panel .review-header {
  cursor: pointer;
  user-select: none;
}
.review-panel.collapsed .review-body { display: none; }
.review-body { font-size: 11px; color: var(--text-secondary); line-height: 1.8; }
.review-body .review-stat {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
}
.review-body .review-stat .rv-label { color: var(--text-muted); }
.review-body .review-stat .rv-val { font-weight: 600; color: var(--text); }
.review-body .review-stage-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.review-body .review-stage-tag {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  background: var(--bg);
  color: var(--text-secondary);
}

/* ── Responsive ── */
@media (max-width: 900px) {
  .column-left, .column-right { width: 100%; min-width: 0; }
  .dashboard { flex-direction: column; }
}

/* ═══════════════════════════════════════════════
   P0-2: Pipeline Kanban Board
   ═══════════════════════════════════════════════ */
.kanban-board {
  display: flex;
  gap: 12px;
  height: 100%;
  padding: 16px;
  overflow-x: auto;
  background: var(--bg);
  border-radius: var(--radius);
}
.kanban-column {
  flex: 1 1 0;
  min-width: 160px;
  max-width: 240px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.kanban-column-header {
  padding: 12px 14px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  text-align: center;
  letter-spacing: 0.3px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.kanban-column-header .col-count {
  background: rgba(255,255,255,0.3);
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11px;
}
.kanban-column-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 200px;
}
.kanban-column-body.drag-over {
  background: rgba(102,126,234,0.05);
  outline: 2px dashed var(--primary);
  outline-offset: -4px;
  border-radius: 4px;
}
.kanban-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  cursor: grab;
  transition: box-shadow .15s, transform .15s;
  user-select: none;
}
.kanban-card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-1px);
}
.kanban-card:active { cursor: grabbing; }
.kanban-card.dragging {
  opacity: 0.5;
  transform: rotate(2deg);
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
.kanban-card .kc-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.kanban-card .kc-contact {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.kanban-card .kc-meta {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 6px;
}
.kanban-card .kc-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
}

/* ═══════════════════════════════════════════════
   P0-3: Timeline View
   ═══════════════════════════════════════════════ */
.timeline {
  position: relative;
  padding: 8px 0 8px 24px;
}
.timeline::before {
  content: '';
  position: absolute;
  left: 10px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--border);
}
.timeline-item {
  position: relative;
  padding: 8px 12px;
  margin-bottom: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 11px;
  line-height: 1.5;
}
.timeline-item::before {
  content: '';
  position: absolute;
  left: -18px;
  top: 12px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
}
.timeline-item.type-email::before { border-color: var(--info); background: var(--info); }
.timeline-item.type-stage::before { border-color: var(--warning); background: var(--warning); }
.timeline-item.type-note::before { border-color: var(--success); background: var(--success); }
.timeline-item.type-task::before { border-color: var(--danger); background: var(--danger); }
.timeline-item.type-followup::before { border-color: var(--primary); background: var(--primary); }
.timeline-item .tl-time {
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 3px;
}
.timeline-item .tl-title {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}
.timeline-item .tl-detail {
  color: var(--text-secondary);
}
.timeline-item .tl-badge {
  display: inline-block;
  padding: 0px 5px;
  border-radius: 6px;
  font-size: 9px;
  margin-right: 4px;
  font-weight: 600;
}

/* ═══════════════════════════════════════════════
   P0-2 Addendum: Company / Contact Views
   ═══════════════════════════════════════════════ */
.company-contact-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  transition: background .15s;
}
.company-contact-row:hover { background: var(--bg); }
/* Stage badge for kanban column headers */
.stage-col-new { background: #e6f7ff; }
.stage-col-negotiating { background: #fff7e6; }
.stage-col-closed { background: #f6ffed; }
/* Drafts Tab */
.draft-card {
  background: var(--bg-card, #fff);
  border: 1px solid var(--border, #e5e7eb);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
}
.draft-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.draft-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 8px;
}
.draft-recipient { font-weight: 600; color: var(--text-primary, #1f2937); }
.draft-subject { font-size: 14px; color: var(--text-secondary, #6b7280); margin-bottom: 8px; }
.draft-body-preview {
  font-size: 13px; color: var(--text-primary, #374151); line-height: 1.5;
  max-height: 120px; overflow: hidden; position: relative;
  margin-bottom: 12px; white-space: pre-wrap;
}
.draft-body-preview::after {
  content: ''; position: absolute; bottom: 0; left: 0; right: 0;
  height: 40px; background: linear-gradient(transparent, var(--bg-card, #fff));
}
.draft-meta { font-size: 12px; color: var(--text-muted, #9ca3af); margin-bottom: 12px; }
.draft-actions { display: flex; gap: 8px; }
.draft-actions .btn-approve {
  background: #52c41a; color: #fff; border: none; padding: 6px 16px;
  border-radius: 4px; cursor: pointer; font-size: 13px;
}
.draft-actions .btn-approve:hover { background: #45a718; }
.draft-actions .btn-reject {
  background: #fff; color: #ff4d4f; border: 1px solid #ff4d4f;
  padding: 6px 16px; border-radius: 4px; cursor: pointer; font-size: 13px;
}
.draft-actions .btn-reject:hover { background: #fff1f0; }
.draft-empty {
  text-align: center; padding: 48px 20px; color: var(--text-muted, #9ca3af);
  font-size: 14px;
}

/* Inbox Review Section */
.inbox-review-bar {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  background: var(--bg-secondary, #f9fafb); border-bottom: 1px solid var(--border, #e5e7eb);
  margin-bottom: 16px;
}
.inbox-review-bar .btn-review {
  background: #1890ff; color: #fff; border: none; padding: 8px 20px;
  border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 500;
}
.inbox-review-bar .btn-review:hover { background: #1677cc; }
.inbox-review-bar .btn-review:disabled { opacity: 0.6; cursor: not-allowed; }
.inbox-review-status { font-size: 13px; color: var(--text-secondary, #6b7280); }
