/* ==========================================================================
   Yash Terra CRM — Design System
   Palette: deep survey-map navy + warm brass accent (ties to "Yash Terra" —
   land/earth — without falling into generic real-estate gold-on-cream).
   Type: Sora (display) + Inter (body/UI) + JetBrains Mono (IDs, figures).
   ========================================================================== */

:root {
  --navy-950: #0F1D33;
  --navy-900: #1F3864;
  --navy-700: #2C4B82;
  --navy-100: #E9EEF6;
  --brass-500: #C9962C;
  --brass-400: #DDB158;
  --brass-100: #FBF1DD;
  --paper: #F7F6F3;
  --surface: #FFFFFF;
  --ink: #16202E;
  --ink-soft: #56616F;
  --line: #E2E4E8;
  --green: #2E7D46;
  --green-bg: #E7F4EA;
  --amber: #B9791A;
  --amber-bg: #FCF0DA;
  --red: #C0392B;
  --red-bg: #FBEAE8;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 29, 51, 0.06);
  --shadow-md: 0 6px 20px rgba(15, 29, 51, 0.10);

  --font-display: 'Sora', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; -webkit-overflow-scrolling: touch; touch-action: manipulation; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
h1, h2, h3, .display { font-family: var(--font-display); letter-spacing: -0.01em; }
a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--brass-500);
  outline-offset: 2px;
}

/* ---- Layout shell -------------------------------------------------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--navy-950);
  color: #EDF1F7;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-logo {
  width: 100%;
  max-width: 168px;
  height: auto;
  display: block;
  margin: 4px 0 2px 10px;
}
.sidebar-tagline {
  font-size: 11px;
  color: var(--brass-400);
  padding: 0 10px 18px;
  letter-spacing: 0.03em;
}

.sidebar-nav { overflow-y: auto; flex: 1 1 auto; }

.nav-group { margin-bottom: 4px; }
.nav-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 12px 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: rgba(237,241,247,0.45);
}
.nav-group-head:hover { color: rgba(237,241,247,0.75); }
.nav-group-chevron { width: 12px; height: 12px; transition: transform .15s ease; transform: rotate(90deg); }
.nav-group-head.collapsed .nav-group-chevron { transform: rotate(0deg); }
.nav-group-body { display: flex; flex-direction: column; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: #C9D2E0;
  text-decoration: none;
  margin-bottom: 2px;
}
.nav-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-link.active { background: var(--brass-500); color: #23180A; font-weight: 600; }
.nav-link .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .5; }

.nav-sublinks { display: flex; flex-direction: column; padding-left: 30px; margin: -1px 0 6px; }
.nav-sublink {
  font-size: 12.5px; color: #9FADC2; text-decoration: none; padding: 5px 10px;
  border-radius: var(--radius-sm); margin-bottom: 1px;
}
.nav-sublink:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-sublink.active { background: var(--brass-500); color: #23180A; font-weight: 600; }

.sidebar-footer {
  margin-top: auto;
  padding: 12px 10px 4px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.sidebar-user { font-size: 13px; font-weight: 600; color: #fff; }
.sidebar-role { font-size: 11px; color: var(--brass-400); text-transform: uppercase; letter-spacing: .04em; }
.logout-btn {
  margin-top: 10px;
  font-size: 12.5px;
  color: #C9D2E0;
  background: none;
  border: 1px solid rgba(255,255,255,0.15);
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  width: 100%;
  text-align: left;
}
.logout-btn:hover { background: rgba(255,255,255,0.08); color: #fff; }

.main {
  flex: 1;
  min-width: 0;
  padding: 26px 32px 60px;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.page-title { font-size: 22px; font-weight: 700; margin: 0; }
.page-subtitle { font-size: 13.5px; color: var(--ink-soft); margin-top: 4px; }

/* ---- Buttons ---------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform .06s ease, box-shadow .15s ease, background .15s ease;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--navy-900); color: #fff; }
.btn-primary:hover { background: var(--navy-700); }
.btn-brass { background: var(--brass-500); color: #23180A; }
.btn-brass:hover { background: var(--brass-400); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: var(--navy-100); }
.btn-ghost.active { background: var(--navy-900); border-color: var(--navy-900); color: #fff; }
.btn-danger { background: var(--red-bg); color: var(--red); }
.btn-danger:hover { background: #f6d9d5; }
.btn-lg { padding: 13px 20px; font-size: 15.5px; border-radius: var(--radius-md); }
.btn-sm { padding: 6px 10px; font-size: 12.5px; border-radius: 6px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---- Cards / surfaces --------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 20px; }

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 16px 18px;
}
.kpi-label { font-size: 12px; color: var(--ink-soft); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.kpi-value { font-family: var(--font-display); font-size: 26px; font-weight: 700; margin-top: 6px; }
.kpi-value.mono { font-family: var(--font-mono); }

/* ---- Forms ------------------------------------------------------------ */

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .02em;
}
.field .required { color: var(--red); }
input[type=text], input[type=tel], input[type=email], input[type=password],
input[type=number], input[type=date], select, textarea {
  width: 100%;
  font-family: var(--font-body);
  /* 16px minimum: iOS Safari auto-zooms the page on focus for any input
     under 16px, which made every search/lead-entry field feel laggy and
     jumpy on iPhone. 16px removes that zoom-on-focus entirely. */
  font-size: 16px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  border-color: var(--navy-700);
  outline: none;
  box-shadow: 0 0 0 3px var(--navy-100);
}
textarea { min-height: 90px; resize: vertical; }
.field-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 16px; }
.hint { font-size: 12px; color: var(--ink-soft); margin-top: 4px; }
.error-text { font-size: 12.5px; color: var(--red); margin-top: 4px; }

