/* ============================================================
   style.css — PC Directory UI Styles
   ระบบค้นหาและจัดการเบอร์โทรศัพท์พนักงาน PC
   ============================================================ */

/* ── Variables (สีและฟอนต์หลัก) ─────────────────────────── */
:root {
  --primary:       #2563eb;   /* น้ำเงินหลัก */
  --primary-dark:  #1d4ed8;
  --primary-light: #dbeafe;
  --secondary:     #0ea5e9;
  --success:       #16a34a;
  --danger:        #dc2626;
  --danger-light:  #fee2e2;
  --warning:       #d97706;
  --warning-light: #fef3c7;
  --gray-50:       #f9fafb;
  --gray-100:      #f3f4f6;
  --gray-200:      #e5e7eb;
  --gray-300:      #d1d5db;
  --gray-500:      #6b7280;
  --gray-600:      #4b5563;
  --gray-700:      #374151;
  --gray-800:      #1f2937;
  --white:         #ffffff;
  --radius:        10px;
  --shadow-sm:     0 1px 3px rgba(0,0,0,.08);
  --shadow-md:     0 4px 16px rgba(0,0,0,.10);
  --shadow-lg:     0 8px 32px rgba(0,0,0,.12);
  --transition:    .2s ease;
  --font:          'Sarabun', 'Prompt', sans-serif;
}

/* ── Reset & Base ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--gray-100);
  color: var(--gray-800);
  min-height: 100vh;
  line-height: 1.6;
}

/* ── Typography ─────────────────────────────────────────── */
h1, h2, h3, h4 { font-weight: 700; line-height: 1.3; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ─────────────────────────────────────────────── */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* ── Navbar ─────────────────────────────────────────────── */
.navbar {
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: var(--white);
  padding: .9rem 0;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .5rem;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--white);
}

.navbar-brand .icon {
  font-size: 1.6rem;
  background: rgba(255,255,255,.2);
  padding: .3rem .4rem;
  border-radius: 8px;
}

.navbar-nav {
  display: flex;
  gap: .5rem;
  list-style: none;
}

.navbar-nav a {
  color: rgba(255,255,255,.85);
  padding: .4rem .9rem;
  border-radius: 6px;
  font-size: .9rem;
  font-weight: 600;
  transition: background var(--transition);
}

.navbar-nav a:hover,
.navbar-nav a.active {
  background: rgba(255,255,255,.2);
  color: var(--white);
  text-decoration: none;
}

/* ── Hero / Search Section ──────────────────────────────── */
.hero {
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: var(--white);
  padding: 2rem 0 3rem;
  text-align: center;
  margin-bottom: -1.5rem;
}

.hero h1 {
  font-size: clamp(1.4rem, 3vw, 2.2rem);
  margin-bottom: .5rem;
}

.hero p {
  font-size: 1rem;
  opacity: .85;
  margin-bottom: 1.6rem;
}

/* ── Search Box ─────────────────────────────────────────── */
.search-wrapper {
  position: relative;
  max-width: 600px;
  margin: 0 auto;
}

.search-input {
  width: 100%;
  padding: .85rem 1.2rem .85rem 3.2rem;
  font-size: 1.05rem;
  font-family: var(--font);
  border: 2px solid transparent;
  border-radius: 50px;
  outline: none;
  box-shadow: var(--shadow-lg);
  transition: border var(--transition), box-shadow var(--transition);
}

.search-input:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 4px rgba(37,99,235,.2), var(--shadow-lg);
}

.search-icon {
  position: absolute;
  left: 1.1rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.1rem;
  color: var(--gray-500);
  pointer-events: none;
}

.search-clear {
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  background: var(--gray-200);
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  cursor: pointer;
  font-size: .75rem;
  color: var(--gray-600);
  display: none;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}

.search-clear:hover { background: var(--gray-300); }
.search-clear.visible { display: flex; }

/* ── Main Content ───────────────────────────────────────── */
.main-content {
  padding: 2.5rem 0 3rem;
}

