/* ===== Reset & Base ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --primary: #0d6efd;
  --primary-dark: #0a58ca;
  --success: #198754;
  --success-dark: #146c43;
  --warning: #ffc107;
  --danger: #dc3545;
  --info: #0dcaf0;
  --purple: #6f42c1;
  --orange: #fd7e14;
  --teal: #20c997;
  --dark: #212529;
  --gray: #6c757d;
  --light: #f8f9fa;
  --white: #ffffff;
  --border: #dee2e6;
  --shadow: 0 4px 12px rgba(0,0,0,0.1);
  --radius: 16px;
  --header-h: 70px;
  --nav-h: 64px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans Devanagari', sans-serif;
  background: #e9ecef;
  color: var(--dark);
  overflow-x: hidden;
  font-size: 15px;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--light);
  position: relative;
  box-shadow: 0 0 30px rgba(0,0,0,0.15);
}

/* ===== Screens ===== */
.screen {
  display: none;
  min-height: 100vh;
  flex-direction: column;
}
.screen.active {
  display: flex;
}

/* ===== Loading ===== */
#loading-screen {
  background: linear-gradient(135deg, #0d6efd, #6f42c1);
  color: white;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.loading-content h1 { margin: 12px 0 4px; font-size: 1.6rem; }
.logo-big { font-size: 4rem; margin-bottom: 8px; }
.spinner {
  width: 40px; height: 40px;
  border: 4px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 20px auto 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Login ===== */
#login-screen {
  background: linear-gradient(160deg, #0d6efd 0%, #6f42c1 100%);
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-container {
  width: 100%;
  max-width: 360px;
  text-align: center;
  color: white;
}
.login-container h1 { font-size: 1.7rem; margin-bottom: 4px; }
.subtitle { opacity: 0.85; margin-bottom: 28px; font-size: 0.95rem; }

#login-options { display: flex; flex-direction: column; gap: 12px; }

.form-card {
  background: white;
  color: var(--dark);
  border-radius: var(--radius);
  padding: 20px;
  text-align: left;
  margin-top: 10px;
  box-shadow: var(--shadow);
}
.form-card h2 { text-align: center; margin-bottom: 16px; font-size: 1.2rem; }
.form-card.hidden { display: none; }

.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--gray);
}
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  outline: none;
  transition: border 0.2s;
  background: #fff;
}
.form-group input:focus, .form-group select:focus {
  border-color: var(--primary);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 18px;
  border: none;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}
