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

:root {
  --bs-primary: #4f46e5;      /* Indigo 600 */
  --bs-primary-rgb: 79, 70, 229;
  --bs-font-sans-serif: 'Kanit', system-ui, sans-serif;
  --bg-subtle: #f8fafc;       /* Slate 50 */
  --border-color: #e2e8f0;    /* Slate 200 */
  --text-main: #0f172a;       /* Slate 900 */
  --text-muted: #64748b;      /* Slate 500 */
}

body {
  font-family: var(--bs-font-sans-serif);
  background-color: var(--bg-subtle);
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
}

/* Primary Color Overrides */
.btn-primary {
  --bs-btn-bg: #4f46e5;
  --bs-btn-border-color: #4f46e5;
  --bs-btn-hover-bg: #4338ca;
  --bs-btn-hover-border-color: #4338ca;
  --bs-btn-active-bg: #3730a3;
  --bs-btn-active-border-color: #3730a3;
  --bs-btn-focus-shadow-rgb: 79, 70, 229;
}
.btn-outline-primary {
  --bs-btn-color: #4f46e5;
  --bs-btn-border-color: #4f46e5;
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: #4f46e5;
  --bs-btn-hover-border-color: #4f46e5;
}
.text-primary { color: #4f46e5 !important; }
.bg-primary { background-color: #4f46e5 !important; }
.border-primary { border-color: #4f46e5 !important; }
.badge.bg-primary { background-color: #4f46e5 !important; }
.bg-primary-subtle { background-color: #e0e7ff !important; color: #4338ca !important; }
.form-check-input:checked { background-color: #4f46e5; border-color: #4f46e5; }
.form-control:focus, .form-select:focus {
  border-color: #a5b4fc;
  box-shadow: 0 0 0 .25rem rgba(79, 70, 229, .2);
}

/* Beautiful UI Utilities */
.card {
  border: none !important;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05), 0 2px 4px -2px rgba(0,0,0,0.05) !important;
  border-radius: 1rem !important;
  background-color: #ffffff;
}
.card-header {
  border-bottom: 1px solid var(--border-color) !important;
  background-color: transparent !important;
  border-top-left-radius: 1rem !important;
  border-top-right-radius: 1rem !important;
  padding: 1rem 1.25rem;
}
.table-light {
  --bs-table-bg: #f8fafc;
}

.shadow-sm { box-shadow: 0 1px 3px 0 rgba(0,0,0,0.05) !important; }
.rounded-4 { border-radius: 1rem !important; }

/* Dashboard Cards (Vibrant Glow) */
.stat-card-gradient {
  border: none;
  border-radius: 1rem;
  padding: 1.5rem;
  color: #fff !important;
  position: relative;
  overflow: hidden;
  box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
}
.stat-card-gradient::before, .stat-card-gradient::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
}
.stat-card-gradient::before { width: 100px; height: 100px; top: -30px; right: -30px; }
.stat-card-gradient::after  { width: 140px; height: 140px; bottom: -50px; right: 10px; }
.stat-card-gradient p.mb-1 { color: rgba(255,255,255,0.85) !important; font-weight: 400; }
.stat-card-gradient i { color: #fff !important; opacity: 0.25 !important; z-index: 0; }

/* Badges */
.badge {
  font-weight: 500;
  border-radius: 0.375rem;
  padding: 0.4em 0.8em;
  border: 1px solid transparent;
}
.bg-success-subtle { background-color: #ecfdf5 !important; border-color: #d1fae5; color: #059669 !important; }
.bg-danger-subtle { background-color: #fef2f2 !important; border-color: #fee2e2; color: #dc2626 !important; }
.bg-warning-subtle { background-color: #fffbeb !important; border-color: #fef3c7; color: #d97706 !important; }
.bg-info-subtle { background-color: #eff6ff !important; border-color: #dbeafe; color: #2563eb !important; }
.bg-secondary-subtle { background-color: #f1f5f9 !important; color: #475569 !important; }

/* Sidebar Fixed Full Height */
#sidebar {
  width: 260px;
  border-right: 1px solid var(--border-color) !important;
  background-color: #ffffff !important;
  flex-shrink: 0;
}
@media (min-width: 992px) {
  #sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    transform: none !important;
    visibility: visible !important;
    display: flex !important;
  }
}
.sidebar-nav-link {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem 1rem;
  border-radius: 0.5rem;
  font-size: .95rem;
  text-decoration: none;
  color: var(--text-muted);
  transition: all .2s;
  margin: 0.2rem 0;
}
.sidebar-nav-link:hover { background: #f1f5f9; color: var(--bs-primary); }
.sidebar-nav-link.active { background: #eef2ff; color: var(--bs-primary); font-weight: 600; }
.sidebar-nav-link.text-danger:hover { background: #fef2f2; color: #dc2626 !important; }

/* Page Structure */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.page-subtitle { font-size: .9rem; color: var(--text-muted); margin-top: .25rem; }
.breadcrumb-text { font-size: .85rem; color: #94a3b8; margin-bottom: .25rem; }
.breadcrumb-text a { color: var(--bs-primary); text-decoration: none; font-weight: 500; }
.breadcrumb-text a:hover { text-decoration: underline; }

/* Classroom Cards */
.classroom-card {
  cursor: pointer;
  transition: transform .2s, box-shadow .2s;
}
.classroom-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 20px -5px rgba(0,0,0,0.08), 0 8px 10px -6px rgba(0,0,0,0.04) !important;
}

/* QR Screen Timer */
.qr-timer-bar {
  height: 6px;
  background: #f1f5f9;
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: .5rem;
}
.qr-timer-fill {
  height: 100%;
  background: linear-gradient(90deg, #6366f1, #3b82f6);
  transition: width .9s linear;
}

/* Checkin Grid */
.student-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  padding-bottom: 2rem;
}
.student-btn {
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  padding: 1rem 0.5rem;
  text-align: center;
  cursor: pointer;
  transition: all .2s;
  color: var(--text-main);
  box-shadow: 0 1px 2px rgba(0,0,0,0.02);
  width: 100%;
}
.student-btn:hover:not(:disabled) { border-color: var(--bs-primary); box-shadow: 0 4px 6px rgba(79,70,229,0.1); transform: translateY(-1px); }
.student-btn.checked { background: #ecfdf5; border-color: #10b981; }
.student-btn:disabled { opacity: .6; cursor: not-allowed; }
.sb-code { font-size: .8rem; color: var(--text-muted); margin-bottom: .25rem; }
.sb-name { font-size: .9rem; font-weight: 500; }
.sb-status { font-size: .8rem; color: #059669; margin-top: .4rem; font-weight: 600; }

/* Custom Search */
.search-bar { position: relative; display: flex; align-items: center; }
.search-bar input {
  width: 100%;
  padding: 0.5rem 0.75rem 0.5rem 2.2rem;
  font-size: 0.9rem;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.search-bar input:focus { border-color: #a5b4fc; box-shadow: 0 0 0 .25rem rgba(79, 70, 229, .15); }
.search-bar .search-icon {
  position: absolute;
  left: 0.75rem;
  color: #94a3b8;
  font-size: 1.1rem;
}

/* Base Layout Container (Full Width support) */
.app-layout { display: flex; min-height: 100vh; }
.main-content { flex-grow: 1; min-width: 0; background: var(--bg-subtle); padding-bottom: 2rem; }
.page-wrap { padding: 1.5rem; margin: 0 auto; width: 100%; /* No max-width restriction for full-width */ }

/* Empty States */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  border: 1.5px dashed var(--border-color);
  border-radius: 1rem;
  background: #f8fafc;
}
.empty-icon { font-size: 2.5rem; margin-bottom: 0.5rem; color: #cbd5e1; }
.empty-text { font-size: 0.95rem; }

/* Tables */
.table-wrap { overflow-x: auto; background: #fff; border: none; border-radius: 1rem; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05); }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 1rem 1.25rem; font-size: 0.8rem; text-transform: uppercase; font-weight: 600; color: #64748b; border-bottom: 2px solid #f1f5f9; background: #f8fafc; }
td { padding: 1rem 1.25rem; font-size: 0.95rem; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background-color: #f8fafc; }

/* Native Dialog Replacement (Bootstrap styles apply instead, but if used natively) */
dialog {
  border: none;
  border-radius: 1rem;
  padding: 1.5rem;
  width: 100%;
  max-width: 450px;
  box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
}
dialog::backdrop { background: rgba(15,23,42,0.4); backdrop-filter: blur(2px); }
.dialog-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.dialog-title { font-weight: 600; font-size: 1.25rem; }
.dialog-close { background: #f1f5f9; border: none; font-size: 1rem; border-radius: 50%; width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: #64748b; transition: all .2s; }
.dialog-close:hover { color: #0f172a; background: #e2e8f0; }
.dialog-footer { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.5rem; }

/* Buttons Custom */
.btn { font-weight: 500; font-family: inherit; }
.btn-ghost { background: transparent; border: 1px solid transparent; color: var(--text-main); padding: 0.45rem 1rem; border-radius: 0.5rem; font-size: 0.95rem; transition: background .15s; }
.btn-ghost:hover { background: #f1f5f9; }
.btn-success { background: #10b981; border-color: #10b981; color: white; display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.45rem 1rem; border-radius: 0.5rem; transition: background .2s;}
.btn-success:hover { background: #059669; }
.btn-danger { display: inline-flex; align-items: center; gap: 0.4rem; border-radius: 0.5rem; padding: 0.45rem 1rem; }

/* Minimalist Toasts that pop */
#toast-container { position: fixed; bottom: 2rem; right: 2rem; z-index: 9999; display: flex; flex-direction: column; gap: 0.75rem; }
.toast { background: #27272a; color: #fff; padding: 1rem 1.25rem; border-radius: 0.75rem; font-size: 0.95rem; font-weight: 500; box-shadow: 0 10px 15px -3px rgba(0,0,0,0.2); }
.toast-error { background: #dc2626; }

/* Form Elements */
.form-group label { display: block; font-size: 0.9rem; font-weight: 500; margin-bottom: 0.5rem; color: #334155; }
.form-group input, .form-group textarea { width: 100%; padding: 0.6rem 0.8rem; border: 1px solid var(--border-color); border-radius: 0.5rem; font-family: inherit; font-size: 0.95rem; transition: all .2s; }
.form-group input:focus, .form-group textarea:focus { outline: none; border-color: var(--bs-primary); box-shadow: 0 0 0 .25rem rgba(79, 70, 229, .15); }

/* QR Standalone Checkin */
.checkin-page { max-width: 600px; margin: 3rem auto; padding: 2rem 1.5rem; background: #fff; border-radius: 1.5rem; box-shadow: 0 10px 25px rgba(0,0,0,0.05); }
@media (max-width: 600px) { .checkin-page { margin: 1rem; border-radius: 1rem; padding: 1.5rem 1rem; } }
.checkin-header { text-align: center; margin-bottom: 1.5rem; padding-bottom: 1.5rem; border-bottom: 1px solid #f1f5f9; }
.ch-icon { font-size: 3rem; line-height: 1; margin-bottom: 0.5rem; color: var(--bs-primary); }
.ch-sub { font-size: 1rem; color: var(--text-muted); margin-top: 0.25rem; }
.checkin-timer { text-align: center; font-size: 0.9rem; color: var(--text-muted); margin-bottom: 1.5rem; padding: 0.75rem; background: #f8fafc; border-radius: 0.75rem;}

/* Admin Details Layout Fixes */
.qr-big-card { background: #fff; border-radius: 1rem; padding: 1.5rem; text-align: center; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05); border: 1px solid var(--border-color); }
.qr-frame { background: #f1f5f9; padding: 1.5rem; border-radius: 1rem; display: inline-block; margin-bottom: 1.5rem; }

/* Stats grid */
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 2rem; }
.stat-card { border: none; border-radius: 1rem; padding: 1.5rem; background: #fff; text-align: center; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05); }
.stat-label { font-size: 0.8rem; color: #64748b; text-transform: uppercase; font-weight: 600; letter-spacing: 0.05em; }
.stat-num { font-size: 1.75rem; font-weight: 700; margin-top: 0.5rem; color: #0f172a; }

@media print {
  #sidebar, .d-lg-none, .no-print { display: none !important; }
  .main-content { margin-left: 0 !important; background: #fff !important; padding: 0 !important; }
  body { background: #fff !important; font-size: 12pt; }
  .card, .table-wrap, .stat-card { border: none !important; box-shadow: none !important; }
  .app-layout { display: block; }
}
