:root {
  --primary-color: #1364A2;
  --accent: #FF7500;
  --secondary-color: #2E3C46;
  --back: #1364A240;
  --bg: #F4F8FC;
  --white: #FFFFFF;
  --font-family: "Poppins", "Tajawal", sans-serif;
  --radius: 12px;
  --radius-sm: 6px;
  --shadow: 0 0 10px #1364A240;
  --sidebar-width: 260px;
}

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

body {
  font-family: var(--font-family);
  font-size: 16px;
  line-height: 1.5;
  color: var(--secondary-color);
  background: var(--bg);
}

.hidden { display: none !important; }

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1364A2, #0d4d7a);
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.login-logo { height: 64px; margin-bottom: 16px; }

.login-card h1 { color: var(--primary-color); font-size: 28px; margin-bottom: 4px; }
.login-card .subtitle { color: #666; margin-bottom: 24px; font-size: 14px; }

.login-card form { display: flex; flex-direction: column; gap: 16px; text-align: left; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; }
.login-card input {
  padding: 10px 14px;
  border: 1px solid var(--back);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 15px;
}

.error-text { color: #c0392b; font-size: 14px; margin-top: 12px; }

/* Dashboard layout */
.dashboard { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  background: var(--primary-color);
  color: var(--white);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  overflow-y: auto;
  z-index: 100;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px 24px;
  border-bottom: 1px solid rgba(255,255,255,0.15);
}

.sidebar-brand img { height: 40px; }
.sidebar-brand strong { display: block; font-size: 18px; }
.sidebar-brand span { font-size: 12px; opacity: 0.8; }

#sidebar-nav { flex: 1; padding: 16px 0; }

.nav-group { margin-bottom: 8px; }
.nav-group-title {
  padding: 8px 20px;
  font-size: 11px;
  text-transform: uppercase;
  opacity: 0.6;
  letter-spacing: 0.5px;
}

.nav-link {
  display: block;
  padding: 10px 20px;
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  font-size: 14px;
  transition: background 0.2s;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}

.nav-link:hover, .nav-link.active {
  background: rgba(255,255,255,0.12);
  color: var(--white);
}

.sidebar-logout { margin: 16px 20px 0; width: calc(100% - 40px); }

.main {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
}

.topbar {
  background: var(--white);
  padding: 20px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar h2 { font-size: 22px; color: var(--primary-color); }
.topbar p { font-size: 13px; color: #666; }

.content { padding: 24px 28px; }

/* Cards & buttons */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.btn {
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  border: none;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s;
}

.btn:hover { transform: translateY(-2px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--accent); color: var(--white); }
.btn-secondary { background: transparent; color: var(--accent); border: 2px solid var(--accent); }
.btn-danger { background: #c0392b; color: var(--white); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-link { background: none; border: none; color: var(--primary-color); cursor: pointer; font-family: inherit; padding: 4px 8px; }

.icon-btn {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--secondary-color);
  line-height: 1;
}

/* KPI grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.kpi-card .label { font-size: 13px; color: #666; margin-bottom: 4px; }
.kpi-card .value { font-size: 28px; font-weight: 700; color: var(--primary-color); }
.kpi-card.accent .value { color: var(--accent); }

/* Tables */
.table-wrap { overflow-x: auto; margin-top: 16px; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th, td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid #eee;
}

th { background: var(--bg); font-weight: 600; color: var(--primary-color); white-space: nowrap; }
tr:hover td { background: #fafcfe; }
tr.clickable { cursor: pointer; }
.table-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--bg);
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-weight: 500; font-size: 14px; }
.form-group input, .form-group select, .form-group textarea {
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
}
.form-group select[multiple] { min-height: 120px; }
.form-group textarea { min-height: 80px; resize: vertical; }
.form-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.object-array-field {
  display: grid;
  gap: 8px;
}
.object-array-rows {
  display: grid;
  gap: 8px;
}
.object-array-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: center;
}
.current-file img {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid #eee;
  margin-bottom: 8px;
}

/* Filters */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 20px;
  padding: 16px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.filter-bar .form-group { min-width: 140px; }

/* Toolbar */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Common Time Calculator */
.calculator-page {
  display: grid;
  gap: 20px;
}

.calculator-card {
  display: grid;
  gap: 20px;
}

.calculator-header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  padding-bottom: 16px;
  border-bottom: 1px solid #eee;
}

.calculator-header h3,
.calculator-results h3 {
  color: var(--primary-color);
  margin-bottom: 6px;
}

.calculator-header p,
.helper-text {
  color: #666;
  font-size: 13px;
}

.calculator-settings {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.calculator-settings label,
.student-card-header label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
}

.calculator-settings input,
.student-card-header input,
.slot-row input,
.slot-row select {
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: var(--radius-sm);
  font-family: inherit;
}

.students-list {
  display: grid;
  gap: 16px;
}

.student-card {
  border: 1px solid #e6eef5;
  border-radius: var(--radius);
  padding: 16px;
  background: #fbfdff;
}

.student-card-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 12px;
}

