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

:root {
  --primary:       #320D57;
  --primary-mid:   #4a1572;
  --primary-light: #6b2fa0;
  --accent:        #8e44ad;
  --accent-light:  #c39bd3;
  --bg:            #f5eeff;
  --bg-card:       #ffffff;
  --text:          #1a0a2e;
  --text-muted:    #7a6d8a;
  --border:        #ddd0ee;
  --success:       #2e7d32;
  --success-bg:    #e8f5e9;
  --error:         #c62828;
  --error-bg:      #ffebee;
  --shadow:        0 8px 32px rgba(50, 13, 87, 0.14);
  --shadow-hover:  0 16px 48px rgba(50, 13, 87, 0.24);
  --radius:        16px;
  --radius-sm:     10px;
}

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

body {
  font-family: 'Sarabun', sans-serif;
  background: linear-gradient(135deg, #f5eeff 0%, #ede0ff 50%, #e8e0f5 100%);
  min-height: 100vh;
  color: var(--text);
  line-height: 1.6;
}

.site-header {
  background: linear-gradient(135deg, #1a0533 0%, var(--primary) 55%, var(--primary-mid) 100%);
  padding: 16px 40px;
  display: flex; align-items: center; gap: 20px;
  box-shadow: 0 4px 24px rgba(50, 13, 87, 0.35);
  position: relative; overflow: hidden;
}
.site-header::before {
  content: ''; position: absolute; inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23ffffff' fill-opacity='0.04'%3E%3Ccircle cx='30' cy='30' r='20'/%3E%3C/g%3E%3C/svg%3E");
  pointer-events: none;
}
.site-header .logo {
  width: 64px; height: 64px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.45);
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  object-fit: cover; flex-shrink: 0; position: relative;
}
.site-header .header-text h1 {
  color: white; font-size: 1.45rem; font-weight: 700; margin: 0;
  text-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
.site-header .header-text p { color: rgba(255,255,255,0.78); font-size: 0.88rem; margin: 0; }

.page-wrapper {
  padding: 40px 20px; display: flex;
  justify-content: center; align-items: flex-start;
  min-height: calc(100vh - 100px);
}
.page-wrapper.centered { align-items: center; }

.card {
  background: var(--bg-card); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; width: 100%;
  border: 1px solid rgba(50,13,87,0.1); transition: box-shadow 0.3s;
}
.card:hover { box-shadow: var(--shadow-hover); }
.card-max-sm { max-width: 480px; }
.card-max-md { max-width: 700px; }
.card-max-lg { max-width: 1200px; }

.card-header {
  background: linear-gradient(135deg, #1a0533, var(--primary) 60%, var(--primary-mid));
  padding: 28px 36px; position: relative; overflow: hidden;
}
.card-header::after {
  content: ''; position: absolute; bottom: -24px; right: -24px;
  width: 130px; height: 130px; border-radius: 50%;
  background: rgba(255,255,255,0.06);
}
.card-header .icon-wrap {
  width: 48px; height: 48px; background: rgba(255,255,255,0.15);
  border-radius: 12px; display: flex; align-items: center; justify-content: center;
  margin-bottom: 12px;
}
.card-header h2 { color: white; font-size: 1.35rem; font-weight: 700; margin: 0 0 4px; }
.card-header p { color: rgba(255,255,255,0.72); font-size: 0.88rem; margin: 0; }
.card-body { padding: 36px; }

.form-group { margin-bottom: 22px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

label {
  display: flex; align-items: center; gap: 8px;
  font-weight: 600; font-size: 0.95rem; color: var(--primary); margin-bottom: 8px;
}
.required::after { content: " *"; color: #e53935; font-weight: 700; }

input[type="text"], input[type="date"], input[type="tel"],
input[type="email"], input[type="password"], input[type="file"],
textarea, select {
  width: 100%; padding: 13px 16px;
  border: 2px solid var(--border); border-radius: var(--radius-sm);
  font-size: 1rem; font-family: 'Sarabun', sans-serif; color: var(--text);
  background: #fafafa; transition: all 0.2s; outline: none; appearance: none;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--primary); background: white;
  box-shadow: 0 0 0 4px rgba(50,13,87,0.1);
}
textarea { resize: vertical; min-height: 90px; }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23320D57' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 44px;
}

/* DATE PICKER */
.date-display-btn {
  width: 100%; padding: 13px 16px;
  border: 2px solid var(--border); border-radius: var(--radius-sm);
  font-size: 1rem; font-family: 'Sarabun', sans-serif; color: var(--text);
  background: #fafafa; cursor: pointer; text-align: left;
  display: flex; align-items: center; gap: 10px;
  transition: all 0.2s; outline: none;
}
.date-display-btn:hover, .date-display-btn:focus {
  border-color: var(--primary); background: white;
  box-shadow: 0 0 0 4px rgba(50,13,87,0.1);
}
.date-display-btn .cal-icon {
  width: 30px; height: 30px; background: var(--primary);
  border-radius: 8px; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}

/* CALENDAR OVERLAY */
.cal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(50,13,87,0.4); z-index: 9999;
  align-items: center; justify-content: center;
  backdrop-filter: blur(3px);
}
.cal-overlay.open { display: flex; }

.cal-popup {
  background: white; border-radius: 20px;
  box-shadow: 0 28px 72px rgba(50,13,87,0.45);
  width: 340px; overflow: hidden;
  animation: calPop 0.22s cubic-bezier(.34,1.56,.64,1);
}
@keyframes calPop {
  from { transform: scale(0.85); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.cal-header {
  background: linear-gradient(135deg, #1a0533, var(--primary));
  padding: 16px 20px;
  display: flex; align-items: center; justify-content: space-between;
}
.cal-header .cal-title { color: white; font-size: 1.1rem; font-weight: 700; }
.cal-nav-btn {
  width: 36px; height: 36px; border-radius: 50%; border: none;
  background: rgba(255,255,255,0.18); color: white; font-size: 1.2rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center; transition: background 0.2s;
}
.cal-nav-btn:hover { background: rgba(255,255,255,0.32); }

.cal-weekdays {
  display: grid; grid-template-columns: repeat(7, 1fr);
  background: #f5eeff; padding: 8px 12px 4px;
}
.cal-weekday {
  text-align: center; font-size: 0.8rem; font-weight: 700; padding: 4px 0;
}
.cal-weekday.sun { color: #e53935; }
.cal-weekday.sat { color: #1565c0; }
.cal-weekday.wd  { color: var(--primary); }

.cal-days {
  display: grid; grid-template-columns: repeat(7, 1fr);
  padding: 8px 12px; gap: 2px;
}
.cal-day {
  aspect-ratio: 1; border: none; background: transparent; border-radius: 50%;
  font-family: 'Sarabun', sans-serif; font-size: 0.95rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s; color: var(--text); position: relative;
}
.cal-day:hover:not(.empty):not(.today):not(.selected) { background: #f0e4ff; color: var(--primary); }
.cal-day.sun   { color: #e53935; }
.cal-day.sat   { color: #1565c0; }
.cal-day.empty { cursor: default; }
.cal-day.today { border: 2px solid var(--primary); color: var(--primary); font-weight: 700; }
.cal-day.selected { background: var(--primary); color: white !important; font-weight: 700; box-shadow: 0 4px 14px rgba(50,13,87,0.4); }

.cal-time {
  padding: 12px 18px; background: #faf7ff;
  display: flex; align-items: center; gap: 10px;
  border-top: 1px solid var(--border);
}
.cal-time .time-icon { font-size: 1.5rem; }
.cal-time input[type="number"] {
  width: 70px; padding: 8px 10px;
  border: 2px solid var(--border); border-radius: 8px;
  font-size: 1.15rem; font-family: 'Sarabun', sans-serif; font-weight: 700;
  text-align: center; color: var(--primary); background: white;
  outline: none; -moz-appearance: textfield;
}
.cal-time input[type="number"]:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(50,13,87,0.1); }
.cal-time input[type="number"]::-webkit-outer-spin-button,
.cal-time input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; }
.cal-time .time-sep { font-size: 1.4rem; font-weight: 700; color: var(--primary); }
.cal-time .time-ampm { font-weight: 600; color: var(--text-muted); }

.cal-close-btn {
  width: 100%; padding: 15px; background: #e53935; color: white; border: none;
  font-family: 'Sarabun', sans-serif; font-size: 1.05rem; font-weight: 700;
  cursor: pointer; transition: background 0.2s; letter-spacing: 0.02em;
}
.cal-close-btn:hover { background: #c62828; }

/* FILE INPUT */
.file-input-wrap {
  position: relative; border: 2px dashed var(--border); border-radius: var(--radius-sm);
  padding: 20px; text-align: center; background: #fafafa; transition: all 0.2s; cursor: pointer;
}
.file-input-wrap:hover, .file-input-wrap:focus-within { border-color: var(--primary); background: #f5eeff; }
.file-input-wrap input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; border: none; padding: 0; }
.file-label-text { color: var(--text-muted); font-size: 0.9rem; pointer-events: none; }
.file-label-text strong { color: var(--primary); }

/* BUTTONS */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 28px; border: none; border-radius: var(--radius-sm);
  font-family: 'Sarabun', sans-serif; font-size: 1rem; font-weight: 700;
  cursor: pointer; transition: all 0.2s; text-decoration: none; white-space: nowrap;
}
.btn-primary { background: linear-gradient(135deg,#1a0533,var(--primary)); color:white; box-shadow:0 4px 16px rgba(50,13,87,.35); }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 28px rgba(50,13,87,.45); }
.btn-secondary { background: var(--bg); color: var(--primary); border: 2px solid var(--border); }
.btn-secondary:hover { background: #e8d5f5; border-color: var(--accent); }
.btn-danger { background: linear-gradient(135deg,#c62828,#e53935); color:white; box-shadow:0 4px 15px rgba(198,40,40,.3); }
.btn-danger:hover { transform: translateY(-2px); box-shadow:0 8px 25px rgba(198,40,40,.4); }
.btn-full { width: 100%; }
.btn-group { display: flex; gap: 14px; margin-top: 28px; }
.btn-group .btn { flex: 1; }

/* ALERTS */
.alert { padding:14px 18px; border-radius:var(--radius-sm); font-weight:600; margin-bottom:22px; display:flex; align-items:center; gap:10px; font-size:0.95rem; }
.alert-success { background:var(--success-bg); color:var(--success); border:1px solid #a5d6a7; }
.alert-error   { background:var(--error-bg);   color:var(--error);   border:1px solid #ef9a9a; }

/* BADGES */
.badge { display:inline-flex; align-items:center; gap:5px; padding:4px 12px; border-radius:20px; font-size:0.82rem; font-weight:600; }
.badge-pending   { background:#fff8e1; color:#f57c00; border:1px solid #ffe082; }
.badge-approved  { background:#e8f5e9; color:#2e7d32; border:1px solid #a5d6a7; }
.badge-rejected  { background:#ffebee; color:#c62828; border:1px solid #ef9a9a; }
.badge-completed { background:#ede7f6; color:var(--primary); border:1px solid var(--border); }

/* TABLE */
.table-wrap { overflow-x:auto; border-radius:var(--radius-sm); border:1px solid var(--border); }
table { width:100%; border-collapse:collapse; }
thead { background:linear-gradient(135deg,#1a0533,var(--primary)); }
th { padding:14px 16px; text-align:left; color:white; font-weight:600; font-size:0.9rem; white-space:nowrap; }
td { padding:13px 16px; border-bottom:1px solid var(--border); color:var(--text); font-size:0.95rem; }
tr:last-child td { border-bottom:none; }
tr:nth-child(even) td { background:#faf7ff; }
tr:hover td { background:#f2e8ff; }

.action-links { display:flex; gap:8px; flex-wrap:wrap; }
.action-links a { padding:5px 12px; border-radius:6px; font-size:0.82rem; font-weight:600; text-decoration:none; transition:all 0.2s; }
.action-view   { background:#ede7f6; color:var(--primary); }
.action-view:hover { background:var(--primary); color:white; }
.action-edit   { background:#e8f5e9; color:#2e7d32; }
.action-edit:hover { background:#2e7d32; color:white; }
.action-delete { background:#ffebee; color:#c62828; }
.action-delete:hover { background:#c62828; color:white; }

/* DASHBOARD */
.dash-topbar { display:flex; justify-content:space-between; align-items:center; margin-bottom:28px; padding-bottom:20px; border-bottom:2px solid var(--border); }
.dash-topbar .welcome { display:flex; align-items:center; gap:12px; }
.welcome .avatar { width:44px; height:44px; background:linear-gradient(135deg,#1a0533,var(--primary)); border-radius:50%; display:flex; align-items:center; justify-content:center; color:white; font-weight:700; font-size:1.1rem; }
.welcome-info strong { display:block; font-size:1rem; color:var(--primary); }
.welcome-info span   { font-size:0.85rem; color:var(--text-muted); }

/* STATS */
.stats-row { display:grid; grid-template-columns:repeat(4,1fr); gap:16px; margin-bottom:28px; }
.stat-card { background:white; border-radius:var(--radius-sm); padding:20px; border:1px solid var(--border); display:flex; align-items:center; gap:14px; transition:all 0.2s; }
.stat-card:hover { box-shadow:var(--shadow); transform:translateY(-2px); }
.stat-icon { width:48px; height:48px; border-radius:12px; display:flex; align-items:center; justify-content:center; font-size:1.4rem; flex-shrink:0; }
.stat-icon-purple { background:#f0e4ff; }
.stat-icon-green  { background:#e8f5e9; }
.stat-icon-blue   { background:#e3f2fd; }
.stat-icon-orange { background:#fff8e1; }
.stat-num   { font-size:1.6rem; font-weight:800; color:var(--primary); line-height:1; }
.stat-label { font-size:0.82rem; color:var(--text-muted); margin-top:2px; }

/* PAGINATION */
.pagination { display:flex; justify-content:center; gap:6px; margin-top:24px; }
.pagination a,.pagination span { display:inline-flex; align-items:center; justify-content:center; width:38px; height:38px; border-radius:8px; font-size:0.9rem; font-weight:600; text-decoration:none; transition:all 0.2s; }
.pagination a { border:2px solid var(--border); color:var(--primary); background:white; }
.pagination a:hover,.pagination a.active { background:var(--primary); border-color:var(--primary); color:white; box-shadow:0 4px 12px rgba(50,13,87,.3); }
.pagination span { border:2px solid var(--border); color:var(--text-muted); background:#f5f5f5; }

/* DETAIL */
.detail-item { padding:14px 20px; border-bottom:1px solid var(--border); display:flex; align-items:flex-start; gap:12px; }
.detail-item:last-child { border-bottom:none; }
.detail-label { font-weight:600; color:var(--primary); font-size:0.9rem; min-width:160px; flex-shrink:0; }
.detail-value { color:var(--text); font-size:0.95rem; }
.file-preview-section { margin-top:24px; padding:24px; background:#faf7ff; border-radius:var(--radius-sm); border:2px solid var(--border); text-align:center; }
.file-preview-section h3 { color:var(--primary); font-size:1rem; margin-bottom:16px; display:flex; align-items:center; gap:8px; justify-content:center; }
.file-preview-section img { max-width:100%; border-radius:var(--radius-sm); box-shadow:var(--shadow); }

.admin-link { text-align:center; margin-top:20px; padding-top:16px; border-top:1px solid var(--border); }
.admin-link a { color:var(--primary); text-decoration:none; font-weight:600; font-size:0.9rem; display:inline-flex; align-items:center; gap:6px; }
.admin-link a:hover { text-decoration:underline; }

.checkbox-wrap { display:flex; align-items:center; gap:10px; margin-top:10px; padding:10px 14px; background:#fff8e1; border-radius:8px; border:1px solid #ffe082; }
.checkbox-wrap input[type="checkbox"] { width:18px; height:18px; accent-color:var(--primary); flex-shrink:0; }
.checkbox-wrap label { margin:0; font-weight:500; color:#e65100; font-size:0.9rem; }

.current-file-info { margin-top:10px; padding:12px 16px; background:#f0e4ff; border-radius:8px; border:1px solid var(--border); font-size:0.9rem; color:var(--text-muted); display:flex; align-items:center; gap:8px; }
.current-file-info a { color:var(--primary); font-weight:600; text-decoration:none; }
.current-file-info a:hover { text-decoration:underline; }

@media (max-width: 768px) {
  .site-header { padding: 14px 20px; }
  .site-header .header-text h1 { font-size: 1.05rem; }
  .card-body { padding: 22px 18px; }
  .form-row { grid-template-columns: 1fr; }
  .stats-row { grid-template-columns: 1fr 1fr; }
  .dash-topbar { flex-direction: column; align-items: flex-start; gap: 12px; }
  .btn-group { flex-direction: column; }
  .cal-popup { width: 310px; }
}
