/* =========================================
   RA Chicken Invoice – style.css
   ========================================= */

/* ----- CSS Variables & Reset ----- */
:root {
  --primary: #DC2626;
  --primary-dark: #B91C1C;
  --primary-light: #FEE2E2;
  --secondary: #F97316;
  --secondary-light: #FFF7ED;
  --success: #10B981;
  --success-light: #D1FAE5;
  --warning: #F59E0B;
  --warning-light: #FEF3C7;
  --danger: #EF4444;
  --danger-light: #FEE2E2;
  --info: #3B82F6;
  --info-light: #EFF6FF;

  --bg: #F8F7F5;
  --card-bg: #FFFFFF;
  --sidebar-bg: #1A1A2E;
  --sidebar-hover: rgba(255,255,255,0.08);
  --sidebar-active: rgba(220,38,38,0.2);
  --sidebar-text: rgba(255,255,255,0.75);
  --sidebar-text-active: #FFFFFF;

  --text: #1C1C1E;
  --text-muted: #6B7280;
  --text-light: #9CA3AF;
  --border: #E5E7EB;
  --border-focus: #DC2626;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --shadow-xl: 0 20px 60px rgba(0,0,0,0.2);

  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --sidebar-w: 260px;
  --topbar-h: 64px;

  --transition: 0.25s ease;
  --transition-fast: 0.15s ease;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ========== SIDEBAR ========== */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform var(--transition);
  overflow: hidden;
  /* Mobile-first: always hidden by default */
  transform: translateX(-100%);
}

.sidebar::before {
  content: '';
  position: absolute;
  top: -100px; right: -100px;
  width: 300px; height: 300px;
  background: radial-gradient(circle, rgba(220,38,38,0.15) 0%, transparent 70%);
  pointer-events: none;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-logo {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  object-fit: contain;
  background: white;
  padding: 2px;
  flex-shrink: 0;
}

.logo-fallback {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  color: white;
  flex-shrink: 0;
}

.sidebar-brand-text {
  display: flex;
  flex-direction: column;
}

.brand-name {
  font-size: 1rem;
  font-weight: 700;
  color: white;
  letter-spacing: -0.3px;
}

.brand-sub {
  font-size: 0.7rem;
  color: var(--sidebar-text);
  font-weight: 400;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all var(--transition-fast);
  position: relative;
}

.nav-item i {
  width: 18px;
  text-align: center;
  font-size: 1rem;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: white;
  transform: translateX(2px);
}

.nav-item.active {
  background: var(--sidebar-active);
  color: white;
  border-left: 3px solid var(--primary);
}

.nav-item.active i { color: var(--secondary); }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.06);
  font-size: 0.7rem;
  color: rgba(255,255,255,0.3);
  text-align: center;
}

/* ========== TOPBAR (MOBILE) ========== */
.topbar {
  display: flex; /* Always show topbar by default (mobile-first) */
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--sidebar-bg);
  z-index: 99;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.2);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  color: white;
  font-weight: 700;
  font-size: 1rem;
}

.topbar-logo {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  object-fit: contain;
  background: white;
  padding: 2px;
}

.burger-btn, .topbar-new-btn {
  background: rgba(255,255,255,0.1);
  border: none;
  color: white;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  transition: background var(--transition-fast);
}

.burger-btn:hover, .topbar-new-btn:hover { background: rgba(255,255,255,0.18); }
.topbar-new-btn { background: var(--primary); }

/* ========== OVERLAY ========== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
  backdrop-filter: blur(4px);
}

/* ========== MAIN CONTENT ========== */
.main-content {
  margin-left: 0; /* Mobile-first: no sidebar offset */
  min-height: 100vh;
  padding: 80px 16px 24px; /* top padding accounts for topbar */
  transition: margin var(--transition);
}

/* ========== PAGES ========== */
.page { display: none; animation: fadeUp 0.3s ease; }
.page.active { display: block; }

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

/* ========== PAGE HEADER ========== */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 28px;
  flex-wrap: wrap;
  gap: 16px;
}

