/* ==========================================================================
   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; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}
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-brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  padding: 6px 10px 4px;
  color: #fff;
}
.sidebar-tagline {
  font-size: 11px;
  color: var(--brass-400);
  padding: 0 10px 18px;
  letter-spacing: 0.03em;
}

.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; }

.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-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);
  font-size: 15px;
  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); }

/* ---- 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); }

/* ---- 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: 420px; }
.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 h2 { font-size: 22px; margin: 0 0 4px; }
.login-card .sub { color: var(--ink-soft); font-size: 13.5px; margin-bottom: 26px; }

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

/* 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; } }
