/* =============================================
   B Solar CRM — Main Stylesheet
   ============================================= */

:root {
  --sun:       #185FA5;
  --sun-light: #85B7EB;
  --navy:      #185FA5;
  --navy-mid:  #0C447C;
  --navy-soft: #85B7EB;
  --white:     #FFFFFF;
  --off-white: #F0F5FB;
  --text:      #2C2C2A;
  --muted:     #888780;
  --danger:    #E53E3E;
  --success:   #38A169;
  --border:    #E8E8E6;
  --shadow:    0 2px 12px rgba(24,95,165,0.10);
  --radius:    8px;
  --font-head: 'Sora', sans-serif;
  --font-body: 'DM Sans', sans-serif;
}
:root {
  /* Corporate Blue Theme */
  --theme-primary: #185FA5;
  --theme-primary-dark: #0C447C;
  --theme-primary-light: #85B7EB;
  --theme-secondary: #85B7EB;
  --theme-accent: #993C1D;
  --theme-bg-light: #E6F1FB;
  --theme-bg-tertiary: #F0F5FB;
  --theme-text-muted: #888780;
  --theme-border: #E8E8E6;
}

/* Light mode adjustments */
@media (prefers-color-scheme: light) {
  :root {
    --theme-primary: #185FA5;
    --theme-primary-dark: #0C447C;
    --theme-primary-light: #85B7EB;
    --theme-accent: #993C1D;
  }
}

/* Dark mode adjustments */
@media (prefers-color-scheme: dark) {
  :root {
    --theme-primary: #85B7EB;
    --theme-primary-dark: #B5D4F4;
    --theme-primary-light: #185FA5;
    --theme-accent: #D4947A;
  }
}

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

body {
  font-family: var(--font-body);
  background: var(--off-white);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.6;
}

a { color: var(--sun); text-decoration: none; }
a:hover { text-decoration: underline; }

h1,h2,h3,h4 { font-family: var(--font-head); font-weight: 700; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 20px;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
}
.btn:hover   { opacity: .88; transform: translateY(-1px); }
.btn:active  { transform: translateY(0); }

