/* IkniteOS Dashboard Styles */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --ink: #0a0a0a;
  --paper: #f8f6f1;
  --accent: #e84e1b;
  --accent-hover: #d4441a;
  --accent-light: #fef0eb;
  --white: #ffffff;
  --gray-50: #fafaf8;
  --gray-100: #f3f1ec;
  --gray-200: #e8e5de;
  --gray-300: #d4d0c8;
  --gray-400: #9c9788;
  --gray-500: #7d7870;
  --gray-600: #6b6660;
  --gray-700: #4d4944;
  --gray-800: #3d3a36;

  --stage-inquiry: #6366f1;
  --stage-proposal: #8b5cf6;
  --stage-negotiation: #f59e0b;
  --stage-signed: #10b981;
  --stage-active: #3b82f6;
  --stage-completed: #6b7280;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
}

body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--paper);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* Layout */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  background: var(--ink);
  color: var(--paper);
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}

.sidebar-logo {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 2rem;
  padding: 0 0.5rem;
  letter-spacing: -0.02em;
}

.sidebar-logo span { color: var(--accent); }

.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 0.25rem; }

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius-md);
  color: var(--gray-400);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.15s;
  cursor: pointer;
}

.sidebar-link:hover { color: var(--paper); background: rgba(255,255,255,0.08); }
.sidebar-link.active { color: var(--paper); background: rgba(255,255,255,0.12); }
.sidebar-link .icon { font-size: 1.1rem; width: 20px; text-align: center; }

.main-content {
  flex: 1;
  margin-left: 240px;
  padding: 1.5rem 2rem;
  min-height: 100vh;
}

/* Top Bar */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.top-bar h1 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.top-bar-actions { display: flex; gap: 0.75rem; align-items: center; }

/* Stats Bar */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
}

.stat-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-500);
  margin-bottom: 0.35rem;
}

.stat-value {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.stat-value.accent { color: var(--accent); }

/* Controls */
.controls-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.controls-left { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.controls-right { display: flex; gap: 0.5rem; align-items: center; }

.search-input {
  padding: 0.55rem 1rem;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  background: var(--white);
  font-family: inherit;
  font-size: 0.9rem;
  width: 260px;
  outline: none;
  transition: border-color 0.15s;
}

.search-input:focus { border-color: var(--accent); }

.filter-select {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  background: var(--white);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  cursor: pointer;
}

.view-toggle {
  display: flex;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.view-btn {
  padding: 0.55rem 1rem;
  border: none;
  background: var(--white);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--gray-500);
  transition: all 0.15s;
}

.view-btn.active { background: var(--ink); color: var(--paper); }
.view-btn:hover:not(.active) { background: var(--gray-100); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }

.btn-secondary {
  background: var(--white);
  color: var(--ink);
  border: 1px solid var(--gray-200);
}

.btn-secondary:hover { border-color: var(--gray-300); background: var(--gray-50); }

.btn-ghost {
  background: transparent;
  color: var(--gray-600);
  padding: 0.4rem 0.6rem;
}

.btn-ghost:hover { color: var(--ink); background: var(--gray-100); }

.btn-danger {
  background: transparent;
  color: #dc2626;
  border: 1px solid #fecaca;
}

.btn-danger:hover { background: #fef2f2; }

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }

/* Table View */
.table-wrapper {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.leads-table {
  width: 100%;
  border-collapse: collapse;
}

.leads-table th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-500);
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.leads-table th:hover { color: var(--ink); }
.leads-table th .sort-arrow { margin-left: 0.25rem; font-size: 0.7rem; }

.leads-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--gray-100);
  font-size: 0.9rem;
  vertical-align: middle;
}

.leads-table tr { cursor: pointer; transition: background 0.1s; }
.leads-table tbody tr:hover { background: var(--gray-50); }

.lead-company {
  font-weight: 600;
  color: var(--ink);
}

.lead-contact {
  color: var(--gray-600);
  font-size: 0.85rem;
}

.lead-value {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
}

/* Stage Badges */
.stage-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border-radius: 100px;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: capitalize;
  white-space: nowrap;
}

