/**
 * assets/css/app.css — Modern Academic UI/UX Design System
 * สำหรับ: timetable.maelai.ac.th (ระบบจัดตารางสอนออนไลน์ โรงเรียนบ้านแม่ไล)
 * มาตรฐานการออกแบบ: Enterprise Academic Design System, Responsive & Accessible
 */

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

:root {
  /* Brand Color Palette */
  --primary: #1e40af;           /* Royal Academic Blue */
  --primary-hover: #1d4ed8;
  --primary-light: #3b82f6;
  --primary-subtle: #eff6ff;
  --primary-border: #bfdbfe;

  --accent: #0284c7;            /* Ocean Cyan */
  --accent-light: #e0f2fe;

  --success: #059669;           /* Emerald Green */
  --success-subtle: #ecfdf5;
  --success-border: #a7f3d0;

  --warning: #d97706;           /* Amber Orange */
  --warning-subtle: #fffbeb;
  --warning-border: #fde68a;

  --danger: #dc2626;            /* Rose Red */
  --danger-subtle: #fef2f2;
  --danger-border: #fecaca;

  /* Neutrals & Surfaces */
  --dark: #0f172a;              /* Slate 900 */
  --text-main: #1e293b;         /* Slate 800 */
  --text-muted: #64748b;        /* Slate 500 */
  --text-light: #94a3b8;        /* Slate 400 */
  --bg-app: #f8fafc;            /* Slate 50 */
  --surface: #ffffff;
  --border: #e2e8f0;            /* Slate 200 */
  --border-focus: #3b82f6;

  /* Thai Day Modern Pastel Palette */
  --day-0-bg: #fef9c3; --day-0-text: #854d0e; --day-0-border: #fef08a; /* จันทร์ - เหลือง */
  --day-1-bg: #fce7f3; --day-1-text: #9d174d; --day-1-border: #fbcfe8; /* อังคาร - ชมพู */
  --day-2-bg: #dcfce7; --day-2-text: #166534; --day-2-border: #bbf7d0; /* พุธ - เขียว */
  --day-3-bg: #ffedd5; --day-3-text: #9a3412; --day-3-border: #fed7aa; /* พฤหัสบดี - ส้ม */
  --day-4-bg: #e0f2fe; --day-4-text: #075985; --day-4-border: #bae6fd; /* ศุกร์ - ฟ้า */
  --day-5-bg: #f3e8ff; --day-5-text: #6b21a8; --day-5-border: #e9d5ff; /* เสาร์ - ม่วง */
  --day-6-bg: #fee2e2; --day-6-text: #991b1b; --day-6-border: #fecaca; /* อาทิตย์ - แดง */

  /* Shadows & Elevation */
  --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.08), 0 1px 2px -1px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.07), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.04);

  /* Geometry */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --radius-full: 9999px;
  --header-height: 68px;
}

/* ══════════ BASE RESET & TYPOGRAPHY ══════════ */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 15px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3, h4, h5, h6, .brand-font, .page-title, .modal-title {
  font-family: 'Prompt', 'Sarabun', sans-serif;
  letter-spacing: -0.01em;
  font-weight: 600;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: all 0.2s ease;
}

a:hover {
  color: var(--primary-hover);
}

/* ══════════ MODERN APP HEADER & NAVBAR ══════════ */
.app-header {
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.header-container {
  max-width: 1360px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: #fff;
}

.header-logo-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.4);
}

.brand-info {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
  color: #ffffff;
}

.brand-subtitle {
  font-size: 12px;
  color: #94a3b8;
  display: flex;
  align-items: center;
  gap: 6px;
}

.school-tag {
  color: #38bdf8;
  font-weight: 600;
}

/* Nav Menu */
.app-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-link-item {
  position: relative;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 13.5px;
  font-weight: 500;
  color: #cbd5e1;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
  white-space: nowrap;
}

.nav-link:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.08);
}

