/* ============================================================
   ระบบสต๊อกวัสดุก่อสร้าง — Glassmorphism Design
   Vibrant gradient background + frosted glass surfaces
   ============================================================ */

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

:root {
  /* Brand - vibrant glass palette */
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --accent: #ea580c;
  --danger: #e11d48;
  --danger-dark: #be123c;
  --success: #16a34a;
  --warning: #d97706;
  --purple: #7c3aed;
  --cyan: #06b6d4;

  /* Glass surfaces — soft, professional */
  --glass-bg: rgba(255, 255, 255, 0.82);
  --glass-bg-strong: rgba(255, 255, 255, 0.92);
  --glass-bg-soft: rgba(255, 255, 255, 0.6);
  --glass-border: rgba(255, 255, 255, 0.9);
  --glass-blur: 20px;
  --glass-shadow: 0 10px 30px -12px rgba(76, 96, 140, 0.35);

  /* Text */
  --text: #1e293b;
  --text-light: #64748b;

  /* Semantic */
  --card: rgba(255, 255, 255, 0.85);
  --bg: #eef2f9;
  --border: rgba(148, 163, 184, 0.25);
  --shadow: 0 10px 30px -12px rgba(76, 96, 140, 0.3);
  --shadow-md: 0 20px 45px -20px rgba(76, 96, 140, 0.4);
  --radius: 18px;
}

html, body {
  min-height: 100%;
}

body {
  font-family: 'Sarabun', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--text);
  display: flex;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

/* ============================================================
   SOFT BACKGROUND — calm blue-violet wash (professional)
   ============================================================ */
