
/* ============================================================
   DASHBOARD.CSS — Specific styles for the Dashboard
   ============================================================ */

/* Anti-overflow resets */
body, html {
  max-width: 100vw;
  overflow-x: hidden;
}

.db-container {
  max-width: 980px;
  width: 100%;
  padding-top: 28px;
  box-sizing: border-box;
}

.card {
  max-width: 100%;
  box-sizing: border-box;
}

.header-inner {
  flex-wrap: wrap;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ---------- Navigation ---------- */
.top-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(5,150,105,.15);
  box-shadow: 0 2px 16px rgba(5,150,105,.08);
}

.nav-inner {
  max-width: 980px;
  margin: 0 auto;
  padding: 0 20px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: 'Prompt', sans-serif;
  font-weight: 600;
  font-size: 16px;
  color: var(--teal-dark);
}
.nav-logo { font-size: 22px; }

.nav-links {
  display: flex;
  gap: 6px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: 99px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-mid);
  text-decoration: none;
  transition: all var(--transition);
}
.nav-link:hover {
  background: var(--primary-light);
  color: var(--primary-dark);
}
.nav-link-active {
  background: linear-gradient(135deg, var(--primary), var(--teal));
  color: white !important;
  box-shadow: 0 4px 12px rgba(5,150,105,.3);
}
.nav-link-active:hover {
  background: linear-gradient(135deg, var(--primary-dark), var(--teal-dark));
  color: white;
}

/* ---------- Dashboard Container ---------- */
.db-container {
  max-width: 980px;
  padding-top: 28px;
}

/* ---------- Dashboard Header ---------- */
.db-header { padding: 0; }

.db-header-inner {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding: 36px 40px;
  flex-wrap: wrap;
}

.db-header-text { 
  flex: 1; 
  min-width: 0;
}

.db-header-actions {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-label {
  font-size: 11px;
  font-weight: 600;
  color: rgba(255,255,255,.7);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.filter-select {
  padding: 8px 12px;
  font-family: 'Sarabun', sans-serif;
  font-size: 14px;
  border-radius: var(--radius-md);
  border: 1.5px solid rgba(255,255,255,.3);
  background: rgba(255,255,255,.15);
  color: white;
  outline: none;
  cursor: pointer;
  transition: all var(--transition);
}
.filter-select option { color: var(--text-dark); background: white; }
.filter-select:focus {
  border-color: rgba(255,255,255,.6);
  background: rgba(255,255,255,.25);
}

.btn-sm {
  padding: 8px 18px !important;
  font-size: 13px !important;
}

.btn-danger {
  background: linear-gradient(135deg, #ef4444, #dc2626) !important;
  color: white !important;
  border: none !important;
  box-shadow: 0 4px 12px rgba(239,68,68,.3) !important;
}
.btn-danger:hover {
  transform: translateY(-2px) !important;
  box-shadow: 0 6px 16px rgba(239,68,68,.4) !important;
}

/* ---------- Empty State ---------- */
.empty-state {
  text-align: center;
  padding: 64px 32px;
}
.empty-icon { font-size: 72px; margin-bottom: 20px; }
.empty-title {
  font-family: 'Prompt', sans-serif;
  font-size: 22px;
  color: var(--text-mid);
  margin-bottom: 12px;
}
.empty-desc { color: var(--text-light); font-size: 15px; line-height: 1.8; }

/* ---------- Stats Grid ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  border-radius: var(--radius-xl);
  padding: 24px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  border: 1px solid rgba(255,255,255,.6);
  box-shadow: var(--shadow-card);
  transition: transform var(--transition-md), box-shadow var(--transition-md);
  position: relative;
  overflow: hidden;
  min-width: 0;
}
.stat-text {
  min-width: 0;
  flex: 1;
}
.stat-card::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: .06;
  background: repeating-linear-gradient(45deg, white 0, white 1px, transparent 1px, transparent 8px);
}
.stat-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.stat-blue  { background: linear-gradient(135deg, #3b82f6, #2563eb); color: white; }
.stat-green { background: linear-gradient(135deg, #059669, #047857); color: white; }
.stat-amber { background: linear-gradient(135deg, #f59e0b, #d97706); color: white; }
.stat-teal  { background: linear-gradient(135deg, #0d9488, #0891b2); color: white; }

.stat-icon {
  font-size: 36px;
  flex-shrink: 0;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.2));
}

.stat-label {
  font-size: 13px;
  font-weight: 500;
  color: rgba(255,255,255,.8);
  margin-bottom: 4px;
}

.stat-value {
  font-family: 'Prompt', sans-serif;
  font-size: 32px;
  font-weight: 700;
  color: white;
  line-height: 1;
  margin-bottom: 2px;
}

.stat-sub {
  font-size: 12px;
  color: rgba(255,255,255,.7);
}

/* ---------- Target Grid ---------- */
.target-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.target-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
}

.target-dept-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-mid);
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.target-input {
  width: 60px;
  padding: 5px 8px;
  font-family: 'Sarabun', sans-serif;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: white;
  color: var(--primary-dark);
  transition: border-color var(--transition);
}
.target-input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(52,211,153,.2);
}
.target-input:disabled {
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: not-allowed;
}