.nav-link.active {
  color: #ffffff;
  background: var(--primary);
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(30, 64, 175, 0.4);
}

/* Dropdown */
.nav-dropdown {
  position: relative;
}

.nav-dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-md);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.2);
  min-width: 220px;
  padding: 6px;
  display: none;
  z-index: 1050;
  animation: dropdownFadeIn 0.18s ease-out;
}

@keyframes dropdownFadeIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

.nav-dropdown:hover .nav-dropdown-menu,
.nav-dropdown:focus-within .nav-dropdown-menu {
  display: block;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  font-size: 13px;
  color: #cbd5e1;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

.dropdown-item:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.dropdown-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  margin: 4px 0;
}

/* User Account & Actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-profile-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-full);
  font-size: 12.5px;
  color: #e2e8f0;
}

.user-role-badge {
  background: #0284c7;
  color: #fff;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 10.5px;
  font-weight: 600;
}

.btn-logout {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  transition: all 0.2s ease;
}

.btn-logout:hover {
  background: #dc2626;
  color: #ffffff;
  border-color: #dc2626;
}

/* ══════════ MAIN CONTENT & LAYOUT ══════════ */
main {
  max-width: 1280px;
  width: 100%;
  margin: 28px auto;
  padding: 0 20px 60px;
  flex: 1;
}

.page-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 24px;
}

.page-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--dark);
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-title::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 24px;
  background: linear-gradient(180deg, var(--primary) 0%, var(--accent) 100%);
  border-radius: 4px;
}

/* ══════════ CARDS & SURFACES ══════════ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
  transition: box-shadow 0.2s ease;
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--dark);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* ══════════ MODERN BUTTONS ══════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.18s ease;
  white-space: nowrap;
  user-select: none;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 4px rgba(30, 64, 175, 0.2);
}
.btn-primary:hover {
  background: var(--primary-hover);
  color: #fff;
  box-shadow: 0 4px 10px rgba(30, 64, 175, 0.3);
}

.btn-success {
  background: var(--success);
  color: #ffffff;
  box-shadow: 0 2px 4px rgba(5, 150, 105, 0.2);
}
.btn-success:hover {
  background: #047857;
  color: #fff;
  box-shadow: 0 4px 10px rgba(5, 150, 105, 0.3);
}

.btn-warning {
  background: var(--warning);
  color: #ffffff;
}
.btn-warning:hover {
  background: #b45309;
  color: #fff;
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
  box-shadow: 0 2px 4px rgba(220, 38, 38, 0.2);
}
.btn-danger:hover {
  background: #b91c1c;
  color: #fff;
}

.btn-secondary {
  background: #f1f5f9;
  color: #475569;
  border-color: #cbd5e1;
}
.btn-secondary:hover {
  background: #e2e8f0;
  color: #1e293b;
}

.btn-outline-primary {
  background: transparent;
  border-color: var(--primary);
  color: var(--primary);
}
.btn-outline-primary:hover {
  background: var(--primary-subtle);
}

.btn-sm {
  padding: 5px 12px;
  font-size: 12px;
  border-radius: 5px;
}

/* ══════════ MODERN FORMS & INPUTS ══════════ */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  align-items: flex-end;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: #334155;
}

.form-control,
input[type="text"],
input[type="number"],
input[type="password"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 9px 13px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text-main);
  background: #ffffff;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all 0.18s ease;
  outline: none;
}

.form-control:focus,
input:focus,
select:focus,
textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
  background: #ffffff;
}

/* ══════════ MODERN TABLES ══════════ */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  text-align: left;
}

th {
  background: #f1f5f9;
  color: #334155;
  font-family: 'Prompt', 'Sarabun', sans-serif;
  font-weight: 600;
  padding: 12px 14px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 11px 14px;
  border-bottom: 1px solid #f1f5f9;
  color: #334155;
  vertical-align: middle;
}

