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

/* ── Design tokens — light mode ── */
:root {
  --bg:             #ffffff;
  --bg2:            #f7f7f5;
  --bg3:            #f5f5f4;
  --text:           #1a1a1a;
  --text2:          #666666;
  --text3:          #999999;
  --border:         #e5e5e5;
  --border2:        #d0d0d0;
  --info-bg:        #e8f0fe;
  --info-text:      #1a56db;
  --success-bg:     #ecfdf5;
  --success-text:   #047857;
  --success-border: #6ee7b7;
  --danger-text:    #dc2626;
  --warn-bg:        #fffbeb;
  --warn-text:      #92400e;
  --radius:         8px;
  --radius-lg:      12px;
}

/* ── Design tokens — dark mode ── */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:             #1e1e1e;
    --bg2:            #272727;
    --bg3:            #181818;
    --text:           #f0f0f0;
    --text2:          #aaaaaa;
    --text3:          #666666;
    --border:         #333333;
    --border2:        #444444;
    --info-bg:        #1e2a4a;
    --info-text:      #93c5fd;
    --success-bg:     #0d2b1e;
    --success-text:   #34d399;
    --success-border: #065f46;
    --danger-text:    #f87171;
    --warn-bg:        #2d2200;
    --warn-text:      #fbbf24;
  }
}

/* ── Base ── */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg3);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Form elements ── */
input, select {
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 13px;
  color: var(--text);
  outline: none;
  font-family: inherit;
}
input:focus, select:focus { border-color: #888; }

/* ── Buttons ── */
button {
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 7px 14px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}
button:hover:not(:disabled) { background: var(--bg2); }
button:disabled              { opacity: 0.4; cursor: default; }

.btn-primary                          { background: var(--text); color: var(--bg); border-color: transparent; }
.btn-primary:hover:not(:disabled)     { opacity: 0.85; background: var(--text); }
.btn-danger                           { color: var(--danger-text); border-color: var(--danger-text); }
.btn-success                          { background: var(--success-bg); color: var(--success-text); border-color: var(--success-border); }

/* ── Cards ── */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
}

/* ── Badges ── */
.badge          { font-size: 11px; padding: 2px 8px; border-radius: var(--radius); font-weight: 500; }
.badge-info     { background: var(--info-bg); color: var(--info-text); }

/* ── Column-access toggle chips ── */
.tag    { display: inline-block; font-size: 12px; padding: 4px 10px; border-radius: var(--radius); cursor: pointer; border: 1px solid var(--border); background: var(--bg2); color: var(--text2); }
.tag.on { background: var(--info-bg); color: var(--info-text); border-color: #93c5fd; }

/* ── Data table ── */
.data-table-wrap {
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;
  overflow-x: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.masked { color: var(--text3); letter-spacing: 3px; font-size: 12px; }

/* ── Sticky table header ── */
.data-table-wrap table { border-collapse: collapse; width: 100%; }
.data-table-wrap thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg2);
  box-shadow: 0 1px 0 var(--border);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text);
  font-weight: 700;
  white-space: nowrap;
}

