/* ====================================================================
   โครงการ: ระบบเบิกจ่ายและจัดการอุปกรณ์สำนักงาน (Clean Rebuild)
   ไฟล์: assets/css/app.css
   วัตถุประสงค์: สไตล์สถาปัตยกรรม UI หลัก, Responsive Layout, Mobile Drawer,
               Typography ภาษาไทย, Unified Design Tokens
   ==================================================================== */

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

:root {
  --font-sans: 'Sarabun', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  
  /* Color Palette - Professional Enterprise Slate & Corporate Blue */
  --bg-main: #f0f4f9;             /* Ice Slate / Light Blue */
  --bg-card: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --border-focus: #2563eb;

  /* Brand Accents */
  --brand-primary: #1e3a8a;       /* Deep Navy */
  --brand-primary-hover: #172554;
  --brand-accent: #2563eb;        /* Royal Blue */
  --header-bg: #1e3a8a;           /* Deep Corporate Blue */
  --header-text: #ffffff;

  /* State Colors */
  --status-success-bg: #ecfdf5;
  --status-success-text: #065f46;
  --status-success-border: #a7f3d0;

  --status-warning-bg: #fffbeb;
  --status-warning-text: #92400e;
  --status-warning-border: #fde68a;

  --status-pending-bg: #fefce8;
  --status-pending-text: #854d0e;
  --status-pending-border: #fef08a;

  --status-waiting-bg: #eff6ff;
  --status-waiting-text: #1e40af;
  --status-waiting-border: #bfdbfe;

  --status-error-bg: #fef2f2;
  --status-error-text: #991b1b;
  --status-error-border: #fecaca;

  /* Layout Measurements */
  --header-height: 64px;
  --sidebar-width: 260px;
  --touch-target-min: 44px;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  position: relative;
  min-height: 100vh;
}

/* Subtle Geometric Decorative Background Layer */
body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: 
    radial-gradient(circle at 10% 20%, rgba(37, 99, 235, 0.035) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(30, 58, 138, 0.04) 0%, transparent 45%),
    radial-gradient(circle at 50% 50%, rgba(203, 213, 225, 0.08) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
}

/* --------------------------------------------------------------------
   App Shell Layout
-------------------------------------------------------------------- */
.app-layout {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
  position: relative;
}

/* Body Wrapper (Sidebar + Main Content below Header) */
.app-body-wrapper {
  display: flex;
  flex-direction: column;
  flex: 1;
  width: 100%;
  min-height: calc(100vh - var(--header-height));
  position: relative;
}

@media (min-width: 1024px) {
  .app-body-wrapper {
    min-height: 100vh;
    padding-top: var(--header-height);
    padding-left: var(--sidebar-width);
  }
}

/* Sidebar Styles */
.app-sidebar {
  width: var(--sidebar-width);
  background-color: #ffffff;
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.25s ease-in-out;
  z-index: 30;
}

@media (min-width: 1024px) {
  .app-sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    height: calc(100vh - var(--header-height));
    overflow-y: hidden; /* ให้พื้นที่เลื่อนจริงเป็นของ .sidebar-nav */
  }

  /* Custom subtle scrollbar สำหรับแถบเมนู Sidebar บน Desktop */
  .sidebar-nav {
    scrollbar-width: thin;
    scrollbar-color: transparent transparent; /* ซ่อน Thumb เมื่อไม่ได้ Hover */
    transition: scrollbar-color 0.2s ease;
  }

  .sidebar-nav:hover,
  .app-sidebar:hover .sidebar-nav {
    scrollbar-color: #cbd5e1 #f1f5f9; /* แสดง Thumb โทนฟ้าอมเทาอ่อนเมื่อ Hover */
  }

  /* Chrome, Edge, Safari (WebKit) */
  .sidebar-nav::-webkit-scrollbar {
    width: 6px;
  }

  .sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
  }

  .sidebar-nav::-webkit-scrollbar-thumb {
    background-color: transparent;
    border-radius: 9999px;
    transition: background-color 0.2s ease;
  }

  .sidebar-nav:hover::-webkit-scrollbar-track,
  .app-sidebar:hover .sidebar-nav::-webkit-scrollbar-track {
    background: #f1f5f9;
  }

  .sidebar-nav:hover::-webkit-scrollbar-thumb,
  .app-sidebar:hover .sidebar-nav::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
  }

  .sidebar-nav:hover::-webkit-scrollbar-thumb:hover,
  .app-sidebar:hover .sidebar-nav::-webkit-scrollbar-thumb:hover {
    background-color: #b8c7d9;
  }
}

