/* Admin PC Portal — sidebar, tables, drawer, global toolbar */
@media (min-width: 960px) {
  body.admin-pc-portal #admin-portal-sidebar {
    display: flex !important;
    visibility: visible !important;
    pointer-events: auto !important;
    opacity: 1 !important;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 248px;
    z-index: 200;
    background: linear-gradient(180deg, #0d47a1 0%, #1565c0 48%, #1976d2 100%);
    color: #fff;
    box-shadow: 4px 0 24px rgba(15, 23, 42, 0.12);
    font-family: inherit;
    transition: transform 0.22s ease, box-shadow 0.22s ease;
  }

  body.admin-pc-portal-sidebar-collapsed #admin-portal-sidebar {
    transform: translateX(-100%);
    box-shadow: none;
    pointer-events: none;
  }

  #admin-sidebar-reopen {
    display: none;
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 210;
    border: none;
    border-radius: 0 10px 10px 0;
    background: #1565c0;
    color: #fff;
    padding: 14px 10px 14px 8px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 2px 0 14px rgba(0, 0, 0, 0.18);
    font-family: inherit;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    line-height: 1.2;
  }

  body.admin-pc-portal.admin-pc-portal-sidebar-collapsed #admin-sidebar-reopen {
    display: flex;
  }

  body.admin-pc-portal-sidebar-collapsed .app {
    margin-left: 0 !important;
  }

  body.admin-pc-portal-sidebar-collapsed #admin-global-toolbar {
    left: 0 !important;
  }

  body.admin-pc-portal-sidebar-collapsed.admin-show-filters #ah-emp-filter-wrap,
  body.admin-pc-portal-sidebar-collapsed.admin-show-filters #s-admin-products .ah-prod-panel,
  body.admin-pc-portal-sidebar-collapsed.admin-show-filters #s-admin-branches .ah-form-card {
    left: 0 !important;
  }

  body.admin-pc-portal .app {
    margin-left: 248px;
    flex: 1 1 auto !important;
    max-width: none !important;
    width: auto !important;
    box-shadow: none;
  }

  /* แอดมินใช้ sidebar แล้ว — ซ่อนแผงขวา + mobile chrome ถาวร */
  body.admin-pc-portal {
    display: block !important;
  }

  body.admin-pc-portal #pc-panel,
  body.admin-pc-portal #pc-panel-desktop-reopen,
  body.admin-pc-portal #pc-panel-backdrop,
  body.admin-pc-portal #pc-panel-collapse-desktop,
  body.admin-pc-portal #mobile-app-header,
  body.admin-pc-portal #mobile-app-tabbar,
  body.admin-pc-portal #mobile-pending-fab,
  body.admin-pc-portal #mob-pwa-install {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
    width: 0 !important;
    max-width: 0 !important;
    overflow: hidden !important;
  }

  body.admin-hide-pc-panel #pc-panel,
  body.admin-hide-pc-panel #pc-panel-desktop-reopen,
  body.admin-hide-pc-panel #pc-panel-backdrop,
  body.admin-hide-pc-panel #pc-panel-collapse-desktop {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
    width: 0 !important;
    max-width: 0 !important;
    overflow: hidden !important;
  }

  body.admin-hide-pc-panel .app {
    flex: 1 1 100% !important;
    width: 100% !important;
    max-width: 100% !important;
    box-shadow: none;
  }

  body.admin-pc-portal .screen.ah-wrap > .ah-hdr .ah-back {
    display: none;
  }

  body.admin-pc-portal #admin-global-toolbar {
    display: none;
    position: fixed;
    top: 0;
    left: 248px;
    right: 0;
    z-index: 150;
  }

  body.admin-pc-portal.admin-pc-global-toolbar #admin-global-toolbar {
    display: flex;
  }

  body.admin-pc-portal.admin-pc-global-toolbar .screen.ah-wrap.active {
    padding-top: 52px;
  }

  body.admin-pc-portal:has(#s-admin-home.active) .screen.ah-wrap.active {
    padding-top: 0;
  }

  body.admin-pc-portal.admin-show-filters #ah-emp-filter-wrap .admin-hide-on-pc-toolbar,
  body.admin-pc-portal.admin-show-filters #s-admin-products .admin-hide-on-pc-toolbar,
  body.admin-pc-portal.admin-show-filters #s-admin-branches .admin-hide-on-pc-toolbar {
    display: block !important;
  }

  body.admin-pc-portal.admin-show-filters #ah-emp-filter-wrap,
  body.admin-pc-portal.admin-show-filters #s-admin-products .ah-prod-panel,
  body.admin-pc-portal.admin-show-filters #s-admin-branches .ah-form-card {
    position: fixed;
    top: 52px;
    left: 248px;
    right: 0;
    z-index: 140;
    max-height: 50vh;
    overflow: auto;
    margin: 0;
    border-radius: 0;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  }

  body.admin-pc-portal .admin-hide-on-pc-toolbar {
    display: none !important;
  }

  body.admin-pc-portal.admin-table-density-compact .admin-data-table th,
  body.admin-pc-portal.admin-table-density-compact .admin-data-table td {
    padding: 5px 8px;
    font-size: 11px;
  }

  body.admin-pc-portal:not(.admin-table-density-compact) .admin-data-table th,
  body.admin-pc-portal:not(.admin-table-density-compact) .admin-data-table td {
    padding: 10px 14px;
    font-size: 13px;
  }

  body.admin-pc-portal .admin-table-enhanced {
    max-height: calc(100vh - 220px);
    overflow: auto;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    background: #fff;
  }

  body.admin-pc-portal .admin-table-enhanced .admin-data-table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
  }

  body.admin-pc-portal .admin-table-enhanced .admin-data-table thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    background: #f1f5f9;
    box-shadow: 0 1px 0 #e2e8f0;
  }

  body.admin-pc-portal .admin-table-enhanced .admin-data-table .admin-sticky-col {
    position: sticky;
    left: 0;
    z-index: 2;
    background: #fff;
    box-shadow: 2px 0 4px rgba(15, 23, 42, 0.06);
  }

  body.admin-pc-portal .admin-table-enhanced .admin-data-table thead .admin-sticky-col {
    z-index: 4;
    background: #f1f5f9;
  }

  body.admin-pc-portal .admin-table-enhanced .admin-data-table tbody tr:hover td {
    background: #eff6ff;
  }

  body.admin-pc-portal .admin-table-enhanced .admin-data-table tbody tr:hover .admin-sticky-col {
    background: #eff6ff;
  }

  /* Side drawer (replaces center modal on PC) */
  body.admin-pc-drawer-open {
    overflow: hidden;
  }

  body.admin-pc-drawer-open .ah-modal.admin-pc-drawer {
    display: flex !important;
    justify-content: flex-end;
    align-items: stretch;
    background: rgba(15, 23, 42, 0.28);
    pointer-events: auto;
    padding: 0;
  }

  body.admin-pc-drawer-open .ah-modal.admin-pc-drawer .ah-modal-box {
    pointer-events: auto;
    width: min(520px, 42vw);
    max-width: 520px;
    min-width: 380px;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    margin: 0;
    box-shadow: -12px 0 40px rgba(15, 23, 42, 0.18);
    animation: adminDrawerSlide 0.22s ease-out;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  body.admin-pc-drawer-open .ah-modal.admin-pc-drawer .ah-modal-body {
    flex: 1;
    overflow-y: auto;
    max-height: none !important;
  }

  body.admin-pc-drawer-open .app {
    pointer-events: auto;
  }
}

