/* ============================================================================
   CHANACHUR FACTORY ERP — Pre-Compiled Production Stylesheet
   Mobile-First | Khata Book + Modern POS + ERP Design | Dark Mode | Print A4/80mm
   ============================================================================ */
:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-soft: #eff6ff;
  --success: #059669;
  --success-soft: #ecfdf5;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
  --radius: 14px;
}

html.dark {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-alt: #334155;
  --border: #334155;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-soft: rgba(59, 130, 246, 0.16);
  --success: #10b981;
  --success-soft: rgba(16, 185, 129, 0.16);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.16);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, 0.16);
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
  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; }
.sidebar {
  width: 260px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 40; display: flex; flex-direction: column;
  transition: transform 0.25s ease, width 0.25s ease;
}
.sidebar.collapsed { width: 76px; }
.sidebar.collapsed .nav-label, .sidebar.collapsed .brand-text, .sidebar.collapsed .nav-section-title { display: none; }
.sidebar-header {
  padding: 16px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; min-height: 64px;
}
.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 10px 80px; }
.nav-section-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); padding: 12px 12px 6px;
}
.nav-link {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
  font-size: 14px; font-weight: 500; color: var(--text-muted); margin-bottom: 2px;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: var(--surface-alt); color: var(--text); }
.nav-link.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }

.main-area {
  flex: 1; margin-left: 260px; display: flex; flex-direction: column; min-width: 0;
  transition: margin-left 0.25s ease;
}
.main-area.sidebar-collapsed { margin-left: 76px; }
.topbar {
  height: 64px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30; padding: 0 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.page-body { flex: 1; padding: 20px; max-width: 1440px; width: 100%; margin: 0 auto; }

/* Mobile Bottom Nav & Responsive Drawer */
.mobile-bottom-nav { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 1023px) {
  .sidebar { transform: translateX(-100%); width: 270px !important; }
  .sidebar.mobile-open { transform: translateX(0); }
  .sidebar-backdrop.open {
    display: block; position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5); z-index: 35;
  }
  .main-area, .main-area.sidebar-collapsed { margin-left: 0; }
  .page-body { padding: 14px 12px 86px; }
  .topbar { padding: 0 12px; }
  .mobile-bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 35;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 4px env(safe-area-inset-bottom, 6px);
    box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.08);
  }
  .mobile-bottom-item {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; font-size: 11px; font-weight: 600; color: var(--text-muted); padding: 4px 2px; border-radius: 10px;
  }
  .mobile-bottom-item.active { color: var(--primary); }
  .mobile-fab {
    background: var(--primary); color: #fff !important; border-radius: 14px;
    padding: 6px 8px; box-shadow: 0 4px 10px rgba(29, 78, 216, 0.35);
  }
}

/* Cards, Buttons & Inputs */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card-header {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
}
.card-body { padding: 18px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 4px;
}
.stat-label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.stat-value { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 600;
  border: 1px solid transparent; cursor: pointer; transition: all 0.15s; white-space: nowrap;
  min-height: 42px;
}
.btn-sm { padding: 6px 12px; font-size: 12.5px; min-height: 34px; border-radius: 8px; }
.btn-lg { padding: 14px 20px; font-size: 16px; min-height: 52px; border-radius: 12px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(0.95); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.95); }
.btn-outline { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-outline:hover { background: var(--surface-alt); }
.btn-whatsapp { background: #16a34a; color: #fff; }
.btn-sms { background: #0284c7; color: #fff; }

.label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }
.input, .select, .textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; font-size: 14px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  min-height: 42px; outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.15);
}
.textarea { min-height: 80px; resize: vertical; }

/* Badges & Alerts */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-neutral { background: var(--surface-alt); color: var(--text-muted); }

.alert { padding: 12px 16px; border-radius: 12px; font-size: 13.5px; font-weight: 500; border: 1px solid transparent; }
.alert-success { background: var(--success-soft); color: var(--success); border-color: rgba(16, 185, 129, 0.25); }
.alert-danger { background: var(--danger-soft); color: var(--danger); border-color: rgba(239, 68, 68, 0.25); }
.alert-warning { background: var(--warning-soft); color: var(--warning); border-color: rgba(245, 158, 11, 0.25); }

/* Responsive Tables & Mobile Card Lists */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; padding: 11px 14px; font-size: 11.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--text-muted); background: var(--surface-alt); border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: rgba(148, 163, 184, 0.06); }