.page-title {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.5px;
  line-height: 1.2;
}

.page-subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.header-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ========== STATS GRID ========== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition);
  border: 1px solid var(--border);
  overflow: hidden;
  position: relative;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 80px; height: 80px;
  border-radius: 50%;
  opacity: 0.08;
  transform: translate(20px, -20px);
}

.stat-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
}

.stat-total::before { background: var(--primary); }
.stat-revenue::before { background: var(--success); }
.stat-today::before { background: var(--info); }
.stat-pending::before { background: var(--warning); }

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}

.stat-total .stat-icon { background: var(--primary-light); color: var(--primary); }
.stat-revenue .stat-icon { background: var(--success-light); color: var(--success); }
.stat-today .stat-icon { background: var(--info-light); color: var(--info); }
.stat-pending .stat-icon { background: var(--warning-light); color: var(--warning); }

.stat-info { display: flex; flex-direction: column; }

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.5px;
  line-height: 1.2;
  margin-top: 4px;
}

/* ========== SECTION HEADER ========== */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.section-link {
  font-size: 0.85rem;
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}

.section-link:hover { text-decoration: underline; }

/* ========== TABLE CARD ========== */
.table-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  overflow: hidden;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table thead tr {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
}

.data-table thead th {
  padding: 14px 16px;
  text-align: left;
  font-size: 0.78rem;
  font-weight: 700;
  color: white;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.data-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition-fast);
}

.data-table tbody tr:hover { background: #FAFAFA; }
.data-table tbody tr:last-child { border-bottom: none; }

.data-table tbody td {
  padding: 14px 16px;
  font-size: 0.88rem;
  color: var(--text);
  vertical-align: middle;
}

.empty-row td { padding: 0 !important; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state i {
  font-size: 3rem;
  color: var(--border);
}

.empty-state p {
  font-size: 0.95rem;
}

/* ========== STATUS BADGES ========== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-lunas { background: var(--success-light); color: var(--success); }
.badge-belum { background: var(--warning-light); color: #D97706; }
.badge-dp { background: var(--info-light); color: var(--info); }
.badge-draft { background: #F3F4F6; color: #6B7280; }

/* ========== BUTTONS ========== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: none;
  outline: none;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
  box-shadow: 0 4px 12px rgba(220,38,38,0.3);
}
.btn-primary:hover { box-shadow: 0 6px 20px rgba(220,38,38,0.4); filter: brightness(1.05); }

.btn-secondary {
  background: linear-gradient(135deg, #6366F1, #8B5CF6);
  color: white;
  box-shadow: 0 4px 12px rgba(99,102,241,0.3);
}
.btn-secondary:hover { filter: brightness(1.05); }

.btn-success {
  background: var(--success);
  color: white;
  box-shadow: 0 4px 12px rgba(16,185,129,0.3);
}
.btn-success:hover { filter: brightness(1.08); }

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover { filter: brightness(1.08); }

.btn-outline {
  background: transparent;
  color: var(--text-muted);
  border: 1.5px solid var(--border);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 6px 10px;
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }

.btn-sm { padding: 7px 14px; font-size: 0.8rem; }
.btn-lg { padding: 13px 28px; font-size: 0.95rem; }
.ml-auto { margin-left: auto; }

/* ========== FORM STYLES ========== */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.form-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  overflow: hidden;
}

.form-card.full-width { grid-column: 1 / -1; }

.form-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px;
  background: linear-gradient(135deg, rgba(220,38,38,0.04), rgba(249,115,22,0.04));
  border-bottom: 1px solid var(--border);
}

.form-card-header i {
  color: var(--primary);
  font-size: 1rem;
}

.form-card-header h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}

.form-body { padding: 20px; display: flex; flex-direction: column; gap: 16px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.required { color: var(--danger); }

.form-input {
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: white;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  width: 100%;
}

.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(220,38,38,0.1);
}

.form-input[readonly] {
  background: #F9FAFB;
  color: var(--text-muted);
  cursor: default;
}