.btn:active { transform: scale(0.97); }
.btn-lg { padding: 14px 20px; font-size: 1.05rem; }
.btn-block { width: 100%; margin-top: 8px; }
.btn-sm { padding: 7px 12px; font-size: 0.85rem; }

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: var(--success-dark); }
.btn-warning { background: var(--warning); color: #212529; }
.btn-danger { background: var(--danger); color: white; }
.btn-info { background: var(--info); color: #000; }
.btn-purple { background: var(--purple); color: white; }
.btn-orange { background: var(--orange); color: white; }
.btn-teal { background: var(--teal); color: white; }
.btn-outline {
  background: transparent;
  border: 2px solid rgba(255,255,255,0.7);
  color: white;
}
.form-card .btn-outline {
  border-color: var(--border);
  color: var(--dark);
}
.btn-light { background: var(--light); color: var(--dark); border: 1px solid var(--border); }

/* ===== Header ===== */
#app-header {
  background: linear-gradient(135deg, #0d6efd, #6610f2);
  color: white;
  padding: 12px 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.group-info { display: flex; align-items: center; gap: 10px; }
.group-logo { font-size: 2rem; }
.group-name { font-weight: 700; font-size: 1.05rem; }
.group-meta { font-size: 0.75rem; opacity: 0.85; }
.header-right { text-align: right; }
.nepali-datetime { font-size: 0.78rem; opacity: 0.9; }
.month-status {
  display: inline-block;
  margin-top: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  background: rgba(255,255,255,0.2);
}

/* ===== Navigation ===== */
#main-nav {
  display: flex;
  background: white;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: var(--header-h);
  z-index: 90;
  box-shadow: 0 2px 6px rgba(0,0,0,0.05);
}
.nav-btn {
  flex: 1;
  padding: 10px 4px;
  border: none;
  background: none;
  font-size: 1.2rem;
  color: var(--gray);
  cursor: pointer;
  transition: all 0.2s;
  line-height: 1.3;
}
.nav-btn span { font-size: 0.7rem; display: block; }
.nav-btn.active {
  color: var(--primary);
  border-bottom: 3px solid var(--primary);
  background: #f0f7ff;
}

/* ===== Tab Content ===== */
#tab-content {
  flex: 1;
  padding: 14px;
  padding-bottom: 30px;
  overflow-y: auto;
}
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ===== Home Cards ===== */
.home-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.stats-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.stat-box {
  flex: 1;
  background: white;
  border-radius: 14px;
  padding: 10px 6px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  border-bottom: 3px solid #dee2e6;
}
.stat-emoji { font-size: 1.3rem; line-height: 1.2; }
.stat-label { font-size: 0.72rem; font-weight: 600; margin-top: 2px; }
.stat-value { font-size: 1rem; font-weight: 700; color: #212529; margin-top: 2px; }

.action-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}
.action-card {
  border-radius: 16px;
  padding: 16px 18px;
  color: white;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  transition: transform 0.15s;
}
.action-card:active { transform: scale(0.97); }
.ac-icon { font-size: 1.6rem; margin-bottom: 4px; }
.ac-title { font-size: 1.1rem; font-weight: 700; }
.ac-desc { font-size: 0.82rem; opacity: 0.9; margin-top: 2px; }
.ac-teal { background: linear-gradient(135deg, #0d9488, #14b8a6); }
.ac-orange { background: linear-gradient(135deg, #ea580c, #f97316); }
.ac-blue { background: linear-gradient(135deg, #2563eb, #3b82f6); }
.ac-purple { background: linear-gradient(135deg, #7c3aed, #8b5cf6); }

.home-card {
  background: white;
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  border-left: 5px solid transparent;
}
.home-card:active { transform: scale(0.98); }
.card-assets { border-left-color: #6f42c1; }
.card-members { border-left-color: #0d6efd; }
.card-collection { border-left-color: #198754; }
.card-loans { border-left-color: #fd7e14; }
.card-reports { border-left-color: #0dcaf0; }

.card-icon { font-size: 1.8rem; margin-bottom: 6px; }
.card-title { font-weight: 700; font-size: 1.05rem; margin-bottom: 8px; }
.card-desc { font-size: 0.85rem; color: var(--gray); }
.card-values {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
}
.val-item {
  flex: 1;
  text-align: center;
  background: var(--light);
  border-radius: 10px;
  padding: 8px 4px;
}
.val-label { display: block; font-size: 0.7rem; color: var(--gray); margin-bottom: 2px; }
.val-num { font-weight: 700; font-size: 0.95rem; color: var(--dark); }

/* ===== Section Cards ===== */
.section-card {
  background: white;
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.section-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-title .badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--primary);
  color: white;
  font-weight: 600;
}

/* ===== Member List ===== */
.search-box {
  position: relative;
  margin-bottom: 12px;
}
.search-box input {
  width: 100%;
  padding: 11px 14px 11px 40px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  font-size: 0.95rem;
}
.search-box::before {
  content: '🔍';
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.1rem;
}
.member-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}
.member-item:last-child { border-bottom: none; }
.member-item:active { background: #f0f7ff; }
.member-avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0d6efd, #6f42c1);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.member-info { flex: 1; min-width: 0; }
.member-name { font-weight: 600; font-size: 0.95rem; }
.member-meta { font-size: 0.78rem; color: var(--gray); margin-top: 2px; }
.member-badge {
  font-size: 0.75rem;
  padding: 3px 8px;
  border-radius: 8px;
  font-weight: 600;
}
.badge-kitta { background: #e7f1ff; color: #0d6efd; }
.badge-loan { background: #fff3cd; color: #856404; }
.badge-advance { background: #d1e7dd; color: #0f5132; }
.badge-due { background: #f8d7da; color: #842029; }

/* ===== Collection ===== */
.collection-header {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.stat-pill {
  flex: 1;
  min-width: 90px;
  background: white;
  border-radius: 12px;
  padding: 10px;
  text-align: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}
.stat-pill .num { font-weight: 700; font-size: 1.1rem; }
.stat-pill .lbl { font-size: 0.7rem; color: var(--gray); }

.pay-summary {
  background: #f0f7ff;
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
}
.pay-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  font-size: 0.9rem;
}
.pay-row.total {
  border-top: 2px solid var(--primary);
  margin-top: 6px;
  padding-top: 8px;
  font-weight: 700;
  font-size: 1.05rem;
}
.pay-row .amount { font-weight: 600; }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; margin: 10px 0; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
th, td {
  padding: 8px 6px;
  text-align: right;
  border-bottom: 1px solid var(--border);
}
th {
  background: var(--light);
  font-weight: 600;
  color: var(--gray);
  white-space: nowrap;
}
td:first-child, th:first-child { text-align: left; }
tr:active { background: #f0f7ff; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: white;
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.25s ease;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.1rem; }
.modal-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--gray);
  padding: 4px 8px;
}
.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.pin-modal { max-width: 320px; border-radius: 16px; margin: auto; }
.pin-input {
  width: 100%;
  padding: 14px;
  font-size: 1.5rem;
  text-align: center;
  letter-spacing: 8px;
  border: 2px solid var(--border);
  border-radius: 12px;
  margin-top: 10px;
}

/* ===== Signature Pad ===== */
.sig-pad-wrap {
  border: 2px dashed var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: #fafafa;
  margin: 10px 0;
}
#sig-canvas {
  width: 100%;
  height: 160px;
  display: block;
  touch-action: none;
}
.sig-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--dark);
  color: white;
  padding: 12px 24px;
  border-radius: 30px;
  font-size: 0.9rem;
  z-index: 2000;
  box-shadow: var(--shadow);
  max-width: 90%;
  text-align: center;
}
.toast.hidden { display: none; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--gray);
}
.empty-state .icon { font-size: 3rem; margin-bottom: 10px; }

/* ===== Settings List ===== */
.settings-list { list-style: none; }
.settings-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.settings-item:last-child { border-bottom: none; }
.settings-icon {
  width: 40px; height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}
.settings-text { flex: 1; }
.settings-text .title { font-weight: 600; }
.settings-text .desc { font-size: 0.78rem; color: var(--gray); }
.settings-arrow { color: var(--gray); font-size: 1.1rem; }

/* ===== Report Card ===== */
.report-card {
  background: white;
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.report-row {
  display: flex;
  justify-content: space-between;
  padding: 7px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 0.9rem;
}
.report-row:last-child { border-bottom: none; }
.report-row .label { color: var(--gray); }
.report-row .value { font-weight: 600; }
.report-row.highlight {
  background: #f0f7ff;
  margin: 4px -8px;
  padding: 8px;
  border-radius: 8px;
  border: none;
}

/* ===== Status Colors ===== */
.status-open { background: #d1e7dd; color: #0f5132; }
.status-collection-closed { background: #fff3cd; color: #856404; }
.status-month-closed { background: #f8d7da; color: #842029; }

/* ===== Utility ===== */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--gray); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-primary { color: var(--primary); }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 14px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 14px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 12px; }
.fw-bold { font-weight: 700; }

/* Print / Image capture area */
.print-area {
  background: white;
  padding: 20px;
  color: #000;
}
.print-area h2 { text-align: center; margin-bottom: 12px; }
.print-area .print-meta { text-align: center; font-size: 0.85rem; color: #555; margin-bottom: 16px; }

/* Responsive small tweaks */
@media (max-width: 360px) {
  .card-values { flex-direction: column; }
  .val-item { display: flex; justify-content: space-between; padding: 6px 10px; }
}

/* Chat */
.chat-messages {
  max-height: 52vh;
  overflow-y: auto;
  padding: 10px 8px;
  background: #eef2f7;
  border-radius: 14px;
  margin-bottom: 10px;
}
.chat-row { display: flex; margin-bottom: 8px; }
.chat-row.mine { justify-content: flex-end; }
.chat-row.theirs, .chat-row.sys { justify-content: flex-start; }
.chat-bubble {
  max-width: 85%;
  padding: 10px 12px;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  font-size: 0.9rem;
  line-height: 1.45;
}
.chat-row.mine .chat-bubble {
  background: linear-gradient(135deg, #0d6efd, #0a58ca);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-row.theirs .chat-bubble { border-bottom-left-radius: 4px; }
.chat-sys {
  background: #fff8e6 !important;
  color: #5c4a00 !important;
  border: 1px solid #ffe08a;
  max-width: 95%;
}
.chat-from { font-size: 0.72rem; font-weight: 700; color: #0d6efd; margin-bottom: 3px; }
.chat-sys .chat-from { color: #b45309; }
.chat-time { font-size: 0.65rem; opacity: 0.7; margin-top: 4px; text-align: right; }
.chat-compose { display: flex; gap: 8px; }
.chat-compose input {
  flex: 1;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid #ced4da;
}

.badge-unread {
  display: inline-block;
  background: #dc3545;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  margin-left: 4px;
  vertical-align: middle;
}

.sync-status {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(0,0,0,0.08);
  margin-top: 2px;
  text-align: center;
  max-width: 140px;
}
.sync-status.sync-offline { color: #6c757d; background: #e9ecef; }
.sync-status.sync-pending { color: #856404; background: #fff3cd; }
.sync-status.sync-saving { color: #084298; background: #cfe2ff; }
.sync-status.sync-saved { color: #0f5132; background: #d1e7dd; }
.sync-status.sync-error { color: #842029; background: #f8d7da; }

.ao-card {
  margin-top: 14px;
  padding: 12px;
  border-radius: 14px;
  background: linear-gradient(145deg, #ffffff 0%, #eef6ff 55%, #f7fbff 100%);
  border: 1px solid #c5daf5;
  box-shadow: 0 4px 14px rgba(13, 110, 253, 0.08);
}
.ao-empty { text-align: center; font-size: 0.75rem; color: #889; padding: 12px; }
.ao-top { display: flex; gap: 10px; align-items: center; }
.ao-photo {
  width: 56px; height: 56px; border-radius: 50%;
  object-fit: cover; border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  flex-shrink: 0;
}
.ao-label {
  font-size: 0.62rem; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: #0d6efd;
}
.ao-name { font-size: 0.95rem; font-weight: 700; color: #1a1a1a; line-height: 1.2; }
.ao-title { font-size: 0.72rem; color: #5a6a7a; margin-top: 2px; text-transform: lowercase; }
.ao-body { margin-top: 8px; padding-top: 8px; border-top: 1px solid #e3eefc; }
.ao-line, a.ao-line {
  display: block; font-size: 0.72rem; color: #334; text-decoration: none;
  margin: 3px 0; text-transform: lowercase; word-break: break-all;
}
a.ao-line:active { color: #0d6efd; }
.ao-note { font-size: 0.68rem; color: #778; margin-top: 6px; font-style: italic; text-transform: lowercase; }