.vibrant-bg {
  position: fixed;
  inset: 0;
  z-index: -2;
  background: linear-gradient(160deg, #eef2fb 0%, #e3e8f9 28%, #e8f0fb 56%, #f0ecfb 100%);
  background-size: 250% 250%;
  animation: gradientShift 22s ease infinite;
}

/* Floating soft orbs for gentle depth */
.orb {
  position: fixed;
  z-index: -1;
  border-radius: 50%;
  filter: blur(70px);
  opacity: 0.55;
  animation: floatOrb 20s ease-in-out infinite alternate;
}

.orb-1 { width: 460px; height: 460px; top: -140px; left: -120px; background: #bfdbfe; }
.orb-2 { width: 420px; height: 420px; top: 32%; right: -150px; background: #ddd6fe; animation-delay: -6s; }
.orb-3 { width: 360px; height: 360px; bottom: -110px; left: 30%; background: #e0f2fe; animation-delay: -11s; }
.orb-4 { width: 240px; height: 240px; top: 16%; left: 46%; background: #c7d2fe; animation-delay: -8s; opacity: 0.45; }

@keyframes gradientShift {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

@keyframes floatOrb {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(40px, 30px) scale(1.15); }
}

@media (prefers-reduced-motion: reduce) {
  .vibrant-bg { animation: none; }
  .orb { animation: none; }
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

/* Glass helper */
.glass {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  box-shadow: var(--glass-shadow);
}

/* ============================================================
   SIDEBAR — glass
   ============================================================ */
.sidebar {
  width: 250px;
  background: rgba(255, 255, 255, 0.9);
  border-right: 1px solid var(--glass-border);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  color: #1e293b;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  transition: transform 0.3s ease;
  box-shadow: 4px 0 30px -18px rgba(76, 96, 140, 0.5);
}

.sidebar-header {
  padding: 22px 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
  font-size: 19px;
  color: #1e293b;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-header h2 .logo-badge {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  display: grid;
  place-items: center;
  color: #fff;
  flex-shrink: 0;
}

.sidebar-header h2 .logo-badge svg { width: 20px; height: 20px; }

.nav-menu {
  list-style: none;
  padding: 14px 12px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  color: #334155;
  text-decoration: none;
  font-size: 15px;
  font-weight: 500;
  transition: all 0.2s;
  border: 1px solid transparent;
  border-radius: 12px;
  margin-bottom: 4px;
}

.nav-link svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.nav-link:hover {
  background: rgba(241, 245, 249, 0.9);
  color: #1e293b;
}

.nav-link.active {
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  color: #fff;
  border: 1px solid transparent;
  font-weight: 600;
  box-shadow: 0 8px 20px -8px rgba(37, 99, 235, 0.5);
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
  margin-left: 250px;
  padding: 28px;
  flex: 1;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

.page { display: none; }
.page.active { display: block; animation: fadeIn 0.3s ease; }

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

/* ============================================================
   MOBILE
   ============================================================ */
.menu-toggle {
  display: none;
  position: fixed;
  top: 18px;
  left: 18px;
  z-index: 200;
  background: var(--glass-bg-strong);
  color: #1e293b;
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 20px;
  cursor: pointer;
  box-shadow: var(--glass-shadow);
  line-height: 1;
}

.overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(2px);
  z-index: 90;
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: block; }
  .overlay.show { display: block; }
  .main-content {
    margin-left: 0;
    padding: 16px;
    padding-top: 64px;
  }
}

/* ============================================================
   CARDS — frosted glass
   ============================================================ */
.card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-radius: var(--radius);
  box-shadow: var(--glass-shadow);
  padding: 22px;
  margin-bottom: 22px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}

.card-header h2 {
  font-size: 19px;
  font-weight: 700;
  color: #1e293b;
}

/* ============================================================
   PAGE HEADER
   ============================================================ */
.page-header {
  margin-bottom: 20px;
  padding: 6px 2px;
}

.page-header h1 {
  font-size: 25px;
  font-weight: 700;
  color: #1e293b;
  display: flex;
  align-items: center;
  gap: 11px;
}

.page-header h1 svg { width: 25px; height: 25px; color: var(--primary); }

.page-header p {
  color: #64748b;
  margin-top: 4px;
  font-weight: 400;
}

/* ============================================================
   FORMS
   ============================================================ */
.form-group { margin-bottom: 14px; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: #334155;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 14px;
  font-family: inherit;
  transition: all 0.2s;
  background: rgba(255, 255, 255, 0.7);
  color: var(--text);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.15);
  background: #fff;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Multi-line item rows (one document, multiple items) */
.tx-item-row {
  display: grid;
  grid-template-columns: 1fr 110px 140px auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.5);
}

.tx-item-row select,
.tx-item-row input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  font-family: inherit;
  background: rgba(255, 255, 255, 0.85);
  color: var(--text);
}

.tx-item-row select:focus,
.tx-item-row input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.tx-item-stock {
  font-size: 12px;
  color: var(--text-light);
  padding: 4px 2px;
}

.tx-item-remove { align-self: center; }

@media (max-width: 640px) {
  .tx-item-row {
    grid-template-columns: 1fr 90px auto;
  }
  .tx-item-stock { display: none; }
}

@media (max-width: 480px) {
  .form-row { grid-template-columns: 1fr; }
}

#txStockInfo svg {
  width: 18px;
  height: 18px;
  vertical-align: middle;
  margin-right: 3px;
  color: var(--primary);
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 18px;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  color: var(--text);
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.btn svg { width: 16px; height: 16px; }

.btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--glass-shadow);
}

.btn-primary {
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  color: #fff;
  border: none;
}

