/* ==========================================================================
   ระบบบันทึกบัญชีครุภัณฑ์และวัสดุคลัง - ฝ่ายเทศกิจ เทศบาลนครพิษณุโลก
   Theme: Deep Forest Green & Golden Accents (เอกลักษณ์องค์กร)
   Fully Responsive & Mobile Optimized
   ========================================================================== */

:root {
  --primary-950: #011913;
  --primary-900: #022c22;
  --primary-800: #064e3b;
  --primary-700: #046c4e;
  --primary-600: #059669;
  --primary-500: #10b981;
  --primary-400: #34d399;
  --primary-100: #d1fae5;
  --primary-50:  #ecfdf5;

  --accent-gold: #d97706;
  --accent-gold-light: #fef3c7;
  --accent-gold-dark: #b45309;

  --thetsakit-maroon: #800000;
  --thetsakit-maroon-light: #fdf2f2;

  --slate-900: #0f172a;
  --slate-800: #1e293b;
  --slate-700: #334155;
  --slate-600: #475569;
  --slate-500: #64748b;
  --slate-400: #94a3b8;
  --slate-300: #cbd5e1;
  --slate-200: #e2e8f0;
  --slate-100: #f1f5f9;
  --slate-50:  #f8fafc;

  --danger-600: #dc2626;
  --danger-100: #fee2e2;
  --warning-600: #ea580c;
  --warning-100: #ffedd5;
  --success-600: #16a34a;
  --success-100: #dcfce7;
  --info-600: #0284c7;
  --info-100: #e0f2fe;

  --font-prompt: 'Prompt', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-sarabun: 'Sarabun', -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sarabun);
  background-color: #f3f7f4;
  color: var(--slate-800);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom, 20px);
}

h1, h2, h3, h4, h5, h6, .font-heading {
  font-family: var(--font-prompt);
  font-weight: 600;
}

/* Header & Banner */
.app-header {
  background: linear-gradient(135deg, #022c22 0%, #064e3b 60%, #046c4e 100%);
  color: white;
  border-bottom: 3px solid var(--accent-gold);
  box-shadow: 0 4px 20px rgba(2, 44, 34, 0.25);
  position: relative;
  overflow: hidden;
}

.app-header::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: radial-gradient(circle at 85% 20%, rgba(217, 119, 6, 0.2), transparent 55%);
  pointer-events: none;
}

.logo-frame {
  background: rgba(255, 255, 255, 0.98);
  border-radius: 9999px;
  padding: 3px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3), 0 0 0 2px rgba(217, 119, 6, 0.7);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s ease;
}

.logo-frame-shield {
  background: rgba(255, 255, 255, 0.98);
  border-radius: 12px;
  padding: 3px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3), 0 0 0 2px rgba(217, 119, 6, 0.7);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s ease;
}

.logo-frame:hover, .logo-frame-shield:hover {
  transform: scale(1.06);
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: #f1f5f9;
}
::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 9999px;
}
::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

.scrollbar-none::-webkit-scrollbar {
  display: none;
}
.scrollbar-none {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

/* Navigation Tabs */
.nav-tab-btn {
  font-family: var(--font-prompt);
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 10px;
  color: #d1fae5;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  font-size: 0.88rem;
  border: 1px solid transparent;
  user-select: none;
}

@media (min-width: 768px) {
  .nav-tab-btn {
    padding: 9px 16px;
    font-size: 0.93rem;
    gap: 8px;
  }
}

.nav-tab-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

.nav-tab-btn.active {
  background: #ffffff;
  color: var(--primary-900);
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  border-color: rgba(217, 119, 6, 0.35);
}

.nav-tab-btn.active svg, .nav-tab-btn.active i {
  color: var(--primary-700) !important;
}

/* Mobile Bottom Navigation Bar */
.mobile-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(10px);
  border-top: 1px solid #e2e8f0;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
  z-index: 40;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px 6px;
  border-radius: 8px;
  color: var(--slate-500);
  font-family: var(--font-prompt);
  font-size: 0.72rem;
  font-weight: 500;
  transition: all 0.15s ease;
  min-height: 48px;
}

.mobile-nav-item i {
  font-size: 1.15rem;
  margin-bottom: 2px;
}

.mobile-nav-item.active {
  color: var(--primary-800);
  font-weight: 600;
  background: var(--primary-50);
}

.mobile-nav-item.active i {
  color: var(--primary-700);
}

/* Cards & Containers */
.stat-card {
  background: #ffffff;
  border-radius: 16px;
  border: 1px solid #e6efe9;
  box-shadow: 0 2px 8px rgba(6, 78, 59, 0.04);
  transition: all 0.25s ease;
  position: relative;
  overflow: hidden;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(6, 78, 59, 0.1);
  border-color: var(--primary-500);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--primary-600);
}

.stat-card.gold::before { background: var(--accent-gold); }
.stat-card.danger::before { background: var(--danger-600); }
.stat-card.blue::before { background: var(--info-600); }
.stat-card.teal::before { background: #0d9488; }

.app-card {
  background: #ffffff;
  border-radius: 16px;
  border: 1px solid #e2e8f0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
}

/* Mobile Responsive Item Cards */
.item-card-mobile {
  background: #ffffff;
  border-radius: 14px;
  border: 1px solid #e2e8f0;
  padding: 14px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.03);
  transition: all 0.2s ease;
}

.item-card-mobile:hover, .item-card-mobile:active {
  border-color: var(--primary-500);
  box-shadow: 0 4px 12px rgba(6, 78, 59, 0.08);
}

/* Form Styles */
.form-label {
  font-family: var(--font-prompt);
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--slate-700);
  margin-bottom: 5px;
  display: block;
}