/* ---- Multi-select chips (Area of Interest) ---------------------------- */

.chip-select { border: 1.5px solid var(--line); border-radius: var(--radius-sm); padding: 8px; }
.chip-select input { border: none; padding: 6px 4px; }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 4px 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--navy-100); color: var(--navy-900);
  font-size: 12.5px; font-weight: 600; padding: 5px 8px 5px 10px; border-radius: 999px;
}
.chip button { background: none; border: none; cursor: pointer; color: var(--navy-700); font-size: 13px; line-height: 1; }
.chip-options { max-height: 160px; overflow-y: auto; border-top: 1px solid var(--line); margin-top: 4px; }
.chip-option { padding: 8px 8px; font-size: 13.5px; cursor: pointer; border-radius: 6px; }
.chip-option:hover { background: var(--navy-100); }

/* ---- Tab bars (Follow-up types, Finance sub-views) --------------------- */

.tab-bar {
  display: flex; flex-wrap: wrap; gap: 6px;
  border-bottom: 1.5px solid var(--line);
  margin-bottom: 18px;
  padding-bottom: 0;
}
.tab-btn {
  background: none; border: none; cursor: pointer;
  padding: 9px 14px; font-size: 13.5px; font-weight: 600;
  color: var(--ink-soft);
  border-bottom: 2.5px solid transparent;
  margin-bottom: -1.5px;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--ink); }
.tab-btn.active { color: var(--navy-900); border-bottom-color: var(--brass-500); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---- Documents module --------------------------------------------------- */

.doc-project-card {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 13px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #fff; margin-bottom: 8px; cursor: pointer;
}
.doc-project-card:hover { border-color: var(--brass-500); }
.doc-project-card.active { border-color: var(--brass-500); background: var(--brass-50, #FBF4E4); }
.doc-type-section { margin-bottom: 18px; }
.doc-type-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.doc-file-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: #fff; margin-bottom: 6px; font-size: 13px;
}
.doc-file-row a { font-weight: 600; }
.doc-dropzone {
  border: 1.5px dashed var(--line); border-radius: var(--radius-sm);
  padding: 16px; text-align: center; font-size: 13px; color: var(--ink-soft);
  cursor: pointer; margin-bottom: 6px;
}
.doc-dropzone:hover { border-color: var(--brass-500); color: var(--ink); }

/* ---- Tables ------------------------------------------------------------ */

table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data-table th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em;
  color: var(--ink-soft); font-weight: 700; padding: 10px 14px; border-bottom: 1.5px solid var(--line);
  white-space: nowrap;
}
table.data-table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data-table tr:hover td { background: var(--navy-100); }
.id-cell { font-family: var(--font-mono); font-size: 12.5px; color: var(--ink-soft); }

/* ---- Sortable column headers (leads.html) ------------------------------ */
table.data-table th[data-sort] { cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent; }
table.data-table th[data-sort]:hover { color: var(--ink); }
table.data-table th[data-sort]::after { content: '\2195'; margin-left: 5px; opacity: .35; font-size: 10px; }
table.data-table th[data-sort].sort-asc::after { content: '\2191'; opacity: 1; color: var(--brass-500); }
table.data-table th[data-sort].sort-desc::after { content: '\2193'; opacity: 1; color: var(--brass-500); }

/* ---- Badges / pipeline stage colors ------------------------------------ */

.badge {
  display: inline-flex; align-items: center; font-size: 11.5px; font-weight: 700;
  padding: 4px 9px; border-radius: 999px; text-transform: uppercase; letter-spacing: .02em;
}
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-navy { background: var(--navy-100); color: var(--navy-900); }
.badge-brass { background: var(--brass-100); color: #8A6417; }

/* ---- Search & toolbar -------------------------------------------------- */

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.search-box { position: relative; flex: 1; min-width: 220px; }
.search-box input { padding-left: 34px; }
.search-box svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--ink-soft); }