textarea.form-input { resize: vertical; min-height: 80px; }

.form-hint {
  font-size: 0.75rem;
  color: var(--text-light);
  margin-top: -4px;
}

/* ========== PRODUCTS TABLE ========== */
.products-table-wrapper { overflow-x: auto; }

.products-table {
  width: 100%;
  border-collapse: collapse;
}

.products-table thead tr {
  background: #F9FAFB;
  border-bottom: 2px solid var(--border);
}

.products-table thead th {
  padding: 12px 14px;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.products-table tbody tr { border-bottom: 1px solid var(--border); }
.products-table tbody tr:last-child { border-bottom: none; }

.products-table tbody td { padding: 10px 14px; }

.products-table .form-input {
  padding: 8px 10px;
  font-size: 0.875rem;
  border-radius: 6px;
}

.remove-row-btn {
  background: none;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: all var(--transition-fast);
  font-size: 0.85rem;
}

.remove-row-btn:hover { background: var(--danger-light); color: var(--danger); }

/* ========== TOTAL SECTION ========== */
.total-section {
  display: flex;
  justify-content: flex-end;
  padding: 20px;
  border-top: 1px solid var(--border);
}

.total-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 280px;
}

.total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.total-row span:last-child { font-weight: 600; color: var(--text); }

.total-final {
  padding-top: 10px;
  border-top: 2px solid var(--border);
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text) !important;
}

.total-final span { color: var(--primary) !important; }

.dp-summary span:last-child { color: var(--success) !important; }
.sisa-summary { font-weight: 700; }
.sisa-summary span:last-child { color: var(--danger) !important; }

/* ========== FORM ACTIONS ========== */
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 24px;
  flex-wrap: wrap;
}

/* ========== HISTORY CONTROLS ========== */
.history-controls {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: center;
}

.search-box {
  flex: 1;
  min-width: 220px;
  position: relative;
}

.search-box i {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-light);
  font-size: 0.9rem;
}

.search-input {
  width: 100%;
  padding: 10px 14px 10px 38px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.875rem;
  outline: none;
  transition: border-color var(--transition-fast);
  background: var(--card-bg);
}

.search-input:focus { border-color: var(--primary); }

.filter-select {
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.875rem;
  outline: none;
  background: var(--card-bg);
  cursor: pointer;
  color: var(--text);
}

/* ========== SETTINGS ========== */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

.logo-upload-area {
  width: 140px;
  height: 140px;
  border-radius: var(--radius);
  border: 2px dashed var(--border);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  margin: 0 auto 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color var(--transition-fast);
  background: #F9FAFB;
}

.logo-upload-area:hover { border-color: var(--primary); }

.logo-upload-area img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 8px;
}