.student-card-header label {
  flex: 1;
}

.slot-list {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.slot-row {
  display: grid;
  grid-template-columns: 150px 150px 130px auto 130px auto;
  gap: 8px;
  align-items: center;
}

.calculator-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* Pagination */
.pagination {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  margin-top: 20px;
}

.pagination span { font-size: 14px; color: #666; }

/* Badge */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.badge-paid, .badge-joined { background: #d4edda; color: #155724; }
.badge-pending, .badge-partial { background: #fff3cd; color: #856404; }
.badge-unpaid, .badge-cancelled { background: #f8d7da; color: #721c24; }

/* Modal & Drawer */
.modal-overlay, .drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.drawer-overlay { justify-content: flex-end; }

.modal { max-width: 640px; width: 90%; max-height: 85vh; overflow: auto; }
.drawer {
  width: 480px;
  max-width: 90vw;
  height: 100vh;
  border-radius: 0;
  overflow-y: auto;
  margin-left: auto;
}

.modal-header, .drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid #eee;
}

.modal-body, .drawer-body { margin-bottom: 16px; }
.modal-footer { display: flex; gap: 8px; justify-content: flex-start; }

.detail-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px 16px;
  font-size: 14px;
}
.detail-grid dt { font-weight: 600; color: #666; }
.detail-grid dd { margin: 0; }
.detail-page { max-width: 980px; }
.detail-page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid #eee;
}
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.detail-list { margin: 0; padding-left: 18px; }
.detail-list li { margin-bottom: 4px; }
.phone-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.phone-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #eaf4fb;
  color: var(--secondary-color);
  border: 1px solid #d7e9f5;
  font-size: 12px;
}
.phone-name {
  font-weight: 700;
  color: var(--primary-color);
}
.phone-number {
  font-family: "Poppins", sans-serif;
}
.detail-image {
  width: 180px;
  height: 180px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid #eee;
}

/* Toast */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  color: var(--white);
  font-size: 14px;
  animation: slideIn 0.3s ease;
  max-width: 360px;
}
.toast-success { background: #27ae60; }
.toast-error { background: #c0392b; }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Loading */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.6);
  z-index: 250;
  display: flex;
  align-items: center;
  justify-content: center;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--back);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Tabs */
.tabs { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 2px solid #eee; }
.tab {
  padding: 10px 20px;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: #666;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}
.tab.active { color: var(--primary-color); border-bottom-color: var(--accent); }

.section-title { font-size: 18px; color: var(--primary-color); margin: 24px 0 12px; }

.empty-state { text-align: center; padding: 40px; color: #999; }

@media (max-width: 900px) {
  .sidebar { width: 200px; }
  .main { margin-left: 200px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s;
  }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .calculator-header,
  .student-card-header {
    flex-direction: column;
    align-items: stretch;
  }
  .slot-row {
    grid-template-columns: 1fr;
  }
}