/* ── Row hover ── */
.data-table-wrap tbody tr {
  transition: background 0.12s;
}
.data-table-wrap tbody tr:hover td {
  background: #f5f3ff !important;
}
@media (prefers-color-scheme: dark) {
  .data-table-wrap tbody tr:hover td { background: #1e2a4a !important; }
}

/* ── Sortable column hover ── */
th.sortable:hover { background: var(--bg3) !important; }
th.sortable .sort-icon { opacity: 0.25; font-size: 10px; margin-left: 3px; }
th.sortable.sorted .sort-icon { opacity: 1; }

/* ── Draggable column headers ── */
th.draggable-col { cursor: grab !important; }
th.draggable-col:active { cursor: grabbing !important; }

/* ── Status badges ── */
.status-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 20px;
  white-space: nowrap;
  letter-spacing: 0.2px;
}
.status-available  { background: #dcfce7; color: #15803d; }
.status-hold       { background: #fef3c7; color: #92400e; }
.status-sold       { background: #fee2e2; color: #b91c1c; }
.status-rented     { background: #ede9fe; color: #6d28d9; }
.status-default    { background: var(--bg2); color: var(--text2); }
@media (prefers-color-scheme: dark) {
  .status-available { background: #14532d; color: #86efac; }
  .status-hold      { background: #451a03; color: #fcd34d; }
  .status-sold      { background: #450a0a; color: #fca5a5; }
  .status-rented    { background: #2e1065; color: #c4b5fd; }
}

/* ── Toast notifications ── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  animation: toast-in 0.2s ease;
  pointer-events: auto;
}
.toast-success { background: #ecfdf5; color: #065f46; border: 1px solid #6ee7b7; }
.toast-error   { background: #fef2f2; color: #991b1b; border: 1px solid #fca5a5; }
.toast-info    { background: #eff6ff; color: #1e40af; border: 1px solid #93c5fd; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Share button tooltip ── */
.share-wrap {
  position: relative;
  display: inline-block;
}
/* Inline tooltips hidden — replaced by #global-share-tooltip via JS */
.share-tooltip { display: none !important; }

#global-share-tooltip {
  display: none;
  position: fixed;
  background: var(--text);
  color: var(--bg);
  font-size: 11px;
  font-weight: 500;
  padding: 7px 12px;
  border-radius: 6px;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  z-index: 99999;
  line-height: 1.7;
  pointer-events: none;
  text-align: left;
}
#global-share-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--text);
}

/* ── Add lead button ── */
#addRowBtn {
  background: #16a34a !important;
  color: #fff !important;
  border-color: #15803d !important;
  font-weight: 600 !important;
  box-shadow: 0 1px 4px rgba(22,163,74,0.3);
}
#addRowBtn:hover:not(:disabled) {
  background: #15803d !important;
  opacity: 1 !important;
}

/* ── Sub-modal root sits above the lead card modal ── */
#subModalRoot .modal-backdrop { z-index: 400; }

/* ── Modal ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal {
  background: var(--bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem;
}

/* ── Two-column form grid ── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 500px) { .form-grid { grid-template-columns: 1fr; } }

/* ── Sidebar layout ── */
.app-layout {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: #18181b;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 50;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width 0.22s cubic-bezier(.4,0,.2,1);
}
.sidebar.collapsed {
  width: 0;
}
.sidebar-content {
  margin-left: 220px;
  flex: 1;
  min-width: 0;
  transition: margin-left 0.22s cubic-bezier(.4,0,.2,1);
}
.sidebar-content.expanded {
  margin-left: 0;
}
/* Toggle button — floats at left edge of content */
#sidebarToggleBtn {
  position: fixed;
  top: 14px;
  left: 228px;
  z-index: 60;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #18181b;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 6px rgba(0,0,0,.35);
  transition: left 0.22s cubic-bezier(.4,0,.2,1), transform 0.22s;
  color: rgba(255,255,255,.7);
  font-size: 11px;
  line-height: 1;
  padding: 0;
}
#sidebarToggleBtn.collapsed {
  left: 8px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 14px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: rgba(255,255,255,.5);
  transition: all .15s;
  user-select: none;
  border: none;
  background: transparent !important;
  font-family: inherit;
  width: 100%;
  text-align: left;
}
.nav-item:hover              { background: rgba(255,255,255,.08) !important; color: rgba(255,255,255,.85); }
.nav-item.active             { background: rgba(99,102,241,.35)  !important; color: #fff; }
.nav-item.active:hover       { background: rgba(99,102,241,.4)   !important; }
.nav-icon { width: 15px; text-align: center; font-size: 13px; flex-shrink: 0; }
.sec-pill {
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all .15s;
  font-family: inherit;
}
.sec-pill.active   { background: #fff; color: #18181b; }
.sec-pill.inactive { background: rgba(255,255,255,.1); color: rgba(255,255,255,.55); }
.sec-pill.inactive:hover { background: rgba(255,255,255,.18); color: rgba(255,255,255,.9); }

/* ── Stat cards ── */
.stat-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
}
.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}
@media (max-width: 900px) { .stat-row { grid-template-columns: repeat(2, 1fr); } }

/* ── Split login ── */
.login-shell {
  min-height: 100vh;
  display: flex;
}
.login-brand {
  flex: 0 0 360px;
  background: #18181b;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 44px 40px;
  position: relative;
  overflow: hidden;
}
.login-brand::before {
  content: '';
  position: absolute;
  top: -80px; right: -80px;
  width: 300px; height: 300px;
  border-radius: 50%;
  background: rgba(255,255,255,.03);
}
.login-brand::after {
  content: '';
  position: absolute;
  bottom: -60px; left: -60px;
  width: 220px; height: 220px;
  border-radius: 50%;
  background: rgba(255,255,255,.03);
}
.login-form-panel {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fafaf9;
}
@media (max-width: 680px) {
  .login-brand { display: none; }
  .login-form-panel { background: var(--bg3); }
}
@media (prefers-color-scheme: dark) {
  .login-form-panel { background: #1a1a1a; }
  .sidebar { background: #111113; }
}

/* ── Searchable select dropdown ── */
.ss-opt:hover { background: var(--bg2) !important; }
.ss-trigger:hover { border-color: #888; }

/* ── Loading spinner ── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border2);
  border-top-color: var(--text2);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Projects tab ── */
.proj-section-title {
  font-size: 15px;
  font-weight: 700;
  border-bottom: 2px solid var(--text);
  padding-bottom: 4px;
  margin-bottom: 12px;
  display: inline-block;
}
.proj-form-section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 14px;
}
.proj-card:hover { box-shadow: 0 8px 28px rgba(0,0,0,.13); transform: translateY(-2px); }
.proj-card:hover img { transform: scale(1.05); }
.proj-card:hover .proj-card-overlay { background: rgba(0,0,0,.18) !important; }
.proj-card:hover .proj-view-btn { opacity: 1 !important; }
.proj-card:hover .proj-card-actions { opacity: 1 !important; }
@media (max-width: 760px) {
  /* Stack two-col detail layout on mobile */
  [style*="grid-template-columns:1fr 300px"] {
    grid-template-columns: 1fr !important;
  }
}

/* ══════════════════════════════════════════════════════════════
   MOBILE & TABLET RESPONSIVE  (≤ 768px)
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ── Sidebar overlay mode ── */
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(.4,0,.2,1);
    width: 260px !important;
    z-index: 200;
  }
  .sidebar.mobile-open {
    transform: translateX(0);
  }
  /* Content always full-width on mobile */
  .sidebar-content {
    margin-left: 0 !important;
  }
  /* Backdrop overlay */
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 190;
  }
  .sidebar-backdrop.visible { display: block; }

  /* Hamburger button repositioned */
  #sidebarToggleBtn {
    left: 12px !important;
    top: 12px !important;
    width: 36px !important;
    height: 36px !important;
    font-size: 14px !important;
    z-index: 210;
  }
  #sidebarToggleBtn.mobile-open {
    left: 268px !important;
  }

  /* ── Nav items: larger tap targets ── */
  .nav-item {
    padding: 12px 16px;
    font-size: 14px;
  }

  /* ── Content padding ── */
  .sidebar-content > div,
  .sidebar-content > main {
    padding-left: 8px !important;
    padding-right: 8px !important;
  }

  /* ── Tables: enforce horizontal scroll ── */
  .data-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .data-table-wrap table {
    min-width: 600px;
  }

  /* ── Modals: full-screen on small screens ── */
  .modal-backdrop {
    padding: 0;
    align-items: flex-end;
  }
  .modal {
    max-width: 100% !important;
    max-height: 95vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }

  /* ── Calling row detail modal: stack comments below details ── */
  #callingDetailBackdrop > div {
    width: 100% !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    height: 100vh;
  }
  /* Force the body flex to column */
  #callingDetailBackdrop > div > div[style*="display:flex;overflow:hidden"] {
    flex-direction: column !important;
  }
  /* Comments sidebar: full width, capped height */
  #callingDetailBackdrop .comments-sidebar-mobile {
    width: 100% !important;
    border-left: none !important;
    border-top: 1px solid var(--border);
    max-height: 40vh;
  }

  /* ── Stat row: 2 cols ── */
  .stat-row {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* ── Form grid: single column ── */
  .form-grid {
    grid-template-columns: 1fr !important;
  }

  /* ── Toast: bottom-center ── */
  #toast-container {
    bottom: 16px;
    right: 50%;
    transform: translateX(50%);
    width: calc(100% - 32px);
    max-width: 380px;
  }

  /* ── Filter panel: full-width pinned to bottom ── */
  #callingFilterPanel {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    width: 100% !important;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0 !important;
    box-shadow: 0 -4px 24px rgba(0,0,0,.18) !important;
  }

  /* ── Login: hide brand panel ── */
  .login-brand { display: none !important; }
  .login-form-panel { background: var(--bg) !important; }

  /* ── Buttons: larger tap area ── */
  button { min-height: 36px; }

  /* ── Top-level padding inside calling/admin panels ── */
  div[style*="padding:24px"] {
    padding: 16px !important;
  }
}

/* ── Small phones (≤ 480px) ── */
@media (max-width: 480px) {
  body { font-size: 13px; }

  /* 1-col stat row */
  .stat-row {
    grid-template-columns: 1fr !important;
  }

  /* Detail grid: 2 cols instead of 3 */
  #callingDetailBackdrop [style*="grid-template-columns:repeat(3,1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Highlight cards: stack */
  #callingDetailBackdrop [style*="grid-template-columns:repeat("] {
    grid-template-columns: 1fr !important;
  }

  /* Header title size */
  #callingDetailBackdrop [style*="font-size:20px"] {
    font-size: 16px !important;
  }

  /* Calling manage panel: single column buttons */
  div[style*="max-width:720px"] {
    padding: 12px !important;
  }
}

/* Unmapped standard column headers — subtle grey to hint "needs mapping" */
.ag-theme-quartz .calling-unmapped-header .ag-header-cell-text {
  color: #9ca3af;
  font-style: italic;
}