@keyframes adminDrawerSlide {
  from { transform: translateX(100%); opacity: 0.6; }
  to { transform: translateX(0); opacity: 1; }
}

#admin-portal-sidebar {
  display: none;
}

.admin-sidebar-brand {
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.admin-sidebar-brand-text {
  flex: 1;
  min-width: 0;
}

.admin-sidebar-collapse-btn {
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.admin-sidebar-collapse-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

.admin-sidebar-reopen-lbl {
  font-size: 10px;
  opacity: 0.92;
}

.admin-sidebar-reopen-ic {
  font-size: 16px;
  line-height: 1;
}

.admin-sidebar-brand h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.admin-sidebar-brand p {
  margin: 4px 0 0;
  font-size: 11px;
  opacity: 0.75;
}

.admin-sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px 8px 16px;
}

.admin-acc {
  margin-bottom: 6px;
  border-radius: 10px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.06);
}

.admin-acc-hdr {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: none;
  background: transparent;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
}

.admin-acc-hdr i {
  width: 18px;
  opacity: 0.9;
}

.admin-acc-hdr .admin-acc-chevron {
  margin-left: auto;
  font-size: 10px;
  opacity: 0.7;
  transition: transform 0.2s;
}

.admin-acc.open .admin-acc-chevron {
  transform: rotate(180deg);
}

