:root {
  --primary: #1a56db;
  --primary-dark: #1e40af;
  --primary-soft: #eff6ff;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --sidebar-bg: #0f172a;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --success: #059669;
  --success-bg: #d1fae5;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --purple: #7c3aed;
  --purple-bg: #ede9fe;
  --radius: 14px;
  --sidebar-w: 256px;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Inter', 'Noto Sans Devanagari', sans-serif; -webkit-tap-highlight-color: transparent; }
body { background: var(--bg); color: var(--text); min-height: 100vh; overflow-x: hidden; }

#authScreen {
  position: fixed; inset: 0; z-index: 500;
  background: linear-gradient(135deg, #0f172a 0%, #1d4ed8 100%);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.auth-card {
  background: #fff; width: 100%; max-width: 410px; border-radius: 18px;
  padding: 24px 20px; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.4);
}
.auth-logo {
  width: 50px; height: 50px; border-radius: 14px; background: var(--primary-soft);
  color: var(--primary); display: flex; align-items: center; justify-content: center; margin-bottom: 12px;
}

#appShell { display: none; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); background: var(--sidebar-bg); color: #f8fafc;
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 130;
  display: flex; flex-direction: column; transition: transform 0.25s ease;
}
.brand { padding: 15px 16px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid #1e293b; }
.brand-img {
  width: 36px; height: 36px; border-radius: 10px; background: #1e293b;
  display: flex; align-items: center; justify-content: center; overflow: hidden; flex-shrink: 0;
}
.brand-img img { width: 100%; height: 100%; object-fit: cover; }
.nav-list { flex: 1; overflow-y: auto; padding: 8px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  border-radius: 9px; color: #cbd5e1; cursor: pointer;
  font-size: 13px; font-weight: 500; margin-bottom: 3px; transition: 0.15s;
}
.nav-item:hover { background: #1e293b; color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; font-weight: 600; }
.nav-item .material-icons-round { font-size: 18px; }
.lock-tag { margin-left: auto; font-size: 10px; background: rgba(255,255,255,0.14); padding: 2px 6px; border-radius: 6px; }
.sidebar-foot {
  padding: 11px 14px; border-top: 1px solid #1e293b; font-size: 11.5px; color: #94a3b8;
  display: flex; align-items: center; justify-content: space-between;
}

.main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-width: 0; padding-bottom: 72px; }
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 10px 16px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 80; gap: 8px;
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.icon-btn {
  background: #f8fafc; border: 1px solid var(--border); width: 36px; height: 36px;
  border-radius: 10px; display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text);
}
.menu-btn { display: none; }
.page-title { font-size: 15.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700;
  padding: 4px 10px; border-radius: 20px; background: var(--success-bg); color: var(--success);
}
.pill.warn { background: var(--warning-bg); color: var(--warning); }
.pill.danger { background: var(--danger-bg); color: var(--danger); }

.content { padding: 16px; max-width: 1440px; width: 100%; margin: 0 auto; }
.section { display: none; }
.section.active { display: block; animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.banner {
  padding: 12px 14px; border-radius: 12px; margin-bottom: 14px;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px;
}
.banner.warn { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.banner.danger { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); gap: 11px; margin-bottom: 16px; }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 13px; }
.kpi-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.kpi-label { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.kpi-ico { width: 28px; height: 28px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 16px; }
.kpi-val { font-size: 19px; font-weight: 800; }
.kpi-sub { font-size: 11px; color: var(--muted); margin-top: 3px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 15px; margin-bottom: 15px; }
.card-header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-title { font-size: 14.5px; font-weight: 700; display: flex; align-items: center; gap: 7px; }

.prog-track { height: 9px; background: #e2e8f0; border-radius: 10px; overflow: hidden; margin: 8px 0; }
.prog-bar { height: 100%; background: var(--primary); border-radius: 10px; transition: width 0.3s; }
.prog-bar.warn { background: var(--warning); }
.prog-bar.danger { background: var(--danger); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  padding: 8px 13px; border-radius: 9px; border: none;
  font-size: 12.5px; font-weight: 600; cursor: pointer; transition: 0.15s; white-space: nowrap;
}
.btn .material-icons-round { font-size: 16px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-outline { background: #fff; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: #f8fafc; }
.btn-success { background: var(--success-bg); color: var(--success); }
.btn-warning { background: var(--warning-bg); color: var(--warning); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-sm { padding: 5px 9px; font-size: 11.5px; border-radius: 7px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.input, select, textarea {
  padding: 8px 11px; border: 1px solid var(--border); border-radius: 9px;
  font-size: 13px; outline: none; background: #fff; color: var(--text);
}
.input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,86,219,0.12); }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th, td { text-align: left; padding: 10px; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
th { background: #f8fafc; font-weight: 600; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.3px; }
tr:hover td { background: #fafcff; }

.person-cell { display: flex; align-items: center; gap: 9px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--primary-soft);
  color: var(--primary); font-weight: 700; display: flex; align-items: center;
  justify-content: center; overflow: hidden; flex-shrink: 0; font-size: 13px;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.badge { padding: 3px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; display: inline-block; }
.b-active, .b-paid { background: var(--success-bg); color: var(--success); }
.b-due, .b-inactive, .b-archived { background: var(--danger-bg); color: var(--danger); }
.b-info { background: var(--primary-soft); color: var(--primary); }

/* Locked Feature Screen */
.locked-box {
  text-align: center; padding: 40px 20px; background: var(--surface);
  border: 1px dashed #cbd5e1; border-radius: var(--radius);
}
.locked-ico {
  width: 56px; height: 56px; border-radius: 50%; background: var(--warning-bg);
  color: var(--warning); display: inline-flex; align-items: center; justify-content: center; margin-bottom: 12px;
}

/* Universal Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.6);
  display: none; align-items: center; justify-content: center; z-index: 300; padding: 14px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: #fff; border-radius: 16px; width: 100%; max-width: 560px;
  max-height: 90vh; overflow-y: auto; padding: 18px;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding-bottom: 10px; margin-bottom: 13px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 15px; font-weight: 700; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-group { margin-bottom: 10px; }
.form-group.full { grid-column: 1 / -1; }
.form-group label { display: block; font-size: 11.5px; font-weight: 600; margin-bottom: 4px; color: #334155; }
.form-group .input, .form-group select, .form-group textarea { width: 100%; }

.bottom-nav {
  display: none; position: fixed; bottom: 0; left: 0; right: 0; height: 60px;
  background: #fff; border-top: 1px solid var(--border); z-index: 95;
  grid-template-columns: repeat(5, 1fr);
}
.bnav-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 10px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.bnav-item.active { color: var(--primary); }
.bnav-item .material-icons-round { font-size: 20px; }

.overlay { display: none; position: fixed; inset: 0; background: rgba(15,23,42,0.45); z-index: 120; }
.overlay.open { display: block; }
.toast {
  position: fixed; bottom: 72px; right: 16px; background: #0f172a; color: #fff;
  padding: 10px 15px; border-radius: 10px; font-size: 12.5px; font-weight: 500;
  z-index: 600; display: none; box-shadow: 0 10px 25px rgba(0,0,0,0.25); max-width: 330px;
}

#printArea { display: none; }
@page { size: A4 portrait; margin: 10mm; }
@media print {
  body * { visibility: hidden; }
  #printArea, #printArea * { visibility: visible; }
  #printArea { display: block !important; position: fixed; left: 0; top: 0; width: 100%; background: #fff; color: #000; }
}

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-btn { display: inline-flex; }
  .grid-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .bottom-nav { display: grid; }
}