.btn-primary  { background: #185FA5;   color: white; border: 1px solid #185FA5; }
.btn-primary:hover { background: #0C447C; border-color: #0C447C; }
.btn-navy     { background: #0C447C;  color: var(--white); }
.btn-ghost    { background: transparent;  color: var(--muted); border: 1px solid var(--border); }
.btn-danger   { background: var(--danger); color: var(--white); }
.btn-sm       { padding: 6px 14px; font-size: 13px; }

/* ── Form elements ── */
.form-group        { margin-bottom: 18px; }
.form-group label  { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: var(--navy-mid); }
.form-group input,
.form-group select {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text);
  background: var(--white);
  transition: border-color .2s;
  outline: none;
}
.form-group input:focus,
.form-group select:focus { border-color: var(--sun); }

.error-msg { color: var(--danger); font-size: 13px; margin-top: 10px; display: none; }
.error-msg.visible { display: block; }

/* ── Cards ── */
.card {
  background: var(--white);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 24px;
}

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 28px; right: 28px;
  background: var(--navy);
  color: var(--white);
  padding: 12px 22px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .25s, transform .25s;
  z-index: 9999;
  max-width: 320px;
}
#toast.show { opacity: 1; transform: translateY(0); }
#toast.success { border-left: 4px solid var(--success); }
#toast.error   { border-left: 4px solid var(--danger);  }

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(13,27,42,.45);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--white);
  border-radius: 14px;
  padding: 32px;
  width: 420px;
  max-width: 95vw;
  box-shadow: 0 20px 60px rgba(13,27,42,.25);
}
.modal h3 { font-size: 18px; margin-bottom: 20px; color: var(--navy); }
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  padding: 11px 14px;
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  border-bottom: 2px solid var(--border);
}
tbody tr { border-bottom: 1px solid var(--border); transition: background .12s; }
tbody tr:hover { background: var(--off-white); }
tbody td { padding: 12px 14px; }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
}
.badge-admin { background: #FEF3C7; color: #92400E; }
.badge-user  { background: #DBEAFE; color: #1E40AF; }
.badge-surveyor { background: #D1D5DB; color: #1F2937; }

/* ── Customer module ── */
.c-name  { font-weight: 600; color: var(--navy); }
.c-sub   { font-size: 12px; color: var(--muted); margin-top: 2px; }

.wa-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: #25D366;
  font-weight: 500;
  font-size: 13px;
}
.wa-link svg { width: 15px; height: 15px; }
.wa-link:hover { text-decoration: underline; }

.badge-discom        { background: #EDE9FE; color: #5B21B6; }
.badge-type-residential { background: #D1FAE5; color: #065F46; }
.badge-type-commercial  { background: #FEF3C7; color: #92400E; }
.badge-type-industrial  { background: #DBEAFE; color: #1E40AF; }

.tbl-msg { text-align: center; padding: 28px; color: var(--muted); }

/* Customer toolbar */
.customers-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.customers-toolbar input[type="text"] {
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 14px;
  width: 220px;
  height: 36px;
  outline: none;
  transition: border-color .2s;
  background: var(--white);
  color: var(--text);
}
.customers-toolbar input[type="text"]:focus { border-color: var(--sun); }
.customers-toolbar select {
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 14px;
  height: 36px;
  background: var(--white);
  color: var(--text);
  outline: none;
  cursor: pointer;
}
.customer-count { font-size: 13px; color: var(--muted); margin-left: auto; }

/* Customer modal — two-column grid */
.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 16px;
}
.form-grid-2 .span-2 { grid-column: 1 / -1; }
.c-form-error { color: var(--danger); font-size: 13px; min-height: 18px; margin-bottom: 4px; }

/* Wider customer modal with fixed height so footer/Save always visible */
.modal-lg {
  width: 680px;
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}
.modal-lg h3 { flex-shrink: 0; }
.modal-lg form { overflow-y: auto; flex: 1; padding-right: 4px; }
.modal-lg .modal-footer { flex-shrink: 0; padding-top: 12px; border-top: 1px solid var(--border); margin-top: 8px; }

/* Address textarea */
#c-address {
  resize: vertical;
  min-height: 62px;
  font-family: var(--font-body);
  font-size: 14px;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  outline: none;
  transition: border-color .2s;
  color: var(--text);
}
#c-address:focus { border-color: var(--sun); }

/* WhatsApp inline link — small like a badge */
.wa-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: #25D366;
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
}
.wa-link svg { width: 13px; height: 13px; flex-shrink: 0; }
.wa-link:hover { text-decoration: underline; }

/* WA action button in table */
.wa-btn {
  color: #25D366 !important;
  border-color: #25D366 !important;
  font-weight: 700;
}

/* ── Inquiry stage badges ── */
.badge-stage-new     { background: #DBEAFE; color: #1E40AF; }
.badge-stage-survey  { background: #EDE9FE; color: #5B21B6; }
.badge-stage-offer   { background: #FEF3C7; color: #92400E; }
.badge-stage-nego    { background: #FFEDD5; color: #9A3412; }
.badge-stage-order   { background: #D1FAE5; color: #065F46; }
.badge-stage-cancel  { background: #FEE2E2; color: #991B1B; }

/* Order chances badges */
.badge-ch-high { background: #D1FAE5; color: #065F46; }
.badge-ch-med  { background: #FEF3C7; color: #92400E; }
.badge-ch-low  { background: #FEE2E2; color: #991B1B; }

/* Customer auto-fill preview strip */
.customer-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  background: var(--off-white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text);
}
.customer-preview .span-all { flex: 0 0 100%; color: var(--muted); }

/* ── Offer Side Panel ── */
#offer-panel-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(13,27,42,.3);
  z-index: 900;
}
#offer-panel-backdrop.open { display: block; }

#offer-panel {
  position: fixed;
  top: 58px; right: 0; bottom: 0;
  width: 760px;
  max-width: 96vw;
  background: var(--white);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 24px rgba(13,27,42,.12);
  z-index: 901;
  display: flex;
  flex-direction: column;
  transform: translateX(110%);
  transition: transform .25s cubic-bezier(.22,1,.36,1);
  overflow: hidden;
  visibility: hidden;
}
#offer-panel.open {
  transform: translateX(0);
  visibility: visible;
}
#offer-panel-backdrop.open { display: block; }

/* open backdrop together with panel */
#offer-panel.open ~ #offer-panel-backdrop,
#offer-panel-backdrop:has(+ #offer-panel.open) { display: block; }

.op-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.op-header h3 { font-size: 16px; color: var(--navy); }

#offer-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px 32px;
}

.op-section {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.op-section:last-child { border-bottom: none; }
.op-section h4 { font-size: 14px; font-weight: 700; color: var(--navy); margin-bottom: 2px; }

/* Revision cards */
.rev-card {
  background: var(--off-white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-top: 10px;
}
.rev-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.rev-drawings {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.rev-drawing-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--navy);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 8px;
}
.rev-drawing-link:hover { background: var(--off-white); text-decoration: none; }

/* Offer panel two-column layout */
.op-two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  height: 100%;
}
.op-col {
  padding: 16px 14px;
  overflow-y: auto;
  border-right: 1px solid var(--border);
}
.op-col:last-child { border-right: none; }

.op-section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  margin-bottom: 4px;
}

/* Latest revision highlight */
.rev-card-latest {
  border-color: var(--sun);
  background: #FFFBF0;
}

/* Next follow-up highlight box */
.fu-next-box {
  background: var(--navy);
  color: var(--white);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 4px;
}
.fu-next-box .c-sub { color: rgba(255,255,255,.6); }


/* ── Quotation modal ── */
.quot-calc-box {
  background: var(--off-white);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-top: 4px;
}
.quot-calc-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: 10px;
}
.quot-calc-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px 20px;
  font-size: 13px;
}
.quot-calc-grid .qc-bold {
  font-weight: 700;
  color: var(--navy);
}

/* ── Projects wide table ──────────────────────────────────── */
.proj-table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  max-height: calc(100vh - 270px);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-top: 12px;
}
.proj-table {
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
  white-space: nowrap;
}
.proj-table th,
.proj-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  overflow: hidden;
  text-overflow: ellipsis;
}
/* All header cells */
.proj-table thead th {
  background: var(--bg-alt);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  position: sticky;
  top: 0;
  z-index: 2;
  cursor: default;
}
/* All body cells */
.proj-table tbody td { background: #ffffff; }

/* ── Frozen columns: Project ID + Customer Name + Actions ── */
.proj-frozen-id {
  position: sticky;
  left: 0;
  z-index: 3;
  width: 120px;
  min-width: 120px;
  max-width: 120px;
  box-sizing: border-box;
  overflow: hidden;
  text-overflow: ellipsis;
  background: #ffffff !important;
}
.proj-frozen-name {
  position: sticky;
  left: 120px;
  z-index: 3;
  width: 170px;
  min-width: 170px;
  max-width: 170px;
  box-sizing: border-box;
  overflow: hidden;
  text-overflow: ellipsis;
  background: #ffffff !important;
}
.proj-frozen-actions {
  position: sticky;
  left: 290px;
  z-index: 3;
  width: 90px;
  min-width: 90px;
  max-width: 90px;
  box-sizing: border-box;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
  background: #ffffff !important;
  box-shadow: 2px 0 6px rgba(0,0,0,.06);
}
thead .proj-frozen-id,
thead .proj-frozen-name,
thead .proj-frozen-actions {
  background: var(--bg-alt) !important;
  z-index: 5;
}

/* Filter row: sits at top: 0, label row below it at top: 34px */
.proj-filter-row th          { top: 0 !important; z-index: 3; background: var(--bg-alt); padding: 3px 5px; }
.proj-filter-row .proj-frozen-id,
.proj-filter-row .proj-frozen-name,
.proj-filter-row .proj-frozen-actions { top: 0 !important; z-index: 5 !important; }
thead tr:nth-child(2) th     { top: 34px; }
thead tr:nth-child(2) .proj-frozen-id,
thead tr:nth-child(2) .proj-frozen-name,
thead tr:nth-child(2) .proj-frozen-actions { top: 34px; z-index: 5; }

.proj-col-filter {
  width: 100%;
  font-size: 11px;
  padding: 2px 5px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #ffffff;
  color: var(--text);
  box-sizing: border-box;
}
.proj-col-filter:focus { outline: none; border-color: var(--navy); }

/* ── Icon buttons ── */
.proj-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
  color: var(--navy);
  cursor: pointer;
  transition: background .15s;
}
.proj-icon-btn:hover { background: var(--bg-alt); }

/* ── Progress dots ── */
.proj-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  vertical-align: middle;
}
.proj-dot.green { background: #10b981; }
.proj-dot.red   { background: #e5e7eb; }

/* ── Drawings popup link ── */
.proj-drawing-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  color: var(--navy);
  text-decoration: none;
  font-size: 13px;
}
.proj-drawing-link:hover { background: var(--bg-alt); }

/* ── Inventory table: frozen headers & search/filter row ────── */
.inv-toolbar-sticky {
  position: sticky;
  top: 0;
  background: var(--white);
  border-bottom: 2px solid var(--border);
  padding: 12px 0;
  margin: 0 -16px;
  padding: 12px 16px;
  z-index: 50;
  box-shadow: 0 2px 4px rgba(0,0,0,.04);
}

.inv-table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  max-height: calc(100vh - 300px);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 12px;
}

.inv-table {
  border-collapse: separate;
  border-spacing: 0;
}

.inv-table thead th {
  position: sticky;
  top: 0;
  background: var(--off-white);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 11px 14px;
  border-bottom: 2px solid var(--border);
  border-right: 1px solid var(--border);
  z-index: 40;
  white-space: nowrap;
}

.inv-table th:last-child {
  border-right: none;
}

.inv-table tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.inv-table tbody td:last-child {
  border-right: none;
}

.inv-table tbody tr:hover {
  background: var(--off-white);
}