/* ---- Empty / loading states --------------------------------------- */

.empty-state { text-align: center; padding: 60px 20px; color: var(--ink-soft); }
.empty-state h3 { font-size: 16px; color: var(--ink); margin-bottom: 6px; }
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid var(--navy-100); border-top-color: var(--navy-900);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-row { display: flex; align-items: center; gap: 10px; color: var(--ink-soft); padding: 30px; justify-content: center; }

/* ---- Toast -------------------------------------------------------------- */

#toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--navy-950); color: #fff; padding: 12px 18px; border-radius: var(--radius-md);
  font-size: 13.5px; font-weight: 600; box-shadow: var(--shadow-md);
  opacity: 0; pointer-events: none; transition: all .2s ease; z-index: 999; max-width: 340px;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--red); }
#toast.success { background: var(--green); }

/* ---- Login page --------------------------------------------------- */

.login-wrap {
  min-height: 100vh; display: flex; background: var(--navy-950); position: relative; overflow: hidden;
}
.login-visual {
  flex: 1.1; position: relative; display: flex; align-items: flex-end; padding: 48px;
  background: radial-gradient(circle at 25% 20%, #1B335A 0%, var(--navy-950) 60%);
}
.plot-grid { position: absolute; inset: 0; opacity: 0.5; }
.login-visual-text { position: relative; z-index: 1; color: #fff; max-width: 440px; }
.login-logo { width: 100%; max-width: 340px; height: auto; margin-bottom: 22px; display: block; }
.login-visual-text .eyebrow { color: var(--brass-400); font-size: 12.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; margin-bottom: 10px; }
.login-visual-text h1 { font-size: 34px; line-height: 1.15; margin: 0 0 12px; }
.login-visual-text p { color: #B7C2D6; font-size: 14.5px; line-height: 1.6; }
.login-form-side { width: 420px; flex-shrink: 0; background: var(--paper); display: flex; align-items: center; justify-content: center; padding: 40px; }
.login-card { width: 100%; max-width: 320px; }
.login-card-logo { width: 100%; max-width: 210px; height: auto; display: block; margin: 0 0 22px; }
.login-card h2 { font-size: 22px; margin: 0 0 4px; }
.login-card .sub { color: var(--ink-soft); font-size: 13.5px; margin-bottom: 26px; }
.auth-links { display: flex; gap: 10px; justify-content: center; margin-top: 16px; font-size: 13px; }
.auth-links a { color: var(--navy-700); font-weight: 600; text-decoration: none; }
.auth-links a:hover { text-decoration: underline; }
.auth-links span { color: var(--line); }

@media (max-width: 860px) {
  .login-visual { display: none; }
  .login-form-side { width: 100%; }
  .app-shell { flex-direction: column; }
  .main { padding: 16px; }
}

/* ---- Mobile top bar + slide-in nav drawer (iOS-safe) --------------------
   Fixes the "can't reach the full menu on mobile" issue: the old bottom
   bar could only ever show 5 icons. Now it shows 4 quick shortcuts + a
   Menu button that opens the SAME grouped nav as the desktop sidebar, in
   a full-height off-canvas drawer. Uses -webkit-overflow-scrolling and
   env(safe-area-inset-*) throughout since this is the part of the site
   iOS Safari is pickiest about. */

.mobile-topbar { display: none; }
.nav-drawer-backdrop { display: none; }
.sidebar-mobile-head { display: none; }

@media (max-width: 860px) {
  .mobile-topbar {
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 40;
    background: var(--navy-950);
    padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  }
  .mobile-topbar-logo { height: 26px; width: auto; }
  .mobile-menu-btn {
    background: none; border: 1px solid rgba(255,255,255,0.18); border-radius: var(--radius-sm);
    color: #EDF1F7; width: 38px; height: 38px; display: flex; align-items: center; justify-content: center;
    cursor: pointer; -webkit-tap-highlight-color: transparent;
  }

  /* The sidebar becomes an off-canvas drawer instead of `display:none` */
  .sidebar {
    display: flex !important;
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 70;
    width: 84%; max-width: 320px;
    height: 100%; height: -webkit-fill-available;
    transform: translateX(-105%);
    transition: transform .22s ease;
    box-shadow: 8px 0 30px rgba(0,0,0,0.35);
    padding-top: calc(16px + env(safe-area-inset-top));
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    -webkit-overflow-scrolling: touch;
  }
  .sidebar-logo { display: none; }
  .sidebar-mobile-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 10px 14px;
  }
  .sidebar-logo-sm { height: 24px; width: auto; }
  .nav-drawer-close {
    background: none; border: 1px solid rgba(255,255,255,0.18); border-radius: var(--radius-sm);
    color: #EDF1F7; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
    cursor: pointer;
  }

  .nav-drawer-backdrop {
    display: block; position: fixed; inset: 0; z-index: 65;
    background: rgba(9, 15, 26, 0.55);
    opacity: 0; pointer-events: none; transition: opacity .2s ease;
  }

  body.nav-drawer-open { overflow: hidden; }
  body.nav-drawer-open .sidebar { transform: translateX(0); }
  body.nav-drawer-open .nav-drawer-backdrop { opacity: 1; pointer-events: auto; }
}

.mobile-nav-more { position: relative; }


/* Mobile bottom nav (shown instead of sidebar on small screens) */
.mobile-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  background: var(--navy-950); border-top: 1px solid rgba(255,255,255,0.08);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
@media (max-width: 860px) {
  .mobile-nav { display: flex; justify-content: space-around; }
  .main { padding-bottom: 84px; }
}
.mobile-nav a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: #9FADC2; font-size: 10.5px; text-decoration: none; padding: 6px 8px; font-weight: 600;
}
.mobile-nav a.active { color: var(--brass-400); }

/* Floating action button (mobile "add lead") */
.fab {
  position: fixed; right: 18px; bottom: 84px; z-index: 60;
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--brass-500); color: #23180A; border: none;
  box-shadow: var(--shadow-md); font-size: 26px; display: none;
  align-items: center; justify-content: center; cursor: pointer;
}
@media (max-width: 860px) { .fab { display: flex; } }