@media (max-width: 1023px) {
  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    z-index: 50;
  }

  .app-sidebar.drawer-open {
    transform: translateX(0);
  }
}

.sidebar-header {
  height: var(--header-height);
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
}

/* Mobile-only header inside drawer */
.sidebar-mobile-header {
  height: var(--header-height);
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  background-color: #ffffff;
  flex-shrink: 0;
}

.sidebar-mobile-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.sidebar-mobile-header .menu-toggle-btn {
  color: var(--text-secondary);
  border-color: var(--border-color);
  background-color: transparent;
}

.sidebar-mobile-header .menu-toggle-btn:hover {
  background-color: #f1f5f9;
  color: var(--text-primary);
}

@media (min-width: 1024px) {
  /* ซ่อน sidebar-header และ sidebar-mobile-header บน Desktop */
  .sidebar-header,
  .sidebar-mobile-header {
    display: none !important;
  }
}

.sidebar-brand {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--brand-primary);
  display: flex;
  align-items: center;
  gap: 0.625rem;
  text-decoration: none;
}

.brand-logo-img {
  width: 38px;
  height: 38px;
  max-width: 38px;
  max-height: 38px;
  object-fit: contain;
  border-radius: 6px;
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

.brand-logo-fallback {
  font-size: 1.5rem;
  line-height: 1;
  display: inline-block;
}

.login-logo-img {
  width: 72px;
  height: 72px;
  max-width: 72px;
  max-height: 72px;
  object-fit: contain;
  display: block;
  margin: 0 auto;
  filter: drop-shadow(0 2px 4px rgba(15, 23, 42, 0.08));
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0.75rem;
  overflow-y: auto;
}

.nav-group-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 0.75rem 0.75rem 0.25rem;
}

.nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 0.75rem;
  margin-bottom: 0.25rem;
  border-radius: 0.375rem;
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.9375rem;
  min-height: var(--touch-target-min);
  transition: all 0.15s ease;
  border-left: 3px solid transparent;
}

.nav-link:hover {
  background-color: #f1f5f9;
  color: var(--brand-primary);
}

.nav-link.active {
  background-color: #eff6ff;
  color: var(--brand-primary);
  font-weight: 600;
  border-left-color: var(--brand-accent);
}

.nav-link-content {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.nav-badge,
.nav-badge-orange {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.125rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
  border-radius: 9999px;
  color: #ffffff;
}

.nav-badge {
  background-color: #ef4444;
}

.nav-badge-orange {
  background-color: #f97316;
}

/* Main Area & Topbar */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
  z-index: 1;
}

@media (min-width: 1024px) {
  .app-main {
    margin-left: var(--sidebar-width);
    padding-top: var(--header-height);
  }
}

.app-topbar {
  height: var(--header-height);
  background-color: var(--header-bg);
  background-image: linear-gradient(135deg, #1e3a8a 0%, #1e40af 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: 0 2px 4px 0 rgba(15, 23, 42, 0.08), 0 1px 2px -1px rgba(15, 23, 42, 0.08);
}

@media (min-width: 1024px) {
  .app-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    z-index: 40;
  }
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.menu-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--touch-target-min);
  height: var(--touch-target-min);
  border: 1px solid rgba(255, 255, 255, 0.2);
  background-color: rgba(255, 255, 255, 0.12);
  border-radius: 0.375rem;
  cursor: pointer;
  color: #ffffff;
  transition: background-color 0.15s ease;
}

.menu-toggle-btn:hover {
  background-color: rgba(255, 255, 255, 0.2);
}

@media (min-width: 1024px) {
  .menu-toggle-btn {
    display: none;
  }
}

.topbar-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--header-text);
  letter-spacing: -0.01em;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.user-profile-badge {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-size: 0.875rem;
}

.user-name {
  font-weight: 600;
  color: #ffffff;
}

