/* ============================================================
   Mokist Ventures CRM — Design System
   Vanilla CSS3. No frameworks.
   ============================================================ */

:root {
  --bg-canvas: #f8fafc;
  --primary-dark: #13203D;
  --accent: #FAA31A;
  --accent-hover: #E0900F;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.10);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.18);

  --sidebar-width: 240px;
  --bottom-nav-height: 64px;
  --mobile-brand-bar-height: 56px;
  --touch-min: 14px; /* minimum touch-target padding */
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-canvas);
  color: var(--text-main);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary-dark); text-decoration: none; }
h1, h2, h3, h4 { margin: 0 0 0.5em; line-height: 1.2; }
p { margin: 0 0 1em; color: var(--text-muted); }

/* ------------------------------------------------------------
   App Shell
   ------------------------------------------------------------ */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* Desktop sidebar */
/* Mobile-only branded top bar — replaces the sidebar's logo on screens
   where the sidebar itself is hidden (< 768px). Hidden on desktop. */
.mobile-brand-bar {
  display: none;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: #374151;
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  padding: 24px 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
}
.sidebar-brand {
  padding: 0 24px 24px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 16px;
}
.sidebar-nav {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  color: #cbd5e1;
  font-size: 0.94rem;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: background 0.15s, color 0.15s;
}
.sidebar-nav a svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar-nav a.active {
  background: rgba(250, 163, 26, 0.18);
  color: #fff;
  border-left-color: var(--accent);
}
.sidebar-footer {
  margin-top: auto;
  padding: 16px 24px;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 0.85rem;
  color: #94a3b8;
}

/* Main content area */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 32px;
  width: 100%;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28px;
}
.topbar h1 { font-size: 1.5rem; }
.topbar .user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px 6px 6px;
  box-shadow: var(--shadow-sm);
}
.avatar-dot {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--primary-dark);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700;
}

/* ------------------------------------------------------------
   Mobile Bottom Navigation Dock (screens < 768px)
   ------------------------------------------------------------ */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bottom-nav-height);
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgba(15,23,42,0.08);
  z-index: 200;
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav ul {
  list-style: none;
  margin: 0; padding: 0;
  height: var(--bottom-nav-height);
  display: flex;
  justify-content: space-around;
  align-items: stretch;
}
.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 8px 2px;
  color: var(--text-muted);
  font-size: 0.62rem;
  font-weight: 600;
}
.bottom-nav a svg { width: 19px; height: 19px; }
.bottom-nav a.active { color: var(--primary-dark); }

/* ------------------------------------------------------------
   Cards / Widgets
   ------------------------------------------------------------ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card { display: flex; flex-direction: column; gap: 6px; }
.stat-card .label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-card .value { font-size: 1.6rem; font-weight: 700; color: var(--primary-dark); }

/* Progress bar */
.progress-track {
  width: 100%;
  height: 10px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #ffcb66);
  border-radius: 999px;
  transition: width 0.4s ease;
}

/* Status badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-pending, .badge-draft, .badge-unpaid { background: #fef3c7; color: #92400e; }
.badge-in-progress, .badge-sent, .badge-partially-paid { background: #e1e5f0; color: var(--primary-dark); }
.badge-completed, .badge-accepted, .badge-paid { background: #dcfce7; color: #166534; }
.badge-declined { background: #fee2e2; color: #991b1b; }
.badge-revision_requested { background: #fde8d0; color: #9a3412; }

/* Tables */
.table-wrap { overflow-x: auto; }

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 20px;
}
.pagination .page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  height: 38px;
  padding: 0 10px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  background: var(--surface);
  border: 1px solid var(--border);
}
.pagination a.page-link:hover { border-color: var(--accent); color: var(--primary-dark); }
.pagination .page-link.active { background: var(--accent); color: var(--primary-dark); border-color: var(--accent); }
.pagination .page-link.disabled { color: var(--text-muted); opacity: 0.5; }
.pagination .page-ellipsis { padding: 0 4px; color: var(--text-muted); }