/* ---- Mobile performance/usability pass ---------------------------------
   Goals: bigger, easier tap targets (44px is the accepted minimum so
   fingers don't mis-tap); denser but still legible tables that scroll
   horizontally with the row's identifying column pinned in view instead
   of scrolling out of sight; less wasted padding on small screens so more
   content fits without extra scrolling; no layout jank from images
   loading in. Nothing here changes desktop. */
@media (max-width: 640px) {
  .main { padding: 12px 12px 84px; }
  .page-header { margin-bottom: 16px; }
  .page-title { font-size: 19px; }
  .card-pad { padding: 14px; }

  /* Data tables: tighter cells, and pin the first column (ID/name) so it
     stays visible while the rest of a wide row scrolls under a thumb. */
  table.data-table th, table.data-table td { padding: 9px 10px; font-size: 12.5px; }
  .card > div[style*="overflow-x"] { -webkit-overflow-scrolling: touch; }
  table.data-table td:first-child, table.data-table th:first-child {
    position: sticky; left: 0; background: #fff; z-index: 1;
  }
  table.data-table tr:hover td:first-child { background: var(--navy-100); }

  /* Toolbars (search + filters) stack full-width instead of a cramped row */
  .toolbar { gap: 8px; }
  .toolbar .search-box { min-width: 100%; }
  .toolbar select { width: 100% !important; }
  .proj-toolbar-row { width: 100%; }
  .proj-toolbar-row select { flex: 1 1 auto; }

  /* Bigger tap targets everywhere a finger — not a cursor — will land */
  .btn { min-height: 44px; }
  .btn-sm { min-height: 38px; }
  .nav-link, .nav-sublink { min-height: 40px; }
  table.data-table td a.btn-sm, table.data-table td button.btn-sm { min-height: 34px; }
}
