/* ───────────── Design Tokens ───────────── */
:root {
  --bg-base: #080c14;
  --bg-surface: #0e1525;
  --bg-card: rgba(255, 255, 255, 0.04);
  --bg-card-hover: rgba(255, 255, 255, 0.07);
  --bg-glass: rgba(14, 21, 37, 0.75);
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.13);

  --accent-1: #6366f1;
  /* indigo */
  --accent-2: #8b5cf6;
  /* violet */
  --accent-glow: rgba(99, 102, 241, 0.35);

  --text-primary: #f0f2f8;
  --text-secondary: #8892a4;
  --text-muted: #4e5870;

  /* Status colours */
  --s-new: #3b82f6;
  --s-new-bg: rgba(59, 130, 246, 0.15);
  --s-contacted: #f59e0b;
  --s-contacted-bg: rgba(245, 158, 11, 0.15);
  --s-qualified: #14b8a6;
  --s-qualified-bg: rgba(20, 184, 166, 0.15);
  --s-closed: #22c55e;
  --s-closed-bg: rgba(34, 197, 94, 0.15);
  --s-lost: #ef4444;
  --s-lost-bg: rgba(239, 68, 68, 0.15);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --shadow-glow: 0 0 40px rgba(99, 102, 241, 0.12);

  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

/* Ensure HTML hidden attribute always wins over CSS display rules */
[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background-color: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(99, 102, 241, 0.18) 0%, transparent 60%),
    radial-gradient(ellipse 50% 30% at 90% 110%, rgba(139, 92, 246, 0.10) 0%, transparent 55%);
}

/* ───────────── Scrollbar ───────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 99px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent-1);
}

/* ───────────── Header ───────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 28px;
  height: 68px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.brand-icon {
  font-size: 22px;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 8px var(--accent-glow));
}

.brand-name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
  background: linear-gradient(120deg, #e0e7ff 30%, var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  flex-wrap: wrap;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 99px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  font-size: 12px;
  white-space: nowrap;
  transition: border-color var(--transition);
}

.stat-pill .stat-label {
  color: var(--text-secondary);
}

.stat-pill .stat-value {
  font-weight: 600;
  color: var(--text-primary);
  min-width: 16px;
  text-align: center;
}

.stat-pill.status-new {
  border-color: rgba(59, 130, 246, 0.3);
}

.stat-pill.status-contacted {
  border-color: rgba(245, 158, 11, 0.3);
}

.stat-pill.status-qualified {
  border-color: rgba(20, 184, 166, 0.3);
}

.stat-pill.status-closed {
  border-color: rgba(34, 197, 94, 0.3);
}

.stat-pill.status-lost {
  border-color: rgba(239, 68, 68, 0.3);
}

/* ───────────── Add Contact Button ───────────── */
.btn-add-contact {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(99, 102, 241, 0.5);
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 0 18px var(--accent-glow), 0 2px 8px rgba(0, 0, 0, 0.4);
  transition: all var(--transition);
}

.btn-add-contact:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 28px var(--accent-glow), 0 4px 16px rgba(0, 0, 0, 0.4);
}

.btn-add-contact:active {
  transform: translateY(0);
}

.btn-icon {
  font-size: 18px;
  line-height: 1;
}

/* ───────────── Main Layout ───────────── */
.app-main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 32px 28px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  transition: grid-template-columns var(--transition);
}

.app-main.panel-open {
  grid-template-columns: 1fr 380px;
}

/* ───────────── Table Section ───────────── */
.table-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow-glow), 0 4px 32px rgba(0, 0, 0, 0.3);
  transition: box-shadow var(--transition);
}

.table-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  gap: 16px;
  flex-wrap: wrap;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.2px;
}

.search-wrap {
  position: relative;
}

.search-input {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  padding: 8px 14px 8px 34px;
  width: 220px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238892a4' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 10px center;
}

.search-input:focus {
  border-color: var(--accent-1);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-input::placeholder {
  color: var(--text-muted);
}

/* ───────────── Table ───────────── */
.table-wrapper {
  overflow-x: auto;
}

.contacts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.contacts-table thead th {
  padding: 12px 20px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.contacts-table tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}

.contacts-table tbody tr:last-child {
  border-bottom: none;
}

.contacts-table tbody tr:hover {
  background: var(--bg-card-hover);
}

.contacts-table tbody tr.row-selected {
  background: rgba(99, 102, 241, 0.1);
}

.contacts-table td {
  padding: 14px 20px;
  vertical-align: middle;
  color: var(--text-primary);
}

.contact-name {
  font-weight: 600;
  font-size: 14px;
}

.contact-email {
  color: var(--text-secondary);
  font-size: 13px;
}

/* ───────────── Status Badges ───────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.badge-new {
  color: var(--s-new);
  background: var(--s-new-bg);
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.badge-new::before {
  background: var(--s-new);
  box-shadow: 0 0 5px var(--s-new);
  animation: pulse 2s infinite;
}

.badge-contacted {
  color: var(--s-contacted);
  background: var(--s-contacted-bg);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-contacted::before {
  background: var(--s-contacted);
}

.badge-qualified {
  color: var(--s-qualified);
  background: var(--s-qualified-bg);
  border: 1px solid rgba(20, 184, 166, 0.3);
}

.badge-qualified::before {
  background: var(--s-qualified);
}

.badge-closed {
  color: var(--s-closed);
  background: var(--s-closed-bg);
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.badge-closed::before {
  background: var(--s-closed);
}

.badge-lost {
  color: var(--s-lost);
  background: var(--s-lost-bg);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.badge-lost::before {
  background: var(--s-lost);
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.4;
  }
}

/* ───────────── Follow-up date ───────────── */
.follow-up-date {
  font-size: 13px;
  color: var(--text-secondary);
}

.follow-up-date.overdue {
  color: var(--s-lost);
  font-weight: 600;
}

.follow-up-date.today {
  color: var(--s-contacted);
  font-weight: 600;
}

.follow-up-date.soon {
  color: var(--s-qualified);
}

/* ───────────── Notes count ───────────── */
.notes-count {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--text-secondary);
}