.target-unit { font-size: 12px; color: var(--text-muted); }

/* ---------- Department Progress ---------- */
.dept-progress-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.dept-row {
  display: grid;
  grid-template-columns: 200px 1fr 80px 100px;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  background: var(--surface-2);
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.dept-row:hover {
  border-color: var(--primary-mid);
  box-shadow: var(--shadow-sm);
}

.dept-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-mid);
  display: flex;
  align-items: center;
  gap: 8px;
}

.dept-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dept-bar-wrap {
  background: var(--border);
  border-radius: 99px;
  height: 10px;
  overflow: hidden;
  position: relative;
}

.dept-bar {
  height: 100%;
  border-radius: 99px;
  transition: width .6s cubic-bezier(.4,0,.2,1);
  min-width: 0;
}

.dept-count {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-mid);
  text-align: center;
  white-space: nowrap;
}

.dept-pct-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 12px;
  border-radius: 99px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.pct-done      { background: #dcfce7; color: #166534; }
.pct-progress  { background: #fef9c3; color: #854d0e; }
.pct-none      { background: #fee2e2; color: #991b1b; }

/* ---------- Charts ---------- */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 24px;
}

.chart-card { 
  margin-bottom: 0 !important; 
  min-width: 0;
}

.chart-wrap {
  position: relative;
  height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chart-wrap canvas { max-height: 280px; }

/* ---------- Result Distribution ---------- */
.result-dist-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
}

.result-dist-item {
  text-align: center;
  padding: 20px 12px;
  border-radius: var(--radius-lg);
  border: 2px solid transparent;
  transition: transform var(--transition), box-shadow var(--transition);
  min-width: 0;
}
.result-dist-item:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.result-dist-item.level-excellent { background: #dcfce7; border-color: #86efac; }
.result-dist-item.level-good      { background: #d1fae5; border-color: #6ee7b7; }
.result-dist-item.level-fair      { background: #fef9c3; border-color: #fde047; }
.result-dist-item.level-poor      { background: #fee2e2; border-color: #fca5a5; }
.result-dist-item.level-fail      { background: #fce7f3; border-color: #f9a8d4; }

.dist-count {
  font-family: 'Prompt', sans-serif;
  font-size: 40px;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 6px;
}
.level-excellent .dist-count { color: #166534; }
.level-good      .dist-count { color: #065f46; }
.level-fair      .dist-count { color: #92400e; }
.level-poor      .dist-count { color: #991b1b; }
.level-fail      .dist-count { color: #831843; }

.dist-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-mid);
  margin-bottom: 2px;
}

.dist-range {
  font-size: 11px;
  color: var(--text-muted);
}

/* ---------- Recent Table ---------- */
.search-input {
  width: 260px !important;
  padding: 8px 14px !important;
  font-size: 14px !important;
}

.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.recent-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  min-width: 100%;
}

.recent-table thead tr {
  background: linear-gradient(135deg, var(--primary), var(--teal));
}

.recent-table th {
  padding: 12px 14px;
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  color: white;
}

.recent-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.recent-table tbody tr:hover { background: #f0fdf4; }
.recent-table tbody tr:last-child { border-bottom: none; }

.recent-table td {
  padding: 11px 14px;
  color: var(--text-mid);
  vertical-align: middle;
}

.recent-table .td-num {
  font-weight: 700;
  color: var(--text-muted);
  width: 40px;
}

.level-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-excellent { background: #dcfce7; color: #166534; }
.badge-good      { background: #d1fae5; color: #065f46; }
.badge-fair      { background: #fef9c3; color: #92400e; }
.badge-poor      { background: #fee2e2; color: #991b1b; }
.badge-fail      { background: #fce7f3; color: #831843; }

.dept-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  background: var(--primary-light);
  color: var(--primary-dark);
  line-height: 1.3;
}

.score-cell { font-weight: 700; color: var(--primary-dark); }

.btn-delete-row {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  line-height: 1;
}
.btn-delete-row:hover { background: #fee2e2; color: var(--danger); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(4px);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-md);
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal-box {
  background: white;
  border-radius: var(--radius-xl);
  padding: 32px;
  max-width: 400px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  transform: scale(.92);
  transition: transform var(--transition-md);
}
.modal-overlay.open .modal-box { transform: scale(1); }

.modal-title {
  font-family: 'Prompt', sans-serif;
  font-size: 20px;
  color: var(--text-dark);
  margin-bottom: 10px;
}
.modal-desc {
  font-size: 15px;
  color: var(--text-light);
  margin-bottom: 24px;
  line-height: 1.7;
}
.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

/* ---------- Responsive: Tablet (max 900px) ---------- */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-row { grid-template-columns: 1fr; }
  .result-dist-grid { grid-template-columns: repeat(3, 1fr); }
  .dept-row {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: 10px;
  }
  .dept-bar-wrap { grid-column: 1 / -1; }
  .db-header-inner { padding: 24px 24px; gap: 16px; }
}

/* ---------- Nav responsive ---------- */
@media (max-width: 768px) {
  .nav-inner { padding: 0 12px; height: 52px; }
  .nav-name { display: none; } /* ซ่อนชื่อโรงเรียนบนมือถือ */
  .nav-logo { font-size: 24px; }
  .nav-link { padding: 7px 12px; font-size: 13px; gap: 4px; }
  .nav-link span { font-size: 16px; }
  .nav-admin-badge { display: none; } /* ซ่อน badge admin */
  .nav-admin-btn { padding: 5px 10px; font-size: 12px; }
  .db-header-inner { flex-direction: column; padding: 20px 20px; }
  .db-header-actions { width: 100%; flex-wrap: wrap; }
  .filter-group { flex: 1; min-width: 100px; }
  .filter-select { width: 100%; }
}

/* ---------- Responsive: Mobile (max 600px) ---------- */
@media (max-width: 600px) {
  .db-container { padding-top: 16px; }
  .db-header-inner { padding: 16px; gap: 12px; }
  .db-header-actions { gap: 8px; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .stat-card { padding: 16px 14px; gap: 12px; }
  .stat-icon { font-size: 28px; }
  .stat-value { font-size: 24px; }
  .stat-label { font-size: 12px; }
  .result-dist-grid { grid-template-columns: 1fr 1fr; }
  .target-grid { grid-template-columns: 1fr 1fr; }
  .search-input { width: 100% !important; }
  .chart-wrap { height: 220px; }
  .chart-wrap canvas { max-height: 220px; }
  .dept-row { padding: 12px; }
  .dept-name { font-size: 13px; }
  .dept-count { font-size: 13px; }
  .login-card { padding: 32px 20px 28px; }
  .login-title { font-size: 20px; }
  .modal-box { padding: 24px 16px; }
  .nav-link { padding: 6px 10px; font-size: 12px; }
  
  .hide-on-mobile { display: none !important; }
  .recent-table { min-width: 100%; }
  .recent-table th, .recent-table td { padding: 8px 6px; font-size: 12px; }
}

/* ---------- Responsive: Small mobile (max 400px) ---------- */
@media (max-width: 400px) {
  .stats-grid { grid-template-columns: 1fr; }
  .result-dist-grid { grid-template-columns: repeat(3, 1fr); }
  .nav-links { gap: 2px; }
  .nav-link { padding: 6px 8px; font-size: 11px; }
  .nav-link span { font-size: 14px; }
}

/* ============================================================
   AUTH — Login Overlay & Admin Bar
   ============================================================ */

/* Full-screen login overlay */
.login-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #064e3b 0%, #065f46 40%, #0d9488 100%);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn .4s ease;
}

.login-card {
  background: white;
  border-radius: 24px;
  padding: 48px 40px 40px;
  max-width: 420px;
  width: 92%;
  box-shadow: 0 32px 80px rgba(0,0,0,.35);
  text-align: center;
  animation: slideUp .4s cubic-bezier(.4,0,.2,1);
}

@keyframes slideUp {
  from { opacity:0; transform: translateY(32px) scale(.96); }
  to   { opacity:1; transform: translateY(0)    scale(1); }
}

.login-logo {
  font-size: 56px;
  margin-bottom: 16px;
  filter: drop-shadow(0 4px 12px rgba(5,150,105,.3));
}

.login-title {
  font-family: 'Prompt', sans-serif;
  font-size: 24px;
  font-weight: 700;
  color: #064e3b;
  margin-bottom: 8px;
}

.login-sub {
  font-size: 14px;
  color: var(--text-light);
  line-height: 1.7;
  margin-bottom: 28px;
}

.login-error {
  background: #fee2e2;
  border: 1.5px solid #fca5a5;
  color: #991b1b;
  border-radius: var(--radius-md);
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
  text-align: left;
}

.login-form { text-align: left; }

.login-field { margin-bottom: 16px; }

.login-label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: 6px;
}

.login-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.login-input {
  width: 100%;
  padding: 12px 42px 12px 16px;
  font-family: 'Sarabun', sans-serif;
  font-size: 15px;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  box-sizing: border-box;
}
.login-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(52,211,153,.2);
}

.toggle-pw-btn {
  position: absolute;
  right: 12px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  color: var(--text-muted);
  padding: 4px;
  transition: color var(--transition);
}
.toggle-pw-btn:hover { color: var(--primary-dark); }

.login-btn {
  width: 100%;
  padding: 14px !important;
  font-size: 16px !important;
  margin-top: 8px;
  border-radius: var(--radius-md) !important;
}

.login-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 20px;
}

/* Admin bar in nav */
.nav-admin-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  border-left: 1.5px solid rgba(5,150,105,.2);
  padding-left: 12px;
  margin-left: 4px;
}

.nav-admin-badge {
  font-size: 12px;
  font-weight: 700;
  color: #059669;
  background: #dcfce7;
  padding: 4px 10px;
  border-radius: 99px;
  white-space: nowrap;
}

.nav-admin-btn {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 99px;
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-mid);
  cursor: pointer;
  transition: all var(--transition);
  font-family: 'Sarabun', sans-serif;
  white-space: nowrap;
}
.nav-admin-btn:hover {
  border-color: var(--primary);
  color: var(--primary-dark);
  background: var(--primary-light);
}

.nav-logout-btn:hover {
  border-color: #ef4444;
  color: #dc2626;
  background: #fee2e2;
}

/* Change password modal wider */
.changepw-box {
  max-width: 480px !important;
}