.admin-acc-body {
  display: none;
  padding: 4px 6px 8px;
}

.admin-acc.open .admin-acc-body {
  display: block;
}

.admin-nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: rgba(255, 255, 255, 0.92);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: background 0.15s;
}

.admin-nav-item:hover {
  background: rgba(255, 255, 255, 0.12);
}

.admin-nav-item.active {
  background: rgba(255, 255, 255, 0.22);
  font-weight: 700;
}

.admin-sidebar-foot {
  padding: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 11px;
  opacity: 0.65;
  text-align: center;
}

#admin-global-toolbar {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  position: sticky;
  top: 0;
  z-index: 6;
  flex-shrink: 0;
}

.admin-global-search-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 0 12px;
  min-height: 40px;
}

.admin-global-search-wrap:focus-within {
  border-color: #1565c0;
  box-shadow: 0 0 0 3px rgba(21, 101, 192, 0.12);
  background: #fff;
}

.admin-global-search-wrap i {
  color: #94a3b8;
  font-size: 14px;
}

#admin-global-search {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  min-width: 0;
}

.admin-global-search-wrap kbd {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: #e2e8f0;
  color: #64748b;
  border: 1px solid #cbd5e1;
}

.admin-toolbar-btn {
  border: 1px solid #e2e8f0;
  background: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  color: #475569;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}

.admin-toolbar-btn:hover {
  border-color: #90caf9;
  color: #1565c0;
}

.admin-toolbar-btn.active {
  background: #e3f2fd;
  border-color: #1565c0;
  color: #0d47a1;
}

.admin-filter-popover {
  position: relative;
}

.admin-filter-panel {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 280px;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.12);
  z-index: 50;
}

.admin-filter-popover.open .admin-filter-panel {
  display: block;
}

.admin-drawer-form .ah-inp:focus,
.admin-drawer-form select:focus {
  outline: none;
  border-color: #1565c0;
  box-shadow: 0 0 0 3px rgba(21, 101, 192, 0.12);
}