.logo-overlay {
  position: absolute;
  inset: 0;
  background: rgba(220,38,38,0.8);
  color: white;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.logo-upload-area:hover .logo-overlay { opacity: 1; }

.bank-accounts { display: flex; flex-direction: column; gap: 12px; }

.bank-item {
  background: #F9FAFB;
  border-radius: var(--radius-sm);
  padding: 12px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bank-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.action-buttons-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.color-themes {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.color-theme {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  cursor: pointer;
  transition: transform var(--transition-fast);
  border: 3px solid transparent;
}

.color-theme:hover { transform: scale(1.1); }
.color-theme.active { border-color: var(--text); box-shadow: 0 0 0 3px rgba(0,0,0,0.1); }

/* ========== MODAL ========== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  backdrop-filter: blur(4px);
  padding: 20px;
  overflow-y: auto;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-overlay.active { display: flex; align-items: flex-start; justify-content: center; }

.modal-box {
  background: var(--card-bg);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 820px;
  box-shadow: var(--shadow-xl);
  animation: slideUp 0.3s ease;
  overflow: hidden;
}

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

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
}

.modal-header h3 {
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.modal-header i { color: var(--primary); }

.modal-header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  font-size: 1rem;
}

.modal-close:hover { background: var(--danger-light); color: var(--danger); }

.modal-body {
  padding: 24px;
  overflow-y: auto;
  max-height: calc(100vh - 160px);
}

/* ========== INVOICE PAPER ========== */
.invoice-paper {
  background: white;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  font-family: 'Inter', sans-serif;
  min-width: 794px; /* Force A4 width to prevent squished layouts on mobile JPGs */
  margin: 0 auto;
}

.inv-header {
  padding: 32px 36px 24px;
  background: linear-gradient(135deg, #1A1A2E 0%, #16213E 100%);
  color: white;
  position: relative;
  overflow: hidden;
}

.inv-header::before {
  content: '';
  position: absolute;
  top: -60px; right: -60px;
  width: 200px; height: 200px;
  border-radius: 50%;
  background: rgba(220,38,38,0.15);
}

.inv-header::after {
  content: '';
  position: absolute;
  bottom: -40px; left: -40px;
  width: 150px; height: 150px;
  border-radius: 50%;
  background: rgba(249,115,22,0.1);
}

.inv-header-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  position: relative;
  z-index: 1;
}

.inv-brand { display: flex; align-items: center; gap: 14px; }

.inv-logo {
  width: 60px;
  height: 60px;
  border-radius: 12px;
  object-fit: contain;
  background: white;
  padding: 4px;
  flex-shrink: 0;
}

.inv-logo-placeholder {
  width: 60px;
  height: 60px;
  border-radius: 12px;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  color: white;
  flex-shrink: 0;
}

.inv-brand-info .inv-biz-name {
  font-size: 1.3rem;
  font-weight: 800;
  color: white;
  letter-spacing: -0.3px;
}

.inv-brand-info .inv-biz-tagline {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.65);
  margin-top: 2px;
}

.inv-title-block { text-align: right; }

.inv-title-block .inv-title {
  font-size: 2rem;
  font-weight: 900;
  color: white;
  letter-spacing: -1px;
  text-transform: uppercase;
}

.inv-title-block .inv-number {
  font-size: 0.8rem;
  color: rgba(255,255,255,0.6);
  margin-top: 4px;
}

.inv-title-block .inv-number span {
  color: var(--secondary);
  font-weight: 700;
}

.inv-header-divider {
  margin: 20px 0;
  height: 1px;
  background: rgba(255,255,255,0.1);
  position: relative;
  z-index: 1;
}

.inv-header-bottom {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  position: relative;
  z-index: 1;
  flex-wrap: wrap;
}

.inv-from, .inv-dates {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.inv-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(255,255,255,0.4);
}

.inv-value {
  font-size: 0.82rem;
  color: rgba(255,255,255,0.85);
  line-height: 1.5;
}

.inv-dates { text-align: right; }

/* Invoice Body */
.inv-body { padding: 28px 36px; }

.inv-customer-section {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.inv-to-block {
  background: linear-gradient(135deg, rgba(220,38,38,0.04), rgba(249,115,22,0.04));
  border-radius: var(--radius);
  padding: 16px 20px;
  flex: 1;
  border-left: 4px solid var(--primary);
}

.inv-to-block .inv-label { color: var(--primary); margin-bottom: 6px; }
.inv-cust-name { font-size: 1.05rem; font-weight: 700; color: var(--text); }
.inv-cust-detail { font-size: 0.82rem; color: var(--text-muted); margin-top: 3px; line-height: 1.5; }

.inv-status-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.inv-status-badge {
  padding: 8px 18px;
  border-radius: 30px;
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.inv-status-badge.lunas { background: var(--success-light); color: var(--success); }
.inv-status-badge.belum { background: var(--warning-light); color: #D97706; }
.inv-status-badge.dp { background: var(--info-light); color: var(--info); }
.inv-status-badge.draft { background: #F3F4F6; color: #6B7280; }

/* Invoice Products */
.inv-products { margin-bottom: 24px; }

.inv-products-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.inv-products-table thead tr {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
}

.inv-products-table thead th {
  padding: 12px 14px;
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-align: left;
}

.inv-products-table thead th:last-child,
.inv-products-table thead th:nth-child(2),
.inv-products-table thead th:nth-child(4) { text-align: right; }

.inv-products-table tbody tr { border-bottom: 1px solid var(--border); }
.inv-products-table tbody tr:nth-child(even) { background: #FAFAFA; }

.inv-products-table tbody td {
  padding: 12px 14px;
  vertical-align: middle;
}

.inv-products-table tbody td:nth-child(2),
.inv-products-table tbody td:nth-child(4),
.inv-products-table tbody td:last-child { text-align: right; }

.inv-product-name { font-weight: 600; color: var(--text); }
.inv-product-num {
  display: inline-flex;
  width: 24px;
  height: 24px;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: white;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  margin-right: 8px;
}

/* Invoice Totals */
.inv-totals {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 24px;
}

.inv-totals-table {
  min-width: 260px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.inv-total-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 16px;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--border);
}

.inv-total-row:last-child { border-bottom: none; }

.inv-total-row .t-label { color: var(--text-muted); }
.inv-total-row .t-value { font-weight: 600; color: var(--text); }

.inv-total-final {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
}

.inv-total-final .t-label,
.inv-total-final .t-value { color: white !important; font-size: 1rem; font-weight: 800; }

.inv-total-dp .t-value { color: var(--success) !important; }
.inv-total-sisa .t-value { color: var(--danger) !important; font-weight: 700; }

/* Invoice Footer */
.inv-footer {
  padding: 20px 36px 28px;
  border-top: 1px solid var(--border);
}

.inv-footer-content {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.inv-bank-info { flex: 1; }
.inv-bank-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.inv-bank-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 8px;
}

.inv-bank-item .bank-name { font-weight: 700; font-size: 0.85rem; }
.inv-bank-item .bank-account { font-size: 0.85rem; color: var(--text-muted); }

.inv-notes-block { flex: 1; }
.inv-notes-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.inv-notes-text { font-size: 0.82rem; color: var(--text-muted); line-height: 1.6; }

.inv-signature {
  text-align: center;
}

.inv-sig-line {
  width: 120px;
  height: 1px;
  background: var(--border);
  margin: 50px auto 8px;
}

.inv-sig-label { font-size: 0.75rem; color: var(--text-muted); }

.inv-footer-bar {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-light);
}

.inv-footer-bar strong { color: var(--primary); }

/* ========== CONFIRM DIALOG ========== */
.confirm-box {
  background: white;
  border-radius: var(--radius-xl);
  padding: 36px;
  max-width: 400px;
  width: 100%;
  margin: auto;
  text-align: center;
  box-shadow: var(--shadow-xl);
  animation: slideUp 0.3s ease;
}

.confirm-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--warning-light);
  color: var(--warning);
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
}

.confirm-box h3 { font-size: 1.2rem; font-weight: 700; margin-bottom: 10px; }
.confirm-box p { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 24px; }

.confirm-actions { display: flex; gap: 12px; justify-content: center; }

/* ========== TOAST ========== */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: white;
  padding: 14px 20px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 300;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 380px;
}

.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--info); }

