/* ==========================================================================
   Modern Inventory System Stylesheet
   ออกแบบสำหรับระบบจัดเก็บพัสดุครุภัณฑ์ (Responsive, Mobile-First, Touch Friendly)
   ========================================================================== */

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

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --secondary: #1e293b;
  --bg-color: #f8fafc;
  --surface: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #06b6d4;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --radius: 12px;
  --nav-height: 64px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Prompt', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-color);
  color: var(--text-main);
  line-height: 1.5;
  padding-top: var(--nav-height);
  padding-bottom: 80px; /* สำหรับ Bottom Nav ใน มือถือ/แท็บเล็ต */
  overflow-x: hidden;
}

@media (min-width: 1024px) {
  body {
    padding-bottom: 30px;
  }
}

/* --- Navigation Bars --- */
.top-navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 1000;
  box-shadow: var(--shadow-sm);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--secondary);
  font-weight: 700;
  font-size: 1.25rem;
}

.brand-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary), var(--info));
  color: #fff;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  box-shadow: 0 2px 5px rgba(37, 99, 235, 0.3);
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-text span {
  line-height: 1.2;
}

.brand-text small {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 400;
}

/* Desktop Navigation (>= 1024px) */
.desktop-nav {
  display: none;
}

@media (min-width: 1024px) {
  .desktop-nav {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #f1f5f9;
    padding: 4px;
    border-radius: 14px;
    border: 1px solid var(--border-color);
  }
  .desktop-nav .nav-item {
    padding: 8px 18px;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
  }
  .desktop-nav .nav-item i {
    font-size: 1.1rem;
  }
  .desktop-nav .nav-item:hover {
    color: var(--primary);
    background: rgba(255, 255, 255, 0.6);
  }
  .desktop-nav .nav-item.active {
    background: var(--surface);
    color: var(--primary);
    font-weight: 600;
    box-shadow: var(--shadow-sm);
  }
}

.user-profile-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--primary-light);
  color: var(--primary);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid #dbeafe;
  cursor: pointer;
  transition: all 0.2s;
}
.user-profile-badge:hover {
  background: #dbeafe;
  transform: translateY(-1px);
}

/* Bottom Navigation (< 1024px) */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 65px;
  background: var(--surface);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 1000;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
  padding-bottom: env(safe-area-inset-bottom);
}

@media (min-width: 1024px) {
  .bottom-nav {
    display: none;
  }
}

.bottom-nav .nav-item {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s;
}

.bottom-nav .nav-item i {
  font-size: 1.25rem;
  transition: transform 0.2s;
}

.bottom-nav .nav-item.active {
  color: var(--primary);
  font-weight: 600;
}
.bottom-nav .nav-item.active i {
  transform: scale(1.15);
}

/* --- Layout Container & Views --- */
.container {
  max-width: 1400px;
  margin: 20px auto;
  padding: 0 16px;
}

.view-section {
  display: none;
  animation: fadeIn 0.3s ease-out;
}
.view-section.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Dashboard Stat Cards (Glassmorphism & Tilt Ready) --- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  padding: 22px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  transform-style: preserve-3d;
}
.stat-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: rgba(37, 99, 235, 0.3);
}

.stat-info h4 {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 6px;
  transform: translateZ(15px);
}
.stat-info .value {
  font-size: 1.85rem;
  font-weight: 700;
  color: var(--secondary);
  line-height: 1;
  transform: translateZ(25px);
}

.stat-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  transform: translateZ(20px);
  box-shadow: 0 4px 10px rgba(0,0,0,0.08);
}
.stat-icon.bg-blue { background: #e0f2fe; color: #0284c7; }
.stat-icon.bg-green { background: #dcfce7; color: #16a34a; }
.stat-icon.bg-yellow { background: #fef9c3; color: #ca8a04; }
.stat-icon.bg-red { background: #fee2e2; color: #dc2626; }

/* --- Interactive 3D Charts Grid --- */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
  gap: 24px;
  margin-bottom: 25px;
}

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

.chart-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-color);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(12px);
}

.chart-card:hover {
  box-shadow: 0 20px 25px -5px rgba(37, 99, 235, 0.12), 0 10px 10px -5px rgba(37, 99, 235, 0.04);
  border-color: rgba(37, 99, 235, 0.3);
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
  border-bottom: 1px dashed var(--border-color);
  padding-bottom: 12px;
}

.chart-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--secondary);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-3d {
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 20px;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  animation: pulseGlow 2.5s infinite;
}

@keyframes pulseGlow {
  0%, 100% { transform: scale(1); box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3); }
  50% { transform: scale(1.05); box-shadow: 0 6px 16px rgba(37, 99, 235, 0.5); }
}

/* --- Filter & Action Card --- */
.filter-card {
  background: var(--surface);
  padding: 18px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border-color);
  margin-bottom: 16px;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.search-box {
  flex: 1;
  min-width: 250px;
  position: relative;
}
.search-box i {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}
.search-box input {
  width: 100%;
  padding: 10px 14px 10px 40px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search-box input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.filter-select {
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 0.9rem;
  color: var(--text-main);
  background-color: var(--surface);
  outline: none;
  cursor: pointer;
}
.filter-select:focus {
  border-color: var(--primary);
}

/* --- Building Pills --- */
.building-pills {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}
.pill-btn {
  padding: 6px 16px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  background: var(--surface);
  color: var(--text-main);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}
.pill-btn:hover {
  background: #f1f5f9;
}
.pill-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 2px 6px rgba(37,99,235,0.25);
}

/* --- Synced Horizontal Scrollbar Table Wrapper --- */
.table-wrapper-outer {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border-color);
  overflow: hidden;
}

.top-scrollbar-container {
  overflow-x: auto;
  overflow-y: hidden;
  height: 12px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border-color);
}
.top-scrollbar-dummy {
  height: 1px;
}

.table-container {
  overflow-x: auto;
  max-height: 70vh;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
  white-space: nowrap;
}

.data-table th, .data-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
}

.data-table th {
  background: #f1f5f9;
  color: var(--secondary);
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 10;
}

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

/* Status Badges */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
}
.status-success { background: #dcfce7; color: #16a34a; }
.status-warning { background: #fef9c3; color: #ca8a04; }
.status-danger { background: #fee2e2; color: #dc2626; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); box-shadow: 0 2px 8px rgba(37,99,235,0.3); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-outline { background: transparent; border: 1px solid var(--border-color); color: var(--text-main); }
.btn-outline:hover { background: #f1f5f9; border-color: #cbd5e1; }

/* --- Forms & Grid --- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--secondary);
}
.form-group input, .form-group select, .form-group textarea {
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--primary);
}

/* --- Scanner Container --- */
.scanner-container {
  max-width: 600px;
  margin: 0 auto;
  background: var(--surface);
  padding: 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border-color);
  text-align: center;
}
#reader {
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  margin-top: 16px;
  background: #000;
  min-height: 250px;
}

/* Hover Image Preview Card */
#hover-preview-card {
  display: none;
  position: fixed;
  z-index: 9999;
  background: #fff;
  padding: 8px;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  border: 1px solid var(--border-color);
  pointer-events: none;
}
#hover-preview-card img {
  max-width: 250px;
  max-height: 250px;
  border-radius: 8px;
  display: block;
}
.hover-img-trigger {
  color: var(--primary);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Role Tag */
.role-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  background: #e2e8f0;
  color: var(--secondary);
}