.form-label.required::after {
  content: ' *';
  color: var(--danger-600);
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid #cbd5e1;
  background-color: #ffffff;
  font-family: var(--font-sarabun);
  font-size: 0.95rem;
  color: var(--slate-900);
  transition: all 0.2s ease;
  outline: none;
}

@media (min-width: 768px) {
  .form-input, .form-select, .form-textarea {
    min-height: 44px;
    padding: 9px 14px;
  }
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--primary-600);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

.form-input:disabled, .form-select:disabled {
  background-color: #f8fafc;
  color: var(--slate-500);
  cursor: not-allowed;
}

/* Buttons */
.btn {
  font-family: var(--font-prompt);
  font-weight: 500;
  min-height: 40px;
  padding: 8px 16px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid transparent;
  user-select: none;
}

@media (min-width: 768px) {
  .btn {
    min-height: 42px;
    padding: 9px 18px;
    font-size: 0.92rem;
    gap: 8px;
  }
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-800) 0%, var(--primary-600) 100%);
  color: white;
  box-shadow: 0 2px 6px rgba(5, 150, 105, 0.25);
}
.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-900) 0%, var(--primary-700) 100%);
  box-shadow: 0 4px 12px rgba(5, 150, 105, 0.35);
}

.btn-gold {
  background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
  color: white;
  box-shadow: 0 2px 6px rgba(217, 119, 6, 0.25);
}
.btn-gold:hover {
  background: linear-gradient(135deg, #b45309 0%, #92400e 100%);
}

.btn-danger {
  background: #ef4444;
  color: white;
}
.btn-danger:hover {
  background: #dc2626;
}

.btn-outline {
  background: white;
  border-color: #cbd5e1;
  color: var(--slate-700);
}
.btn-outline:hover {
  background: #f8fafc;
  border-color: #94a3b8;
  color: var(--slate-900);
}

.btn-outline-green {
  background: white;
  border-color: var(--primary-600);
  color: var(--primary-700);
}
.btn-outline-green:hover {
  background: var(--primary-50);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 9999px;
  font-family: var(--font-prompt);
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
}

.badge-green { background: var(--success-100); color: #15803d; }
.badge-gold { background: var(--accent-gold-light); color: #b45309; }
.badge-red { background: var(--danger-100); color: #b91c1c; }
.badge-blue { background: var(--info-100); color: #0369a1; }
.badge-purple { background: #f3e8ff; color: #7e22ce; }
.badge-gray { background: var(--slate-100); color: var(--slate-700); }

/* Login Screen Overlay */
#login-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: radial-gradient(circle at 50% 30%, #064e3b 0%, #022c22 70%, #011913 100%);
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

#login-screen.hidden {
  display: none !important;
}

.login-card {
  background: rgba(255, 255, 255, 0.98);
  border-radius: 24px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.1);
  width: 100%;
  max-width: 440px;
  padding: 32px 28px;
  border-top: 5px solid var(--accent-gold);
  animation: loginCardAppear 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes loginCardAppear {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Table Styles */
.custom-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.custom-table th {
  background: #f1f8f4;
  color: var(--primary-900);
  font-family: var(--font-prompt);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 10px 12px;
  text-align: left;
  border-bottom: 2px solid #cbd5e1;
  white-space: nowrap;
}

.custom-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.9rem;
  vertical-align: middle;
}

@media (min-width: 768px) {
  .custom-table th {
    font-size: 0.88rem;
    padding: 12px 14px;
  }
  .custom-table td {
    padding: 12px 14px;
    font-size: 0.92rem;
  }
}

.custom-table tbody tr {
  transition: background-color 0.15s ease;
}

.custom-table tbody tr:hover {
  background-color: #f0fdf4;
}

/* Modal Overlay & Card (Mobile Bottom Sheet Adaptive) */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 9999;
  padding: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

@media (min-width: 640px) {
  .modal-backdrop {
    align-items: center;
    padding: 16px;
  }
}

.modal-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: white;
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.2);
  width: 100%;
  max-width: 720px;
  max-height: 92vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  padding: 20px 18px;
}

@media (min-width: 640px) {
  .modal-content {
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    transform: scale(0.95);
    padding: 24px 28px;
  }
}

.modal-backdrop.active .modal-content {
  transform: translateY(0);
}

@media (min-width: 640px) {
  .modal-backdrop.active .modal-content {
    transform: scale(1);
  }
}

/* Toast Notifications */
#toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  left: 16px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

@media (min-width: 640px) {
  #toast-container {
    top: auto;
    bottom: 24px;
    right: 24px;
    left: auto;
    max-width: 420px;
  }
}

.toast {
  background: white;
  border-radius: 12px;
  padding: 12px 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-prompt);
  font-size: 0.88rem;
  border-left: 5px solid var(--primary-600);
  pointer-events: auto;
  animation: slideInDown 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (min-width: 640px) {
  .toast {
    animation: slideInRight 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  }
}

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

@keyframes slideInDown {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Print Specific Rules */
@media print {
  body {
    background: white !important;
    color: black !important;
    font-size: 12pt;
  }

  .no-print, .app-header, .nav-tabs-wrapper, .mobile-bottom-nav, #toast-container, .btn, .modal-backdrop {
    display: none !important;
  }

  .print-only {
    display: block !important;
  }

  .print-page {
    page-break-after: always;
    padding: 20px;
  }

  table {
    border-collapse: collapse !important;
    width: 100% !important;
  }

  table, th, td {
    border: 1px solid #000 !important;
  }

  th {
    background-color: #eee !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

.print-only {
  display: none;
}
