/* ==========================================================================
   Temple Billing - design system
   Tokens -> base -> layout -> components. Page stylesheets only add
   page-specific layout and never redefine these components.
   ========================================================================== */

:root {
  /* Brand */
  --brand: #1e40af;
  --brand-hover: #1a3699;
  --brand-soft: #e8eefc;
  --brand-ring: rgba(30, 64, 175, 0.18);

  /* Surfaces */
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  /* Text */
  --text: #0f172a;
  --text-muted: #64748b;

  /* Sidebar */
  --sidebar-bg: #0f172a;
  --sidebar-border: #1e293b;
  --sidebar-text: #94a3b8;
  --sidebar-hover: #1e293b;
  --sidebar-width: 248px;

  /* Status */
  --success: #15803d;
  --danger: #dc2626;
  --warning: #b45309;

  /* Shape & depth */
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 4px 16px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.18);

  --font: "Segoe UI", system-ui, -apple-system, "Nirmala UI", "Noto Sans Malayalam", Roboto, "Helvetica Neue", Arial, sans-serif;

  /* Bootstrap bridge */
  --bs-body-font-family: var(--font);
  --bs-body-color: var(--text);
  --bs-body-bg: var(--bg);
  --bs-border-color: var(--border);
  --bs-primary: var(--brand);
  --bs-primary-rgb: 30, 64, 175;
  --bs-link-color: var(--brand);
  --bs-link-hover-color: var(--brand-hover);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: var(--font);
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--bg);
  margin: 0;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 { color: inherit; font-weight: 600; letter-spacing: -0.01em; }
label, .form-label { font-weight: 500; font-size: 0.875rem; color: var(--text); margin-bottom: 0.375rem; }
.text-muted, .text-secondary { color: var(--text-muted) !important; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; background-clip: content-box; border: 2px solid transparent; }
::-webkit-scrollbar-track { background: transparent; }

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

/* ==========================================================================
   Layout
   ========================================================================== */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  z-index: 1040;
  overflow-y: auto;
  transition: transform 0.25s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.25rem 1.25rem 1.25rem;
  border-bottom: 1px solid var(--sidebar-border);
}

.brand-mark {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  display: grid;
  place-items: center;
  background: var(--brand);
  color: #fff;
  border-radius: 10px;
  font-size: 1.2rem;
}

.brand-name { color: #fff; font-weight: 700; font-size: 1.05rem; line-height: 1.15; margin: 0; }
.brand-sub { color: var(--sidebar-text); font-size: 0.75rem; }

.sidebar-section {
  padding: 1.25rem 1.25rem 0.5rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #64748b;
}

.sidebar .nav { padding: 0 0.75rem; gap: 2px; }

.sidebar .nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-weight: 500;
  font-size: 0.9rem;
  transition: background 0.15s, color 0.15s;
}