/* ── Card ───────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.4rem;
  border-bottom: 1px solid var(--gray-200);
  flex-wrap: wrap;
  gap: .5rem;
}

.card-header h2 {
  font-size: 1rem;
  color: var(--gray-700);
  display: flex;
  align-items: center;
  gap: .4rem;
}

.badge {
  background: var(--primary-light);
  color: var(--primary);
  font-size: .78rem;
  font-weight: 700;
  padding: .2rem .6rem;
  border-radius: 50px;
}

/* ── Table ──────────────────────────────────────────────── */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .92rem;
}

.data-table thead th {
  background: var(--gray-50);
  color: var(--gray-600);
  font-weight: 700;
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: .75rem 1rem;
  text-align: left;
  border-bottom: 2px solid var(--gray-200);
  white-space: nowrap;
}

.data-table tbody td {
  padding: .8rem 1rem;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

.data-table tbody tr:hover { background: var(--gray-50); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* Avatar cell */
.td-name {
  display: flex;
  align-items: center;
  gap: .6rem;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: var(--white);
  font-weight: 700;
  font-size: .85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Position badge */
.pos-badge {
  display: inline-block;
  font-size: .75rem;
  font-weight: 700;
  padding: .2rem .65rem;
  border-radius: 50px;
}

.pos-badge.supervisor {
  background: var(--warning-light);
  color: var(--warning);
}

.pos-badge.pc {
  background: var(--primary-light);
  color: var(--primary);
}

.pos-badge.other {
  background: var(--gray-100);
  color: var(--gray-600);
}

/* ── Custom Location Delete Confirm Dialog ───────────────── */
.loc-confirm-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.55);
  backdrop-filter: blur(4px);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fadeIn .15s ease;
}
.loc-confirm-overlay.active { display: flex; }

@keyframes fadeIn { from { opacity:0 } to { opacity:1 } }
@keyframes slideUp { from { opacity:0; transform:translateY(24px) scale(.96) } to { opacity:1; transform:translateY(0) scale(1) } }

.loc-confirm-box {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.18), 0 4px 16px rgba(0,0,0,.08);
  padding: 2rem 2rem 1.6rem;
  max-width: 360px;
  width: 100%;
  text-align: center;
  animation: slideUp .2s ease;
}
.loc-confirm-icon {
  font-size: 3rem;
  line-height: 1;
  margin-bottom: .75rem;
  display: block;
  filter: drop-shadow(0 2px 8px rgba(239,68,68,.25));
}
.loc-confirm-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gray-800);
  margin: 0 0 .5rem;
}
.loc-confirm-msg {
  font-size: .9rem;
  color: var(--gray-500);
  margin: 0 0 1.5rem;
  line-height: 1.6;
}
.loc-confirm-actions {
  display: flex;
  gap: .75rem;
  justify-content: center;
}
.loc-confirm-actions .btn { min-width: 100px; }

/* Toggle Switch */
.toggle-switch { display:inline-flex; align-items:center; gap:.5rem; cursor:pointer; user-select:none; }
.toggle-switch input { display:none; }
.toggle-track {
  width: 42px; height: 24px;
  background: var(--gray-300);
  border-radius: 999px;
  position: relative;
  transition: background .2s;
  flex-shrink: 0;
}
.toggle-track::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 18px; height: 18px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
  transition: transform .2s;
}
.toggle-switch input:checked + .toggle-track { background: var(--success); }
.toggle-switch input:checked + .toggle-track::after { transform: translateX(18px); }
.toggle-label { font-size: .82rem; color: var(--gray-600); white-space: nowrap; }

/* Staff address (แสดงใต้ชื่อสาขาในหน้าค้นหา) */
.staff-address {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
  margin-top: .3rem;
  font-size: .78rem;
  color: var(--gray-500);
  line-height: 1.4;
}
.maps-link {
  display: inline-flex;
  align-items: center;
  gap: .2rem;
  color: var(--primary);
  font-weight: 600;
  white-space: nowrap;
  text-decoration: none;
  padding: .1rem .35rem;
  border-radius: 4px;
  background: var(--primary-light);
  font-size: .75rem;
  transition: opacity .15s;
}
.maps-link:hover { opacity: .8; text-decoration: none; }

/* Phone link */
.phone-link {
  color: var(--success);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: .3rem;
  white-space: nowrap;
}

.phone-link:hover { opacity: .8; text-decoration: none; }