.user-role-tag {
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 0.25rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.role-user { background: rgba(224, 242, 254, 0.95); color: #0369a1; }
.role-admin { background: rgba(254, 243, 199, 0.95); color: #92400e; }
.role-masterkey { background: rgba(243, 232, 255, 0.95); color: #6b21a8; }

/* Backdrop Overlay for Mobile Drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(2px);
  z-index: 45;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

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

/* Page Container */
.page-container {
  flex: 1;
  min-width: 0;
  padding: 1.25rem;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

@media (min-width: 768px) {
  .page-container {
    padding: 1.75rem;
  }
}

/* --------------------------------------------------------------------
   Flash Messages & Alerts
-------------------------------------------------------------------- */
.alert-banner {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border-radius: 0.5rem;
  margin-bottom: 1.25rem;
  font-size: 0.9375rem;
  border: 1px solid transparent;
}

.alert-success {
  background-color: var(--status-success-bg);
  color: var(--status-success-text);
  border-color: var(--status-success-border);
}

.alert-warning {
  background-color: var(--status-warning-bg);
  color: var(--status-warning-text);
  border-color: var(--status-warning-border);
}

.alert-pending {
  background-color: var(--status-pending-bg);
  color: var(--status-pending-text);
  border-color: var(--status-pending-border);
}

.alert-waiting {
  background-color: var(--status-waiting-bg);
  color: var(--status-waiting-text);
  border-color: var(--status-waiting-border);
}

.alert-error {
  background-color: var(--status-error-bg);
  color: var(--status-error-text);
  border-color: var(--status-error-border);
}

/* --------------------------------------------------------------------
   Design System Primitives (Cards, Tables, Buttons, Inputs)
-------------------------------------------------------------------- */
.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 1px 3px 0 rgba(15, 23, 42, 0.06), 0 1px 2px -1px rgba(15, 23, 42, 0.06);
}

.card-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.9375rem;
  font-weight: 500;
  border-radius: 0.375rem;
  border: 1px solid transparent;
  cursor: pointer;
  min-height: var(--touch-target-min);
  text-decoration: none;
  transition: background-color 0.15s, border-color 0.15s;
}

.btn-primary {
  background-color: var(--brand-accent);
  color: #ffffff;
}
.btn-primary:hover {
  background-color: #1d4ed8;
}

.btn-secondary {
  background-color: #ffffff;
  border-color: var(--border-color);
  color: var(--text-secondary);
}
.btn-secondary:hover {
  background-color: #f8fafc;
  color: var(--text-primary);
}

.btn-danger {
  background-color: #dc2626;
  color: #ffffff;
}
.btn-danger:hover {
  background-color: #b91c1c;
}

/* --------------------------------------------------------------------
   Unified Standard: View / Detail Action Buttons (.btn-action-view)
   -------------------------------------------------------------------- */
.btn-action-view {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.35rem 0.65rem;
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.25;
  color: #334155;
  background-color: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  text-decoration: none;
  cursor: pointer;
  min-height: 34px;
  box-sizing: border-box;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
  white-space: nowrap;
}

.btn-action-view:hover {
  background-color: #f8fafc;
  border-color: #94a3b8;
  color: #0f172a;
  text-decoration: none;
}

.btn-action-view:focus-visible,
.btn-action-view:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.25);
  color: #0f172a;
}

/* Icon-Only Modifier */
.btn-action-view--icon {
  min-width: 34px;
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  font-size: 0.875rem;
}

/* Mobile Responsive Touch Target (approx 40px) */
@media (max-width: 640px) {
  .btn-action-view {
    min-height: 40px;
    padding: 0.45rem 0.75rem;
    font-size: 0.875rem;
  }
  .btn-action-view--icon {
    min-width: 40px;
    width: 40px;
    height: 40px;
    min-height: 40px;
    font-size: 1rem;
  }
}

/* Responsive Table Wrapper */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  background-color: #ffffff;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.875rem;
}

.data-table th {
  background-color: #f8fafc;
  padding: 0.75rem 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.data-table td {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}

.data-table tr:last-child td {
  border-bottom: none;
}

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

/* --------------------------------------------------------------------
   Modern Form Inputs (Consistent Theme across all pages)
   -------------------------------------------------------------------- */
.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.375rem;
}

.form-control,
.form-input,
.form-select,
textarea.form-control {
  width: 100%;
  padding: 0.625rem 0.875rem;
  font-size: 0.9375rem;
  font-family: inherit;
  color: var(--text-primary);
  background-color: #ffffff;
  border: 1.5px solid var(--border-color);
  border-radius: 0.5rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus,
.form-input:focus,
.form-select:focus,
textarea.form-control:focus {
  outline: none;
  border-color: var(--brand-accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* Category Accent Modifiers for Dashboard Cards */
.card-accent-blue {
  border-top: 3px solid #1e40af !important;
}
.card-accent-indigo {
  border-top: 3px solid #4f46e5 !important;
}
.card-accent-amber {
  border-top: 3px solid #d97706 !important;
}
.card-accent-teal {
  border-top: 3px solid #0d9488 !important;
}
