/* ==========================================================================
   CSS DESIGN SYSTEM - CETAK & PENOMORAN KUPON F4 (JALAN SEHAT RT 14)
   ========================================================================== */

:root {
  /* Color Palette */
  --bg-dark: #0f172a;
  --bg-sidebar: #1e293b;
  --bg-card: #334155;
  --bg-input: #0f172a;
  
  --primary-red: #dc2626;
  --primary-red-hover: #b91c1c;
  --accent-gold: #f59e0b;
  --accent-blue: #38bdf8;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dark: #1e293b;
  
  --border-color: #475569;
  --border-light: rgba(255, 255, 255, 0.1);
  
  /* Dimensions F4 Paper: 215mm x 330mm */
  --f4-width-mm: 215mm;
  --f4-height-mm: 330mm;
  
  /* Fonts */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-dark);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ==========================================================================
   LAYOUT ENGINE (SCREEN UI)
   ========================================================================== */

.app-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* SIDEBAR STYLING */
.sidebar {
  width: 380px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 10;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
}

.brand {
  padding: 1.25rem;
  background: linear-gradient(135deg, #881337 0%, #dc2626 100%);
  display: flex;
  align-items: center;
  gap: 0.85rem;
  border-bottom: 1px solid var(--border-color);
}

.brand-icon {
  width: 44px;
  height: 44px;
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(8px);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  color: #fff;
}

.brand h1 {
  font-size: 1.1rem;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.02em;
}

.brand .subtitle {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.85);
}

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

.sidebar-scroll::-webkit-scrollbar {
  width: 6px;
}
.sidebar-scroll::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

/* TABS */
.nav-tabs {
  display: flex;
  background: var(--bg-input);
  padding: 4px;
  border-radius: 8px;
  margin-bottom: 1rem;
  gap: 2px;
}

.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.5rem 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.tab-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
  background: var(--primary-red);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(220, 38, 38, 0.4);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* CARDS & FORM CONTROLS */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.card h3 {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent-gold);
  margin-bottom: 0.85rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.form-group {
  margin-bottom: 0.85rem;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-group label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.form-row {
  display: flex;
  gap: 0.75rem;
}

.form-row .form-group {
  flex: 1;
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s ease;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--primary-red);
}

input[type="color"] {
  width: 100%;
  height: 36px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  cursor: pointer;
  padding: 2px;
}

.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-main);
}

.checkbox-group input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary-red);
}

/* SUMMARY BOX */
.summary-box {
  background: var(--bg-input);
  border: 1px dashed var(--border-color);
  border-radius: 8px;
  padding: 0.75rem;
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.summary-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
}

.badge {
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.75rem;
}

.badge-red {
  background: rgba(220, 38, 38, 0.2);
  color: #fca5a5;
  border: 1px solid var(--primary-red);
}

.badge-gold {
  background: rgba(245, 158, 11, 0.2);
  color: #fde68a;
  border: 1px solid var(--accent-gold);
}

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: 600;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-block {
  width: 100%;
}

.btn-lg {
  padding: 0.85rem 1.25rem;
  font-size: 0.95rem;
}

.btn-primary {
  background: linear-gradient(135deg, #dc2626 0%, #991b1b 100%);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(220, 38, 38, 0.4);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%);
  transform: translateY(-1px);
}

.nudge-btn-group {
  display: flex;
  gap: 4px;
}

.nudge-btn-group .nudge-btn {
  flex: 1;
  padding: 4px 6px;
  font-size: 0.72rem;
  background: var(--bg-input);
}

.nudge-btn-group .nudge-btn:hover {
  background: var(--primary-red);
  color: #fff;
  border-color: var(--primary-red);
}

.btn-secondary:hover {
  background: var(--border-color);
}

.btn-icon {
  width: 34px;
  height: 34px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: 6px;
}

.btn-icon:hover {
  background: var(--primary-red);
  border-color: var(--primary-red);
}

.sidebar-footer {
  padding: 1rem;
  background: var(--bg-sidebar);
  border-top: 1px solid var(--border-color);
}

/* MAIN PREVIEW AREA */
.main-preview {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-dark);
  position: relative;
  overflow: hidden;
}

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

.header-title {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.header-title h2 {
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-main);
}

.page-indicator {
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent-blue);
  border: 1px solid rgba(56, 189, 248, 0.3);
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.page-select-wrapper select {
  padding: 0.35rem 0.5rem;
  font-size: 0.8rem;
  width: auto;
}

.preview-viewport {
  flex: 1;
  overflow: auto;
  padding: 2rem;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  background: radial-gradient(circle, #1e293b 0%, #0f172a 100%);
}

/* F4 SHEET CANVAS STYLING (SCREEN PREVIEW) */
.f4-paper-wrapper {
  transition: transform 0.2s ease;
  transform-origin: top center;
}

.f4-sheet-preview {
  background: #ffffff;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.1);
  box-sizing: border-box;
  position: relative;
  overflow: hidden;
  margin: 0 auto;
}

/* Dimensions in Screen Preview (F4 Aspect Ratio 215mm x 330mm) */
.f4-sheet-preview.portrait {
  width: 215mm;
  min-height: 330mm;
  padding: 5mm;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.f4-sheet-preview.landscape {
  width: 330mm;
  min-height: 215mm;
  padding: 5mm;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  gap: 2mm;
}

/* INDIVIDUAL COUPON ITEM IN SHEET */
.coupon-item {
  position: relative;
  width: 100%;
  overflow: visible;
  background: #ffffff;
  display: block;
}

.coupon-item img.coupon-bg,
.coupon-item img {
  width: 100%;
  height: 100%;
  object-fit: fill;
  display: block;
  user-select: none;
  pointer-events: none;
}

/* CUT GUIDES (Dotted lines between coupons) */
.cut-line-bottom {
  border-bottom: 1px dashed #a0a0a0;
}
.cut-line-right {
  border-right: 1px dashed #a0a0a0;
}

/* OVERLAY NUMBERS */
.coupon-number {
  position: absolute;
  user-select: none;
  touch-action: none;
  white-space: nowrap;
  line-height: 1;
  cursor: grab;
  transition: border-color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
  padding: 3px 8px;
  border: 1px dashed #999;
  transform: translate(-50%, -50%);
  text-align: center;
  border-radius: 4px;
  z-index: 50 !important;
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  background: rgba(255, 255, 255, 0.9);
}

.coupon-number:hover {
  border-color: #dc2626;
  background: #ffffff;
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.5);
}

.coupon-number.dragging {
  cursor: grabbing !important;
  border-color: #dc2626 !important;
  background: #ffffff !important;
  box-shadow: 0 4px 16px rgba(220, 38, 38, 0.6) !important;
  z-index: 100 !important;
}

.preview-footer-hint {
  height: 36px;
  background: var(--bg-sidebar);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.preview-footer-hint strong {
  color: var(--accent-gold);
}

.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 1rem; }

/* ==========================================================================
   PRINT ENGINE (@media print - F4 Exact Dimensions 215mm x 330mm)
   ========================================================================== */

/* Default print hidden container */
.print-only {
  display: none;
}

@media print {
  @page {
    size: 215mm 330mm;
    margin: 0mm;
  }

  html, body {
    width: 215mm;
    height: 330mm;
    background: #ffffff !important;
    color: #000000 !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* Hide screen UI */
  .no-print,
  #app {
    display: none !important;
  }

  /* Show print container */
  .print-only {
    display: block !important;
    width: 100% !important;
  }

  /* Individual Print F4 Sheet Page */
  .print-page {
    width: 215mm !important;
    height: 330mm !important;
    box-sizing: border-box !important;
    page-break-after: always !important;
    break-after: page !important;
    overflow: hidden !important;
    position: relative !important;
    background: #ffffff !important;
  }

  .print-page.portrait {
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
  }

  .print-page.landscape {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    grid-template-rows: 1fr 1fr 1fr !important;
  }

  .print-coupon-item {
    position: relative !important;
    width: 100% !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }

  .print-coupon-item img {
    width: 100% !important;
    height: 100% !important;
    object-fit: fill !important;
    display: block !important;
  }

  .print-coupon-number {
    position: absolute !important;
    white-space: nowrap !important;
    line-height: 1 !important;
    user-select: none !important;
    transform: translate(-50%, -50%) !important;
    text-align: center !important;
  }
}