/* ── Action Buttons (จัดการ column) ─────────────────────── */
.td-actions {
  text-align: center;
  white-space: nowrap;
}
.td-actions .btn {
  display: inline-flex;
  vertical-align: middle;
  margin: .15rem .2rem;
}

/* ── Empty / Loading States ─────────────────────────────── */
.state-box {
  text-align: center;
  padding: 3.5rem 1rem;
  color: var(--gray-500);
}

.state-box .state-icon {
  font-size: 3rem;
  margin-bottom: .8rem;
  display: block;
}

.state-box p { font-size: 1rem; }

/* Spinner */
.spinner {
  width: 42px;
  height: 42px;
  border: 4px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto 1rem;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1.1rem;
  font-size: .88rem;
  font-family: var(--font);
  font-weight: 600;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); text-decoration: none; }
.btn:active { transform: translateY(0); }

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

.btn-success  { background: var(--success); color: var(--white); }
.btn-success:hover  { background: #15803d; color: var(--white); }

.btn-danger   { background: var(--danger); color: var(--white); }
.btn-danger:hover   { background: #b91c1c; color: var(--white); }

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

.btn-outline  {
  background: transparent;
  color: var(--primary);
  border: 2px solid var(--primary);
}
.btn-outline:hover { background: var(--primary-light); }

.btn-sm { padding: .3rem .7rem; font-size: .8rem; }
.btn-lg { padding: .75rem 1.6rem; font-size: 1rem; }
.btn-icon { padding: .4rem .5rem; }

/* ── Forms ──────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: .3rem;
}

.form-group.full-width { grid-column: 1 / -1; }

label {
  font-size: .85rem;
  font-weight: 600;
  color: var(--gray-700);
}

label .required { color: var(--danger); margin-left: .2rem; }

.form-control {
  padding: .6rem .9rem;
  font-size: .95rem;
  font-family: var(--font);
  border: 1.5px solid var(--gray-300);
  border-radius: 7px;
  outline: none;
  transition: border var(--transition), box-shadow var(--transition);
  background: var(--white);
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}

.form-control.error { border-color: var(--danger); }

/* ── Modal ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition), visibility var(--transition);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(20px) scale(.97);
  transition: transform var(--transition);
}

.modal-overlay.active .modal { transform: translateY(0) scale(1); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.4rem;
  border-bottom: 1px solid var(--gray-200);
}

.modal-header h3 { font-size: 1.1rem; color: var(--gray-800); }

.modal-close {
  background: var(--gray-100);
  border: none;
  border-radius: 6px;
  width: 30px;
  height: 30px;
  cursor: pointer;
  font-size: 1rem;
  color: var(--gray-600);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}

.modal-close:hover { background: var(--gray-200); }

.modal-body { padding: 1.4rem; }

.modal-footer {
  display: flex;
  gap: .6rem;
  justify-content: flex-end;
  padding: 1rem 1.4rem;
  border-top: 1px solid var(--gray-200);
  flex-wrap: wrap;
}

/* ── Confirm Dialog ─────────────────────────────────────── */
.confirm-dialog .modal { max-width: 400px; }
.confirm-dialog .modal-body { text-align: center; padding: 2rem 1.4rem; }
.confirm-dialog .confirm-icon { font-size: 3rem; margin-bottom: .8rem; display: block; }
.confirm-dialog h4 { font-size: 1.1rem; margin-bottom: .4rem; }
.confirm-dialog p { color: var(--gray-500); font-size: .9rem; }

/* ── Toast Notification ─────────────────────────────────── */
.toast-container {
  position: fixed;
  top: 1.2rem;
  right: 1.2rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  max-width: 340px;
  width: 100%;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: .7rem;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: .9rem 1rem;
  border-left: 4px solid var(--primary);
  animation: slideIn .25s ease;
  transition: opacity .3s ease, transform .3s ease;
}

.toast.success { border-color: var(--success); }
.toast.error   { border-color: var(--danger); }
.toast.warning { border-color: var(--warning); }

.toast-icon { font-size: 1.2rem; flex-shrink: 0; }
.toast-text { flex: 1; }
.toast-title { font-weight: 700; font-size: .9rem; color: var(--gray-800); }
.toast-msg   { font-size: .83rem; color: var(--gray-600); margin-top: .1rem; }

.toast-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: .8rem;
  color: var(--gray-400);
  padding: .1rem .2rem;
}

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

/* ── Admin Stats Cards ──────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 1.2rem 1.4rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 1rem;
  border-left: 4px solid var(--primary);
}

.stat-card.success { border-color: var(--success); }
.stat-card.warning { border-color: var(--warning); }
.stat-card.danger  { border-color: var(--danger); }

.stat-icon {
  font-size: 1.8rem;
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-info .num  { font-size: 1.6rem; font-weight: 700; color: var(--gray-800); }
.stat-info .lbl  { font-size: .8rem; color: var(--gray-500); }

/* ── Page Header ────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-header h1 { font-size: 1.4rem; color: var(--gray-800); }

/* ── Filter Bar ─────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: .6rem;
  align-items: center;
  flex-wrap: wrap;
  padding: .9rem 1.2rem;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
}

.filter-bar .form-control { flex: 1; min-width: 160px; max-width: 280px; }

/* ── Responsive ─────────────────────────────────────────── */

/* ─ Tablet (≤ 900px) ─ */
@media (max-width: 900px) {
  .data-table { font-size: .85rem; }
  .data-table thead th,
  .data-table tbody td { padding: .65rem .75rem; }
}

/* ─ Mobile (≤ 768px): ตาราง → Card layout 100% ─ */
@media (max-width: 768px) {

  /* Navbar */
  .navbar-brand .brand-text { display: none; }
  .hero { padding: 1.6rem 0 2.8rem; }

  /* Page header stack */
  .page-header { flex-direction: column; align-items: stretch; }
  .page-header .btn { width: 100%; justify-content: center; }

  /* ── ซ่อน thead ── */
  .data-table thead { display: none; }

  /* ── table และ wrapper ไม่ scroll ── */
  .table-responsive { overflow-x: visible; }
  .data-table       { display: block; width: 100%; }
  .data-table tbody {
    display: flex;
    flex-direction: column;
    gap: .75rem;
    padding: .85rem;
  }

  /* ── แต่ละ tr = card เต็มความกว้าง ── */
  .data-table tbody tr {
    display: block;
    width: 100%;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: box-shadow var(--transition);
  }
  .data-table tbody tr:hover {
    box-shadow: var(--shadow-md);
    background: var(--white);
  }

  /* ── แต่ละ td = แถว label | value ── */
  .data-table tbody td {
    display: flex;
    align-items: center;
    width: 100%;
    padding: .65rem 1rem;
    border-bottom: 1px solid var(--gray-100);
    min-height: 46px;
    gap: .5rem;
  }
  .data-table tbody td:last-child { border-bottom: none; }

  /* label ทางซ้าย */
  .data-table tbody td::before {
    content: attr(data-label);
    font-size: .71rem;
    font-weight: 700;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: .05em;
    min-width: 78px;
    flex-shrink: 0;
    line-height: 1.3;
  }

  /* ค่าข้อมูลชิดขวา */
  .data-table tbody td > *   { margin-left: auto; text-align: right; }
  .data-table tbody td > div {
    margin-left: auto;
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
    justify-content: flex-end;
  }
  .td-name {
    margin-left: auto;
    justify-content: flex-end;
  }

  /* ── แถวปุ่มจัดการ: ปุ่มเต็มความกว้าง ── */
  .data-table tbody td.td-actions {
    flex-direction: column;
    align-items: stretch;
    gap: .45rem;
    padding: .75rem 1rem;
  }
  .data-table tbody td.td-actions::before {
    min-width: unset;
    margin-bottom: .1rem;
  }
  .data-table tbody td.td-actions .btn {
    width: 100%;
    justify-content: center;
    padding: .6rem;
    font-size: .88rem;
  }

  /* Modal, Stats, Filter */
  .stats-grid { grid-template-columns: 1fr; gap: .6rem; }
  .filter-bar .form-control { max-width: 100%; min-width: 0; }
  .modal-footer .btn { flex: 1; }
}

/* ─ Small phone (≤ 480px) ─ */
@media (max-width: 480px) {
  .container { padding: 0 .75rem; }
  .hero h1   { font-size: 1.15rem; }
  .hero p    { font-size: .88rem; }

  .data-table tbody { padding: .6rem; gap: .6rem; }
  .data-table tbody td { padding: .6rem .85rem; min-height: 44px; }
  .data-table tbody td::before { min-width: 68px; font-size: .68rem; }

  /* Modal — กลางจอ, scroll ได้, ไม่ล้นหน้าจอ */
  .modal-overlay {
    align-items: center;
    padding: .75rem;
  }
  .modal {
    border-radius: 14px;
    max-height: calc(100dvh - 1.5rem);
    max-height: calc(100vh  - 1.5rem);
    width: 100%;
    display: flex;
    flex-direction: column;
    transform: translateY(24px) scale(.97);
  }
  .modal-overlay.active .modal {
    transform: translateY(0) scale(1);
  }
  /* ส่วน body ของ modal ให้ scroll ได้ ไม่ใช่ทั้ง modal */
  .modal-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
  }
  /* form grid 1 คอลัมน์บนมือถือ */
  .form-grid {
    grid-template-columns: 1fr;
  }
  .modal-footer { flex-direction: column; }
  .modal-footer .btn { width: 100%; }

  .stats-grid { grid-template-columns: 1fr; }
}

