/* ===================================================
   style.css - ระบบขออนุญาตสอนคาบศูนย์
   โรงเรียนจอมสุรางค์อุปถัมภ์
   =================================================== */

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

:root {
  --primary:     #1a237e;
  --primary-light: #3949ab;
  --primary-dark: #0d1b5e;
  --accent:      #ffd600;
  --accent2:     #e53935;
  --success:     #2e7d32;
  --warning:     #f57f17;
  --danger:      #c62828;
  --bg:          #f0f2f5;
  --card-bg:     #ffffff;
  --text:        #1a1a2e;
  --text-muted:  #6b7280;
  --border:      #dde1e7;
  --shadow:      0 4px 24px rgba(26,35,126,0.10);
  --shadow-lg:   0 8px 40px rgba(26,35,126,0.18);
  --radius:      14px;
  --radius-sm:   8px;
}

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

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

/* ===== HEADER ===== */
.site-header {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, var(--primary-light) 100%);
  color: #fff;
  padding: 0;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 24px;
  gap: 16px;
}

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

.header-logo {
  width: 64px;
  height: 64px;
  object-fit: contain;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.3));
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  padding: 4px;
}

.header-title {
  line-height: 1.3;
}

.header-title h1 {
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.header-title p {
  font-size: 0.85rem;
  opacity: 0.85;
  font-weight: 400;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 20px;
  border-radius: 50px;
  font-family: 'Sarabun', sans-serif;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all 0.25s ease;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, #ffab00 100%);
  color: var(--primary-dark);
  box-shadow: 0 4px 15px rgba(255,214,0,0.4);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(255,214,0,0.5);
}

.btn-outline {
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 1.5px solid rgba(255,255,255,0.5);
  backdrop-filter: blur(10px);
}

.btn-outline:hover {
  background: rgba(255,255,255,0.25);
  border-color: #fff;
}

.btn-success {
  background: linear-gradient(135deg, #43a047, #2e7d32);
  color: #fff;
  box-shadow: 0 4px 15px rgba(46,125,50,0.3);
}

.btn-success:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(46,125,50,0.4);
}

.btn-danger {
  background: linear-gradient(135deg, #ef5350, #c62828);
  color: #fff;
  box-shadow: 0 4px 15px rgba(198,40,40,0.3);
}

.btn-danger:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(198,40,40,0.4);
}

.btn-secondary {
  background: linear-gradient(135deg, #607d8b, #455a64);
  color: #fff;
}

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

.btn-warning {
  background: linear-gradient(135deg, #ffa726, #f57f17);
  color: #fff;
}

.btn-sm {
  padding: 6px 14px;
  font-size: 0.82rem;
}

.btn-lg {
  padding: 14px 32px;
  font-size: 1.05rem;
}

/* ===== FOOTER ===== */
.site-footer {
  background: var(--primary-dark);
  color: rgba(255,255,255,0.8);
  text-align: center;
  padding: 20px;
  margin-top: 60px;
  font-size: 0.9rem;
}

.site-footer strong {
  color: var(--accent);
}

/* ===== MAIN CONTAINER ===== */
.main-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 30px 24px;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 30px 24px;
}

/* ===== PAGE TITLE ===== */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  flex-wrap: wrap;
  gap: 16px;
}

.page-title {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-title::before {
  content: '';
  display: block;
  width: 5px;
  height: 36px;
  background: linear-gradient(to bottom, var(--accent), var(--primary-light));
  border-radius: 3px;
}

/* ===== CARD ===== */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 24px;
  border: 1px solid var(--border);
  transition: box-shadow 0.25s;
}

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

.card-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: #fff;
  padding: 18px 24px;
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-body {
  padding: 24px;
}

/* ===== FORM ===== */
.form-section {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 24px;
  border: 1px solid var(--border);
}

.form-section-header {
  background: linear-gradient(135deg, var(--primary) 0%, #283593 100%);
  color: #fff;
  padding: 14px 22px;
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-section-body {
  padding: 22px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 7px;
  color: var(--primary-dark);
  font-size: 0.95rem;
}

.form-group label .required {
  color: var(--accent2);
  margin-left: 4px;
}

.form-control {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Sarabun', sans-serif;
  font-size: 0.95rem;
  color: var(--text);
  background: #fff;
  transition: border-color 0.2s, box-shadow 0.2s;
  appearance: none;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(57,73,171,0.15);
}

select.form-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%231a237e' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 18px;
}

/* ===== CHECKLIST ===== */
.checklist-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  cursor: pointer;
  transition: all 0.2s;
  background: #fafbff;
}

.checklist-item:hover {
  border-color: var(--primary-light);
  background: #eef2ff;
}

.checklist-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin-top: 2px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

.checklist-item.checked {
  border-color: var(--primary-light);
  background: #eef2ff;
}

/* ===== SIGNATURE PAD ===== */
.sig-box {
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: #fafbff;
  text-align: left;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 8px;
}

.sig-container canvas {
  display: block;
  width: 100%;
  height: 180px;
  background: #fff;
  border-radius: 6px;
  cursor: crosshair;
  touch-action: none;
}

.sig-toolbar {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  justify-content: flex-end;
}

.sig-label {
  position: absolute;
  top: 16px;
  left: 16px;
  color: #ccc;
  font-size: 0.85rem;
  pointer-events: none;
  user-select: none;
}

/* ===== TABLE ===== */
.table-responsive {
  overflow-x: auto;
  border-radius: var(--radius-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.93rem;
}

table thead tr {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
}

table thead th {
  padding: 13px 16px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
}

table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

table tbody tr:hover {
  background: #f5f7ff;
}

table tbody td {
  padding: 12px 16px;
  vertical-align: middle;
}

table tbody tr:nth-child(even) {
  background: #fafbff;
}

table tbody tr:nth-child(even):hover {
  background: #f0f4ff;
}

/* ===== BADGES ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: 50px;
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge-success {
  background: #e8f5e9;
  color: #2e7d32;
  border: 1px solid #a5d6a7;
}

.badge-danger {
  background: #ffebee;
  color: #c62828;
  border: 1px solid #ef9a9a;
}

.badge-warning {
  background: #fff8e1;
  color: #f57f17;
  border: 1px solid #ffe082;
}

.badge-info {
  background: #e3f2fd;
  color: #1565c0;
  border: 1px solid #90caf9;
}

/* ===== STAT CARDS ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}

.stat-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.stat-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  flex-shrink: 0;
}

.stat-icon.blue   { background: #e8eaf6; }
.stat-icon.green  { background: #e8f5e9; }
.stat-icon.red    { background: #ffebee; }
.stat-icon.orange { background: #fff3e0; }

.stat-info .stat-number {
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
}

.stat-info .stat-label {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ===== CHARTS ===== */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 28px;
}

.chart-card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 20px;
}

