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

:root {
  --primary:      #2563EB;
  --primary-dark: #1D4ED8;
  --bg:           #F5F7FA;
  --surface:      #FFFFFF;
  --border:       #E5E7EB;
  --text:         #111827;
  --muted:        #6B7280;
  --tag-bg:       #DBEAFE;
  --tag-text:     #1D4ED8;
  --personal-bg:  #F0FDF4;
  --personal-txt: #15803D;
  --business-bg:  #EFF6FF;
  --business-txt: #1D4ED8;
  --danger:       #DC2626;
  --radius:       8px;
}

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

/* ── Header ───────────────────────────────────────────────── */
.app-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: 56px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px; padding: 0 20px;
}
.app-logo { font-size: 18px; font-weight: 700; color: var(--primary); letter-spacing: 1px; flex-shrink: 0; }
.header-center { flex: 1; max-width: 480px; }
.search-bar {
  width: 100%; padding: 7px 12px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 14px; outline: none; background: var(--bg);
}
.search-bar:focus { border-color: var(--primary); background: #fff; }
.header-right { margin-left: auto; }

/* ── View Tabs ─────────────────────────────────────────────── */
.view-tabs {
  position: fixed; top: 56px; left: 0; right: 0; z-index: 90;
  display: flex; background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 20px;
}
.view-tab {
  padding: 10px 16px; border: none; background: none; cursor: pointer;
  font-size: 14px; font-weight: 500; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color .15s, border-color .15s;
}
.view-tab:hover { color: var(--text); }
.view-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── Layout ───────────────────────────────────────────────── */
.app-body {
  display: flex; height: 100vh; padding-top: 96px;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  width: 180px; flex-shrink: 0; background: var(--surface);
  border-right: 1px solid var(--border); padding: 16px 12px;
  overflow-y: auto;
}
.type-nav { display: flex; flex-direction: column; gap: 2px; margin-bottom: 24px; }
.type-btn {
  width: 100%; text-align: left; padding: 8px 10px; border: none;
  background: none; border-radius: 6px; cursor: pointer; font-size: 14px;
  color: var(--muted); font-weight: 500; transition: background .15s, color .15s;
}
.type-btn:hover   { background: var(--bg); color: var(--text); }
.type-btn.active  { background: var(--tag-bg); color: var(--primary); font-weight: 600; }

.sidebar-section-label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; padding: 0 2px; }
.tag-filter-list { display: flex; flex-direction: column; gap: 2px; }
.tag-filter-btn {
  width: 100%; text-align: left; padding: 6px 10px; border: none;
  background: none; border-radius: 6px; cursor: pointer; font-size: 13px;
  color: var(--muted); display: flex; align-items: center; gap: 6px;
}
.tag-filter-btn:hover { background: var(--bg); color: var(--text); }
.tag-filter-btn.active { background: var(--tag-bg); color: var(--tag-text); font-weight: 600; }
.tag-filter-btn .tag-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); flex-shrink: 0; }

/* ── Contact list ─────────────────────────────────────────── */
.contact-list-panel {
  width: 300px; flex-shrink: 0; background: var(--surface);
  border-right: 1px solid var(--border); overflow-y: auto;
}
.contact-list { display: flex; flex-direction: column; }
.contact-card {
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background .12s;
}
.contact-card:hover    { background: var(--bg); }
.contact-card.selected { background: var(--tag-bg); border-left: 3px solid var(--primary); padding-left: 13px; }

