/* Modern MOPH Green e-Payroll Design System */
@import url('https://fonts.googleapis.com/css2?family=Sarabun:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&family=Prompt:wght@400;500;600&display=swap');

:root {
  --primary-color: #046a38;        /* Official MOPH Emerald Green */
  --primary-dark: #004b23;         /* Deep Forest Green */
  --primary-light: #00875a;        /* Fresh Green */
  --accent-color: #0d9488;         /* MOPH Teal Accent */
  --accent-hover: #0f766e;
  --bg-gradient: linear-gradient(135deg, #004b23 0%, #046a38 50%, #00875a 100%);
  
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --danger-color: #dc2626;
  
  --bg-main: #f4f9f5;             /* Light Sage Background */
  --card-bg: #ffffff;
  --text-main: #0f172a;
  --text-muted: #475569;
  --border-color: #cbd5e1;
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  
  --shadow-sm: 0 1px 3px rgba(4, 106, 56, 0.08);
  --shadow-md: 0 4px 12px rgba(4, 106, 56, 0.12);
  --shadow-lg: 0 10px 25px rgba(0, 75, 35, 0.2);
  --transition: all 0.25s ease;
}

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

body {
  font-family: 'Sarabun', 'TH Sarabun New', sans-serif;
  font-size: 16px;
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a {
  color: var(--primary-color);
  text-decoration: none;
  transition: var(--transition);
}

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

/* Layout Containers */
.app-container {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  background: var(--bg-gradient);
  color: #ffffff;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: var(--transition);
  box-shadow: var(--shadow-md);
}

.sidebar-header {
  padding: 24px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.sidebar-header .logo-icon {
  width: 44px;
  height: 44px;
  background: #ffffff;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  box-shadow: var(--shadow-sm);
}

.sidebar-header .brand-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.sidebar-menu {
  list-style: none;
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sidebar-menu a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: #e2e8f0;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 500;
}

.sidebar-menu a:hover,
.sidebar-menu a.active {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.15);
  border-left: 4px solid #f59e0b;
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

.navbar {
  height: 64px;
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 12px;
}

.content-body {
  padding: 28px;
  flex: 1;
}

/* Auth Cards */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-gradient);
  padding: 20px;
}

.auth-card {
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(10px);
  width: 100%;
  max-width: 440px;
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.auth-card .auth-logo {
  text-align: center;
  margin-bottom: 20px;
}

.auth-card .auth-logo h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--primary-color);
  margin-top: 6px;
}

/* Forms */
.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  font-size: 15px;
  font-family: inherit;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--text-main);
  transition: var(--transition);
}

.form-control:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(4, 106, 56, 0.2);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
}

.btn-primary {
  background: var(--primary-color);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-dark);
  color: #ffffff;
}

.btn-secondary {
  background: #e2e8f0;
  color: var(--text-main);
}

.btn-secondary:hover {
  background: #cbd5e1;
}

.btn-success {
  background: var(--success-color);
  color: #ffffff;
}

.btn-success:hover {
  background: #059669;
}

.btn-danger {
  background: var(--danger-color);
  color: #ffffff;
}

.btn-danger:hover {
  background: #b91c1c;
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13.5px;
}

/* Cards & Grid */
.card {
  background: var(--card-bg);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  padding: 24px;
  margin-bottom: 24px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
}