/* ── Footer ─────────────────────────────────────────────── */
.footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--gray-500);
  font-size: .85rem;
  border-top: 1px solid var(--gray-200);
  background: var(--white);
  margin-top: auto;
}

/* ── Highlight matched text ─────────────────────────────── */
mark {
  background: #fef08a;
  color: inherit;
  border-radius: 2px;
  padding: 0 2px;
}

/* ── Login Page Styles ──────────────────────────────────── */
body.login-page {
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 40%, #2563eb 100%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.login-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  position: relative;
}

/* Floating particles background */
.login-wrapper::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 80%, rgba(37,99,235,.15) 0, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(14,165,233,.12) 0, transparent 50%),
    radial-gradient(circle at 50% 50%, rgba(255,255,255,.03) 0, transparent 70%);
  pointer-events: none;
}

.login-card {
  background: rgba(255,255,255,.97);
  backdrop-filter: blur(20px);
  border-radius: 20px;
  box-shadow:
    0 25px 60px rgba(0,0,0,.3),
    0 0 0 1px rgba(255,255,255,.1);
  width: 100%;
  max-width: 420px;
  padding: 2.5rem 2rem;
  position: relative;
  z-index: 1;
  animation: cardSlideUp .6s cubic-bezier(.16,1,.3,1);
}