.notes-count .note-dot {
  font-size: 16px;
  opacity: 0.7;
}

/* ───────────── Action buttons ───────────── */
.action-buttons {
  display: flex;
  gap: 6px;
  align-items: center;
}

.btn-action {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12px;
  font-family: inherit;
  font-weight: 500;
  padding: 5px 10px;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-action:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
  background: var(--bg-card-hover);
}

.btn-action.btn-danger:hover {
  border-color: rgba(239, 68, 68, 0.5);
  color: var(--s-lost);
  background: rgba(239, 68, 68, 0.08);
}

/* ───────────── Empty state ───────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 64px 24px;
  color: var(--text-secondary);
  text-align: center;
}

.empty-icon {
  font-size: 40px;
}

/* ───────────── Notes Panel ───────────── */
.notes-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-glow), 0 4px 32px rgba(0, 0, 0, 0.3);
  max-height: calc(100vh - 120px);
  position: sticky;
  top: 88px;
}

.notes-panel[hidden] {
  display: none !important;
}

.notes-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.notes-panel-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.notes-panel-name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.btn-close-panel {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 14px;
  padding: 4px 8px;
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}

.btn-close-panel:hover {
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.notes-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.notes-list .empty-notes {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin: auto;
}

.note-item {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  animation: note-in 0.25s ease;
}

@keyframes note-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.note-timestamp {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 5px;
  font-weight: 500;
}

.note-text {
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.55;
}

.notes-add-form {
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.note-textarea {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  padding: 10px 12px;
  resize: vertical;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.note-textarea:focus {
  border-color: var(--accent-1);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.note-textarea::placeholder {
  color: var(--text-muted);
}

.btn-add-note {
  background: rgba(99, 102, 241, 0.15);
  border: 1px solid rgba(99, 102, 241, 0.4);
  border-radius: var(--radius-md);
  color: #a5b4fc;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 8px;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-add-note:hover {
  background: rgba(99, 102, 241, 0.25);
  border-color: rgba(99, 102, 241, 0.6);
  color: #c7d2fe;
}

/* ───────────── Modal ───────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(4, 6, 14, 0.75);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: overlay-in 0.2s ease;
}

.modal-overlay[hidden] {
  display: none !important;
}

@keyframes overlay-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.modal {
  background: #111827;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  padding: 28px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6), var(--shadow-glow);
  animation: modal-in 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(10px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.btn-close-modal {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 14px;
  padding: 4px 9px;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-close-modal:hover {
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.4px;
  text-transform: uppercase;
  margin-bottom: 2px;
  display: block;
}

.required {
  color: var(--s-lost);
}

.form-input {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  padding: 10px 14px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-input:focus {
  border-color: var(--accent-1);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-input::placeholder {
  color: var(--text-muted);
}

.form-error {
  font-size: 13px;
  color: var(--s-lost);
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}

.form-error[hidden] {
  display: none !important;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 6px;
}

.btn-cancel {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 9px 18px;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-cancel:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.btn-submit {
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  border: none;
  border-radius: var(--radius-md);
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 9px 22px;
  cursor: pointer;
  box-shadow: 0 0 16px var(--accent-glow);
  transition: all var(--transition);
}

.btn-submit:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 24px var(--accent-glow);
}

/* ───────────── Toast ───────────── */
.toast {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 300;
  min-width: 220px;
  max-width: 380px;
  background: #1e2534;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast.toast-success {
  border-color: rgba(34, 197, 94, 0.4);
  color: #86efac;
}

.toast.toast-error {
  border-color: rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

/* ───────────── Row highlight animation ───────────── */
@keyframes row-flash {
  0% {
    background: rgba(99, 102, 241, 0.25);
  }

  100% {
    background: transparent;
  }
}

.row-flash {
  animation: row-flash 1.2s ease;
}

/* ───────────── Responsive ───────────── */
@media (max-width: 900px) {
  .header-inner {
    flex-wrap: wrap;
    height: auto;
    padding: 12px 16px;
  }

  .header-stats {
    display: none;
  }

  .app-main {
    padding: 16px;
  }

  .app-main.panel-open {
    grid-template-columns: 1fr;
  }

  .notes-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    max-height: 55vh;
    z-index: 150;
  }

  .search-input {
    width: 160px;
  }
}