@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --primary:       #4f46e5;
  --primary-dark:  #3730a3;
  --primary-light: #818cf8;
  --sidebar-bg:    #1e1b4b;
  --sidebar-hover: #312e81;
  --sidebar-active:#4f46e5;
  --body-bg:       #f8fafc;
  --card-bg:       #ffffff;
  --text-main:     #0f172a;
  --text-muted:    #64748b;
  --border:        #e2e8f0;
  --success:       #10b981;
  --warning:       #f59e0b;
  --danger:        #ef4444;
  --info:          #0ea5e9;
  --sidebar-width: 260px;
  --header-h:      64px;
}

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

body {
  font-family: 'Sarabun', 'Inter', sans-serif;
  background: var(--body-bg);
  color: var(--text-main);
  font-size: 15px;
  line-height: 1.6;
}

/* ─── SIDEBAR ─── */
.sidebar {
  position: fixed; top: 0; left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex; flex-direction: column;
  z-index: 1000;
  transition: transform .3s ease;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; gap: 12px;
}
.sidebar-brand img { width: 40px; height: 40px; border-radius: 10px; object-fit: cover; background: #fff; }
.sidebar-brand .brand-logo-placeholder {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--primary); display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}
.sidebar-brand .brand-text { flex: 1; min-width: 0; }
.sidebar-brand .school-name {
  font-size: 13px; font-weight: 600; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-brand .app-name { font-size: 11px; color: rgba(255,255,255,.5); }

.sidebar-user {
  padding: 14px 20px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-user .avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary); display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 600; color: #fff; flex-shrink: 0;
}
.sidebar-user .user-name { font-size: 13px; color: #fff; font-weight: 500; }
.sidebar-user .user-role { font-size: 11px; color: rgba(255,255,255,.5); }

.sidebar-nav { padding: 12px 0; flex: 1; }
.nav-label {
  padding: 8px 20px 4px;
  font-size: 10px; font-weight: 700;
  color: rgba(255,255,255,.35);
  text-transform: uppercase; letter-spacing: 1px;
}
.nav-item { display: block; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px;
  color: rgba(255,255,255,.65);
  text-decoration: none;
  font-size: 14px; font-weight: 400;
  border-left: 3px solid transparent;
  transition: all .15s;
}
.nav-link i { width: 18px; text-align: center; font-size: 15px; flex-shrink: 0; }
.nav-link:hover { background: var(--sidebar-hover); color: #fff; }
.nav-link.active {
  background: rgba(79,70,229,.25);
  color: #fff; font-weight: 600;
  border-left-color: var(--primary-light);
}
.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.sidebar-footer a {
  display: flex; align-items: center; gap: 10px;
  color: rgba(255,255,255,.5); text-decoration: none; font-size: 13px;
  transition: color .15s;
}
.sidebar-footer a:hover { color: #fff; }

/* ─── MAIN LAYOUT ─── */
.main-wrapper {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex; flex-direction: column;
}
.topbar {
  height: var(--header-h);
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px;
  position: sticky; top: 0; z-index: 100;
}
.topbar-title { font-size: 17px; font-weight: 600; color: var(--text-main); }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.page-content { padding: 28px; flex: 1; }

/* ─── CARDS ─── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.card-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  background: transparent;
  border-radius: 14px 14px 0 0;
}
.card-header h5 { font-size: 15px; font-weight: 600; margin: 0; }
.card-body { padding: 22px; }

/* ─── STAT CARDS ─── */
.stat-card {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 22px;
  border: 1px solid var(--border);
  display: flex; align-items: flex-start; gap: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.stat-icon {
  width: 52px; height: 52px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; flex-shrink: 0;
}
.stat-icon.indigo  { background: #eef2ff; color: #4f46e5; }
.stat-icon.green   { background: #f0fdf4; color: #10b981; }
.stat-icon.amber   { background: #fffbeb; color: #f59e0b; }
.stat-icon.red     { background: #fef2f2; color: #ef4444; }
.stat-icon.sky     { background: #f0f9ff; color: #0ea5e9; }
.stat-icon.purple  { background: #faf5ff; color: #8b5cf6; }
.stat-val { font-size: 28px; font-weight: 700; line-height: 1; }
.stat-label { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* ─── TABLES ─── */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
table th {
  background: #f8fafc; color: var(--text-muted);
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px;
  padding: 12px 16px; text-align: left;
  border-bottom: 2px solid var(--border);
}
table td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px; vertical-align: middle;
}
table tr:last-child td { border-bottom: none; }
table tr:hover td { background: #f8fafc; }

/* ─── BADGES ─── */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 99px;
  font-size: 12px; font-weight: 500; gap: 4px;
}
.bg-purple { background: #7c3aed !important; }
.badge.bg-indigo { background: #eef2ff; color: #4f46e5; }
.badge.bg-green-soft { background: #f0fdf4; color: #16a34a; }
.badge.bg-amber-soft { background: #fffbeb; color: #d97706; }
.badge.bg-red-soft { background: #fef2f2; color: #dc2626; }

/* ─── BUTTONS ─── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 18px; border-radius: 9px;
  font-size: 14px; font-weight: 500;
  border: none; cursor: pointer; text-decoration: none;
  transition: all .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-main); }
.btn-outline:hover { background: #f1f5f9; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; color: #fff; }
.btn-sm { padding: 6px 13px; font-size: 13px; border-radius: 7px; }
.btn-icon { padding: 7px 10px; }

/* ─── FORMS ─── */
.form-label { font-size: 13px; font-weight: 500; margin-bottom: 6px; display: block; }
.form-control, .form-select {
  width: 100%; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: 9px;
  font-size: 14px; font-family: inherit;
  background: #fff; color: var(--text-main);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}
.form-control.is-invalid { border-color: var(--danger); }
.input-group { display: flex; }
.input-group .form-control { border-radius: 9px 0 0 9px; }
.input-group .btn { border-radius: 0 9px 9px 0; }

/* ─── ALERTS ─── */
.alert {
  padding: 13px 18px; border-radius: 10px;
  font-size: 14px; margin-bottom: 16px;
  display: flex; align-items: flex-start; gap: 10px;
}
.alert-success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.alert-danger  { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alert-info    { background: #f0f9ff; color: #075985; border: 1px solid #bae6fd; }

/* ─── LOGIN PAGE ─── */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #1e1b4b 100%);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  background: #fff; border-radius: 20px;
  padding: 44px 40px; width: 100%; max-width: 420px;
  box-shadow: 0 25px 60px rgba(0,0,0,.35);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .logo-circle {
  width: 72px; height: 72px; border-radius: 18px;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 32px; margin-bottom: 14px;
}
.login-logo h1 { font-size: 20px; font-weight: 700; color: #1e1b4b; }
.login-logo p { font-size: 13px; color: var(--text-muted); }

/* ─── PROFILE ─── */
.profile-header {
  background: linear-gradient(135deg, var(--sidebar-bg), #312e81);
  border-radius: 14px; padding: 32px; color: #fff;
  display: flex; align-items: center; gap: 24px;
  margin-bottom: 24px;
}
.profile-avatar {
  width: 80px; height: 80px; border-radius: 50%;
  background: var(--primary); display: flex; align-items: center;
  justify-content: center; font-size: 32px; font-weight: 700;
  border: 3px solid rgba(255,255,255,.3); flex-shrink: 0;
}

/* ─── SCORE CIRCLE ─── */
.score-circle {
  width: 90px; height: 90px; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 700; border: 4px solid;
}
.score-circle.success { border-color: var(--success); color: var(--success); }
.score-circle.warning { border-color: var(--warning); color: var(--warning); }
.score-circle.danger  { border-color: var(--danger); color: var(--danger); }
.score-circle .score-num { font-size: 22px; line-height: 1; }
.score-circle .score-unit { font-size: 11px; }

/* ─── PROGRESS ─── */
.progress { height: 8px; border-radius: 99px; background: #f1f5f9; overflow: hidden; }
.progress-bar { height: 100%; border-radius: 99px; transition: width .4s; }
.progress-bar.bg-success { background: var(--success); }
.progress-bar.bg-warning { background: var(--warning); }
.progress-bar.bg-danger  { background: var(--danger); }

/* ─── FORM BUILDER ─── */
.item-block {
  background: #f8fafc; border: 1px solid var(--border);
  border-radius: 10px; padding: 16px; margin-bottom: 10px;
  position: relative;
}
.item-block .drag-handle {
  cursor: grab; color: var(--text-muted); margin-right: 8px;
}
.item-block:hover { border-color: var(--primary-light); }

/* ─── RESPONSIVE ─── */

/* Hamburger: hidden on desktop, shown on mobile via media query */
#menuBtn { display: none !important; }

/* Bootstrap-compatible utility classes */
.d-none { display: none !important; }
@media (min-width: 769px) { .d-md-inline { display: inline !important; } }

@media (max-width: 768px) {
  /* Sidebar slide-in */
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-wrapper { margin-left: 0; }
  .page-content { padding: 14px; }
  .stat-card { padding: 14px; }

  /* Show hamburger on mobile */
  #menuBtn { display: flex !important; }

  /* Topbar: compact on mobile */
  .topbar { padding: 0 10px; gap: 0; }
  .topbar .d-flex { flex: 1; min-width: 0; overflow: hidden; }
  .topbar-title { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
  .topbar-right { gap: 4px; flex-shrink: 0; }
  /* Hide user name text on mobile — keep only icon */
  .topbar-user-name { display: none; }
  /* Smaller action buttons */
  .topbar-right .btn-sm { padding: 7px 10px; }

  /* Period banner compact */
  .period-banner { padding: 5px 12px !important; font-size: 11px !important; }

  /* Profile header: stack on mobile */
  .profile-header { flex-direction: column; text-align: center; padding: 20px 16px; gap: 12px; }
  .profile-avatar { margin: 0 auto; }

  /* Score circle smaller on mobile */
  .score-circle { width: 72px; height: 72px; }
  .score-circle .score-num { font-size: 18px; }

  /* Table: touch-friendly scroll */
  .table-wrapper { -webkit-overflow-scrolling: touch; }

  /* Card body padding tighter */
  .card-body { padding: 16px; }
  .card-header { padding: 14px 16px; }

  /* Form elements: always full-width on mobile */
  .form-control, .form-select { font-size: 16px; } /* prevents iOS zoom */

  /* Login card: reduce padding */
  .login-card { padding: 28px 20px; }

  /* Stat grid: 2 columns on tablet, already handled in grid-4 */
  .grid-2 { gap: 12px; }
}

@media (max-width: 480px) {
  /* Topbar title even shorter on very small screens */
  .topbar-title { max-width: 110px; font-size: 13px; }

  /* Notification dropdown: fit within viewport */
  #notifDropdown { width: min(340px, calc(100vw - 20px)) !important; max-height: 70vh; overflow-y: auto; }

  /* Stat cards: smaller numbers on very small screens */
  .stat-val { font-size: 22px; }
  .stat-icon { width: 42px; height: 42px; font-size: 18px; }

  /* Page content: tighter */
  .page-content { padding: 10px; }
  .card-body { padding: 12px; }

  /* Eval record: rating buttons wrap nicely */
  .score-row { padding: 14px 12px !important; }

  /* Button row: wrap on very small screens */
  .topbar-right { gap: 2px; }
  .topbar-right .btn-sm { padding: 6px 8px; font-size: 12px; }

  /* Hide "dark mode" text if any */
  #darkToggle { padding: 6px; }
}

/* ─── UTILS ─── */
.text-muted    { color: var(--text-muted)  !important; }
.text-primary  { color: var(--primary)     !important; }
.text-success  { color: var(--success)     !important; }
.text-warning  { color: var(--warning)     !important; }
.text-danger   { color: var(--danger)      !important; }
.text-center   { text-align: center !important; }
.text-right    { text-align: right  !important; }
.fw-600 { font-weight: 600; }
.gap-2 { gap: .5rem; }
.gap-3 { gap: .75rem; }
.d-flex { display: flex; }
.align-items-center { align-items: center; }
.justify-content-between { justify-content: space-between; }
.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: .25rem !important; }
.mb-2 { margin-bottom: .5rem !important; }
.mb-3 { margin-bottom: .75rem !important; }
.mb-4 { margin-bottom: 1rem !important; }
.mt-1 { margin-top: .25rem !important; }
.mt-3 { margin-top: .75rem !important; }
.ms-auto { margin-left: auto !important; }
.me-1 { margin-right: .25rem !important; }
.me-2 { margin-right: .5rem !important; }
.w-100 { width: 100% !important; }
.small { font-size: 12px; }
.fs-13 { font-size: 13px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
@media (max-width: 900px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 600px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* Sidebar overlay for mobile */
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.5); z-index: 999;
}
.sidebar-overlay.show { display: block; }

/* Toast */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: #1e293b; color: #fff; padding: 14px 20px;
  border-radius: 12px; font-size: 14px; display: flex; align-items: center; gap: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  animation: slideIn .25s ease;
}
.toast.success { border-left: 4px solid var(--success); }
.toast.error   { border-left: 4px solid var(--danger); }
@keyframes slideIn { from { transform: translateX(80px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ─── DARK MODE ─── */
[data-theme="dark"] {
  --body-bg:    #0f172a;
  --card-bg:    #1e293b;
  --text-main:  #e2e8f0;
  --text-muted: #94a3b8;
  --border:     #334155;
}
[data-theme="dark"] body { background: var(--body-bg); color: var(--text-main); }
[data-theme="dark"] .topbar { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .topbar-title { color: #e2e8f0; }
[data-theme="dark"] .card { background: var(--card-bg); border-color: var(--border); }
[data-theme="dark"] .stat-card { background: var(--card-bg); border-color: var(--border); }
[data-theme="dark"] table th { background: #273347; color: #94a3b8; border-color: #334155; }
[data-theme="dark"] table td { border-color: #334155; }
[data-theme="dark"] table tr:hover td { background: #243044; }
[data-theme="dark"] .form-control, [data-theme="dark"] .form-select { background: #273347; color: #e2e8f0; border-color: #334155; }
[data-theme="dark"] .form-control:focus, [data-theme="dark"] .form-select:focus { border-color: var(--primary); }
[data-theme="dark"] .btn-outline { border-color: #334155; color: #e2e8f0; }
[data-theme="dark"] .btn-outline:hover { background: #334155; }
[data-theme="dark"] .item-block { background: #273347; border-color: #334155; }
[data-theme="dark"] #notifDropdown { background: #1e293b !important; border-color: #334155 !important; }
[data-theme="dark"] .card-header { border-color: #334155; }
[data-theme="dark"] .progress { background: #334155; }
[data-theme="dark"] .stat-icon.indigo  { background: #1e1b4b; }
[data-theme="dark"] .stat-icon.green   { background: #064e3b; }
[data-theme="dark"] .stat-icon.amber   { background: #451a03; }
[data-theme="dark"] .stat-icon.red     { background: #450a0a; }
[data-theme="dark"] .stat-icon.sky     { background: #082f49; }
[data-theme="dark"] .stat-icon.purple  { background: #2e1065; }
