/* =========================================================
   Engineering Stock System — Main Stylesheet
   ========================================================= */
:root {
  --sidebar-width: 240px;
  --topbar-height: 56px;
  --primary: #1e3a8a;
  --navy: #1e3a8a;
  --sidebar-bg: #ffffff;
  --sidebar-text: #374151;
  --sidebar-active-bg: #eff6ff;
  --sidebar-active-text: #1e3a8a;
  --sidebar-hover-bg: #f9fafb;
  --sidebar-border: #e5e7eb;
  --nav-section-color: #9ca3af;
}

/* ---- BASE ---- */
body {
  font-family: 'Segoe UI', 'Noto Sans Thai', sans-serif;
  background: #f3f4f8;
  font-size: 14px;
}

/* ---- SIDEBAR ---- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  z-index: 1045;
  transition: transform .25s ease;
  display: flex;
  flex-direction: column;
}

/* Sidebar top: logo + new WO button */
.sidebar-top { flex-shrink: 0; }

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--sidebar-border);
}
.sidebar-logo-icon {
  width: 36px;
  height: 36px;
  background: var(--navy);
  color: #fff;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
  letter-spacing: -.5px;
}
.sidebar-logo-name {
  font-weight: 700;
  font-size: 15px;
  color: #111827;
  line-height: 1.2;
}
.sidebar-logo-sub {
  font-size: 10.5px;
  color: #9ca3af;
  line-height: 1.3;
}

.sidebar-new-wrap { padding: 12px 14px 6px; }
.sidebar-new-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  padding: 9px 14px;
  background: var(--navy);
  color: #fff;
  border-radius: 8px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  transition: background .15s;
}
.sidebar-new-btn:hover { background: #1e40af; color: #fff; }

/* Sidebar middle: scrollable nav */
.sidebar-inner {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px 0 12px;
  scrollbar-width: thin;
  scrollbar-color: #e5e7eb transparent;
}

.sidebar-nav { display: flex; flex-direction: column; }

.nav-section {
  padding: 12px 20px 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--nav-section-color);
}

.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: var(--sidebar-text);
  text-decoration: none;
  border-radius: 0;
  font-size: 13.5px;
  transition: background .15s, color .15s;
  border-left: 3px solid transparent;
}
.sidebar-nav .nav-link i { font-size: 16px; min-width: 18px; }
.sidebar-nav .nav-link:hover { background: var(--sidebar-hover-bg); color: #111827; }
.sidebar-nav .nav-link.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
  border-left-color: var(--primary);
  font-weight: 600;
}