tbody tr {
  transition: background 0.12s ease;
}

tbody tr:hover {
  background: #f8fafc;
}

tbody tr:last-child td {
  border-bottom: none;
}

/* ══════════ MODERN BADGES & PILLS ══════════ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.4;
}

.badge-primary { background: var(--primary-subtle); color: var(--primary); border: 1px solid var(--primary-border); }
.badge-success { background: var(--success-subtle); color: var(--success); border: 1px solid var(--success-border); }
.badge-warning { background: var(--warning-subtle); color: var(--warning); border: 1px solid var(--warning-border); }
.badge-danger  { background: var(--danger-subtle);  color: var(--danger);  border: 1px solid var(--danger-border); }
.badge-neutral { background: #f1f5f9; color: #475569; border: 1px solid #cbd5e1; }

/* ══════════ FLOATING TOAST ALERTS ══════════ */
.alert-toast {
  position: fixed;
  top: 80px;
  right: 24px;
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-xl);
  animation: slideInRight 0.25s ease-out;
  max-width: 420px;
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

.alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-danger  { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alert-info    { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* ══════════ THAI DAY PILLS & COLORING ══════════ */
.day-pill-0 { background: var(--day-0-bg); color: var(--day-0-text); border: 1.5px solid var(--day-0-border); }
.day-pill-1 { background: var(--day-1-bg); color: var(--day-1-text); border: 1.5px solid var(--day-1-border); }
.day-pill-2 { background: var(--day-2-bg); color: var(--day-2-text); border: 1.5px solid var(--day-2-border); }
.day-pill-3 { background: var(--day-3-bg); color: var(--day-3-text); border: 1.5px solid var(--day-3-border); }
.day-pill-4 { background: var(--day-4-bg); color: var(--day-4-text); border: 1.5px solid var(--day-4-border); }
.day-pill-5 { background: var(--day-5-bg); color: var(--day-5-text); border: 1.5px solid var(--day-5-border); }
.day-pill-6 { background: var(--day-6-bg); color: var(--day-6-text); border: 1.5px solid var(--day-6-border); }

/* ══════════ MODERN PRINT & EXPORT TOOLBAR ══════════ */
.no-print {
  background: var(--surface) !important;
  border: 1px solid var(--border) !important;
  padding: 14px 20px !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-sm) !important;
  margin-bottom: 20px !important;
  display: flex !important;
  gap: 12px !important;
  align-items: center !important;
  flex-wrap: wrap !important;
}

.no-print strong {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
  margin-right: 4px;
}

.no-print .form-group {
  margin-bottom: 0 !important;
  display: flex;
  align-items: center;
  gap: 8px;
}

.no-print select, .no-print input {
  padding: 8px 12px !important;
  border: 1.5px solid var(--border) !important;
  border-radius: var(--radius-sm) !important;
  font-family: inherit !important;
  font-size: 13.5px !important;
  background-color: var(--surface) !important;
  color: var(--text-main) !important;
}

.no-print select:focus, .no-print input:focus {
  border-color: var(--primary) !important;
  outline: none;
  box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.12) !important;
}

.print-page {
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-md) !important;
  background: #ffffff !important;
}

@media print {
  header, nav, .no-print, .alert-toast { display: none !important; }
  main { margin: 0 !important; padding: 0 !important; max-width: none !important; }
  body { background: white !important; }
  .print-page {
    border-radius: 0 !important;
    box-shadow: none !important;
    margin: 0 !important;
  }
}

/* ══════════ RESPONSIVE ADJUSTMENTS ══════════ */
@media (max-width: 1024px) {
  .header-container {
    height: auto;
    padding: 10px 16px;
    flex-wrap: wrap;
    gap: 10px;
  }
  .app-nav {
    order: 3;
    width: 100%;
    overflow-x: auto;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }
  .app-nav::-webkit-scrollbar {
    height: 3px;
  }
  .app-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
  }
}