/* ========== ACTION BTNS IN TABLE ========== */
.table-actions { display: flex; gap: 6px; }

/* ========== PRINT STYLES ========== */
@media print {
  .sidebar, .topbar, .sidebar-overlay, .main-content, .modal-header, .toast, #confirm-modal { display: none !important; }
  .modal-overlay { 
    display: block !important; 
    position: static !important;
    background: none !important; 
    padding: 0 !important; 
    overflow: visible !important;
  }
  .modal-box { 
    box-shadow: none !important; 
    border-radius: 0 !important; 
    max-width: 100% !important;
    transform: none !important;
    animation: none !important;
    margin: 0 !important;
  }
  .modal-body { 
    padding: 0 !important; 
    max-height: none !important; 
    overflow: visible !important;
  }
  .invoice-paper { border: none !important; border-radius: 0 !important; box-shadow: none !important; }
  body { background: white !important; overflow: visible !important; }
  @page { margin: 0; size: A4; }
}

/* ========== RESPONSIVE ========== */

/* Sidebar layout is controlled ENTIRELY by JS via body.desktop-mode class.
   - body.desktop-mode = real desktop (no touch, wide screen) → sidebar always visible
   - No body.desktop-mode = mobile/tablet → sidebar hidden, opens only via .open */
body.desktop-mode .sidebar {
  transform: translateX(0);
}
body.desktop-mode .topbar {
  display: none;
}
body.desktop-mode .main-content {
  margin-left: var(--sidebar-w);
  padding: 32px;
}