/* Simple vanilla CSS bar chart (Reports page) */
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  height: 220px;
  padding-top: 20px;
}
.bar-chart-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  min-width: 0;
}
.bar-chart-value { font-size: 0.7rem; color: var(--text-muted); font-weight: 600; margin-bottom: 4px; height: 14px; }
.bar-chart-track {
  flex: 1;
  width: 100%;
  max-width: 34px;
  display: flex;
  align-items: flex-end;
  background: var(--bg-canvas);
  border-radius: 6px 6px 0 0;
  overflow: hidden;
}
.bar-chart-fill {
  width: 100%;
  background: linear-gradient(180deg, var(--accent), #ffcb66);
  border-radius: 6px 6px 0 0;
  min-height: 2px;
  transition: height 0.3s ease;
}
.bar-chart-label { font-size: 0.7rem; color: var(--text-muted); margin-top: 8px; }

@media (max-width: 640px) {
  .bar-chart { height: 160px; gap: 4px; }
  .bar-chart-label { font-size: 0.62rem; }
  .bar-chart-value { font-size: 0.6rem; }
}

/* Quotation negotiation message thread */
.message-thread {
  max-height: 280px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
  padding-right: 4px;
}
.message-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
}
.message-bubble .msg-meta {
  font-size: 0.72rem;
  font-weight: 600;
  margin-bottom: 3px;
  opacity: 0.7;
}
.message-bubble.from-client { align-self: flex-start; background: var(--bg-canvas); border: 1px solid var(--border); }
.message-bubble.from-admin { align-self: flex-end; background: var(--accent); color: var(--primary-dark); }
.message-bubble.from-admin .msg-meta { opacity: 0.85; }
.message-thread-empty { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 16px; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.data-table th, table.data-table td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
table.data-table th { color: var(--text-muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: var(--touch-min) 20px;
  border-radius: var(--radius-md);
  border: none;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
  min-height: 44px; /* accessible touch target */
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: var(--primary-dark); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text-main); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-mpesa { background: #00A651; color: #fff; } /* M-Pesa brand green */
.btn-mpesa:hover { background: #008a43; }
.btn-block { width: 100%; }

/* Forms */
.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 6px; }
.form-control {
  width: 100%;
  padding: var(--touch-min) 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  background: var(--surface);
}
.form-control:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(250,163,26,0.25); }

/* Signature pad (client contract signing) */
.signature-pad-wrap { display: flex; flex-direction: column; align-items: flex-start; }
.signature-pad {
  width: 100%;
  max-width: 440px;
  aspect-ratio: 440 / 150;
  background: #fff;
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  touch-action: none;
  cursor: crosshair;
}

/* ------------------------------------------------------------
   Modal Engine (desktop: center panel / mobile: bottom sheet)
   ------------------------------------------------------------ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 500;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.modal-overlay.is-open { display: flex; opacity: 1; }

.modal-panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: min(520px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: translateY(16px) scale(0.98);
  transition: transform 0.22s ease;
  padding: 28px;
}
.modal-overlay.is-open .modal-panel { transform: translateY(0) scale(1); }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
}

/* Login page */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card { width: min(400px, 100%); }
.auth-logo { text-align: center; margin-bottom: 20px; }

/* ------------------------------------------------------------
   Mobile breakpoint (< 768px)
   ------------------------------------------------------------ */
@media (max-width: 767px) {
  .sidebar { display: none; }
  .mobile-brand-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--mobile-brand-bar-height);
    padding-top: env(safe-area-inset-top, 0px);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 8px rgba(15,23,42,0.05);
    z-index: 200;
  }
  .mobile-brand-bar img {
    height: 32px;
    width: auto;
    max-width: 70%;
    display: block;
  }
  .main-content {
    margin-left: 0;
    padding: 16px;
    padding-top: calc(var(--mobile-brand-bar-height) + env(safe-area-inset-top, 0px) + 16px);
    padding-bottom: calc(var(--bottom-nav-height) + 24px);
  }
  .bottom-nav { display: block; }

  /* Modal becomes a slide-up bottom sheet */
  .modal-overlay { align-items: flex-end; }
  .modal-panel {
    width: 100%;
    max-height: 90vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    transform: translateY(100%);
    padding: 24px 20px calc(20px + env(safe-area-inset-bottom));
  }
  .modal-overlay.is-open .modal-panel { transform: translateY(0); }
  .modal-panel::before {
    content: "";
    display: block;
    width: 40px; height: 4px;
    background: var(--border);
    border-radius: 999px;
    margin: 0 auto 16px;
  }

  .topbar h1 { font-size: 1.2rem; }
  .card-grid { grid-template-columns: 1fr; }

  /* Stacked-card tables — each row becomes a labeled card instead of a
     horizontally-scrolling table. Requires td[data-label] on each cell. */
  table.data-table thead { display: none; }
  table.data-table, table.data-table tbody, table.data-table tr, table.data-table td {
    display: block;
    width: 100%;
  }
  table.data-table tr {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 12px;
    padding: 4px 14px;
    background: var(--surface);
  }
  table.data-table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    text-align: right;
  }
  table.data-table td:last-child { border-bottom: none; }
  table.data-table td::before {
    content: attr(data-label);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    text-align: left;
    flex-shrink: 0;
  }
  /* A cell with no meaningful label (e.g. an actions column) spans full width, stacked. */
  table.data-table td:not([data-label]) {
    justify-content: flex-start;
    flex-wrap: wrap;
  }
}

/* ------------------------------------------------------------
   Print styles — Invoices & Quotations
   ------------------------------------------------------------ */
