/* =============================================
   PPK-Canteen Design System
   ระบบจัดการโรงอาหาร โรงเรียนพะเยาพิทยาคม
   Responsive: Mobile-first
   ============================================= */
:root {
  --primary: #059669; --primary-light: #34D399; --primary-dark: #047857;
  --accent: #0891B2; --accent-light: #22D3EE;
  --danger: #EF4444; --warning: #F59E0B; --success: #22C55E; --info: #3B82F6;
  --bg: #F0FDF4; --bg-card: #FFFFFF; --bg-sidebar: #022c22;
  --text: #1E293B; --text-light: #64748B; --text-white: #F8FAFC;
  --border: #E2E8F0; --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
  --shadow: 0 4px 12px rgba(0,0,0,.08); --shadow-lg: 0 12px 32px rgba(0,0,0,.12);
  --radius: 12px; --radius-sm: 8px; --radius-full: 9999px;
  --sidebar-w: 260px; --topbar-h: 56px;
  --font: 'Kanit', sans-serif;
  --transition: .2s ease;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body { font-family: var(--font); color: var(--text); background: var(--bg); line-height: 1.6; -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
img { max-width: 100%; display: block; }
input, select, textarea, button { font-family: inherit; font-size: inherit; }

/* === LAYOUT === */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: var(--bg-sidebar); color: var(--text-white); position: fixed; top: 0; left: 0; bottom: 0; z-index: 100; display: flex; flex-direction: column; transition: transform var(--transition); }
.sidebar-header { padding: 20px; text-align: center; border-bottom: 1px solid rgba(255,255,255,.1); }
.sidebar-header h2 { font-size: 1rem; font-weight: 500; color: var(--primary-light); }
.sidebar-header small { color: rgba(255,255,255,.5); font-size: .75rem; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 0; }
.sidebar-nav a, .sidebar-nav button { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 20px; color: rgba(255,255,255,.7); background: none; border: none; cursor: pointer; font-size: .9rem; text-align: left; transition: var(--transition); }
.sidebar-nav a:hover, .sidebar-nav button:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar-nav a.active { background: rgba(5,150,105,.3); color: var(--primary-light); border-right: 3px solid var(--primary-light); }
.sidebar-section { padding: 8px 20px 4px; font-size: .7rem; text-transform: uppercase; letter-spacing: 1px; color: rgba(255,255,255,.3); margin-top: 8px; }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar-footer .user-info { font-size: .85rem; }
.sidebar-footer .user-role { font-size: .7rem; color: var(--primary-light); }

.topbar { display: none; height: var(--topbar-h); background: var(--bg-sidebar); color: var(--text-white); position: fixed; top: 0; left: 0; right: 0; z-index: 101; padding: 0 16px; align-items: center; gap: 12px; }
.topbar-title { font-size: .95rem; flex: 1; }
.hamburger { background: none; border: none; color: var(--text-white); font-size: 1.5rem; cursor: pointer; padding: 4px; }
.overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 99; }

.main-content { flex: 1; margin-left: var(--sidebar-w); padding: 24px; min-height: 100vh; }
.page-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 24px; }
.page-header h1 { font-size: 1.5rem; font-weight: 600; }

/* === CARDS === */
.card { background: var(--bg-card); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 20px; margin-bottom: 16px; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.card-title { font-size: 1.1rem; font-weight: 600; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--bg-card); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm); border-left: 4px solid var(--primary); }
.stat-card.danger { border-left-color: var(--danger); }
.stat-card.warning { border-left-color: var(--warning); }
.stat-card.info { border-left-color: var(--info); }
.stat-value { font-size: 1.8rem; font-weight: 700; color: var(--text); }
.stat-label { font-size: .85rem; color: var(--text-light); margin-top: 4px; }

/* === BUTTONS === */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 10px 20px; border-radius: var(--radius-sm); border: none; cursor: pointer; font-weight: 500; font-size: .9rem; transition: var(--transition); white-space: nowrap; }
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-info { background: var(--info); color: #fff; }
.btn-outline { background: transparent; border: 1.5px solid var(--primary); color: var(--primary); }
.btn-sm { padding: 6px 12px; font-size: .8rem; }
.btn-lg { padding: 14px 28px; font-size: 1rem; }
.btn-icon { padding: 8px; border-radius: var(--radius-sm); background: none; border: none; cursor: pointer; color: var(--text-light); }
.btn-icon:hover { background: var(--border); color: var(--text); }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* === FORMS === */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: .85rem; font-weight: 500; margin-bottom: 6px; color: var(--text); }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 10px 14px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: #fff; color: var(--text); transition: var(--transition); font-size: .9rem;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(5,150,105,.15); }
.form-input.error { border-color: var(--danger); }
.form-hint { font-size: .75rem; color: var(--text-light); margin-top: 4px; }
.form-error { font-size: .75rem; color: var(--danger); margin-top: 4px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.form-check { display: flex; align-items: center; gap: 8px; }
.form-check input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); }