@keyframes cardSlideUp {
  from { opacity: 0; transform: translateY(40px) scale(.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.login-header {
  text-align: center;
  margin-bottom: 2rem;
}

.login-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1rem;
  font-size: 2rem;
  box-shadow: 0 8px 24px rgba(37,99,235,.3);
  animation: avatarPulse 3s ease-in-out infinite;
}

@keyframes avatarPulse {
  0%, 100% { box-shadow: 0 8px 24px rgba(37,99,235,.3); }
  50%      { box-shadow: 0 8px 32px rgba(37,99,235,.5); }
}

.login-header h1 {
  font-size: 1.4rem;
  color: var(--gray-800);
  margin-bottom: .3rem;
}

.login-header p {
  font-size: .88rem;
  color: var(--gray-500);
}

/* Form styles */
.login-form .form-group {
  margin-bottom: 1.2rem;
}

.login-form label {
  font-size: .85rem;
  font-weight: 600;
  color: var(--gray-700);
  display: flex;
  align-items: center;
  gap: .4rem;
  margin-bottom: .4rem;
}

.login-form .form-control {
  width: 100%;
  padding: .75rem 1rem .75rem 2.8rem;
  font-size: .95rem;
  border: 2px solid var(--gray-200);
  border-radius: 10px;
  transition: all .25s ease;
  background: var(--gray-50);
}

.login-form .form-control:focus {
  border-color: var(--primary);
  background: var(--white);
  box-shadow: 0 0 0 4px rgba(37,99,235,.1);
}

.input-wrapper {
  position: relative;
}

.input-icon {
  position: absolute;
  left: .9rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.1rem;
  color: var(--gray-400);
  pointer-events: none;
  transition: color .2s;
}

.input-wrapper:focus-within .input-icon {
  color: var(--primary);
}

.toggle-password {
  position: absolute;
  right: .7rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--gray-400);
  padding: .2rem;
  transition: color .2s;
}

.toggle-password:hover { color: var(--gray-600); }

.login-btn {
  width: 100%;
  padding: .85rem;
  font-size: 1rem;
  font-weight: 700;
  font-family: var(--font);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: var(--white);
  transition: all .25s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  margin-top: 1.5rem;
  position: relative;
  overflow: hidden;
}

.login-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent, rgba(255,255,255,.15));
  opacity: 0;
  transition: opacity .25s;
}