/* Sidebar bottom: logout */
.sidebar-bottom {
  flex-shrink: 0;
  border-top: 1px solid var(--sidebar-border);
  padding: 6px 0;
}
.sidebar-logout-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: #6b7280;
  text-decoration: none;
  font-size: 13.5px;
  transition: background .15s, color .15s;
}
.sidebar-logout-link:hover { background: #fef2f2; color: #dc2626; }
.sidebar-logout-link i { font-size: 16px; }

/* ---- TOPBAR ---- */
.topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  height: var(--topbar-height);
  background: #ffffff;
  border-bottom: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  z-index: 1030;
  gap: 12px;
}
.topbar-toggle {
  background: none;
  border: none;
  padding: 6px 8px;
  color: #374151;
  font-size: 20px;
  cursor: pointer;
  border-radius: 6px;
  line-height: 1;
  flex-shrink: 0;
}
.topbar-toggle:hover { background: #f3f4f6; }

.topbar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 6px 14px;
  min-width: 200px;
  max-width: 360px;
  flex: 1;
}
.topbar-search i { color: #9ca3af; font-size: 14px; flex-shrink: 0; }
.topbar-search input {
  border: none;
  background: none;
  outline: none;
  font-size: 13.5px;
  color: #374151;
  width: 100%;
  font-family: inherit;
}
.topbar-search input::placeholder { color: #9ca3af; }

.topbar-icon-btn {
  background: none;
  border: none;
  padding: 7px;
  color: #4b5563;
  font-size: 18px;
  cursor: pointer;
  border-radius: 8px;
  position: relative;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
  flex-shrink: 0;
}
.topbar-icon-btn:hover { background: #f3f4f6; }

.notif-badge {
  position: absolute;
  top: 3px;
  right: 3px;
  background: #dc2626;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  line-height: 1;
}

.topbar-user-btn {
  background: none;
  border: none;
  padding: 2px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.topbar-user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--navy);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

/* ---- MAIN CONTENT ---- */
.main-content {
  margin-left: var(--sidebar-width);
  margin-top: var(--topbar-height);
  min-height: calc(100vh - var(--topbar-height));
  padding: 28px 24px 60px 24px;
}

/* ---- FOOTER ---- */
.app-footer {
  position: fixed;
  bottom: 0;
  left: var(--sidebar-width);
  right: 0;
  height: 40px;
  background: #ffffff;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 1030;
  font-size: 12px;
  color: #6b7280;
}

/* ---- OVERLAY (mobile) ---- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 1040;
}
.sidebar-overlay.show { display: block; }

/* ---- RESPONSIVE ---- */
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .topbar { left: 0; }
  .app-footer { left: 0; padding: 0 16px; }
  .main-content { margin-left: 0; padding: 24px 16px 60px 16px; }
}

/* ---- BOOTSTRAP PRIMARY OVERRIDES ---- */
.btn-primary {
  --bs-btn-bg: var(--navy);
  --bs-btn-border-color: var(--navy);
  --bs-btn-hover-bg: #1e40af;
  --bs-btn-hover-border-color: #1e40af;
  --bs-btn-active-bg: #1d4ed8;
  --bs-btn-focus-shadow-rgb: 30,58,138;
}
.btn-outline-primary {
  --bs-btn-color: var(--navy);
  --bs-btn-border-color: var(--navy);
  --bs-btn-hover-bg: var(--navy);
  --bs-btn-hover-border-color: var(--navy);
  --bs-btn-active-bg: var(--navy);
}
.text-primary { color: var(--navy) !important; }
.bg-primary   { background-color: var(--navy) !important; }
.border-primary { border-color: var(--navy) !important; }
.badge.bg-primary { background-color: var(--navy) !important; }
a.text-primary:hover { color: #1e40af !important; }

/* Soft background variants (for notification icons & badges) */
.bg-soft-primary   { background-color: rgba(30,58,138,.12)  !important; }
.bg-soft-success   { background-color: rgba(25,135,84,.12)  !important; }
.bg-soft-danger    { background-color: rgba(220,53,69,.12)  !important; }
.bg-soft-warning   { background-color: rgba(255,193,7,.15)  !important; }
.bg-soft-info      { background-color: rgba(13,202,240,.15) !important; }
.bg-soft-secondary { background-color: rgba(108,117,125,.12)!important; }

/* ---- CARDS ---- */
.card {
  border: none;
  border-radius: 12px;
  box-shadow: 0 1px 6px rgba(0,0,0,.07);
}

.card-header {
  background: transparent;
  border-bottom: 1px solid rgba(0,0,0,.08);
  font-weight: 600;
  padding: 14px 20px;
}

/* ---- STAT CARDS (legacy) ---- */
.stat-card {
  border-radius: 12px;
  padding: 20px;
  color: #fff;
  position: relative;
  overflow: hidden;
}
.stat-card .stat-icon {
  position: absolute;
  right: 16px;
  top: 16px;
  font-size: 40px;
  opacity: .25;
}
.stat-card .stat-value { font-size: 28px; font-weight: 700; }
.stat-card .stat-label { font-size: 13px; opacity: .85; }

/* ---- DASHBOARD STAT CARDS (new design) ---- */
.dash-stat-card {
  border: 1px solid #e5e7eb !important;
  box-shadow: none !important;
  transition: box-shadow .15s, border-color .15s;
}
.dash-stat-card:hover { box-shadow: 0 2px 12px rgba(0,0,0,.09) !important; }
.dash-stat-card--alert { border-color: #fca5a5 !important; }
.dash-stat-card--warn  { border-color: #fcd34d !important; }

.dash-stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #9ca3af;
  margin-bottom: 6px;
}
.dash-stat-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
}
.dash-stat-sub {
  font-size: 12px;
  margin-top: 5px;
}
.dash-stat-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.dash-stat-icon i { font-size: 22px; }

/* ---- ACTIVITY TOGGLE ---- */
.act-toggle {
  font-size: 12px;
  padding: 3px 10px;
}
.act-toggle.active {
  background: var(--navy) !important;
  border-color: var(--navy) !important;
  color: #fff !important;
}

/* ---- UTILITY ---- */
.page-title {
  font-size: 28px;
  font-weight: 700;
  color: #111827;
}
.section-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 20px;
}
.progress-bar-navy { background-color: var(--navy) !important; }
.timeline-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 4px;
}
.timeline-dot-current { background: var(--navy); }
.timeline-dot-past    { background: #d1d5db; }

/* ---- TIMELINE LIST ---- */
.timeline-list { list-style: none; padding: 0; margin: 0; }
.timeline-item {
  display: flex;
  gap: 12px;
  position: relative;
  padding-bottom: 16px;
}
.timeline-item:not(:last-child)::before {
  content: '';
  position: absolute;
  left: 4px;
  top: 14px;
  bottom: 0;
  width: 2px;
  background: #e5e7eb;
}

/* ---- CHECKLIST ITEMS ---- */
.checklist-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid #f3f4f6;
}
.checklist-item:last-child { border-bottom: none; }
.checklist-check {
  width: 18px; height: 18px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 2px;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px;
}
.checklist-check-done    { background: #dcfce7; color: #166534; }
.checklist-check-pending { border: 2px solid #d1d5db; }

/* ---- PAGE HEADER ---- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 10px;
}
.page-header h4 {
  margin: 0;
  font-weight: 700;
  font-size: 22px;
  color: #111827;
}
.page-subtitle {
  font-size: 13px;
  color: #6b7280;
  margin-top: 2px;
}

/* ---- TABLE ---- */
.table th {
  font-weight: 600;
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: .04em;
  background: #f8f9fc;
  color: #555;
  border-top: none;
}
.table td { vertical-align: middle; }

/* ---- FORM ---- */
.form-label { font-weight: 500; color: #374151; }
.form-control,
.form-select {
  border: 1px solid #d1d5db;
  border-radius: 6px;
}
.form-control:focus,
.form-select:focus {
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(30,58,138,.15);
}
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid #e5e7eb;
  margin-top: 8px;
}

/* ---- BADGE STOCK ---- */
.stock-low  { color: #dc3545; font-weight: 600; }
.stock-ok   { color: #198754; }
.stock-zero { color: #dc3545; font-weight: 700; }

/* ---- BUTTON EXTRA SMALL ---- */
.btn-xs {
  padding: 2px 7px;
  font-size: 12px;
  border-radius: 4px;
}

/* ---- AVATAR ---- */
.avatar-sm {
  width: 32px; height: 32px;
  border-radius: 50%;
  object-fit: cover;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
}

/* ---- SOFT STATUS / PRIORITY BADGES ---- */
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  line-height: 1.4;
}
.badge-in-progress  { background: #dbeafe; color: #1e40af; }
.badge-pending      { background: #fef9c3; color: #854d0e; }
.badge-completed    { background: #dcfce7; color: #166534; }
.badge-cancelled    { background: #f1f5f9; color: #475569; }
.badge-on-hold      { background: #fef3c7; color: #92400e; }
.badge-critical     { background: #dc2626; color: #fff; }
.badge-high         { background: #ea580c; color: #fff; }
.badge-medium       { background: #7c3aed; color: #fff; }
.badge-optimal      { background: #dcfce7; color: #166534; }
.badge-low-stock    { background: #fef9c3; color: #854d0e; }
.badge-out-of-stock { background: #fee2e2; color: #991b1b; }

/* ---- PROJECT STAT TABS ---- */
.project-stat-tab {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  color: #6b7280;
  background: #f3f4f6;
  text-decoration: none;
  transition: all .15s;
}
.project-stat-tab:hover { background: #e5e7eb; color: #374151; }
.project-stat-tab.active { background: #1e3a8a; color: #fff; }
.project-stat-tab span { font-size: 11px; font-weight: 700; }
.project-stat-tab--blue.active  { background: #1d4ed8; }
.project-stat-tab--blue:not(.active):hover  { background: #dbeafe; color: #1e40af; }
.project-stat-tab--purple.active { background: #7c3aed; }
.project-stat-tab--purple:not(.active):hover { background: #ede9fe; color: #5b21b6; }
.project-stat-tab--green.active { background: #166534; }
.project-stat-tab--green:not(.active):hover { background: #dcfce7; color: #166534; }
.project-stat-tab--yellow.active { background: #92400e; }
.project-stat-tab--yellow:not(.active):hover { background: #fef3c7; color: #92400e; }

/* ---- ADMIN CHIPS ---- */
.admin-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px 5px 10px;
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 20px;
  font-size: 13px;
  color: #374151;
  transition: border-color .15s, box-shadow .15s;
}
.admin-chip:hover { border-color: #c7d2fe; box-shadow: 0 1px 6px rgba(30,58,138,.07); }
.admin-chip--inactive { opacity: .55; }
.admin-chip-count {
  font-size: 11px; color: #6b7280;
  background: #e5e7eb; padding: 1px 7px; border-radius: 10px;
}
.admin-chip-actions { display: flex; gap: 1px; margin-left: 2px; }
.admin-chip-btn {
  width: 22px; height: 22px;
  border-radius: 50%; border: none;
  background: transparent;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; color: #9ca3af; cursor: pointer;
  transition: background .12s, color .12s; padding: 0;
}
.admin-chip-btn:hover { background: #e5e7eb; color: #374151; }
.admin-chip-btn.danger:hover { background: #fee2e2; color: #dc2626; }
.admin-chip-add {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 5px 14px;
  background: transparent;
  border: 1.5px dashed #d1d5db;
  border-radius: 20px;
  font-size: 13px; color: #9ca3af; cursor: pointer;
  transition: border-color .15s, color .15s;
}
.admin-chip-add:hover { border-color: var(--navy); color: var(--navy); }

/* ---- SCROLLBAR ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }

/* ---- LOGIN PAGE ---- */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0d6efd 0%, #0a4baa 100%);
  padding: 16px;
}
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,.18);
}
.login-card .login-logo {
  text-align: center;
  margin-bottom: 28px;
}
.login-card .login-logo i { font-size: 48px; color: var(--primary); }
.login-card .login-logo h5 { font-weight: 700; margin-top: 8px; color: #222; }
.login-card .login-logo p { color: #888; font-size: 13px; }

/* =========================================================
   UPLOAD DROP ZONE
   ========================================================= */
.upload-drop-zone {
  border: 2px dashed #c5cfe0;
  border-radius: 12px;
  padding: 28px 20px;
  text-align: center;
  background: #f8faff;
  transition: border-color .2s, background .2s;
  cursor: pointer;
}
.upload-drop-zone.drag-over {
  border-color: var(--primary);
  background: #e8f0ff;
}

/* =========================================================
   IMAGE PREVIEW GRID
   ========================================================= */
.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 8px;
}
.preview-item {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 1;
  background: #f0f0f0;
}
.preview-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.preview-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(220,53,69,.9);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 12px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}
.preview-name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0,0,0,.5);
  color: #fff;
  font-size: 10px;
  padding: 2px 4px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* =========================================================
   IMAGE GALLERY
   ========================================================= */
.image-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
}
.gallery-item {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  aspect-ratio: 1;
  cursor: pointer;
  background: #f0f0f0;
}
.gallery-item:hover .gallery-overlay { opacity: 1; }
.gallery-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform .2s;
}
.gallery-item:hover .gallery-thumb { transform: scale(1.05); }
.gallery-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.35);
  display: flex;
  align-items: flex-end;
  padding: 6px;
  opacity: 0;
  transition: opacity .2s;
}

/* Mobile: bigger touch targets */
@media (max-width: 576px) {
  .image-gallery { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); }
  .preview-grid  { grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); }
  .gallery-overlay { opacity: 1; }
}