.card-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary-color);
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.stat-card {
  background: #ffffff;
  padding: 20px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.stat-icon.blue { background: #e0f2fe; color: #0369a1; }
.stat-icon.green { background: #d1fae5; color: #047857; }
.stat-icon.red { background: #fee2e2; color: #b91c1c; }
.stat-icon.purple { background: #f3e8ff; color: #6b21a8; }

.stat-info .stat-label {
  font-size: 13.5px;
  color: var(--text-muted);
}

.stat-info .stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--primary-color);
}

/* Tables */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

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

.table th {
  background: #f0fdf4;
  color: var(--primary-dark);
  font-weight: 700;
  padding: 12px 16px;
  border-bottom: 2px solid var(--border-color);
}

.table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

.table tbody tr:hover {
  background: #f8fafc;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 20px;
}

.badge-admin { background: #fef3c7; color: #92400e; }
.badge-user { background: #d1fae5; color: #065f46; }
.badge-success { background: #d1fae5; color: #065f46; }

/* Alerts */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  margin-bottom: 20px;
}

.alert-danger {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.alert-success {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.alert-info {
  background: #eff6ff;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}

/* Print Rules */
@media print {
  body {
    background: #ffffff;
  }
  .sidebar, .navbar, .btn, .no-print {
    display: none !important;
  }
  .main-content {
    margin: 0;
    padding: 0;
  }
  .content-body {
    padding: 0;
  }
}

/* =====================================================
   Responsive Layout (Mobile & Tablet)
   - Tablet  : <= 1024px  → Sidebar ซ่อน เปิดด้วยปุ่ม ☰
   - Mobile  : <= 600px   → จัดเรียงคอลัมน์เดียว ปุ่มขนาดนิ้วสัมผัส
   ===================================================== */
html { -webkit-text-size-adjust: 100%; }
img { max-width: 100%; }

.menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  margin-right: 10px;
  flex-shrink: 0;
  font-size: 22px;
  line-height: 1;
  color: var(--primary-color);
  background: #f0fdf4;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.sidebar-overlay { display: none; }
.navbar-left { display: flex; align-items: center; min-width: 0; }

@media (max-width: 1024px) {
  .menu-toggle { display: inline-flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1000;
    width: 270px;
    max-width: 82vw;
    overflow-y: auto;
    transform: translateX(-100%);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }

  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 999;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }
  body.sidebar-open .sidebar-overlay { opacity: 1; pointer-events: auto; }
  body.sidebar-open { overflow: hidden; }

  .main-content { width: 100%; min-width: 0; }
  .navbar { padding: 0 16px; position: sticky; top: 0; z-index: 50; }
  .content-body { padding: 20px 16px; }
  .grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
}

@media (max-width: 600px) {
  body { font-size: 15px; }

  /* Navbar */
  .navbar { height: auto; min-height: 58px; padding: 8px 12px; gap: 8px; }
  .navbar-left > div { font-size: 14px !important; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .user-badge { gap: 6px; flex-shrink: 0; }
  .user-badge .badge { display: none; }
  .user-badge .btn { padding: 8px 10px; }

  .content-body { padding: 14px 12px; }

  /* Headings */
  .content-body h1 { font-size: 20px !important; }
  .content-body h2 { font-size: 18px !important; }

  /* Cards */
  .card { padding: 16px; margin-bottom: 16px; border-radius: var(--radius-sm); }
  .card-header { flex-wrap: wrap; gap: 10px; align-items: flex-start; }
  .card-header .btn { width: 100%; }
  .card-title { font-size: 16.5px; }

  .grid-3 { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
  .stat-card { flex-direction: column; align-items: flex-start; gap: 8px; padding: 14px; }
  .stat-icon { width: 38px; height: 38px; font-size: 18px; }
  .stat-info .stat-label { font-size: 12.5px; }
  .stat-info .stat-value { font-size: 17px; }

  /* Inline flex rows (หัวหน้า, แถบค้นหา) ให้ตัดบรรทัดได้ */
  .content-body div[style*="justify-content:space-between"],
  .content-body div[style*="justify-content: space-between"] { flex-wrap: wrap; gap: 12px; }
  .content-body > div[style*="justify-content:space-between"] > .btn { width: 100%; }

  /* ฟอร์มค้นหา/ตัวกรอง: เรียงคอลัมน์เดียว */
  .content-body form[style*="display:flex"] { flex-direction: column; align-items: stretch !important; }
  .content-body form[style*="display:flex"] > * { width: 100%; max-width: 100% !important; }
  .content-body form[style*="display:flex"] > div[style*="display:flex"] > .btn { flex: 1; }
  .card[style*="bg-gradient"] form[style*="display:flex"] select { width: 100% !important; }

  /* Grid ที่กำหนด inline ให้เป็นคอลัมน์เดียว */
  .content-body [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }

  /* ฟอร์ม: กันซูมอัตโนมัติบน iOS และขนาดกดง่าย */
  .form-control { font-size: 16px; padding: 11px 12px; max-width: 100% !important; }
  .btn { min-height: 42px; }
  .btn-sm { min-height: 36px; }

  /* ตาราง: เลื่อนแนวนอน */
  .table-responsive { -webkit-overflow-scrolling: touch; margin: 0 -16px; padding: 0 16px; width: calc(100% + 32px); }
  .table { font-size: 14px; }
  .table th, .table td { padding: 10px 10px; white-space: nowrap; }

  /* Modal */
  div[id$="Modal"] .card { margin: 0 10px !important; max-height: 92vh; overflow-y: auto; }
  div[id$="Modal"] div[style*="justify-content:flex-end"] { flex-direction: column-reverse; }
  div[id$="Modal"] div[style*="justify-content:flex-end"] .btn { width: 100%; }

  /* หน้าเข้าสู่ระบบ */
  .auth-wrapper { padding: 16px 12px; align-items: flex-start; }
  .auth-card { padding: 26px 18px; margin-top: 12px; }
  .auth-card .auth-logo img { width: 80px !important; height: 80px !important; }
  .auth-card .auth-logo h1 { font-size: 20px; }
}

@media (max-width: 360px) {
  .grid-3 { grid-template-columns: 1fr; }
}

@media print {
  .menu-toggle, .sidebar-overlay { display: none !important; }
}