/* Sidebar open (mobile/tablet only, triggered by burger button) */
.sidebar.open {
  transform: translateX(0);
  box-shadow: var(--shadow-xl);
}
.sidebar-overlay.show { display: block; }

/* Tablet layout adjustments */
@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }

  .page-header { flex-direction: column; align-items: stretch; }
  .page-header > div:last-child, .header-actions { justify-content: stretch; }
  .page-header .btn, .header-actions .btn { flex: 1; justify-content: center; }

  .data-table { font-size: 0.8rem; }
  .data-table thead th, .data-table tbody td { padding: 10px 10px; }

  .history-controls { flex-direction: column; }
  .search-box { min-width: 100%; }

  .form-row { grid-template-columns: 1fr; }

  .modal-overlay { padding: 10px; }
  .modal-box { border-radius: var(--radius-lg); }
  .modal-header-actions { flex-wrap: wrap; }

  /* Responsive Table for Product Inputs */
  #products-tbody { display: block; }
  #products-tbody tr {
    display: block;
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    background: #f8fafc;
    position: relative;
  }
  #products-tbody td {
    display: flex;
    flex-direction: column;
    padding: 6px 0 !important;
    border: none;
    gap: 4px;
  }
  #products-tbody td::before {
    content: attr(data-label);
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
  }
  #products-tbody td:last-child {
    position: absolute;
    top: 12px;
    right: 12px;
    padding: 0 !important;
  }
  #products-tbody td:last-child::before { display: none; }
  #products-tbody td .form-input { min-width: 0 !important; width: 100%; }
  #products-tbody tr::before { display: none; }
  table:has(#products-tbody) thead { display: none; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stat-card { padding: 16px; }
  .stat-value { font-size: 1.2rem; }
}