.btn-primary:hover { background: linear-gradient(135deg, #1d4ed8, #2563eb); }

.btn-danger {
  background: linear-gradient(135deg, #e11d48, #fb7185);
  color: #fff;
  border: none;
}

.btn-danger:hover { background: linear-gradient(135deg, #be123c, #e11d48); }

.btn-success {
  background: linear-gradient(135deg, #16a34a, #22c55e);
  color: #fff;
  border: none;
}

.btn-success:hover { background: linear-gradient(135deg, #15803d, #16a34a); }

.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 10px; }

.btn-group { display: flex; gap: 6px; flex-wrap: wrap; }

/* ============================================================
   TABLE
   ============================================================ */
.table-container {
  overflow-x: auto;
  margin: -4px;
  padding: 4px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  border-radius: 12px;
  overflow: hidden;
}

th, td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  background: rgba(241, 245, 249, 0.85);
  font-weight: 700;
  color: #475569;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  position: sticky;
  top: 0;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

tr:hover { background: rgba(255, 255, 255, 0.5); }

td.number {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   BADGE
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.badge-in {
  background: rgba(220, 252, 231, 0.8);
  color: #166534;
  border-color: rgba(22, 101, 52, 0.2);
}

.badge-out {
  background: rgba(254, 226, 226, 0.8);
  color: #991b1b;
  border-color: rgba(153, 27, 27, 0.2);
}

.badge-active {
  background: rgba(220, 252, 231, 0.8);
  color: #166534;
  border-color: rgba(22, 101, 52, 0.2);
}

.badge-completed {
  background: rgba(226, 232, 240, 0.8);
  color: #475569;
  border-color: rgba(71, 85, 105, 0.2);
}

/* ============================================================
   MODAL — glass
   ============================================================ */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 300;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.modal-overlay.show { display: flex; }

.modal {
  background: var(--glass-bg-strong);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-radius: 20px;
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 26px;
}

.modal h3 {
  margin-bottom: 16px;
  font-size: 19px;
  font-weight: 700;
  color: #1e293b;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 14px 22px;
  border-radius: 14px;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  z-index: 500;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s ease;
  box-shadow: var(--shadow-md);
  max-width: 90%;
  border: 1px solid rgba(255,255,255,0.2);
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast.success { background: linear-gradient(135deg, #16a34a, #22c55e); }
.toast.error { background: linear-gradient(135deg, #e11d48, #f43f5e); }

/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: #475569;
}

.empty-state .icon {
  margin-bottom: 12px;
}

.empty-state .icon svg {
  width: 48px;
  height: 48px;
}

/* ============================================================
   SUMMARY CARDS
   ============================================================ */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.summary-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--glass-shadow);
  text-align: center;
  transition: transform 0.25s ease;
}

.summary-card:hover { transform: translateY(-3px); }

.summary-card .value {
  font-size: 30px;
  font-weight: 800;
  color: var(--primary);
}

.summary-card .label {
  font-size: 13px;
  font-weight: 600;
  color: #475569;
  margin-top: 4px;
}

/* ============================================================
   FILTER BAR
   ============================================================ */
.filter-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.filter-bar .form-group { margin-bottom: 0; min-width: 150px; }
.filter-bar select,
.filter-bar input { padding: 9px 12px; font-size: 13px; }

/* ============================================================
   SEARCH
   ============================================================ */
.search-box { position: relative; }

.search-box input { padding-left: 40px; }

.search-box svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: #64748b;
  pointer-events: none;
}

/* ============================================================
   SCROLLABLE TABLE
   ============================================================ */
.table-scroll {
  max-height: 60vh;
  overflow-y: auto;
  border-radius: 12px;
}

/* ============================================================
   PRINT DOCUMENT STYLES (keep clean for paper)
   ============================================================ */
.print-doc {
  font-size: 14px;
  color: #000;
  padding: 20px;
  background: #fff;
  border-radius: 12px;
}

.print-doc.header {
  text-align: center;
  border-bottom: 2px solid #000;
  padding-bottom: 12px;
  margin-bottom: 16px;
}

.print-doc.header h2 { font-size: 22px; margin-bottom: 4px; }
.print-doc.header .doc-title { font-size: 28px; font-weight: 700; letter-spacing: 2px; color: #000; }

.print-meta { display: flex; justify-content: space-between; margin-bottom: 16px; gap: 20px; }
.print-meta table { border: 1px solid #000; border-collapse: collapse; }
.print-meta table td { border: 1px solid #000; padding: 6px 10px; font-size: 13px; }
.print-meta table td:first-child { background: #f1f5f9; font-weight: 600; width: 120px; }

.print-sign { display: flex; justify-content: space-between; margin-top: 40px; gap: 20px; }
.print-sign .sign-box { text-align: center; flex: 1; }
.print-sign .sign-line { margin-top: 50px; border-top: 1px solid #000; padding-top: 4px; font-size: 12px; }

/* Print: only the print modal */
@media print {
  body * { visibility: hidden; }
  #printModal, #printModal * { visibility: visible; }
  #printModal {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: auto;
    background: #fff;
    display: block;
    padding: 20px;
  }
  #printModal .modal {
    box-shadow: none;
    max-width: 100%;
    max-height: none;
    overflow: visible;
    border: none;
    background: #fff;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  #printModal .btn-group { display: none; }
  .no-print { display: none !important; }
}

@media print {
  .sidebar, .menu-toggle, .overlay, .main-content .card .btn, .toast,
  .vibrant-bg, .orb {
    display: none !important;
  }
  .main-content { margin-left: 0; padding: 0; }
  body { background: #fff; }
}