.chart-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ===== LOGIN ===== */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 60%, var(--primary-light) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: #fff;
  border-radius: 20px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  animation: slideUp 0.4s ease;
}

@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.login-logo {
  text-align: center;
  margin-bottom: 24px;
}

.login-logo img {
  width: 80px;
  height: 80px;
  object-fit: contain;
  border-radius: 50%;
  padding: 8px;
  background: var(--primary);
  box-shadow: 0 8px 24px rgba(26,35,126,0.3);
}

.login-logo h2 {
  margin-top: 14px;
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1.4;
}

.login-logo p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ===== ALERT ===== */
.alert {
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
  font-size: 0.93rem;
  display: flex;
  align-items: center;
  gap: 10px;
}

.alert-success { background: #e8f5e9; border-left: 4px solid #2e7d32; color: #1b5e20; }
.alert-danger  { background: #ffebee; border-left: 4px solid #c62828; color: #b71c1c; }
.alert-info    { background: #e3f2fd; border-left: 4px solid #1565c0; color: #0d47a1; }
.alert-warning { background: #fff8e1; border-left: 4px solid #f57f17; color: #e65100; }

/* ===== PAGINATION ===== */
.pagination {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.pagination a, .pagination span {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.pagination a {
  background: #fff;
  color: var(--primary);
  border: 1.5px solid var(--border);
}

.pagination a:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.pagination span {
  background: var(--primary);
  color: #fff;
  border: 1.5px solid var(--primary);
}

/* ===== SEARCH BAR ===== */
.search-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.search-bar .form-control {
  flex: 1;
  min-width: 200px;
}

/* ===== MODAL ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
}

.modal-overlay.active {
  display: flex;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-box {
  background: #fff;
  border-radius: var(--radius);
  max-width: 500px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  animation: zoomIn 0.25s ease;
}

@keyframes zoomIn {
  from { transform: scale(0.9); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

.modal-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
  padding: 18px 22px;
  border-radius: var(--radius) var(--radius) 0 0;
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  padding: 16px 22px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid var(--border);
}

.modal-close {
  background: none;
  border: none;
  color: rgba(255,255,255,0.8);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
  padding: 0;
}

.modal-close:hover { color: #fff; }

/* ===== STATUS INDICATOR ===== */
.status-flow {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  flex-wrap: wrap;
}

.status-step {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 50px;
  font-weight: 600;
}

.status-step.done    { background: #e8f5e9; color: #2e7d32; }
.status-step.pending { background: #fff8e1; color: #f57f17; }
.status-step.fail    { background: #ffebee; color: #c62828; }

.status-arrow { color: var(--text-muted); font-size: 1rem; }

/* ===== THAI DATE ===== */
.thai-date-inputs {
  display: grid;
  grid-template-columns: 1fr 2fr 1.5fr;
  gap: 10px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .header-inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .header-nav {
    width: 100%;
  }
  .form-row, .form-row-3, .charts-grid {
    grid-template-columns: 1fr;
  }
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }
  .page-title {
    font-size: 1.3rem;
  }
  .main-container, .container {
    padding: 16px;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
  .header-title h1 {
    font-size: 1rem;
  }
}

/* ===== PRINT ===== */
@media print {
  @page { margin: 1cm; size: A4 portrait; }
  body {
    background: #fff;
    font-size: 11pt !important;
    line-height: 1.3 !important;
    color: #000 !important;
  }
  .site-header, .site-footer, .btn, .header-nav, .no-print, .status-flow {
    display: none !important;
  }
  .main-container, .container {
    padding: 0 !important;
    margin: 0 !important;
    max-width: 100% !important;
  }
  .page-header { margin-bottom: 15px !important; }
  .page-title { font-size: 1.2rem !important; }
  .card, .form-section {
    box-shadow: none !important;
    border: 1px solid #aaa !important;
    margin-bottom: 6px !important;
    border-radius: 4px !important;
    page-break-inside: avoid;
  }
  .card-header, .form-section-header {
    background: #f0f0f0 !important;
    color: #000 !important;
    padding: 4px 8px !important;
    font-size: 10pt !important;
    border-bottom: 1px solid #aaa !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .card-body, .form-section-body {
    padding: 4px 8px !important;
  }
  .view-field {
    padding: 3px 0 !important;
    border-bottom: 1px dashed #eee !important;
    display: flex !important;
    align-items: baseline !important;
    line-height: 1.2 !important;
  }
  .view-label {
    min-width: 120px !important;
    font-size: 9.5pt !important;
  }
  .view-value {
    font-size: 9.5pt !important;
  }
  .form-row {
    gap: 6px !important;
    margin-bottom: 6px !important;
  }
  p { margin-bottom: 4px !important; }
  .sig-box {
    min-height: 50px !important;
    padding: 2px !important;
    border: 1px solid #aaa !important;
  }
  .sig-box img {
    max-height: 50px !important;
  }
  .badge {
    padding: 2px 6px !important;
    font-size: 8.5pt !important;
    border: 1px solid #aaa !important;
    background: transparent !important;
    color: #000 !important;
  }
  .sig-person {
    font-size: 8.5pt !important;
  }
}

/* ===== ANIMATIONS ===== */
.fade-in {
  animation: fadeInUp 0.4s ease forwards;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #f1f1f1; }
::-webkit-scrollbar-thumb { background: var(--primary-light); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }
