/* ═══════════════════════════════════════════════════════
   CNC DRAWER / SLIDE-IN PANEL SYSTEM
   Modern replacement for Bootstrap modals
   ═══════════════════════════════════════════════════════ */

:root {
  --drawer-width: 520px;
  --drawer-width-lg: 700px;
  --drawer-width-sm: 380px;
  --drawer-bg: #fff;
  --drawer-header-bg: #f8f9fa;
  --drawer-border: #e9ecef;
  --drawer-shadow: -8px 0 40px rgba(0,0,0,0.12), -2px 0 12px rgba(0,0,0,0.06);
  --drawer-radius: 0;
  --drawer-z: 9998;
  --drawer-transition: 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ── Backdrop ── */
.cnc-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(4px);
  z-index: var(--drawer-z);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

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

/* ── Drawer Panel ── */
.cnc-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: var(--drawer-width);
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: var(--drawer-bg);
  box-shadow: var(--drawer-shadow);
  z-index: calc(var(--drawer-z) + 1);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--drawer-transition);
  will-change: transform;
}

.cnc-drawer--active {
  transform: translateX(0);
}

/* Size variants */
.cnc-drawer--sm { width: var(--drawer-width-sm); }
.cnc-drawer--lg { width: var(--drawer-width-lg); }
.cnc-drawer--full { width: 100vw; }

/* ── Header ── */
.cnc-drawer__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--drawer-border);
  background: var(--drawer-header-bg);
  flex-shrink: 0;
  min-height: 60px;
}

.cnc-drawer__title {
  font-size: 18px;
  font-weight: 700;
  color: var(--cnc-primary, #42695d);
  margin: 0;
  line-height: 1.3;
  display: flex;
  align-items: center;
  gap: 10px;
}

.cnc-drawer__title-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #fff;
  background: var(--cnc-primary, #42695d);
  flex-shrink: 0;
}

.cnc-drawer__close {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: #666;
  font-size: 20px;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.cnc-drawer__close:hover {
  background: rgba(0,0,0,0.08);
  color: #333;
  transform: rotate(90deg);
}

/* ── Body ── */
.cnc-drawer__body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

/* Custom scrollbar */
.cnc-drawer__body::-webkit-scrollbar {
  width: 6px;
}
.cnc-drawer__body::-webkit-scrollbar-track {
  background: transparent;
}
.cnc-drawer__body::-webkit-scrollbar-thumb {
  background: #d0d0d0;
  border-radius: 3px;
}
.cnc-drawer__body::-webkit-scrollbar-thumb:hover {
  background: #aaa;
}

/* ── Footer ── */
.cnc-drawer__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid var(--drawer-border);
  background: var(--drawer-header-bg);
  flex-shrink: 0;
}

/* ── Loading state ── */
.cnc-drawer__loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  gap: 16px;
  color: #888;
  font-size: 14px;
}

.cnc-drawer__spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #e0e0e0;
  border-top-color: var(--cnc-primary, #42695d);
  border-radius: 50%;
  animation: drawerSpin 0.8s linear infinite;
}

@keyframes drawerSpin {
  to { transform: rotate(360deg); }
}

/* ── Content animations ── */
.cnc-drawer__body > * {
  animation: drawerContentFadeIn 0.4s ease forwards;
  opacity: 0;
}

.cnc-drawer__body > *:nth-child(1) { animation-delay: 0.05s; }
.cnc-drawer__body > *:nth-child(2) { animation-delay: 0.1s; }
.cnc-drawer__body > *:nth-child(3) { animation-delay: 0.15s; }
.cnc-drawer__body > *:nth-child(4) { animation-delay: 0.2s; }
.cnc-drawer__body > *:nth-child(5) { animation-delay: 0.25s; }

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

/* ── Tables inside drawer ── */
.cnc-drawer__body table {
  width: 100%;
  border-collapse: collapse;
}

.cnc-drawer__body table th {
  background: var(--cnc-primary, #42695d);
  color: #fff;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
}

.cnc-drawer__body table td {
  padding: 10px 14px;
  font-size: 13px;
  border-bottom: 1px solid #eee;
  color: #333;
}

.cnc-drawer__body table tr:hover td {
  background: #f8f9fa;
}

/* ── Badges inside drawer ── */
.cnc-drawer__body .badge {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── Alert boxes inside drawer ── */
.cnc-drawer__body .alert {
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 13px;
  border-left-width: 4px;
  border-left-style: solid;
}

/* ── Form elements inside drawer ── */
.cnc-drawer__body .form-label {
  font-weight: 600;
  font-size: 13px;
  color: #444;
  margin-bottom: 6px;
}

.cnc-drawer__body .form-control,
.cnc-drawer__body .form-select {
  border-radius: 8px;
  border: 1px solid #d0d5dd;
  padding: 10px 14px;
  font-size: 14px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.cnc-drawer__body .form-control:focus,
.cnc-drawer__body .form-select:focus {
  border-color: var(--cnc-primary, #42695d);
  box-shadow: 0 0 0 3px rgba(66,105,93,0.15);
}

/* ── Swipe-to-close on touch ── */
.cnc-drawer--swiping {
  transition: none !important;
}

/* ── Responsive ── */
@media (max-width: 576px) {
  .cnc-drawer {
    width: 100vw;
    border-radius: 0;
  }
  .cnc-drawer__header {
    padding: 12px 16px;
  }
  .cnc-drawer__body {
    padding: 16px;
  }
  .cnc-drawer__footer {
    padding: 12px 16px;
  }
}

/* ── Drawer entrance body scroll lock ── */
body.cnc-drawer-open {
  overflow: hidden;
}
