/* ==========================================================================
   CORPORATE INSTITUTIONAL DESIGN SYSTEM — KOPERASI SMPKVSA BERHAD
   Personaliti: Tegas, Tersusun, Berwibawa (Anti-AI-Slop)
   ========================================================================== */
:root {
  --brand-navy: #0B1F3A;
  --brand-navy-hover: #132F56;
  --brand-navy-soft: #EBF0F7;
  --brand-gold: #B88A2E;
  --brand-gold-soft: #FDF8EC;
  --brand-crimson: #991B1B;
  --surface: #F4F6F9;
  --surface-raised: #FFFFFF;
  --surface-subtle: #F8FAFC;
  --text-primary: #0F172A;
  --text-secondary: #334155;
  --text-muted: #64748B;
  --border: #CBD5E1;
  --border-strong: #94A3B8;
  --success: #15803D;
  --success-bg: #ECFDF3;
  --warning: #B45309;
  --warning-bg: #FFFBEB;
  --danger: #B91C1C;
  --danger-bg: #FEF2F2;
  --focus-ring: 0 0 0 3px rgba(184, 138, 46, 0.38);
  --radius-sm: 6px;
  --radius-md: 10px;
  --font-head: 'Outfit', system-ui, -apple-system, sans-serif;
  --font-body: 'DM Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, monospace;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--surface);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.tabular-nums {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.hidden { display: none !important; }

/* Focus accessibility (WCAG 2.2 AA) */
:focus-visible {
  outline: 2px solid var(--brand-gold);
  outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* --- Status Banners --- */
.status-banner {
  padding: 10px 16px;
  font-size: 0.85rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
}
.status-banner.offline { background: #7F1D1D; color: #FFFFFF; }
.status-banner.demo { background: var(--brand-gold-soft); color: #78350F; border-bottom: 1px solid #E5C882; }

/* --- Top Institutional Header --- */
.app-header {
  background: var(--brand-navy);
  color: #FFFFFF;
  border-bottom: 3px solid var(--brand-gold);
  position: sticky;
  top: 0;
  z-index: 40;
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-logo {
  width: 46px;
  height: 46px;
  object-fit: contain;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 50%;
  padding: 2px;
}

.brand-text { min-width: 0; }
.brand-title {
  margin: 0;
  font-family: var(--font-head);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-sub {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: #CBD5E1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* --- Primary Navigation Bar --- */
.nav-bar {
  background: var(--surface-raised);
  border-bottom: 1px solid var(--border);
}

.nav-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.nav-inner::-webkit-scrollbar { display: none; }

.nav-tab {
  appearance: none;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 13px 16px;
  min-height: 46px;
  font-family: var(--font-head);
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}
.nav-tab:hover { color: var(--brand-navy); }
.nav-tab.active {
  color: var(--brand-navy);
  border-bottom-color: var(--brand-gold);
}

/* --- Main Container & Split Layout --- */
.app-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 16px 96px;
}

.order-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  align-items: start;
}

@media (min-width: 1024px) {
  .order-layout {
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 24px;
  }
  .summary-aside {
    position: sticky;
    top: 88px;
  }
  .app-main { padding-bottom: 40px; }
}

/* --- Panels & Section Blocks --- */
.panel {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 18px;
}

.panel-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.panel-head-title {
  margin: 0;
  font-family: var(--font-head);
  font-size: 1rem;
  font-weight: 700;
  color: var(--brand-navy);
  display: flex;
  align-items: center;
  gap: 8px;
}

.step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  background: var(--brand-navy);
  color: #FFFFFF;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
  flex-shrink: 0;
}

.panel-body { padding: 18px; }

/* --- Forms --- */
.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}
@media (min-width: 640px) {
  .form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.field { display: flex; flex-direction: column; gap: 5px; }
.field label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
}
.req { color: var(--danger); }

.input, .select, .textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #FFFFFF;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.94rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--brand-navy);
  box-shadow: var(--focus-ring);
}
.textarea { min-height: 76px; resize: vertical; }
.field-hint { font-size: 0.76rem; color: var(--text-muted); }

/* Segmented Radio Pills (Jantina / Agama) */
.seg-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.seg-btn {
  appearance: none;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #FFFFFF;
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.seg-btn[aria-pressed="true"] {
  background: var(--brand-navy);
  border-color: var(--brand-navy);
  color: #FFFFFF;
}

/* --- Item Checklist Rows --- */
.section-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.item-list {
  display: flex;
  flex-direction: column;
  divide-y: 1px solid var(--border);
}

.item-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  gap: 10px 12px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #E2E8F0;
  transition: background 0.12s;
}
.item-row:last-child { border-bottom: none; }
.item-row:hover { background: var(--surface-subtle); }
.item-row.unchecked { opacity: 0.58; background: #FAFBFC; }
.item-row.locked { background: var(--brand-gold-soft); }

.item-check {
  width: 20px;
  height: 20px;
  accent-color: var(--brand-navy);
  cursor: pointer;
  margin: 0;
}
.item-check:disabled { cursor: not-allowed; }

.item-info { min-width: 0; }
.item-name {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.item-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.item-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.size-select {
  min-height: 36px;
  padding: 4px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  font-size: 0.82rem;
  font-weight: 600;
  background: #FFFFFF;
  color: var(--text-primary);
}

.qty-stepper {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  overflow: hidden;
  background: #FFFFFF;
}
.qty-btn {
  width: 32px;
  height: 34px;
  border: none;
  background: var(--surface-subtle);
  font-weight: 700;
  cursor: pointer;
  color: var(--brand-navy);
}
.qty-val {
  min-width: 28px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
}

.item-price {
  min-width: 78px;
  text-align: right;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--brand-navy);
}

@media (max-width: 639px) {
  .item-row {
    grid-template-columns: 28px minmax(0, 1fr);
    padding: 12px;
  }
  .item-controls {
    grid-column: 2 / 3;
    justify-content: space-between;
    width: 100%;
    padding-top: 4px;
  }
}

/* --- Badges --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge-lock { background: #FEF3C7; color: #92400E; border: 1px solid #F59E0B; }
.badge-navy { background: var(--brand-navy-soft); color: var(--brand-navy); }
.badge-success { background: var(--success-bg); color: var(--success); border: 1px solid #BBF7D0; }
.badge-warning { background: var(--warning-bg); color: var(--warning); border: 1px solid #FDE68A; }
.badge-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid #FECACA; }
.badge-muted { background: #F1F5F9; color: #475569; border: 1px solid #CBD5E1; }

/* --- Buttons --- */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font-head);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary { background: var(--brand-navy); color: #FFFFFF; }
.btn-primary:hover:not(:disabled) { background: var(--brand-navy-hover); }

.btn-gold { background: var(--brand-gold); color: #FFFFFF; }
.btn-gold:hover:not(:disabled) { background: #9E7422; }

.btn-whatsapp { background: #15803D; color: #FFFFFF; }
.btn-whatsapp:hover:not(:disabled) { background: #166534; }

.btn-outline { background: #FFFFFF; color: var(--brand-navy); border-color: var(--border-strong); }
.btn-outline:hover:not(:disabled) { background: var(--surface-subtle); border-color: var(--brand-navy); }

.btn-ghost-light {
  background: rgba(255, 255, 255, 0.12);
  color: #FFFFFF;
  border-color: rgba(255, 255, 255, 0.28);
  min-height: 38px;
  padding: 6px 12px;
  font-size: 0.82rem;
}
.btn-ghost-light:hover { background: rgba(255, 255, 255, 0.22); }

.btn-danger-outline { background: #FFFFFF; color: var(--danger); border-color: #FCA5A5; }
.btn-danger-outline:hover { background: var(--danger-bg); }

.btn-sm { min-height: 34px; padding: 5px 10px; font-size: 0.8rem; }
.btn-full { width: 100%; }

/* --- Summary Card & BSN Info --- */
.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
}
.summary-divider { border: 0; border-top: 1px solid var(--border); margin: 10px 0; }
.summary-total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 8px 0;
}
.summary-total .lbl { font-family: var(--font-head); font-weight: 700; font-size: 0.95rem; color: var(--brand-navy); }
.summary-total .val { font-size: 1.45rem; font-weight: 700; color: var(--brand-navy); }

.bank-box {
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand-gold);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin: 14px 0;
  font-size: 0.83rem;
}
.bank-box-title { font-weight: 700; color: var(--brand-navy); margin-bottom: 4px; }
.bank-acc-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
}
.bank-acc-num { font-size: 0.96rem; font-weight: 700; color: var(--text-primary); }

/* Mobile Sticky Checkout Bar */
.mobile-sticky-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--brand-navy);
  color: #FFFFFF;
  border-top: 2px solid var(--brand-gold);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 35;
}
@media (min-width: 1024px) { .mobile-sticky-bar { display: none; } }

/* --- Admin KPI & Charts --- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
@media (min-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
.kpi-card {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-top: 3px solid var(--brand-navy);
  border-radius: var(--radius-sm);
  padding: 14px;
}
.kpi-card.gold { border-top-color: var(--brand-gold); }
.kpi-card.green { border-top-color: var(--success); }
.kpi-card.red { border-top-color: var(--danger); }
.kpi-label { font-size: 0.76rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.kpi-value { font-size: 1.32rem; font-weight: 700; color: var(--brand-navy); margin-top: 4px; }
.kpi-sub { font-size: 0.76rem; color: var(--text-muted); margin-top: 2px; }

.chart-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  margin-bottom: 20px;
}
@media (min-width: 960px) {
  .chart-grid { grid-template-columns: 1.45fr 1fr; }
}
.chart-wrap { position: relative; height: 290px; width: 100%; }

/* --- Data Tables --- */
.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}
.data-table th {
  text-align: left;
  padding: 10px 12px;
  background: var(--surface-subtle);
  border-bottom: 2px solid var(--border);
  font-family: var(--font-head);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  white-space: nowrap;
}
.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #E2E8F0;
  vertical-align: middle;
}
.data-table tr:hover td { background: #F8FAFC; }
.num-col { text-align: right; white-space: nowrap; }

/* Sub-tabs inside Admin */
.subtabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.subtab-btn {
  min-height: 40px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: #FFFFFF;
  color: var(--text-secondary);
  font-family: var(--font-head);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
}
.subtab-btn.active {
  background: var(--brand-navy);
  border-color: var(--brand-navy);
  color: #FFFFFF;
}

/* --- Modals --- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11, 31, 58, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 60;
  overflow-y: auto;
}
.modal-box {
  background: #FFFFFF;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  width: 100%;
  max-width: 760px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-box.narrow { max-width: 440px; }
.modal-head {
  padding: 16px 20px;
  background: var(--brand-navy);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.modal-head h3 { margin: 0; font-family: var(--font-head); font-size: 1.05rem; }
.modal-close {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.3);
  color: #FFFFFF;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  font-size: 1.1rem;
  cursor: pointer;
}
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-subtle);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* --- Official Receipt Visual --- */
.receipt-sheet {
  background: #FFFFFF;
  color: #0F172A;
  border: 1px solid #CBD5E1;
  padding: 20px;
  border-radius: 6px;
}
.receipt-header {
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 2px solid #0B1F3A;
  padding-bottom: 12px;
  margin-bottom: 14px;
}
.receipt-header img { width: 64px; height: 64px; object-fit: contain; }
.receipt-org h4 { margin: 0; font-family: var(--font-head); font-size: 1.05rem; color: #0B1F3A; }
.receipt-org p { margin: 2px 0; font-size: 0.78rem; color: #334155; }

.receipt-meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 14px;
  font-size: 0.83rem;
  margin-bottom: 14px;
  padding: 10px 12px;
  background: #F8FAFC;
  border: 1px solid #E2E8F0;
}

/* --- Toast Notification --- */
.toast-stack {
  position: fixed;
  top: 74px;
  right: 16px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
}
.toast {
  background: var(--brand-navy);
  color: #FFFFFF;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--brand-gold);
  font-size: 0.88rem;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.22);
}
.toast.error { background: #7F1D1D; border-left-color: #FCA5A5; }
.toast.success { background: #14532D; border-left-color: #86EFAC; }

/* --- Empty State & Skeleton --- */
.empty-state {
  text-align: center;
  padding: 36px 20px;
  color: var(--text-muted);
}
.empty-state p { margin: 6px 0 14px; }

/* --- Print A4 Rules (Resit & Laporan Analitik) --- */
#printArea { display: none; }

@media print {
  body > *:not(#printArea) { display: none !important; }
  #printArea {
    display: block !important;
    position: static !important;
    width: 100% !important;
    background: #FFFFFF !important;
    color: #000000 !important;
    font-size: 11pt;
  }
  .receipt-sheet { border: none; padding: 0; }
  .no-print { display: none !important; }
  @page { size: A4 portrait; margin: 14mm; }
}
