/* ====================================================
   EduManage Pro — Foundation Stylesheet v2
   Modern, clean, mobile-first
   ==================================================== */

:root {
  --primary:       #16a34a;
  --primary-dark:  #15803d;
  --primary-light: #f0fdf4;
  --accent:        #f59e0b;
  --success:       #22c55e;
  --danger:        #ef4444;
  --warning:       #f59e0b;
  --info:          #3b82f6;
  --dark:          #0f172a;
  --sidebar-bg:    #111827;
  --sidebar-w:     250px;
  --topbar-h:      60px;
  --text:          #1e293b;
  --text-muted:    #64748b;
  --border:        #e5e7eb;
  --bg:            #f8fafc;
  --white:         #ffffff;
  --card-shadow:   0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
  --shadow-lg:     0 4px 24px rgba(0,0,0,.08);
  --radius:        12px;
  --radius-sm:     8px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { text-decoration: none; color: inherit; }
img { max-width: 100%; }

/* ---- SIDEBAR ---- */
/* Base sidebar styles are in style.css — app.css only adds foundation variables */

.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 18px; border-bottom: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;
}
.logo-icon {
  width: 38px; height: 38px;
  background: var(--primary); border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 1.1rem; flex-shrink: 0;
}
.logo-text { color: #e2e8f0; font-weight: 700; font-size: .88rem; line-height: 1.3; }
.logo-name { color: #f1f5f9; font-weight: 700; font-size: .92rem; }
.logo-plan { color: var(--accent); font-size: .7rem; text-transform: uppercase; font-weight: 600; letter-spacing: .5px; }

.sidebar-nav { padding: 8px 0 60px; }
.nav-section {
  color: rgba(255,255,255,.35); font-size: .65rem; font-weight: 700;
  letter-spacing: 1.2px; padding: 16px 18px 6px; text-transform: uppercase;
}

/* ---- TOPBAR ---- */
.topbar {
  height: var(--topbar-h); background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 20px; gap: 12px;
  position: sticky; top: 0; z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.topbar-center { position: absolute; left: 50%; transform: translateX(-50%); display: flex; align-items: center; justify-content: center; pointer-events: none; }
.topbar-right { display: flex; align-items: center; gap: 14px; flex: 1; justify-content: flex-end; }

.user-menu { position: relative; display: flex; align-items: center; gap: 10px; cursor: pointer; }
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .88rem; overflow: hidden;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-name { font-weight: 600; font-size: .85rem; }
.user-role { font-size: .72rem; color: var(--text-muted); }
.dropdown-menu {
  display: none; position: absolute; top: calc(100% + 8px); right: 0;
  background: var(--white); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  min-width: 180px; z-index: 300; padding: 4px 0;
}
.user-menu.open .dropdown-menu { display: block; }
.dropdown-menu a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; color: var(--text); font-size: .85rem;
  transition: background .15s;
}
.dropdown-menu a:hover { background: var(--bg); }
.dropdown-menu hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

/* ---- MAIN WRAP ---- */
.main-wrap {
  margin-left: var(--sidebar-w);
  width: calc(100% - var(--sidebar-w));
  min-height: 100vh;
  display: flex; flex-direction: column;
  overflow-x: hidden;
}

/* ---- FLASH ---- */
.flash {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px; font-size: .88rem; position: relative;
  border-radius: var(--radius-sm); margin: 12px 0;
}
.flash button { position: absolute; right: 12px; background: none; border: none; font-size: 1.1rem; cursor: pointer; opacity: .5; }
.flash-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.flash-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.flash-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.flash-info    { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

/* ---- CONTENT ---- */
.content { padding: 24px; flex: 1; }

/* ---- PAGE HEADER ---- */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; gap: 10px; flex-wrap: wrap;
}
.page-header h2 { font-size: 1.2rem; font-weight: 700; }
.page-header .breadcrumb { color: var(--text-muted); font-size: .82rem; margin-top: 2px; }

/* ---- STAT CARDS ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.stat-card {
  background: var(--white); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--card-shadow);
  display: flex; align-items: center; gap: 14px;
  border: 1px solid var(--border);
  transition: box-shadow .15s;
}
.stat-card:hover { box-shadow: var(--shadow-lg); }
.stat-icon {
  width: 48px; height: 48px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; flex-shrink: 0;
}
.stat-icon.blue   { background: #eff6ff; color: var(--info); }
.stat-icon.green  { background: #dcfce7; color: var(--success); }
.stat-icon.yellow { background: #fef3c7; color: var(--warning); }
.stat-icon.red    { background: #fee2e2; color: var(--danger); }
.stat-icon.purple { background: #ede9fe; color: #7c3aed; }
.stat-icon.teal   { background: #ccfbf1; color: #0d9488; }
.stat-value { font-size: 1.5rem; font-weight: 800; line-height: 1; }
.stat-label { color: var(--text-muted); font-size: .78rem; margin-top: 4px; }

/* ---- CARDS ---- */
.card {
  background: var(--white); border-radius: var(--radius);
  box-shadow: var(--card-shadow); border: 1px solid var(--border);
  overflow: hidden;
}
.card-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; flex-wrap: wrap;
}
.card-header h3 { font-size: .92rem; font-weight: 700; }
.card-body { padding: 20px; }

/* ---- TABLES ---- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
thead th {
  background: var(--bg); padding: 11px 14px;
  text-align: left; font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody td {
  padding: 12px 14px; border-bottom: 1px solid #e5e7eb;
  font-size: .86rem; vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }

/* ---- BADGES ---- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 20px;
  font-size: .72rem; font-weight: 600;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info    { background: #dbeafe; color: #1e40af; }
.badge-gray    { background: #f1f5f9; color: #475569; }
.badge-purple  { background: #ede9fe; color: #6d28d9; }

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: var(--radius-sm);
  font-family: inherit; font-size: .86rem;
  font-weight: 600; cursor: pointer; border: 1px solid transparent;
  transition: background .12s ease, box-shadow .12s ease; white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 2px 8px rgba(15,23,42,.12); }
.btn-success { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-success:hover { background: var(--primary-dark); box-shadow: 0 2px 8px rgba(15,23,42,.12); }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; box-shadow: 0 2px 8px rgba(239,68,68,.25); }
.btn-outline {
  background: var(--white); border: 1.5px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: 6px 12px; font-size: .78rem; border-radius: 6px; }
.btn-icon { padding: 8px 10px; }
.btn-secondary { background: #f1f5f9; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #e2e8f0; }
.type-btn.active { background: var(--primary) !important; color: #fff !important; border-color: var(--primary) !important; }

/* Legacy inline green buttons still exist on a few pages. Force them onto the active theme. */
button[style*="background:#1a6b3c"],
button[style*="background:#16a34a"],
button[style*="background: #1a6b3c"],
button[style*="background: #16a34a"],
a[style*="background:#1a6b3c"],
a[style*="background:#16a34a"],
a[style*="background: #1a6b3c"],
a[style*="background: #16a34a"],
input[type="submit"][style*="background:#1a6b3c"],
input[type="submit"][style*="background:#16a34a"],
input[type="submit"][style*="background: #1a6b3c"],
input[type="submit"][style*="background: #16a34a"] {
  background: var(--primary) !important;
  border-color: var(--primary) !important;
  color: #fff !important;
}

button[style*="border-color:#1a6b3c"],
button[style*="border-color:#16a34a"],
button[style*="border-color: #1a6b3c"],
button[style*="border-color: #16a34a"],
a[style*="border-color:#1a6b3c"],
a[style*="border-color:#16a34a"],
a[style*="border-color: #1a6b3c"],
a[style*="border-color: #16a34a"],
input[type="submit"][style*="border-color:#1a6b3c"],
input[type="submit"][style*="border-color:#16a34a"],
input[type="submit"][style*="border-color: #1a6b3c"],
input[type="submit"][style*="border-color: #16a34a"] {
  border-color: var(--primary) !important;
}

/* ---- FORMS ---- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 18px; }
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block; font-size: .78rem; font-weight: 600;
  color: var(--text-muted); margin-bottom: 6px;
  text-transform: uppercase; letter-spacing: .3px;
}
.form-control,
input[type="text"], input[type="email"], input[type="password"],
input[type="date"], input[type="number"], input[type="tel"],
select, textarea {
  width: 100%; padding: 10px 13px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-family: inherit; font-size: .88rem; color: var(--text);
  background: var(--white); transition: border .2s, box-shadow .2s;
  -webkit-appearance: none; appearance: none;
}
.form-control:focus,
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(22,163,74,.1);
}
select { cursor: pointer; }
textarea { resize: vertical; min-height: 80px; }

/* ---- SEARCH BAR ---- */
.search-bar {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 18px; flex-wrap: wrap;
}

/* ---- AVATAR ---- */
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .82rem; overflow: hidden; flex-shrink: 0;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ---- PAGINATION ---- */
.pagination {
  display: flex; align-items: center; gap: 4px;
  justify-content: flex-end; padding-top: 14px;
}
.pagination a, .pagination span {
  width: 34px; height: 34px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: .82rem; font-weight: 600;
  border: 1.5px solid var(--border); color: var(--text);
  transition: all .15s;
}
.pagination a:hover { border-color: var(--primary); color: var(--primary); }
.pagination .active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---- MODAL ---- */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(15,23,42,.5); z-index: 500;
  align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--white); border-radius: var(--radius);
  width: 92%; max-width: 540px; max-height: 90vh;
  overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.2);
  animation: modalIn .18s ease;
}
@keyframes modalIn { from { opacity:0; transform:translateY(5px); } to { opacity:1; transform:translateY(0); } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: .95rem; font-weight: 700; }
.modal-close {
  background: var(--bg); border: none; font-size: 1.1rem;
  cursor: pointer; color: var(--text-muted);
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.modal-close:hover { background: #e2e8f0; }
.modal-body { padding: 22px; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ---- RESPONSIVE: TABLET ---- */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .main-wrap { margin-left: 0; width: 100%; }
  .menu-toggle { display: flex; }
}

/* ---- RESPONSIVE: MOBILE ---- */
@media (max-width: 640px) {
  .content { padding: 14px 12px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 14px 12px; }
  /* Modals become bottom sheets on mobile */
  .modal-overlay { align-items: flex-end; }
  .modal {
    width: 100% !important; max-width: 100% !important;
    border-radius: 20px 20px 0 0;
    max-height: 90vh; overflow-y: auto;
    padding-bottom: env(safe-area-inset-bottom, 16px);
    animation: sheetIn .2s ease;
  }
  .modal form { padding-bottom: 24px; }
  .modal-body { padding-bottom: 24px; }
  @keyframes sheetIn { from { transform: translateY(100%); } to { transform: translateY(0); } }
}

/* ---- NAV GROUP TOGGLE ---- */
.nav-group-toggle { cursor: pointer !important; }
.nav-group-toggle * { cursor: pointer !important; }

/* ---- SIDEBAR OVERLAY ---- */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 199;
}
.sidebar-overlay.active { display: block; }

@media (max-width: 900px) {
  #sidebar-close-btn { display: block !important; }
}

/* ---- FILTER BAR ---- */
.filter-bar {
  display: flex; gap: 12px; flex-wrap: wrap;
  align-items: flex-end; margin-bottom: 18px;
  padding: 14px 18px; background: var(--white);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.filter-bar label { font-size: .72rem; font-weight: 700; color: var(--text-muted); display: block; margin-bottom: 4px; text-transform: uppercase; letter-spacing: .3px; }
.filter-bar select, .filter-bar input { min-width: 160px; }

/* ---- EMPTY STATE ---- */
.empty-state { text-align: center; padding: 40px 16px; color: var(--text-muted); }
.empty-icon  { font-size: 40px; margin-bottom: 10px; opacity: .7; }

/* ====================================================
   THEME SYSTEM — Override CSS variables per theme
   Applied via data-theme attribute on <body>
   ==================================================== */

/* Blue (Light Blue) */
[data-theme="blue"] {
  --primary:       #1895f5;
  --primary-dark:  #0e7de0;
  --primary-light: #e8f4fe;
  --accent:        #f59e0b;
  --sidebar-bg:    #051e36;
}
[data-theme="blue"] .sidebar { background: linear-gradient(180deg, #083a6b 0%, #051e36 100%); }
[data-theme="blue"] .btn-gold { background: #1895f5; border-color: #1895f5; }
[data-theme="blue"] .badge-green { background: #dbeafe; color: #0e7de0; }

/* Maroon */
[data-theme="maroon"] {
  --primary:       #700103;
  --primary-dark:  #550102;
  --primary-light: #fff1f2;
  --accent:        #f59e0b;
  --sidebar-bg:    #1a0001;
}
[data-theme="maroon"] .sidebar { background: linear-gradient(180deg, #3a0102 0%, #1a0001 100%); }
[data-theme="maroon"] .btn-gold { background: #700103; border-color: #700103; }
[data-theme="maroon"] .badge-green { background: #ffe4e6; color: #700103; }

/* Brown */
[data-theme="brown"] {
  --primary:       #92400e;
  --primary-dark:  #78350f;
  --primary-light: #fffbeb;
  --accent:        #d97706;
  --sidebar-bg:    #1c1510;
}
[data-theme="brown"] .sidebar { background: linear-gradient(180deg, #44280f 0%, #1c1510 100%); }
[data-theme="brown"] .btn-gold { background: #92400e; border-color: #92400e; }
[data-theme="brown"] .badge-green { background: #fef3c7; color: #92400e; }

/* Purple */
[data-theme="purple"] {
  --primary:       #59034f;
  --primary-dark:  #42023b;
  --primary-light: #fdf0fc;
  --accent:        #f59e0b;
  --sidebar-bg:    #1a0118;
}
[data-theme="purple"] .sidebar { background: linear-gradient(180deg, #2e0128 0%, #1a0118 100%); }
[data-theme="purple"] .btn-gold { background: #59034f; border-color: #59034f; }
[data-theme="purple"] .badge-green { background: #fce7fb; color: #59034f; }

/* Navy */
[data-theme="navy"] {
  --primary:       #015580;
  --primary-dark:  #013f60;
  --primary-light: #e6f2f9;
  --accent:        #f59e0b;
  --sidebar-bg:    #01202f;
}
[data-theme="navy"] .sidebar { background: linear-gradient(180deg, #013a57 0%, #01202f 100%); }
[data-theme="navy"] .btn-gold { background: #015580; border-color: #015580; }
[data-theme="navy"] .badge-green { background: #cce8f4; color: #015580; }

/* Red */
[data-theme="red"] {
  --primary:       #cc0b04;
  --primary-dark:  #a80903;
  --primary-light: #fff0f0;
  --accent:        #f59e0b;
  --sidebar-bg:    #1f0100;
}
[data-theme="red"] .sidebar { background: linear-gradient(180deg, #420200 0%, #1f0100 100%); }
[data-theme="red"] .btn-gold { background: #cc0b04; border-color: #cc0b04; }
[data-theme="red"] .badge-green { background: #ffe4e4; color: #cc0b04; }

[data-theme="grey"] {
  --primary:       #475569;
  --primary-dark:  #334155;
  --primary-light: #f1f5f9;
  --accent:        #94a3b8;
  --sidebar-bg:    #1e293b;
}
[data-theme="grey"] .sidebar { background: linear-gradient(180deg, #334155 0%, #1e293b 100%); }
[data-theme="grey"] .btn-gold { background: #475569; border-color: #475569; }
[data-theme="grey"] .badge-green { background: #f1f5f9; color: #475569; }
/* Compact three-dot action menus, matching the fee/schedule row menu style */
.action-menu{position:relative;display:inline-flex;align-items:center;justify-content:flex-end}
.action-menu>summary{list-style:none;width:36px;height:36px;border:1px solid var(--border,#e2e8f0);border-radius:10px;background:var(--card-bg,#fff);color:var(--text,#334155);display:flex;align-items:center;justify-content:center;font-weight:800;font-size:20px;line-height:1;letter-spacing:1px;cursor:pointer;box-shadow:0 1px 3px rgba(15,23,42,.08);transition:.15s ease;transform:translateY(-1px)}
.action-menu>summary::-webkit-details-marker{display:none}
.action-menu>summary:hover{background:#f8fafc;border-color:#cbd5e1;transform:translateY(-2px)}
.action-menu[open]>summary{background:var(--primary-light,#f0fdf4);border-color:#86efac;color:var(--primary,#1a6b3c)}
.action-menu-panel{position:absolute;right:0;top:44px;z-index:99999;min-width:176px;background:var(--card-bg,#fff);border:1px solid var(--border,#e2e8f0);border-radius:14px;box-shadow:0 16px 40px rgba(15,23,42,.14);padding:8px}
.action-menu-panel a,.action-menu-panel button{width:100%;display:flex;align-items:center;gap:10px;text-align:left;text-decoration:none;border:0;background:transparent;color:#334155;font:inherit;font-size:13px;padding:10px 12px;border-radius:10px;cursor:pointer;white-space:nowrap;transition:background .12s}
.action-menu-panel a:hover,.action-menu-panel button:hover{background:#f8fafc}
.action-menu-panel form{margin:0}
.action-menu-icon{width:16px;height:16px;display:inline-flex;align-items:center;justify-content:center;flex-shrink:0;text-align:center}
.action-menu-icon svg{width:16px;height:16px;display:block}
.action-menu-label{flex:1;min-width:0}
.action-menu-sep{height:1px;background:var(--border,#e2e8f0);margin:4px 8px}
.action-menu-panel .danger{color:#dc2626}
.action-menu-panel .danger:hover{background:#fef2f2}
.compact-card{padding:10px 12px!important}
.compact-title{font-size:13px!important;line-height:1.25!important}