/* ========== SCROLL BAR ========== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-light); }


/* ========== THEME OVERRIDES ========== */
body.theme-green { --primary: #059669; --primary-dark: #047857; --primary-light: #D1FAE5; --secondary: #10B981; }
body.theme-blue { --primary: #2563EB; --primary-dark: #1D4ED8; --primary-light: #EFF6FF; --secondary: #7C3AED; }
body.theme-dark { --primary: #475569; --primary-dark: #334155; --primary-light: #F1F5F9; --secondary: #1E293B; }

/* ========== SIGNATURE & STAMP ========== */
.sig-stamp-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.sig-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sig-panel-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.sig-panel-label i { color: var(--primary); }

/* Signature Canvas */
.sig-canvas-wrapper {
  position: relative;
  background: #FAFAFA;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: crosshair;
  transition: border-color var(--transition-fast);
  touch-action: none;
}

.sig-canvas-wrapper:hover { border-color: var(--primary); }
.sig-canvas-wrapper.has-sig { border-style: solid; border-color: var(--success); background: white; }

#sig-canvas {
  display: block;
  width: 100%;
  height: 180px;
  touch-action: none;
}

.sig-canvas-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  color: var(--text-light);
  pointer-events: none;
  transition: opacity 0.3s;
}

.sig-canvas-wrapper.has-sig .sig-canvas-hint { opacity: 0; }

.sig-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.sig-name-row {
  display: flex;
  gap: 12px;
}

/* Stamp Preview Area */
.stamp-preview-area {
  display: flex;
  align-items: center;
  justify-content: center;
  background: repeating-linear-gradient(
    45deg,
    #F9FAFB,
    #F9FAFB 10px,
    #F3F4F6 10px,
    #F3F4F6 20px
  );
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 24px;
  min-height: 200px;
}

/* The actual stamp circle */
.stamp-preview {
  position: relative;
  width: 180px;
  height: 180px;
  color: var(--primary);
  filter: drop-shadow(0 2px 8px rgba(220,38,38,0.25));
  animation: stampAppear 0.4s ease;
}

@keyframes stampAppear {
  from { transform: scale(0.7) rotate(-15deg); opacity: 0; }
  to { transform: scale(1) rotate(-18deg); opacity: 1; }
}

.stamp-ring {
  position: relative;
  width: 100%;
  height: 100%;
  border: 4px double currentColor;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stamp-ring::before {
  content: '';
  position: absolute;
  inset: 6px;
  border: 2px solid currentColor;
  border-radius: 50%;
  opacity: 0.5;
}

.stamp-arc-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.stamp-arc-text { font-family: 'Inter', sans-serif; }

.stamp-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  z-index: 1;
  padding-top: 16px;
}

.stamp-main-text {
  font-size: 1.4rem;
  font-weight: 900;
  letter-spacing: 2px;
  text-transform: uppercase;
  line-height: 1;
  text-align: center;
}

.stamp-sub-icon { font-size: 1.4rem; line-height: 1; }

.stamp-settings { display: flex; flex-direction: column; gap: 12px; }

/* Status-based stamp colors */
.stamp-lunas   { --stamp-color: #059669; color: #059669; }
.stamp-belum   { --stamp-color: #D97706; color: #D97706; }
.stamp-dp      { --stamp-color: #2563EB; color: #2563EB; }
.stamp-draft   { --stamp-color: #9CA3AF; color: #9CA3AF; }

/* ====== Invoice stamp & signature rendering ====== */
.inv-sig-stamp-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  flex-wrap: wrap;
  padding-top: 12px;
}

.inv-sig-block {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.inv-sig-img-wrap {
  width: 200px;
  height: 90px;
  display: flex;
  align-items: flex-end;
}

.inv-sig-img {
  max-width: 200px;
  max-height: 88px;
  object-fit: contain;
}

.inv-sig-underline {
  width: 180px;
  height: 1.5px;
  background: #D1D5DB;
  margin-top: 6px;
}

.inv-sig-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
}

.inv-sig-jobtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.inv-stamp-block {
  position: relative;
}

/* Stamp on invoice paper */
.inv-stamp {
  width: 130px;
  height: 130px;
  border: 3px double currentColor;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transform: rotate(-18deg);
  transition: transform 0.3s;
  flex-shrink: 0;
}

.inv-stamp::before {
  content: '';
  position: absolute;
  inset: 5px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  opacity: 0.4;
}

.inv-stamp svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.inv-stamp-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1;
  padding-top: 12px;
}

.inv-stamp-main {
  font-size: 1rem;
  font-weight: 900;
  letter-spacing: 1.5px;
  text-align: center;
  line-height: 1;
  text-transform: uppercase;
}

.inv-stamp-icon { font-size: 1rem; }

/* ====== Toggle Switch ====== */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
  flex-shrink: 0;
}

.toggle-switch input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #D1D5DB;
  transition: .3s;
  border-radius: 26px;
}

.toggle-slider::before {
  position: absolute;
  content: "";
  height: 20px; width: 20px;
  left: 3px; bottom: 3px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.toggle-switch input:checked + .toggle-slider { background-color: var(--success); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(20px); }

/* Responsive */
@media (max-width: 768px) {
  .sig-stamp-grid { grid-template-columns: 1fr; }
  .sig-name-row { flex-direction: column; }
  .sig-actions { justify-content: center; }
  .inv-sig-stamp-row { justify-content: center; }
}

@media print {
  .inv-stamp { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .inv-sig-img { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