.stage-badge .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.stage-badge.inquiry { background: #eef2ff; color: #4338ca; }
.stage-badge.inquiry .dot { background: var(--stage-inquiry); }
.stage-badge.proposal { background: #f5f3ff; color: #6d28d9; }
.stage-badge.proposal .dot { background: var(--stage-proposal); }
.stage-badge.negotiation { background: #fffbeb; color: #b45309; }
.stage-badge.negotiation .dot { background: var(--stage-negotiation); }
.stage-badge.signed { background: #ecfdf5; color: #047857; }
.stage-badge.signed .dot { background: var(--stage-signed); }
.stage-badge.active { background: #eff6ff; color: #1d4ed8; }
.stage-badge.active .dot { background: var(--stage-active); }
.stage-badge.completed { background: #f3f4f6; color: #374151; }
.stage-badge.completed .dot { background: var(--stage-completed); }

/* Kanban View */
.kanban-board {
  display: flex;
  gap: 0.75rem;
  overflow-x: auto;
  padding-bottom: 1rem;
  min-height: 500px;
}

.kanban-column {
  flex: 1;
  min-width: 230px;
  max-width: 300px;
  background: var(--gray-100);
  border-radius: var(--radius-lg);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
}

.kanban-column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.5rem 0.75rem;
}

.kanban-column-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kanban-count {
  background: var(--gray-200);
  color: var(--gray-600);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 100px;
}

.kanban-cards {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 60px;
  padding: 0.25rem 0;
}

.kanban-cards.drag-over {
  background: var(--accent-light);
  border-radius: var(--radius-md);
}

.kanban-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  cursor: grab;
  transition: all 0.15s;
}

.kanban-card:hover { border-color: var(--accent); box-shadow: var(--shadow-sm); }
.kanban-card.dragging { opacity: 0.5; transform: rotate(2deg); }

.kanban-card-company {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.25rem;
}

.kanban-card-contact {
  font-size: 0.8rem;
  color: var(--gray-500);
  margin-bottom: 0.5rem;
}

.kanban-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.kanban-card-value {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--accent);
}

.kanban-card-type {
  font-size: 0.72rem;
  color: var(--gray-400);
  background: var(--gray-100);
  padding: 0.15rem 0.5rem;
  border-radius: 100px;
}

/* Detail Sidebar */
.detail-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.3);
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s;
}

.detail-overlay.open { opacity: 1; visibility: visible; }

.detail-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 480px;
  max-width: 100vw;
  background: var(--white);
  z-index: 201;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.detail-sidebar.open { transform: translateX(0); }

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--gray-200);
}

.detail-header h2 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.25rem;
  font-weight: 700;
}

.detail-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--gray-400);
  padding: 0.25rem;
  line-height: 1;
}

.detail-close:hover { color: var(--ink); }

.detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}

.detail-section {
  margin-bottom: 1.5rem;
}

.detail-section h3 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--gray-500);
  margin-bottom: 0.75rem;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--gray-100);
}

.detail-row:last-child { border-bottom: none; }

.detail-label { color: var(--gray-500); font-size: 0.88rem; }
.detail-value { font-weight: 500; font-size: 0.88rem; }

.detail-notes {
  background: var(--gray-50);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--gray-700);
  white-space: pre-wrap;
}

.detail-actions {
  display: flex;
  gap: 0.5rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--gray-200);
}

/* Activity Timeline */
.activity-timeline { display: flex; flex-direction: column; gap: 0.75rem; }

.activity-item {
  display: flex;
  gap: 0.75rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--gray-100);
}

.activity-item:last-child { border-bottom: none; }

.activity-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: 0.45rem;
  flex-shrink: 0;
}

.activity-dot.stage_change { background: var(--stage-signed); }
.activity-dot.note { background: var(--stage-inquiry); }
.activity-dot.call { background: var(--stage-active); }
.activity-dot.email { background: var(--stage-proposal); }
.activity-dot.meeting { background: var(--stage-negotiation); }
.activity-dot.created { background: var(--gray-400); }
.activity-dot.archived { background: #dc2626; }

.activity-content { flex: 1; }
.activity-desc { font-size: 0.88rem; }

.activity-meta {
  font-size: 0.78rem;
  color: var(--gray-400);
  margin-top: 0.2rem;
}

/* Add Activity Form */
.add-activity-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.add-activity-row { display: flex; gap: 0.5rem; }

.add-activity-form select,
.add-activity-form textarea {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
}

.add-activity-form textarea {
  resize: vertical;
  min-height: 60px;
}

.add-activity-form select:focus,
.add-activity-form textarea:focus { border-color: var(--accent); }

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s;
}

.modal-overlay.open { opacity: 1; visibility: visible; }

.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  width: 520px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px);
  transition: transform 0.2s;
}

.modal-overlay.open .modal { transform: translateY(0); }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--gray-200);
}

.modal-header h2 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
}

.modal-body { padding: 1.5rem; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--gray-200);
}

/* Form */
.form-group { margin-bottom: 1rem; }

.form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 0.35rem;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
  background: var(--white);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--accent); }

.form-group textarea { resize: vertical; min-height: 80px; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--gray-500);
}

.empty-state .icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-state h3 { font-family: 'Space Grotesk', sans-serif; font-size: 1.15rem; margin-bottom: 0.5rem; color: var(--ink); }
.empty-state p { margin-bottom: 1.5rem; }

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: var(--ink);
  color: var(--paper);
  padding: 0.85rem 1.5rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 400;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s;
}

.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { background: #dc2626; }
.toast.success { background: #059669; }

/* Responsive */
@media (max-width: 1024px) {
  .sidebar { display: none; }
  .main-content { margin-left: 0; }
  .kanban-column { min-width: 200px; }
}

@media (max-width: 768px) {
  .main-content { padding: 1rem; }
  .top-bar { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
  .stats-bar { grid-template-columns: repeat(2, 1fr); }
  .controls-bar { flex-direction: column; align-items: stretch; }
  .controls-left, .controls-right { width: 100%; }
  .search-input { width: 100%; }
  .detail-sidebar { width: 100%; }
  .form-row { grid-template-columns: 1fr; }
  .kanban-board { flex-direction: column; }
  .kanban-column { max-width: 100%; }
}

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--gray-200);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

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

/* Mobile sidebar toggle */
.mobile-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  background: var(--ink);
  color: var(--paper);
}

.mobile-header .logo {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 1.2rem;
}

.mobile-header .logo span { color: var(--accent); }

@media (max-width: 1024px) {
  .mobile-header { display: flex; }
}
