/* styles.css v19 */

body {
  margin: 0;
  background: #f7f7f5;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ===== HEADER ===== */
.header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  background: #ffffff;
  border-bottom: 1px solid #eee;
  z-index: 1000;
  transition: all 0.3s ease;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 8px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header.shrink .header-inner {
  padding: 6px 24px;
}

.header.shrink {
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}

.logo {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.3px;
  cursor: pointer;
}

.nav {
  display: flex;
  gap: 14px;
  align-items: center;
}

.nav a {
  text-decoration: none;
  color: #555;
  font-size: 12px;
  font-weight: 500;
}

.login-btn {
  background: #e5e5e5;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}

/* ===== HERO SPACE ===== */
.hero-space {
  height: 60px;
}

/* ===== SPACING ===== */
.spacing-large {
  height: 40px;
}

/* ===== FOOTER ===== */
.footer {
  margin-top: 80px;
  padding: 40px 0;
  text-align: center;
  font-size: 12px;
  color: #888;
}

/* ===== MOBILE ===== */
@media (max-width: 768px) {
  .header-inner {
    padding: 14px 20px;
  }
  .hero-space {
    height: 80px;
  }
}

/* ===================================================== */
/* ===== POPUP SYSTEM ===== */
/* ===================================================== */

.popup-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.3);
  opacity: 0;
  visibility: hidden;
  transition: 0.3s;
  z-index: 2000;
}

.popup-overlay.active {
  opacity: 1;
  visibility: visible;
}

.popup-container {
  position: fixed;
  top: 0;
  right: -360px;
  width: 360px;
  height: 100%;
  background: #fff;
  box-shadow: -2px 0 12px rgba(0,0,0,0.08);
  transition: 0.3s;
  z-index: 2001;
  display: flex;
  flex-direction: column;
}

.popup-container.active {
  right: 0;
}

.popup-header {
  padding: 16px;
  border-bottom: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  font-weight: 600;
}

.popup-close {
  cursor: pointer;
}

.popup-body {
  padding: 16px;
  overflow-y: auto;
  height: calc(100vh - 60px);
}

/* ===== DASHBOARD TABLE ===== */
.mock-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.mock-table th,
.mock-table td {
  padding: 8px;
  border-bottom: 1px solid #eee;
  text-align: left;
}

.mock-table th {
  background: #fafafa;
  font-weight: 600;
}

/* ===== STICKY ACTION BAR ===== */
.popup-body > div:first-child {
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 10;
  padding-bottom: 10px;
  border-bottom: 1px solid #eee;
}

/* ===== IMAGE PREVIEW LIST (FORM) ===== */
#imagePreviewList img {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 6px;
}

/* ===== KEYPAD ===== */

.keypad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.key {
  background: #1e1e1e;
  color: #fff;
  text-align: center;
  padding: 18px 0;
  border-radius: 14px;
  font-size: 18px;
  cursor: pointer;
  user-select: none;
  transition: all 0.15s ease;
}

.key:hover {
  background: #333;
}

.key:active {
  transform: scale(0.95);
}

.key:last-child {
  background: #4caf50;
}

.key:nth-last-child(2) {
  background: #e53935;
}

/* ===== DESKTOP KEYPAD ===== */
@media (min-width: 768px) {
  .keypad-grid {
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
  }

  .key {
    padding: 12px 0;
    font-size: 14px;
  }
}

/* ===== MOBILE KEYPAD ===== */
@media (max-width: 768px) {
  .keypad-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }

  .key {
    padding: 14px 0;
    font-size: 16px;
    border-radius: 12px;
  }
}

/* ===== DASHBOARD EXPAND ===== */
.popup-container.popup-large {
  width: 80vw;
  max-width: 1200px;
  height: 100%;
  right: 0;
  left: auto;
  transform: none;
  border-radius: 0;
}

@media (max-width: 768px) {
  .popup-container.popup-large {
    width: 100%;
  }
}

/* ===================================================== */
/* ===== 🔥 IMAGE PREVIEW (FIX Z-INDEX) ===== */
/* ===================================================== */

#imagePreview {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;

  display: none;
  justify-content: center;
  align-items: center;

  background: rgba(0, 0, 0, 0.95);

  z-index: 20000; /* 🔥 สำคัญ: ต้องสูงกว่า detail popup */
}

#imagePreview img {
  max-width: 90%;
  max-height: 90%;
}