@media print {
  .sidebar, .bottom-nav, .mobile-brand-bar, .topbar .user-chip, .no-print { display: none !important; }
  .main-content { margin-left: 0; padding: 0; }
  body { background: #fff; }

  .doc-sheet {
    box-shadow: none;
    border: none;
    padding: 0;
    max-width: 100%;
  }
  .doc-accent-bar { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  table.data-table th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .doc-stamp { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  @page { margin: 16mm 14mm; }
}

/* ------------------------------------------------------------
   Document Letterhead — Invoices & Quotations
   ------------------------------------------------------------ */
.doc-page-wrap { padding: 32px 16px; }
.doc-page-wrap .doc-back-link {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 820px;
  margin: 0 auto 16px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9rem;
}
.doc-page-wrap .doc-back-link:hover { color: var(--primary-dark); }

.doc-sheet {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  max-width: 820px;
  margin: 0 auto;
}

/* Thin brand accent bar across the very top of the sheet */
.doc-accent-bar {
  height: 8px;
  background: linear-gradient(90deg, var(--primary-dark) 0%, var(--accent) 100%);
}

.doc-sheet-inner { padding: 40px 44px 44px; }

/* Letterhead header: logo mark + company block on the left, doc type/meta on the right */
.doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 32px;
}
.doc-logo-row { display: flex; align-items: flex-start; gap: 14px; }
.doc-logo-mark {
  width: 52px; height: 52px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--primary-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
  flex-shrink: 0;
  overflow: hidden;
}
.doc-header .company-block strong {
  display: block;
  color: var(--primary-dark);
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.doc-header .company-block span.tagline {
  display: block;
  font-size: 0.78rem;
  color: var(--primary-dark);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 2px;
}
.doc-header .company-block .contact-line {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 6px;
  line-height: 1.5;
}

.doc-meta {
  text-align: right;
  flex-shrink: 0;
}
.doc-meta .doc-type-label {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #fff;
  background: var(--primary-dark);
  padding: 6px 14px;
  border-radius: 999px;
  margin-bottom: 10px;
}
.doc-meta .doc-number {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 6px;
}
.doc-meta .doc-dates {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.6;
}

/* Bill-to strip */
.doc-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  background: var(--bg-canvas);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  margin-bottom: 28px;
}
.doc-parties .party-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.doc-parties .party-name { font-weight: 700; color: var(--text-main); font-size: 0.98rem; }
.doc-parties .party-detail { font-size: 0.85rem; color: var(--text-muted); }

/* Line-item table, letterhead style */
.doc-items-table { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
.doc-items-table thead th {
  text-align: left;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #fff;
  background: var(--primary-dark);
  padding: 11px 14px;
}
.doc-items-table thead th.num { text-align: right; }
.doc-items-table tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
  color: var(--text-main);
}
.doc-items-table tbody td.num { text-align: right; white-space: nowrap; }
.doc-items-table tbody tr:nth-child(even) { background: #f8fafc; }

/* Totals block, right-aligned card */
.doc-totals-block { display: flex; justify-content: flex-end; margin-top: 18px; }
.doc-totals-card { width: 280px; }
.doc-totals-card .row {
  display: flex; justify-content: space-between;
  padding: 8px 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.doc-totals-card .row.grand {
  border-top: 2px solid var(--primary-dark);
  margin-top: 6px;
  padding-top: 12px;
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--primary-dark);
}

/* Payment details box */
.doc-payment-box {
  margin-top: 32px;
  background: var(--bg-canvas);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 16px 20px;
}
.doc-payment-box .box-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.doc-payment-box .box-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  font-size: 0.86rem;
}
.doc-payment-box .box-grid strong { display: block; color: var(--text-main); }

/* Status stamp — sits in the flow under the meta block, so it can never overlap the dates */
.doc-stamp {
  display: inline-block;
  margin-top: 14px;
  transform: rotate(-8deg);
  border: 3px solid var(--success);
  color: var(--success);
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 5px 16px;
  border-radius: 8px;
  opacity: 0.85;
}
.doc-stamp.stamp-unpaid,
.doc-stamp.stamp-declined { border-color: var(--danger); color: var(--danger); }
.doc-stamp.stamp-partially-paid,
.doc-stamp.stamp-sent,
.doc-stamp.stamp-draft { border-color: var(--warning); color: var(--warning); }

/* Footer note + signature strip */
.doc-footer {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  flex-wrap: wrap;
}
.doc-footer .thank-you { font-size: 0.92rem; font-weight: 600; color: var(--primary-dark); }
.doc-footer .fine-print { font-size: 0.76rem; color: var(--text-muted); margin-top: 4px; max-width: 380px; }
.doc-footer .signature-block { text-align: right; font-size: 0.8rem; color: var(--text-muted); }
.doc-footer .signature-line {
  width: 180px;
  border-bottom: 1px solid var(--text-muted);
  margin-bottom: 6px;
  height: 28px;
}

@media (max-width: 640px) {
  .doc-sheet-inner { padding: 28px 20px 32px; }
  .doc-header { flex-direction: column; }
  .doc-meta { text-align: left; }
  .doc-parties { grid-template-columns: 1fr; }
  .doc-footer { flex-direction: column; align-items: flex-start; }
  .doc-footer .signature-block { text-align: left; }
}
