/* ==========================================================================
   School HRMS - Mobile-first stylesheet
   ========================================================================== */

:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --success: #16a34a;
  --success-light: #dcfce7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.10);
  --nav-height: 60px;
  --header-height: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 12px);
  min-height: 100vh;
}

h1, h2, h3, h4 { margin: 0 0 4px; font-weight: 700; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }

button { font-family: inherit; }

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

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--header-height);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}

.app-header .title {
  font-size: 17px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-header .logo-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--primary);
  flex-shrink: 0;
}

.app-header .back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: transparent;
  border: none;
  font-size: 20px;
  color: var(--text);
}
.app-header .back-btn:active { background: var(--bg); }

.app-header .header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--text);
  cursor: pointer;
}
.icon-btn:active { background: var(--border); }

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

/* ---------------- Bottom nav ---------------- */

.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 30;
  max-width: 720px;
  margin: 0 auto;
}
@media (min-width: 720px) {
  .bottom-nav { left: 50%; transform: translateX(-50%); border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}

.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
}

.bottom-nav a .nav-icon { font-size: 21px; line-height: 1; }
.bottom-nav a.active { color: var(--primary); }

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
  z-index: 25;
  cursor: pointer;
}
.fab:active { background: var(--primary-dark); }
@media (min-width: 720px) {
  .fab { right: calc(50% - 340px); }
}

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

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 6px;
}

.stat-card .stat-value {
  font-size: 22px;
  font-weight: 800;
}

.stat-card.accent-primary .stat-value { color: var(--primary); }
.stat-card.accent-success .stat-value { color: var(--success); }
.stat-card.accent-warning .stat-value { color: var(--warning); }

.section-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 20px 0 10px;
}
.section-title:first-child { margin-top: 0; }

/* ---------------- List items ---------------- */

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 8px;
  cursor: pointer;
}
.list-item:active { background: var(--primary-light); }

.avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}

.list-item-body { flex: 1; min-width: 0; }
.list-item-title { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item-meta { text-align: right; flex-shrink: 0; }
.list-item-meta .amount { font-weight: 800; font-size: 15px; color: var(--success); }
.list-item-meta .date { font-size: 11px; color: var(--text-muted); }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
}
.badge-success { background: var(--success-light); color: var(--success); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-primary { background: var(--primary-light); color: var(--primary); }

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

.form-group { margin-bottom: 14px; }

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

input, select, textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  background: var(--card-bg);
  color: var(--text);
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
}
textarea { resize: vertical; min-height: 80px; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1.5px solid var(--border); }
.btn-danger { background: var(--danger-light); color: var(--danger); }
.btn-block { width: 100%; margin-top: 6px; }
.btn-sm { width: auto; padding: 8px 14px; font-size: 13px; }
.btn:disabled { opacity: 0.6; }

.btn-group { display: flex; gap: 10px; }
.btn-group .btn { flex: 1; }

/* ---------------- Search / filter bar ---------------- */

.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card-bg);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 10px 16px;
  margin-bottom: 12px;
}
.search-bar input {
  border: none;
  padding: 0;
  flex: 1;
}
.search-bar input:focus { outline: none; }

.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 12px;
  -ms-overflow-style: none;
  scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }

.chip {
  flex-shrink: 0;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--card-bg);
  border: 1.5px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---------------- Login page ---------------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, var(--primary) 0%, #7c3aed 100%);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card-bg);
  border-radius: 20px;
  padding: 32px 26px;
  box-shadow: var(--shadow-md);
}

.login-logo {
  width: 56px; height: 56px;
  border-radius: 16px;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  margin: 0 auto 16px;
}

.login-title { text-align: center; font-size: 20px; margin-bottom: 4px; }
.login-sub { text-align: center; color: var(--text-muted); font-size: 13px; margin-bottom: 24px; }

.login-demo {
  margin-top: 18px;
  padding: 10px 12px;
  background: var(--primary-light);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--primary-dark);
  text-align: center;
}

/* ---------------- Empty state ---------------- */

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 42px; margin-bottom: 10px; }
.empty-state .empty-title { font-weight: 700; color: var(--text); margin-bottom: 4px; }

/* ---------------- Toast ---------------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 20px);
  transform: translateX(-50%) translateY(20px);
  background: #1e293b;
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  max-width: 90%;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--danger); }
#toast.success { background: var(--success); }

/* ---------------- Modal / bottom sheet ---------------- */

.sheet-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 50;
  display: none;
}
.sheet-overlay.open { display: block; }

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: 720px;
  margin: 0 auto;
  background: var(--card-bg);
  border-radius: 20px 20px 0 0;
  padding: 20px 16px calc(20px + var(--safe-bottom));
  z-index: 51;
  transform: translateY(100%);
  transition: transform 0.25s ease;
  max-height: 85vh;
  overflow-y: auto;
}
.sheet-overlay.open .sheet { transform: translateY(0); }

.sheet-handle {
  width: 40px; height: 4px;
  background: var(--border);
  border-radius: 999px;
  margin: 0 auto 16px;
}

/* ---------------- Loader ---------------- */

.loader {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 0;
  color: var(--text-muted);
  font-size: 13px;
  gap: 10px;
}
.spinner {
  width: 18px; height: 18px;
  border: 2.5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- Receipt / print ---------------- */

.receipt-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 24px 20px;
  box-shadow: var(--shadow);
}
.receipt-header { text-align: center; border-bottom: 2px dashed var(--border); padding-bottom: 16px; margin-bottom: 16px; }
.receipt-header .school-name { font-size: 18px; font-weight: 800; }
.receipt-header .school-meta { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.receipt-row { display: flex; justify-content: space-between; padding: 7px 0; font-size: 14px; border-bottom: 1px solid var(--bg); }
.receipt-row .label { color: var(--text-muted); }
.receipt-row .value { font-weight: 600; text-align: right; }
.receipt-amount { text-align: center; margin: 18px 0; padding: 16px; background: var(--success-light); border-radius: var(--radius-sm); }
.receipt-amount .amt { font-size: 28px; font-weight: 800; color: var(--success); }
.receipt-amount .lbl { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.receipt-footer { text-align: center; font-size: 11px; color: var(--text-muted); margin-top: 16px; }

@media print {
  .app-header, .bottom-nav, .fab, .no-print { display: none !important; }
  body { padding: 0; background: #fff; }
  .container { max-width: 100%; padding: 0; }
}

/* ---------------- Utility ---------------- */

.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-0 { margin-bottom: 0; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 13px; }