/* === TABLES === */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
thead { background: #F8FAFC; }
th { padding: 12px 16px; text-align: left; font-weight: 600; color: var(--text-light); font-size: .8rem; text-transform: uppercase; letter-spacing: .5px; border-bottom: 2px solid var(--border); white-space: nowrap; }
td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: #F0FDF4; }
.table-empty { text-align: center; padding: 40px 16px; color: var(--text-light); }

/* === BADGES === */
.badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: var(--radius-full); font-size: .75rem; font-weight: 500; }
.badge-success { background: #DCFCE7; color: #166534; }
.badge-danger { background: #FEE2E2; color: #991B1B; }
.badge-warning { background: #FEF3C7; color: #92400E; }
.badge-info { background: #DBEAFE; color: #1E40AF; }
.badge-secondary { background: #F1F5F9; color: #475569; }

/* === MODAL === */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 16px; animation: fadeIn .2s; }
.modal { background: var(--bg-card); border-radius: var(--radius); width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg); animation: scaleIn .22s cubic-bezier(.4,0,.2,1); }
.modal-lg { max-width: 800px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 20px 24px 0; }
.modal-header h2 { font-size: 1.2rem; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-light); padding: 4px; }
.modal-body { padding: 16px 24px 24px; }
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; padding: 0 24px 20px; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { transform: scale(.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* === TOAST === */
.toast-container { position: fixed; top: 16px; right: 16px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 12px 20px; border-radius: var(--radius-sm); color: #fff; font-size: .9rem; box-shadow: var(--shadow); animation: slideIn .3s; min-width: 280px; display: flex; align-items: center; gap: 8px; }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warning { background: var(--warning); color: #000; }
.toast-info { background: var(--info); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* === TABS === */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tab { padding: 10px 20px; cursor: pointer; font-size: .9rem; color: var(--text-light); border-bottom: 2px solid transparent; margin-bottom: -2px; white-space: nowrap; transition: var(--transition); background: none; border-top: none; border-left: none; border-right: none; }
.tab:hover { color: var(--primary); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* === CAMERA === */
.camera-container { position: relative; width: 100%; max-width: 480px; margin: 0 auto; background: #000; border-radius: var(--radius); overflow: hidden; }
.camera-container video { width: 100%; display: block; }
.camera-container canvas { display: none; }
.camera-preview img { width: 100%; border-radius: var(--radius); border: 2px solid var(--primary); }
.camera-actions { display: flex; gap: 12px; justify-content: center; margin-top: 12px; }

/* === UPLOAD === */
.upload-zone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 40px 20px; text-align: center; cursor: pointer; transition: var(--transition); }
.upload-zone:hover { border-color: var(--primary); background: rgba(5,150,105,.05); }
.upload-zone.dragover { border-color: var(--primary); background: rgba(5,150,105,.1); }
.upload-preview { margin-top: 12px; }
.upload-preview img { max-height: 200px; margin: 0 auto; border-radius: var(--radius-sm); }

/* === LOADING === */
.loading { display: flex; align-items: center; justify-content: center; padding: 40px; color: var(--text-light); gap: 8px; }
.spinner { width: 24px; height: 24px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* === LOGIN PAGE === */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--bg-sidebar) 0%, #064E3B 100%); padding: 20px; }
.login-card { background: var(--bg-card); border-radius: var(--radius); padding: 40px; width: 100%; max-width: 400px; box-shadow: var(--shadow-lg); }
.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo h1 { font-size: 1.3rem; color: var(--primary-dark); margin-top: 12px; }
.login-logo p { font-size: .85rem; color: var(--text-light); }

/* === SEARCH/FILTER === */
.filter-bar { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.search-input { flex: 1; min-width: 200px; }

/* === EMPTY STATE === */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-light); }
.empty-state .icon { font-size: 3rem; margin-bottom: 12px; }

/* === RESPONSIVE === */
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .topbar { display: flex; }
  .overlay.show { display: block; }
  .main-content { margin-left: 0; padding-top: calc(var(--topbar-h) + 16px); padding-left: 16px; padding-right: 16px; }
  .page-header h1 { font-size: 1.2rem; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .stats-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .btn-group { width: 100%; }
  .btn-group .btn { flex: 1; justify-content: center; }
  .modal { margin: 8px; }
  td, th { padding: 8px 10px; font-size: .8rem; }
}

/* === PRINT === */
@media print {
  .sidebar, .topbar, .overlay, .toast-container, .btn, .filter-bar { display: none !important; }
  .main-content { margin: 0; padding: 0; }
  body { background: #fff; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}

/* === UTILITIES === */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-light { color: var(--text-light); }
.text-sm { font-size: .85rem; }
.text-xs { font-size: .75rem; }
.font-bold { font-weight: 700; }
.mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.gap-1 { gap: 8px; } .gap-2 { gap: 16px; }
.flex { display: flex; } .flex-col { flex-direction: column; }
.items-center { align-items: center; } .justify-between { justify-content: space-between; }
.w-full { width: 100%; }
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