.sidebar .nav-link .bi { font-size: 1.05rem; width: 1.25rem; text-align: center; flex: 0 0 1.25rem; }
.sidebar .nav-link:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar .nav-link.active { background: var(--brand); color: #fff; }

.sidebar-footer {
  padding: 1rem 1.25rem 1.25rem;
  border-top: 1px solid var(--sidebar-border);
  font-size: 0.8125rem;
}

.sidebar-clock { display: flex; flex-direction: column; gap: 2px; margin-bottom: 0.875rem; }
.sidebar-clock .time { color: #fff; font-size: 1.25rem; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.2; }
.sidebar-clock .date { color: var(--sidebar-text); }

.sidebar-logout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius-sm);
  color: #fca5a5;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.sidebar-logout:hover { background: #7f1d1d; color: #fff; border-color: #7f1d1d; }

.sidebar-credit { margin-top: 0.875rem; color: #64748b; font-size: 0.6875rem; line-height: 1.5; text-align: center; }

.topbar { display: none; }
.sidebar-backdrop { display: none; }

.content {
  margin-left: var(--sidebar-width);
  padding: 1.75rem 2rem 2rem;
  min-height: 100vh;
}

/* Pages wrap their body in .container; keep one consistent column width. */
.content .container {
  max-width: 1280px;
  padding-left: 0;
  padding-right: 0;
  margin: 0 auto;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  margin-bottom: 1.5rem;
}
.page-title { display: flex; align-items: center; gap: 0.75rem; margin: 0; font-size: 1.375rem; font-weight: 700; }
.page-title .bi { color: var(--brand); font-size: 1.35rem; }
.page-subtitle { margin: 0.125rem 0 0; color: var(--text-muted); font-size: 0.875rem; }

@media (max-width: 991.98px) {
  .topbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    height: 56px;
    padding: 0 1rem;
    background: var(--sidebar-bg);
    color: #fff;
  }
  .topbar .menu-btn { background: none; border: 0; color: #fff; font-size: 1.5rem; line-height: 1; padding: 0.25rem; }
  .topbar .brand-name { font-size: 1rem; }

  .sidebar { transform: translateX(-100%); }
  body.sidebar-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  body.sidebar-open .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 1035;
  }

  .content { margin-left: 0; padding: 1.25rem 1rem 1.5rem; min-height: calc(100vh - 56px); }
}

@media (max-width: 767.98px) {
  /* Wide tables scroll sideways instead of squeezing their columns. */
  .table-responsive > .table { min-width: 640px; }
}

/* ==========================================================================
   Components
   ========================================================================== */

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.875rem 1.25rem;
  border-radius: var(--radius) var(--radius) 0 0 !important;
}
.card-header h5, .card-header h6 { margin: 0; font-size: 1rem; font-weight: 600; }
.card-title { font-size: 0.8125rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }
.card-body { padding: 1.25rem; }
.list-group { --bs-list-group-bg: var(--surface); --bs-list-group-border-color: var(--border); }
.list-group-item { padding: 0.75rem 1.25rem; }