.contact-card-name { font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.contact-relationship { font-weight: 400; font-size: 12px; color: var(--muted); }
.contact-card-sub  { font-size: 12px; color: var(--muted); margin-bottom: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-card-tags { display: flex; flex-wrap: wrap; gap: 4px; }

.contact-empty { padding: 40px 20px; text-align: center; color: var(--muted); }

/* ── Detail panel ─────────────────────────────────────────── */
.detail-panel { flex: 1; overflow-y: auto; background: var(--bg); }
.detail-content { max-width: 680px; margin: 0 auto; padding: 28px 24px; }
.detail-empty { display: flex; height: 100%; align-items: center; justify-content: center; color: var(--muted); padding: 60px; }

.detail-header {
  background: var(--surface); border-radius: var(--radius); padding: 24px;
  margin-bottom: 16px; display: flex; align-items: flex-start; gap: 16px;
  border: 1px solid var(--border);
}
.detail-avatar {
  width: 56px; height: 56px; border-radius: 50%; background: var(--primary);
  color: #fff; font-size: 22px; font-weight: 700; display: flex; align-items: center;
  justify-content: center; flex-shrink: 0; text-transform: uppercase;
}
.detail-info { flex: 1; min-width: 0; }
.detail-name { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.detail-company { font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.detail-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.detail-actions { display: flex; gap: 8px; }

.detail-meta {
  background: var(--surface); border-radius: var(--radius); padding: 20px;
  margin-bottom: 16px; border: 1px solid var(--border);
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
}
.meta-item label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; display: block; margin-bottom: 2px; }
.meta-item span  { font-size: 14px; color: var(--text); }
.meta-item a     { color: var(--primary); text-decoration: none; }
.meta-item a:hover { text-decoration: underline; }
.meta-item.full  { grid-column: 1 / -1; }

.detail-notes-box {
  background: var(--surface); border-radius: var(--radius); padding: 20px;
  margin-bottom: 16px; border: 1px solid var(--border);
}
.detail-section-title { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 12px; }

/* ── Interaction log ──────────────────────────────────────── */
.interaction-log { background: var(--surface); border-radius: var(--radius); padding: 20px; border: 1px solid var(--border); }
.log-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.log-entries { display: flex; flex-direction: column; gap: 12px; }
.log-entry {
  display: flex; gap: 12px; padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.log-entry:last-child { border-bottom: none; padding-bottom: 0; }
.log-icon {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 15px;
}
.log-icon.call    { background: #DCFCE7; }
.log-icon.email   { background: #DBEAFE; }
.log-icon.meeting { background: #FEF9C3; }
.log-icon.lunch   { background: #D1FAE5; }
.log-icon.dinner  { background: #FFEDD5; }
.log-icon.note    { background: #F3E8FF; }
.log-body { flex: 1; min-width: 0; }
.log-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 3px; }
.log-type { font-size: 12px; font-weight: 600; text-transform: capitalize; color: var(--text); }
.log-date { font-size: 12px; color: var(--muted); }
.log-notes { font-size: 13px; color: var(--text); line-height: 1.5; white-space: pre-wrap; }
.log-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 20px 0; }
.log-entry-upcoming { background: #FFFBEB; border-radius: 6px; padding: 8px; margin: -4px; }
.log-upcoming-badge { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; background: #FEF9C3; color: #854D0E; padding: 1px 6px; border-radius: 99px; }

/* ── Tags ─────────────────────────────────────────────────── */
.tag {
  display: inline-flex; align-items: center; padding: 2px 8px;
  border-radius: 99px; font-size: 11px; font-weight: 600;
  background: var(--tag-bg); color: var(--tag-text);
}
.tag-icsc { background: #FEE2E2; color: #991B1B; }
.type-badge-personal { background: var(--personal-bg); color: var(--personal-txt); }
.type-badge-business { background: var(--business-bg); color: var(--business-txt); }

/* ── Buttons ──────────────────────────────────────────────── */
.btn-primary {
  padding: 8px 16px; background: var(--primary); color: #fff;
  border: none; border-radius: var(--radius); cursor: pointer; font-size: 14px;
  font-weight: 500; transition: background .15s;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary {
  padding: 7px 14px; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; font-size: 13px; font-weight: 500; transition: background .15s;
}
.btn-secondary:hover { background: var(--border); }
.btn-danger {
  padding: 7px 14px; background: none; color: var(--danger);
  border: 1px solid var(--danger); border-radius: var(--radius);
  cursor: pointer; font-size: 13px; font-weight: 500;
}
.btn-danger:hover { background: #FEE2E2; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ── Modal ────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; z-index: 500;
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: var(--surface); border-radius: 12px; width: 100%;
  max-width: 520px; max-height: 90vh; display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 16px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 16px; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--muted); line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ── Form ─────────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group.full { grid-column: 1 / -1; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.form-group input,
.form-group select,
.form-group textarea {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 14px; outline: none; font-family: inherit; background: var(--bg);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--primary); background: #fff; }
.form-group textarea { resize: vertical; min-height: 80px; }

/* ── App Launcher ─────────────────────────────────────────── */
.app-launcher { position: relative; }
.launcher-btn {
  display: flex; align-items: center; gap: 6px;
  background: none; border: none; cursor: pointer; padding: 0;
}
.launcher-chevron { font-size: 10px; opacity: 0.5; color: var(--text); }
.launcher-menu {
  position: absolute; top: calc(100% + 8px); left: 0;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12); min-width: 180px;
  z-index: 999; padding: 6px;
}
.launcher-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 6px; text-decoration: none;
  color: var(--text); font-size: 14px; font-weight: 500; cursor: pointer;
}
.launcher-item:hover { background: var(--bg); }
.launcher-item.current { opacity: 0.4; cursor: default; pointer-events: none; }
.launcher-item-icon { font-size: 16px; width: 24px; text-align: center; }

/* ── Utilities ────────────────────────────────────────────── */
.hidden { display: none !important; }
.text-muted { color: var(--muted); }

/* ── Mobile controls (hidden on desktop) ─────────────────── */
.mobile-filter-btn {
  display: none; align-items: center; justify-content: center;
  width: 36px; height: 36px; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); cursor: pointer; font-size: 16px; flex-shrink: 0;
}
.mobile-back-btn {
  display: none; align-items: center; gap: 6px;
  padding: 10px 16px; background: var(--surface); border: none; border-bottom: 1px solid var(--border);
  color: var(--primary); font-size: 14px; font-weight: 600; cursor: pointer;
  width: 100%; text-align: left; position: sticky; top: 0; z-index: 10;
}
.sidebar-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 49;
}
.sidebar-backdrop:not(.hidden) { display: block; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Header: shrink add button */
  .header-center { max-width: none; }
  .mobile-filter-btn { display: flex; }

  /* Sidebar: off-canvas overlay */
  .sidebar {
    position: fixed; top: 96px; left: 0; bottom: 0; z-index: 50;
    width: 240px; transform: translateX(-100%);
    transition: transform .22s ease; box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0); box-shadow: 4px 0 20px rgba(0,0,0,.12);
  }

  /* Contact list: full width */
  .contact-list-panel { width: 100%; border-right: none; }

  /* Detail panel: full-screen overlay, slides in from right */
  .detail-panel {
    position: fixed; top: 96px; left: 0; right: 0; bottom: 0; z-index: 40;
    transform: translateX(100%); transition: transform .22s ease;
    background: var(--bg);
  }
  .detail-panel.active { transform: translateX(0); }

  /* Show back button on mobile */
  .mobile-back-btn { display: flex; }

  /* Detail content: full width, less padding */
  .detail-content { max-width: 100%; padding: 16px; }

  /* Detail header: wrap avatar + info */
  .detail-header { flex-wrap: wrap; gap: 12px; padding: 16px; }
  .detail-name { font-size: 17px; }

  /* Meta grid: single column */
  .detail-meta { grid-template-columns: 1fr; padding: 16px; }
  .meta-item.full { grid-column: 1; }

  /* Form: single column */
  .form-grid { grid-template-columns: 1fr; }
  .form-group.full { grid-column: 1; }

  /* Modal: full screen on small phones */
  .modal-box { max-width: 100%; max-height: 100%; border-radius: 0; }

  /* Touch-friendly tap targets */
  .contact-card { padding: 16px; }
  .type-btn, .tag-filter-btn { padding: 10px 10px; font-size: 14px; }
  .events-list { padding: 16px; }
}

/* ── Events View ───────────────────────────────────────────── */
.events-view {
  padding-top: 96px; min-height: 100vh; background: var(--bg);
}
.events-list {
  max-width: 720px; margin: 0 auto; padding: 24px;
}
.events-section-title {
  font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .08em;
  padding: 0 4px; margin-bottom: 12px; margin-top: 28px;
}
.events-section-title:first-child { margin-top: 0; }
.events-empty { color: var(--muted); font-size: 14px; text-align: center; padding: 48px 0; }

.event-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  display: flex; align-items: flex-start; gap: 16px;
  margin-bottom: 10px; transition: box-shadow .12s;
}
.event-card.completed { opacity: 0.5; }
.event-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.07); }

.event-date-badge {
  flex-shrink: 0; width: 48px; text-align: center;
  background: var(--bg); border-radius: 6px; padding: 6px 4px;
  border: 1px solid var(--border);
}
.event-date-month { font-size: 10px; font-weight: 700; text-transform: uppercase; color: var(--muted); letter-spacing: .05em; }
.event-date-day   { font-size: 22px; font-weight: 700; color: var(--text); line-height: 1.1; }

.event-body { flex: 1; min-width: 0; }
.event-title { font-size: 15px; font-weight: 600; margin-bottom: 5px; }
.event-meta  { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 4px; }
.event-location { font-size: 12px; color: var(--muted); }
.event-contact-link { font-size: 12px; color: var(--primary); cursor: pointer; }
.event-contact-link:hover { text-decoration: underline; }
.event-notes { font-size: 13px; color: var(--muted); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.event-actions { display: flex; gap: 6px; flex-shrink: 0; align-items: flex-start; }

.event-type-badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; }
.event-type-conference { background: #EDE9FE; color: #5B21B6; }
.event-type-meeting    { background: #FEF9C3; color: #854D0E; }
.event-type-call       { background: #DCFCE7; color: #166534; }
.event-type-follow-up  { background: #DBEAFE; color: #1D4ED8; }
.event-type-other      { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }

/* ── Calendar View ─────────────────────────────────────────── */
.calendar-view {
  padding-top: 96px; min-height: 100vh; background: var(--bg);
}
.cal-container {
  max-width: 760px; margin: 0 auto; padding: 24px;
}
.cal-nav {
  display: flex; align-items: center; gap: 10px; margin-bottom: 20px;
}
.cal-month-label {
  flex: 1; text-align: center; font-size: 18px; font-weight: 700;
}
.cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  border-top: 1px solid var(--border); border-left: 1px solid var(--border);
  background: var(--surface); border-radius: var(--radius); overflow: hidden;
}
.cal-header {
  text-align: center; padding: 8px 0;
  font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
  background: var(--bg);
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.cal-cell {
  min-height: 88px; padding: 8px; cursor: pointer;
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: flex-start;
  transition: background .12s;
}
.cal-cell:not(.cal-cell-empty):hover { background: var(--bg); }
.cal-cell-empty { background: #FAFAFA; cursor: default; opacity: 0.5; }
.cal-day-num {
  font-size: 13px; font-weight: 600; color: var(--text);
  width: 24px; height: 24px; display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
}
.cal-today .cal-day-num { background: var(--primary); color: #fff; }
.cal-selected { background: #EFF6FF !important; }
.cal-event-chip {
  font-size: 11px; line-height: 1.35; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; width: 100%;
  margin-top: 3px; padding: 1px 3px; border-radius: 3px;
  color: var(--text);
}
.cal-event-chip-upcoming {
  color: #92400E; background: #FEF3C7;
}
.cal-event-more {
  font-size: 10px; color: var(--muted); margin-top: 2px; padding: 0 3px;
}

/* ── Calendar Day Panel ─────────────────────────────────────── */
.cal-day-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); margin-top: 16px; padding: 20px;
}
.cal-day-panel-title {
  font-size: 15px; font-weight: 700; margin-bottom: 16px;
}
.cal-day-item {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.cal-day-item:last-child { border-bottom: none; padding-bottom: 0; }
.cal-day-item-upcoming {
  background: #FFFBEB; border-radius: 6px; padding: 10px; margin: 0 -8px;
}
.cal-day-item-icon { font-size: 20px; flex-shrink: 0; line-height: 1; margin-top: 1px; }
.cal-day-item-body { flex: 1; min-width: 0; }
.cal-day-item-name { font-size: 14px; font-weight: 600; margin-bottom: 2px; }
.cal-day-item-meta { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
.cal-day-item-type { font-size: 12px; color: var(--muted); text-transform: capitalize; }
.cal-day-item-notes { font-size: 13px; color: var(--muted); line-height: 1.4; }
.cal-day-empty { color: var(--muted); font-size: 14px; padding: 8px 0; }

@media (max-width: 768px) {
  .cal-container { padding: 12px; }
  .cal-cell { min-height: 52px; padding: 5px; }
  .cal-day-num { font-size: 12px; width: 20px; height: 20px; }
  .cal-month-label { font-size: 15px; }
}

/* ---- Auth login overlay (Supabase Auth / Google) ---- */
#login-overlay {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg, #0d1117);
}
.login-card {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 40px 48px; border: 1px solid var(--border, #30363d);
  border-radius: 12px; background: var(--surface, #161b22); text-align: center;
}
.login-logo { font-size: 40px; line-height: 1; }
.login-card h1 { margin: 6px 0 0; font-size: 20px; color: var(--text, #e6edf3); }
.login-card p { margin: 0 0 14px; color: var(--muted, #8b949e); font-size: 14px; }
.google-btn {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 10px 18px; border: 1px solid var(--border, #30363d); border-radius: 8px;
  background: #fff; color: #1f1f1f; font-size: 14px; font-weight: 500; cursor: pointer;
  transition: filter 0.15s;
}
.google-btn:hover { filter: brightness(0.96); }
.btn-signout {
  background: none; border: 1px solid var(--border, #30363d); border-radius: 6px;
  color: var(--muted, #8b949e); cursor: pointer; padding: 6px 12px; font-size: 13px;
  transition: color 0.15s, border-color 0.15s;
}
.btn-signout:hover { color: var(--text, #e6edf3); border-color: var(--muted, #8b949e); }