.login-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(37,99,235,.35);
}

.login-btn:hover::after { opacity: 1; }

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

.login-btn:disabled {
  opacity: .7;
  cursor: not-allowed;
  transform: none;
}

/* Alert messages */
.alert {
  padding: .75rem 1rem;
  border-radius: 10px;
  font-size: .88rem;
  font-weight: 600;
  margin-bottom: 1.2rem;
  display: flex;
  align-items: center;
  gap: .5rem;
  animation: alertShake .4s ease;
}

@keyframes alertShake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-6px); }
  40%      { transform: translateX(6px); }
  60%      { transform: translateX(-4px); }
  80%      { transform: translateX(4px); }
}

.alert-error {
  background: #fef2f2;
  color: #dc2626;
  border: 1.5px solid #fca5a5;
}

.alert-success {
  background: #f0fdf4;
  color: #16a34a;
  border: 1.5px solid #86efac;
}

/* Footer link */
.login-footer {
  text-align: center;
  margin-top: 1.5rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--gray-200);
}

.login-footer a {
  font-size: .88rem;
  color: var(--gray-500);
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  transition: color .2s;
}

/* ── Reference Data List (zone/mall manager in admin.php) ── */
.ref-list {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  max-height: 230px;
  overflow-y: auto;
  padding-right: .25rem;
}
.ref-list::-webkit-scrollbar { width: 4px; }
.ref-list::-webkit-scrollbar-track { background: transparent; }
.ref-list::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 2px; }