/* ไอดีแอดมิน (role=admin ไม่ใช่ admin-employee) — ซ่อนไทล์เมนูหน้าแรก ใช้ sidebar แทน */
@media (min-width: 960px) {
  body.admin-pc-portal:has(#s-admin-home.active) #admin-portal-sidebar {
    display: flex !important;
    visibility: visible !important;
    pointer-events: auto !important;
    opacity: 1 !important;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-banner,
  body.admin-pc-pure-admin #s-admin-home .ah-card-grid,
  body.admin-pc-pure-admin #s-admin-home .ah-tile-profile,
  body.admin-pc-pure-admin #s-admin-home .ah-tile-payroll,
  body.admin-pc-pure-admin #s-admin-home .ah-tile-audit {
    display: none !important;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-dashboard {
    display: block !important;
    margin: 0 16px 20px;
    padding: 0 0 8px;
    max-width: 100%;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-head {
    margin-bottom: 18px;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-title {
    margin: 0;
    font-size: 22px;
    font-weight: 800;
    color: #0d47a1;
    letter-spacing: -0.02em;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-head-rule {
    margin-top: 10px;
    height: 3px;
    border-radius: 2px;
    background: linear-gradient(90deg, #1565c0, #64b5f6 55%, transparent);
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-kpi-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 16px;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-kpi-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 16px 18px;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.05);
    min-height: 148px;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-kpi-alert {
    border-color: #fecaca;
    background: linear-gradient(180deg, #fff 0%, #fff5f5 100%);
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-kpi-top {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-kpi-icon {
    font-size: 20px;
    line-height: 1;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-kpi-icon-alert {
    filter: saturate(1.2);
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-kpi-label {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    color: #475569;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-kpi-value {
    font-size: 28px;
    font-weight: 800;
    color: #0f172a;
    line-height: 1.15;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-kpi-pct {
    font-size: 32px;
    color: #1565c0;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-kpi-urgent {
    color: #dc2626;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-kpi-route-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-donut-wrap {
    width: 64px;
    height: 64px;
    flex-shrink: 0;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-progress-wrap {
    margin: 4px 0 2px;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-progress-bar {
    height: 8px;
    border-radius: 999px;
    background: #e2e8f0;
    overflow: hidden;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-progress-fill {
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, #22c55e, #16a34a);
    transition: width 0.5s ease;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-kpi-sub {
    margin: 0;
    font-size: 12px;
    color: #64748b;
    line-height: 1.4;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-lower {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 14px;
    align-items: stretch;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-panel,
  body.admin-pc-pure-admin #s-admin-home .ah-ops-chart-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.05);
    padding: 14px 16px;
    min-height: 280px;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-panel-title,
  body.admin-pc-pure-admin #s-admin-home .ah-ops-chart-title {
    margin: 0 0 12px;
    font-size: 14px;
    font-weight: 700;
    color: #1e3a5f;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-table-wrap {
    overflow: auto;
    max-height: 320px;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-table th {
    text-align: left;
    padding: 8px 10px;
    background: #f1f5f9;
    color: #475569;
    font-weight: 600;
    border-bottom: 1px solid #e2e8f0;
    white-space: nowrap;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-table td {
    padding: 9px 10px;
    border-bottom: 1px solid #f1f5f9;
    color: #334155;
    vertical-align: middle;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-table tr:hover td {
    background: #f8fafc;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-status {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-status-pending {
    background: #fef3c7;
    color: #b45309;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-status-urgent {
    background: #fee2e2;
    color: #b91c1c;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-empty {
    text-align: center;
    color: #94a3b8;
    padding: 24px !important;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-charts {
    display: flex;
    flex-direction: column;
    gap: 14px;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-chart-canvas-wrap {
    position: relative;
    height: 200px;
  }

  body.admin-pc-pure-admin #s-admin-home .ah-ops-chart-canvas-wrap canvas {
    max-height: 200px;
  }

  @media (max-width: 1200px) {
    body.admin-pc-pure-admin #s-admin-home .ah-ops-kpi-row {
      grid-template-columns: 1fr;
    }
    body.admin-pc-pure-admin #s-admin-home .ah-ops-lower {
      grid-template-columns: 1fr;
    }
  }

  body.admin-pc-pure-admin #s-admin-home #ah-daily-report-section {
    display: none !important;
  }

  body.admin-pc-portal .db-report-screen {
    display: none;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    background: #f5f8ff;
  }

  body.admin-pc-portal .db-report-screen.active {
    display: flex !important;
  }

  body.admin-pc-portal .db-report-screen .db-report-mount {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
  }

  body.admin-pc-portal #page-dashboard.admin-db-embedded {
    display: flex !important;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    position: relative !important;
    top: auto !important;
    left: auto !important;
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    z-index: 1 !important;
    overflow-y: auto;
    background: #f0f4fa;
  }

  body.admin-pc-portal #page-dashboard.admin-db-embedded .db-tabs {
    display: none !important;
  }

  body.admin-pc-portal #page-dashboard.admin-db-embedded .db-back {
    display: none !important;
  }

  body.admin-pc-portal #page-dashboard.admin-db-embedded .db-hdr {
    position: sticky;
    top: 0;
    z-index: 5;
  }
}
