/* Solar Street Light CRM — hand-written CSS (no build step needed) */

:root {
  --background: #f4f7f5;
  --foreground: #16211b;
  --brand: #0f7a4d;
  --brand-dark: #0b5c3a;
  --brand-light: #e6f4ec;
  --border: #e2e8f0;
  --muted: #64748b;
  --muted-light: #f8fafc;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --warn: #b45309;
  --warn-light: #fffbeb;
  --sidebar-w: 16rem;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: var(--background);
  color: var(--foreground);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }

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

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

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 30;
  height: 3.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: #fff;
  padding: 0 1rem;
}
@media (min-width: 768px) { .topbar { display: none; } }

.topbar-btn {
  border: none;
  background: none;
  padding: 0.5rem;
  border-radius: 0.375rem;
  color: #475569;
  cursor: pointer;
}
.topbar-btn:hover { background: #f1f5f9; }
.topbar-title { font-size: 0.875rem; font-weight: 700; color: var(--brand-dark); }

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0,0,0,0.4);
  display: none;
}
.backdrop.open { display: block; }
@media (min-width: 768px) { .backdrop { display: none !important; } }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 50;
  width: 18rem;
  max-width: 85vw;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: #fff;
  transform: translateX(-100%);
  transition: transform 0.2s ease;
}
.sidebar.open { transform: translateX(0); }
@media (min-width: 768px) {
  .sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    width: var(--sidebar-w);
    max-width: none;
    transform: none;
    z-index: 0;
  }
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: 3.5rem;
  border-bottom: 1px solid #f1f5f9;
  padding: 0 1.25rem;
  flex-shrink: 0;
}
.sidebar-brand .emoji { font-size: 1.25rem; }
.sidebar-brand .text { font-size: 0.875rem; font-weight: 700; line-height: 1.2; color: var(--brand-dark); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 1rem 0.75rem; }
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-radius: 0.5rem;
  padding: 0.625rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: #475569;
  margin-bottom: 0.125rem;
}
.sidebar-nav a:hover { background: #f8fafc; }
.sidebar-nav a.active { background: var(--brand-light); color: var(--brand-dark); }
.sidebar-nav .icon { font-size: 1rem; }

.sidebar-footer { border-top: 1px solid #f1f5f9; padding: 1rem; flex-shrink: 0; }
.sidebar-user { border-radius: 0.5rem; background: #f8fafc; padding: 0.625rem 0.75rem; margin-bottom: 0.75rem; }
.sidebar-user .name { font-size: 0.875rem; font-weight: 600; color: #1e293b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .role { font-size: 0.75rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .company { font-size: 0.75rem; color: #94a3b8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.btn-signout {
  display: flex; width: 100%; align-items: center; justify-content: center;
  gap: 0.5rem; border-radius: 0.5rem; border: 1px solid var(--border);
  padding: 0.5rem 0.75rem; font-size: 0.875rem; font-weight: 500; color: #475569;
  background: #fff; cursor: pointer;
}
.btn-signout:hover { background: #f8fafc; }

.main-content { min-width: 0; flex: 1; padding: 5rem 1rem 2.5rem; }
@media (min-width: 768px) { .main-content { padding: 2rem 2rem 2.5rem; } }
.main-inner { max-width: 80rem; margin: 0 auto; }

/* ---------- Page header ---------- */

.page-header { margin-bottom: 1.5rem; display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.page-header h1 { margin: 0 0 0.25rem; font-size: 1.5rem; font-weight: 700; color: #0f172a; }
.page-header p { margin: 0; color: var(--muted); font-size: 0.9rem; }

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

.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.card h2 { margin: 0 0 1rem; font-size: 1.05rem; font-weight: 600; color: #0f172a; }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; margin-bottom: 1.5rem; }
@media (min-width: 640px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1024px) { .stat-grid { grid-template-columns: repeat(5, 1fr); } }
.stat-card { background: #fff; border: 1px solid var(--border); border-radius: 0.75rem; padding: 1rem; }
.stat-card .label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 0.35rem; }
.stat-card .value { font-size: 1.6rem; font-weight: 700; color: var(--brand-dark); }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  border-radius: 0.5rem; border: 1px solid transparent; cursor: pointer;
  font-size: 0.875rem; font-weight: 600; padding: 0.55rem 1rem; text-decoration: none;
  line-height: 1.2;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: #fff; border-color: var(--border); color: #334155; }
.btn-secondary:hover { background: #f8fafc; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }

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

.field { margin-bottom: 1rem; }
.field label { display: block; font-size: 0.8rem; font-weight: 600; color: #334155; margin-bottom: 0.3rem; }
.field .hint { font-size: 0.75rem; color: var(--muted); margin-top: 0.25rem; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=tel], select, textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 0.5rem;
  padding: 0.55rem 0.7rem; font-size: 0.9rem; font-family: inherit; background: #fff; color: var(--foreground);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }
input.input-duplicate, input.input-missing, select.input-missing {
  border-color: var(--danger); background: #fef2f2; color: #7f1d1d;
}
input.input-duplicate:focus, input.input-missing:focus, select.input-missing:focus {
  outline-color: var(--danger); border-color: var(--danger);
}
textarea { resize: vertical; min-height: 4.5rem; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 640px) { .form-grid.cols-2 { grid-template-columns: 1fr 1fr; } }
@media (min-width: 640px) { .form-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; } }
.form-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 1.25rem; }

/* ---------- Stock receiving: mode toggle + dynamic serial rows ---------- */

.mode-toggle { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.mode-toggle-option {
  display: flex; align-items: center; gap: 0.45rem;
  border: 1px solid var(--border); border-radius: 0.5rem;
  padding: 0.55rem 0.9rem; font-size: 0.85rem; font-weight: 600; color: #334155;
  background: #fff; cursor: pointer;
}
.mode-toggle-option input { margin: 0; }
.mode-toggle-option:has(input:checked) { border-color: var(--brand); background: var(--brand-light); color: var(--brand-dark); }
.serial-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); gap: 0.5rem 0.6rem; margin-top: 0.5rem; }
.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0.4rem; }
.checkbox-grid label {
  display: flex; align-items: center; gap: 0.35rem;
  font-weight: 400; font-size: 0.85rem; color: #334155;
  border: 1px solid var(--border); border-radius: 0.4rem; padding: 0.3rem 0.55rem;
}
.checkbox-grid label span { font-family: monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

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

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
th, td { text-align: left; padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); font-weight: 600; background: var(--muted-light); }
tbody tr:hover { background: #fafcfb; }
td.wrap, th.wrap { white-space: normal; }

/* ---------- Badges ---------- */

.badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.2rem 0.6rem; border-radius: 999px; font-size: 0.72rem; font-weight: 600;
  white-space: nowrap;
}
.badge-green { background: var(--brand-light); color: var(--brand-dark); }
.badge-amber { background: var(--warn-light); color: var(--warn); }
.badge-slate { background: #f1f5f9; color: #475569; }
.badge-red { background: var(--danger-light); color: var(--danger); }
.badge-blue { background: #eff6ff; color: #1d4ed8; }

/* ---------- Alerts / flash ---------- */

.alert { border-radius: 0.5rem; padding: 0.75rem 1rem; margin-bottom: 1.25rem; font-size: 0.875rem; border: 1px solid transparent; }
.alert-success { background: var(--brand-light); color: var(--brand-dark); border-color: #bfe3cf; }
.alert-error { background: var(--danger-light); color: var(--danger); border-color: #fecaca; }
.alert-info { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }

/* ---------- Auth pages ---------- */

.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.auth-card { width: 100%; max-width: 24rem; background: #fff; border: 1px solid var(--border); border-radius: 1rem; padding: 2rem; }
.auth-card .logo { text-align: center; font-size: 2rem; margin-bottom: 0.5rem; }
.auth-card h1 { text-align: center; font-size: 1.15rem; margin: 0 0 0.25rem; color: var(--brand-dark); }
.auth-card .sub { text-align: center; color: var(--muted); font-size: 0.85rem; margin-bottom: 1.5rem; }

/* ---------- Modal (status change confirm) ---------- */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; background: rgba(15,23,42,0.5);
  display: none; align-items: center; justify-content: center; padding: 1rem;
}
.modal-backdrop.open { display: flex; }
.modal-box { background: #fff; border-radius: 0.75rem; max-width: 30rem; width: 100%; padding: 1.5rem; }
.modal-box h3 { margin: 0 0 0.5rem; font-size: 1.05rem; color: #0f172a; }
.modal-box p { margin: 0 0 1rem; color: #475569; font-size: 0.875rem; }

/* ---------- Photo grid ---------- */

.photo-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
@media (min-width: 640px) { .photo-grid { grid-template-columns: repeat(4, 1fr); } }
.photo-card { border: 1px solid var(--border); border-radius: 0.6rem; overflow: hidden; background: #fff; }
.photo-card .thumb { aspect-ratio: 1; background: #f1f5f9; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.photo-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-card .meta { padding: 0.5rem 0.6rem; font-size: 0.72rem; color: var(--muted); }
.photo-card .meta .type { font-weight: 700; color: #0f172a; display: block; margin-bottom: 0.15rem; font-size: 0.78rem; }

/* ---------- Misc ---------- */

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty-state .icon { font-size: 2rem; margin-bottom: 0.5rem; }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }
.mb-0 { margin-bottom: 0 !important; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; }
.gap-2 { gap: 0.5rem; }
.stack { display: flex; flex-direction: column; gap: 0.5rem; }
.pill-row { display: flex; flex-wrap: wrap; gap: 0.4rem; }
hr.sep { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }

/* ---------- Installer (field) app shell ---------- */

.installer-body { background: #f8fafc; min-height: 100vh; display: flex; flex-direction: column; }
.installer-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border); background: #fff; padding: 0.75rem 1rem;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.installer-header .brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; color: var(--brand-dark); font-size: 0.9rem; }
.installer-header .right { display: flex; align-items: center; gap: 0.75rem; }
.installer-header .uname { font-size: 0.85rem; color: #475569; }
.installer-main { max-width: 40rem; width: 100%; margin: 0 auto; flex: 1; padding: 1.25rem 1rem; }

/* ---------- Print styles for DC / JCR ---------- */

@media print {
  .no-print { display: none !important; }
  .print-only { display: block !important; }
  body { background: #fff !important; }
  .print-sheet { box-shadow: none !important; margin: 0 !important; padding: 0 !important; max-width: 100% !important; }
  @page { margin: 12mm; }
}
.print-only { display: none; }

/* ---------- Supervisor (read-only oversight) app nav row ---------- */

.supervisor-nav {
  display: flex; flex-wrap: wrap; gap: 1rem;
  max-width: 40rem; width: 100%; margin: 0 auto; padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border); background: #fff;
}
.supervisor-nav a { font-size: 0.85rem; font-weight: 600; color: var(--muted); text-decoration: none; }
.supervisor-nav a:hover { color: var(--brand-dark); }
.supervisor-nav a.active { color: var(--brand-dark); text-decoration: underline; }

/* ---------- Work Orders: village entry (workorder_new.php / workorder_edit.php) ---------- */
/* Every village is typed directly, right where it's used — there's no
   picking from a saved list anywhere in the work order flow. */

/* workorder_edit.php's single "+ Add another village" row: a responsive
   card of plain fields (auto-fit means it reflows itself instead of relying
   on a fixed column count, since this card holds more fields than it used
   to now that village name/block/district/sarpanch are always inline). */
.wo-line-item-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 0.75rem;
  align-items: start;
  padding: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: #fff;
}
.wo-line-item-row .field { margin-bottom: 0; }

/* workorder_new.php's village table: one header row, one compact <tr> per
   village (with a plain running serial number), instead of a repeated card
   per row. Cloned <tr>s land in #wo-line-items (a <tbody>); see
   initWorkOrderLineItems() in app.js. */
.wo-table td, .wo-table th { vertical-align: middle; white-space: normal; }
.wo-table td select, .wo-table td > input[type=text] { width: 100%; }
.wo-table input.wo-qty-input, .wo-table input.wo-rate-input { width: 6rem; }
.wo-table .wo-line-item-remove { padding: 0.4rem 0.6rem; line-height: 1; }
.wo-row-num { color: var(--muted); font-variant-numeric: tabular-nums; text-align: center; }

/* ---------- Work Order Excel/CSV import (wo_import.php) ---------- */

.import-mapping-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 640px) { .import-mapping-grid { grid-template-columns: 1fr; } }
.import-preview-table th { white-space: nowrap; }
.import-header-row td { background: var(--muted-light); }