.ref-item {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .42rem .65rem;
  border-radius: 8px;
  background: var(--white);
  border: 1.5px solid var(--gray-200);
  min-height: 38px;
  transition: border-color .15s, box-shadow .15s;
}
.ref-item:hover                { border-color: var(--gray-300); box-shadow: var(--shadow-sm); }
.ref-item.is-editing           { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.ref-item.is-deleting          { border-color: var(--danger);  background: #fff8f8; }
.ref-item.is-dragging          { opacity: .55; border-color: var(--primary); border-style: dashed; box-shadow: var(--shadow-md); }

/* ปุ่มจับลากจัดเรียง (กดค้างแล้วลาก) — touch-action:none ให้ลากบนมือถือได้โดยไม่เลื่อนจอ */
.ref-item-drag {
  flex-shrink: 0; cursor: grab; user-select: none; touch-action: none;
  color: var(--gray-300); font-size: 1.05rem; line-height: 1;
  padding: 0 .35rem; margin: -.42rem 0 -.42rem -.3rem;
  display: inline-flex; align-items: center; align-self: stretch;
  transition: color .13s;
}
.ref-item-drag:hover  { color: var(--gray-500); }
.ref-item-drag:active { cursor: grabbing; }
.ref-item.is-editing  .ref-item-drag,
.ref-item.is-deleting .ref-item-drag { visibility: hidden; }

.ref-item-name {
  flex: 1; font-size: .875rem; font-weight: 600; color: var(--gray-700);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ref-item-input {
  flex: 1; font-size: .875rem; font-family: var(--font); font-weight: 600;
  padding: .15rem .3rem; border: none; outline: none;
  background: transparent; color: var(--gray-800); min-width: 0;
}
.ref-item-del-label {
  flex: 1; font-size: .8rem; font-weight: 600; color: var(--danger);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Tiny action buttons */
.ref-item-acts { display: flex; gap: .2rem; flex-shrink: 0; }
.rib {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 28px; height: 28px; padding: 0 .45rem;
  border: 1.5px solid transparent; border-radius: 7px;
  cursor: pointer; font-size: .8rem; font-family: var(--font); font-weight: 700;
  transition: background .13s, border-color .13s, transform .1s;
  white-space: nowrap; line-height: 1;
}
.rib:active   { transform: scale(.88); }
.rib:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.rib-edit    { background: #eff6ff; color: #2563eb; }
.rib-edit:not(:disabled):hover  { background: #dbeafe; border-color: #93c5fd; }
.rib-del     { background: #fef2f2; color: #dc2626; }
.rib-del:not(:disabled):hover   { background: #fee2e2; border-color: #fca5a5; }
.rib-save    { background: #f0fdf4; color: #15803d; }
.rib-save:not(:disabled):hover  { background: #dcfce7; border-color: #86efac; }
.rib-cancel  { background: var(--gray-100); color: var(--gray-600); }
.rib-cancel:not(:disabled):hover{ background: var(--gray-200); border-color: var(--gray-300); }
.rib-yes     { background: #dc2626; color: #fff; padding: 0 .6rem; font-size: .75rem; }
.rib-yes:not(:disabled):hover   { background: #b91c1c; }

/* ── Mall Quick-Filter Chips (index.php) ─────────────────── */
.mall-chips-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  justify-content: center;
  margin-top: 1rem;
  min-height: 2.2rem;
}

.mall-chip {
  display: inline-flex;
  align-items: center;
  padding: .38rem 1.1rem;
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,.45);
  background: rgba(255,255,255,.12);
  color: rgba(255,255,255,.95);
  font-size: .875rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s, transform .1s;
  white-space: nowrap;
  user-select: none;
  letter-spacing: .01em;
}

.mall-chip:hover {
  background: rgba(255,255,255,.28);
  border-color: rgba(255,255,255,.8);
  transform: translateY(-1px);
}

.mall-chip.active {
  background: #fff;
  color: var(--primary);
  border-color: #fff;
  box-shadow: 0 3px 10px rgba(0,0,0,.18);
  transform: translateY(-1px);
}

/* active indicator dot */
.mall-chip.active::before {
  content: '●';
  margin-right: .35rem;
  font-size: .55rem;
  vertical-align: middle;
}

@media (max-width: 480px) {
  .mall-chips-wrap { gap: .35rem; margin-top: .75rem; }
  .mall-chip { font-size: .8rem; padding: .32rem .85rem; }
}

.login-footer a:hover {
  color: var(--primary);
  text-decoration: none;
}

/* Responsive */
@media (max-width: 480px) {
  .login-card { padding: 2rem 1.4rem; margin: .5rem; }
  .login-header h1 { font-size: 1.2rem; }
}

/* ── Import Page Styles ─────────────────────────────────── */
.import-wrapper   { max-width: 900px; margin: 0 auto; }

/* Drop Zone */
.drop-zone {
  border: 2.5px dashed var(--gray-300);
  border-radius: 14px;
  padding: 3rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: all .22s ease;
  background: var(--gray-50);
  position: relative;
}
.drop-zone:hover,
.drop-zone.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
}
.drop-zone input[type=file] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%;
}
.drop-icon  { font-size: 3.5rem; display: block; margin-bottom: .6rem; }
.drop-title { font-size: 1.1rem; font-weight: 700; color: var(--gray-700); }
.drop-sub   { font-size: .88rem; color: var(--gray-500); margin-top: .3rem; }
.drop-zone.has-file { border-color: var(--success); background: #f0fdf4; }
.drop-zone.has-file .drop-icon { filter: grayscale(0); }

/* Template download banner */
.template-banner {
  background: linear-gradient(135deg,#eff6ff,#dbeafe);
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  padding: 1rem 1.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.4rem;
}
.template-banner p   { font-size: .9rem; color: var(--gray-700); }
.template-banner p b { color: var(--primary); }

/* Mapping table */
.map-table  { width: 100%; border-collapse: collapse; font-size: .9rem; margin-bottom: 1rem; }
.map-table th { background: var(--gray-50); padding: .6rem .8rem; text-align: left;
                font-size: .75rem; font-weight: 700; color: var(--gray-500);
                text-transform: uppercase; letter-spacing: .05em;
                border-bottom: 2px solid var(--gray-200); }
.map-table td { padding: .55rem .8rem; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
.map-table select { padding: .35rem .6rem; border: 1.5px solid var(--gray-300);
                    border-radius: 6px; font-family: var(--font); font-size: .88rem;
                    background: var(--white); width: 100%; min-width: 140px; }
.map-table select:focus { outline: none; border-color: var(--primary); }
.required-star { color: var(--danger); font-weight: 700; margin-left: .15rem; }

/* Preview table area */
#previewSection  { display: none; }
#resultSection   { display: none; }

.section-title {
  font-size: 1rem; font-weight: 700; color: var(--gray-700);
  margin-bottom: .75rem; display: flex; align-items: center; gap: .4rem;
}

/* Row count pills */
.count-pills { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.pill {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .3rem .75rem; border-radius: 50px; font-size: .82rem; font-weight: 700;
}
.pill-total   { background: var(--primary-light); color: var(--primary); }
.pill-valid   { background: #dcfce7; color: #15803d; }
.pill-invalid { background: var(--danger-light);   color: var(--danger); }

/* Result box */
.result-box {
  border-radius: 12px;
  padding: 1.5rem;
  text-align: center;
  border: 2px solid transparent;
}
.result-box.success { background: #f0fdf4; border-color: #86efac; }
.result-box.error   { background: #fef2f2; border-color: #fca5a5; }
.result-icon  { font-size: 3rem; display: block; margin-bottom: .5rem; }
.result-title { font-size: 1.2rem; font-weight: 700; margin-bottom: .3rem; }
.result-sub   { font-size: .9rem; color: var(--gray-600); }

.error-list {
  margin-top: 1rem; text-align: left; max-height: 180px; overflow-y: auto;
  background: var(--white); border-radius: 8px; padding: .75rem;
  border: 1px solid #fca5a5; font-size: .82rem; color: var(--danger);
}
.error-list li { margin-bottom: .25rem; }

/* Progress bar */
.progress-wrap { background: var(--gray-200); border-radius: 50px; height: 8px; overflow: hidden; margin: .75rem 0; }
.progress-bar  { height: 100%; background: var(--primary);
                 border-radius: 50px; transition: width .3s ease; width: 0%; }

/* Preview table scroll */
.preview-scroll { max-height: 320px; overflow-y: auto; }

@media (max-width: 600px) {
  .template-banner { flex-direction: column; align-items: flex-start; }
  .template-banner .btn { width: 100%; justify-content: center; }
}

/* ── Template Generator Page Styles ─────────────────────── */
.template-page {
  min-height: 80vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.template-card {
  background: var(--white);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 3rem 2.5rem;
  text-align: center;
  max-width: 480px;
  width: 100%;
  animation: fadeInUp .5s ease;
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(30px); }
  to   { opacity: 1; transform: translateY(0); }
}
.template-card .icon-big {
  font-size: 4rem;
  display: block;
  margin-bottom: 1rem;
  animation: pulse 1.5s infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.1); }
}
.template-card h2 {
  font-size: 1.3rem;
  color: var(--gray-800);
  margin-bottom: .5rem;
}
.template-card p {
  font-size: .92rem;
  color: var(--gray-500);
  margin-bottom: 1.5rem;
}
.template-card .status {
  font-size: .88rem;
  color: var(--primary);
  font-weight: 600;
}
.template-card .status.done {
  color: var(--success);
}
.template-card .status.error {
  color: var(--danger);
}
.template-card .btn {
  margin-top: 1.2rem;
}
.progress-ring {
  width: 48px; height: 48px;
  border: 4px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto 1rem;
}
.done-check {
  display: none;
  font-size: 3rem;
  margin: 0 auto 1rem;
  animation: bounceIn .5s ease;
}
@keyframes bounceIn {
  0%   { transform: scale(0); }
  60%  { transform: scale(1.15); }
  100% { transform: scale(1); }
}
.done-check.show { display: block; }

/* ── Scrollbar ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--gray-100); }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-500); }