/* ---------- Buttons ---------- */
.btn {
  --bs-btn-font-weight: 500;
  --bs-btn-border-radius: var(--radius-sm);
  --bs-btn-padding-x: 1rem;
  --bs-btn-padding-y: 0.45rem;
  --bs-btn-font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  box-shadow: none;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.btn-sm { --bs-btn-padding-x: 0.75rem; --bs-btn-padding-y: 0.3rem; --bs-btn-font-size: 0.8125rem; }
.btn-lg { --bs-btn-padding-x: 1.25rem; --bs-btn-padding-y: 0.65rem; --bs-btn-font-size: 1rem; }
.btn:focus-visible { box-shadow: 0 0 0 3px var(--brand-ring); outline: none; }

/* Primary actions: btn-primary and btn-dark share the brand colour. */
.btn-primary, .btn-dark {
  --bs-btn-color: #fff;
  --bs-btn-bg: var(--brand);
  --bs-btn-border-color: var(--brand);
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: var(--brand-hover);
  --bs-btn-hover-border-color: var(--brand-hover);
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: var(--brand-hover);
  --bs-btn-active-border-color: var(--brand-hover);
  --bs-btn-disabled-bg: var(--brand);
  --bs-btn-disabled-border-color: var(--brand);
}

/* Secondary / neutral outline actions */
.btn-outline-dark, .btn-outline-secondary {
  --bs-btn-color: #334155;
  --bs-btn-bg: var(--surface);
  --bs-btn-border-color: var(--border-strong);
  --bs-btn-hover-color: var(--text);
  --bs-btn-hover-bg: var(--surface-muted);
  --bs-btn-hover-border-color: #94a3b8;
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: var(--brand);
  --bs-btn-active-border-color: var(--brand);
}
.btn-outline-primary {
  --bs-btn-color: var(--brand);
  --bs-btn-border-color: #b9c7ee;
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: var(--brand);
  --bs-btn-hover-border-color: var(--brand);
  --bs-btn-active-bg: var(--brand);
  --bs-btn-active-border-color: var(--brand);
}
.btn-outline-danger { --bs-btn-border-color: #f5b5b5; }
.btn-outline-info { --bs-btn-color: #0e7490; --bs-btn-border-color: #a5d8e6; --bs-btn-hover-bg: #0e7490; --bs-btn-hover-border-color: #0e7490; --bs-btn-hover-color: #fff; }
.btn-secondary { --bs-btn-bg: #64748b; --bs-btn-border-color: #64748b; --bs-btn-hover-bg: #475569; --bs-btn-hover-border-color: #475569; }
.btn-success { --bs-btn-bg: var(--success); --bs-btn-border-color: var(--success); --bs-btn-hover-bg: #166534; --bs-btn-hover-border-color: #166534; }
.btn-warning { --bs-btn-color: #422006; }

.btn-close:focus { box-shadow: 0 0 0 3px var(--brand-ring); }

/* ---------- Forms ---------- */
.form-control, .form-select {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
}
.form-control::placeholder { color: #94a3b8; }
.form-control:focus, .form-select:focus {
  background-color: var(--surface);
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
}
.form-control:disabled, .form-select:disabled { background-color: var(--surface-muted); color: var(--text-muted); }
.input-group-text { background: var(--surface-muted); border-color: var(--border-strong); color: var(--text-muted); }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.form-check-input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.form-switch .form-check-input { cursor: pointer; }

/* ---------- Tables ---------- */
.table {
  --bs-table-bg: transparent;
  --bs-table-hover-bg: var(--surface-muted);
  --bs-table-border-color: var(--border);
  margin-bottom: 0;
  color: var(--text);
}
.table > :not(caption) > * > * { padding: 0.8rem 1rem; vertical-align: middle; }
.table thead th {
  background: var(--surface-muted);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.table-light { --bs-table-bg: var(--surface-muted); }
.table > tbody > tr:last-child > * { border-bottom-width: 0; }

.table-responsive {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}
.table-responsive + .report-summary { margin-top: 1.25rem; }
.card > .table-responsive { border: 0; border-radius: 0 0 var(--radius) var(--radius); box-shadow: none; }

/* ---------- Badges ---------- */
.badge { font-weight: 600; padding: 0.4em 0.7em; border-radius: 999px; }

/* ---------- Modals ---------- */
.modal-content { border: 0; border-radius: var(--radius-lg) !important; box-shadow: var(--shadow-lg); overflow: hidden; background: var(--surface); }
.modal-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.modal-header.bg-dark, .modal-header.bg-primary { background: var(--sidebar-bg) !important; color: #fff; border-bottom: 0; }
.modal-header.bg-danger { border-bottom: 0; }
.modal-title { font-size: 1.05rem; font-weight: 600; }
.modal-body { padding: 1.25rem; }
.modal-footer { padding: 0.875rem 1.25rem; border-top: 1px solid var(--border); background: var(--surface-muted); gap: 0.5rem; }
.modal-footer > * { margin: 0; }

/* ---------- Autocomplete dropdowns ---------- */
[id$="suggestions"], [id*="suggestions_fam_"] {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 1056;
  max-height: 220px;
  overflow-y: auto;
}
[id$="suggestions"] .list-group-item,
[id*="suggestions_fam_"] .list-group-item,
#suggestions .item {
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  cursor: pointer;
  user-select: none;
  border: 0;
  background: transparent;
  color: var(--text);
}
[id$="suggestions"] .list-group-item:hover,
[id*="suggestions_fam_"] .list-group-item:hover,
#suggestions .item:hover { background: var(--surface-muted); }
[id$="suggestions"] .list-group-item.active,
[id*="suggestions_fam_"] .list-group-item.active,
#suggestions .item.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }

/* ---------- Alerts ---------- */
.alert { border: 0; border-radius: var(--radius-sm); font-size: 0.9rem; }

/* Summary tiles (also used inside printed reports) */
.report-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.report-summary .stat {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.stat-label { font-size: 0.75rem; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-muted); }
.stat-value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Empty / status helpers ---------- */
.empty-state { padding: 2.5rem 1rem; text-align: center; color: var(--text-muted); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