/* Khata Book Action Bar (BORROW RED / PAID GREEN) */
.khata-actions {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
.khata-btn-red {
  background: #dc2626; color: #fff; font-weight: 800; font-size: 16px;
  padding: 15px 16px; border-radius: 14px; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 6px 14px rgba(220, 38, 38, 0.28);
}
.khata-btn-green {
  background: #059669; color: #fff; font-weight: 800; font-size: 16px;
  padding: 15px 16px; border-radius: 14px; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 6px 14px rgba(5, 150, 105, 0.28);
}

/* Modal / Mobile Bottom Sheet */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55); z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-box {
  background: var(--surface); border-radius: 18px; max-width: 540px; width: 100%;
  max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
@media (max-width: 640px) {
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal-box { border-radius: 20px 20px 0 0; max-width: 100%; max-height: 88vh; }
}

/* Attendance Calendar Grid */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-cell {
  border-radius: 10px; padding: 8px 4px; text-align: center; border: 1px solid var(--border);
  font-size: 12px; font-weight: 700; min-height: 54px; display: flex; flex-direction: column; justify-content: center; align-items: center;
}
.cal-present { background: var(--success-soft); color: var(--success); border-color: rgba(16, 185, 129, 0.35); }
.cal-absent  { background: var(--danger-soft); color: var(--danger); border-color: rgba(239, 68, 68, 0.35); }
.cal-half    { background: var(--warning-soft); color: var(--warning); border-color: rgba(245, 158, 11, 0.35); }
.cal-leave   { background: var(--primary-soft); color: var(--primary); border-color: rgba(59, 130, 246, 0.35); }

/* Toast Container */
#toast-container {
  position: fixed; top: 16px; right: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: 340px;
}
.toast {
  padding: 12px 16px; border-radius: 12px; font-size: 13.5px; font-weight: 600; color: #fff;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.18); animation: fadeIn 0.2s ease;
}
.toast-success { background: #059669; }
.toast-error { background: #dc2626; }
.toast-info { background: #1d4ed8; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

/* Utility Classes (Pre-Compiled Tailwind-Compatible Subset) */
.flex { display: flex; } .inline-flex { display: inline-flex; } .grid { display: grid; } .hidden { display: none; }
.flex-col { flex-direction: column; } .flex-wrap { flex-wrap: wrap; } .flex-1 { flex: 1 1 0%; }
.items-center { align-items: center; } .items-start { align-items: flex-start; } .justify-between { justify-content: space-between; } .justify-center { justify-content: center; } .justify-end { justify-content: flex-end; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; } .gap-5 { gap: 20px; } .gap-6 { gap: 24px; }
.grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (min-width: 640px) {
  .sm\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sm\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sm\:col-span-2 { grid-column: span 2 / span 2; }
  .sm\:flex-row { flex-direction: row; }
}
@media (min-width: 768px) {
  .md\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .md\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .md\:grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .md\:table { display: table; } .md\:hidden { display: none; }
}
@media (min-width: 1024px) {
  .lg\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lg\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .lg\:grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .lg\:col-span-2 { grid-column: span 2 / span 2; }
  .lg\:hidden { display: none; }
  .lg\:flex { display: flex; }
}
.w-full { width: 100%; } .w-10 { width: 40px; } .h-10 { height: 40px; } .w-16 { width: 64px; } .h-16 { height: 64px; }
.max-w-md { max-width: 28rem; } .max-w-2xl { max-width: 42rem; } .max-w-4xl { max-width: 56rem; } .mx-auto { margin-left: auto; margin-right: auto; }
.min-h-screen { min-height: 100vh; }
.p-2 { padding: 8px; } .p-2\.5 { padding: 10px; } .p-3 { padding: 12px; } .p-4 { padding: 16px; } .p-5 { padding: 20px; } .p-6 { padding: 24px; } .p-8 { padding: 32px; }
.px-3 { padding-left: 12px; padding-right: 12px; } .px-4 { padding-left: 16px; padding-right: 16px; }
.py-2 { padding-top: 8px; padding-bottom: 8px; } .py-3 { padding-top: 12px; padding-bottom: 12px; } .py-8 { padding-top: 32px; padding-bottom: 32px; }
.mb-1 { margin-bottom: 4px; } .mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; } .mb-5 { margin-bottom: 20px; } .mb-6 { margin-bottom: 24px; }
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; } .mt-6 { margin-top: 24px; }
.space-y-3 > * + * { margin-top: 12px; } .space-y-4 > * + * { margin-top: 16px; } .space-y-5 > * + * { margin-top: 20px; }
.text-xs { font-size: 12px; } .text-sm { font-size: 13.5px; } .text-base { font-size: 15px; } .text-lg { font-size: 17px; } .text-xl { font-size: 20px; } .text-2xl { font-size: 24px; } .text-4xl { font-size: 36px; }
.font-medium { font-weight: 500; } .font-semibold { font-weight: 600; } .font-bold { font-weight: 700; } .font-extrabold { font-weight: 800; }
.uppercase { text-transform: uppercase; } .tracking-wider { letter-spacing: 0.06em; }
.text-center { text-align: center; } .text-right { text-align: right; } .text-left { text-align: left; }
.text-slate-900 { color: var(--text); } .text-slate-600 { color: var(--text-muted); } .text-slate-500 { color: var(--text-muted); }
.text-blue-700 { color: var(--primary); } .text-emerald-600, .text-emerald-700, .text-emerald-800 { color: var(--success); }
.text-red-600, .text-red-700 { color: var(--danger); } .text-amber-600, .text-amber-700 { color: var(--warning); }
.bg-slate-50 { background: var(--bg); } .bg-white { background: var(--surface); } .bg-emerald-50 { background: var(--success-soft); } .bg-red-50 { background: var(--danger-soft); } .bg-blue-50 { background: var(--primary-soft); } .bg-amber-50 { background: var(--warning-soft); }
.rounded-lg { border-radius: 10px; } .rounded-xl { border-radius: 14px; } .rounded-2xl { border-radius: 18px; } .rounded-full { border-radius: 9999px; }
.border { border: 1px solid var(--border); } .border-t { border-top: 1px solid var(--border); } .border-b { border-bottom: 1px solid var(--border); }
.shadow { box-shadow: var(--shadow); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Print Styles (A4 & 80mm Thermal) */
@media print {
  .no-print, .sidebar, .topbar, .mobile-bottom-nav, #toast-container { display: none !important; }
  .main-area { margin-left: 0 !important; }
  body { background: #fff !important; color: #000 !important; }
  .card { border: none !important; box-shadow: none !important; }
}
.thermal-sheet {
  width: 78mm; margin: 0 auto; font-family: "Courier New", Courier, monospace; font-size: 12px; color: #000; background: #fff; padding: 8px;
}
