/* ===================================================
   SỔ CÔNG NỢ TẠP HÓA LOAN VY - DESIGN SYSTEM & APP STYLES
   Phong cách SAPO POS: Trắng, Đen Xám, Xanh Lá, Xanh Dương Đậm
   Góc bo cứng cáp, chuyên nghiệp cho bán lẻ & kế toán
   =================================================== */

@import url('https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:wght@400;500;600;700;800&display=swap');

:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, 'Be Vietnam Pro';

  /* 1. Sapo Grayscale & Surface: Trắng & Đen Xám */
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-2: #f4f6f8;
  --surface-3: #e4e8ec;
  --border: #dfe3e8;
  --border-dark: #c4cdd5;
  --text: #182538;
  --text-muted: #637381;
  --text-sub: #919eab;

  /* 2. Xanh dương đậm Sapo (Primary Brand) */
  --primary: #004899;
  --primary-hover: #003673;
  --primary-active: #002855;
  --primary-soft: #eaf2fb;
  --primary-text: #ffffff;

  /* 3. Ghi nợ - Đỏ gạch Sapo (Nổi bật, dứt khoát) */
  --debt: #de3618;
  --debt-hover: #c42b10;
  --debt-soft: #fdf0ed;

  /* 4. Trả nợ / Bán hàng - Xanh lá Sapo (Tươi tắn, uy tín) */
  --pay: #008848;
  --pay-hover: #00703c;
  --pay-soft: #e6f6ee;

  /* Cảnh báo & trạng thái */
  --warning: #f4811f;
  --warning-soft: #fff6ee;
  --danger: #d82c0d;

  /* 5. Góc bo cong GIẢM ÍT LẠI - Cứng cáp, góc cạnh chuẩn POS/ERP */
  --radius-xs: 2px;
  --radius-sm: 3px;
  --radius: 4px;
  --radius-md: 5px;
  --radius-lg: 6px;
  --radius-full: 4px;

  /* Đổ bóng nhẹ, sắc nét */
  --shadow-sm: 0 1px 2px rgba(24, 37, 56, 0.05);
  --shadow: 0 2px 6px -1px rgba(24, 37, 56, 0.08), 0 1px 3px -1px rgba(24, 37, 56, 0.04);
  --shadow-lg: 0 8px 20px -2px rgba(24, 37, 56, 0.12), 0 2px 6px -1px rgba(24, 37, 56, 0.05);
  --shadow-sheet: 0 -4px 24px rgba(24, 37, 56, 0.14);

  /* Gradient Hero: Xanh dương đậm Sapo */
  --gradient-hero: linear-gradient(135deg, #004899 0%, #002b5e 100%);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111822;
    --surface: #182538;
    --surface-2: #21324a;
    --surface-3: #2d4260;
    --text: #f4f6f8;
    --text-muted: #9aa9bc;
    --border: #2d4260;
    --border-dark: #3e587d;
    --primary: #1976d2;
    --primary-hover: #1565c0;
    --primary-soft: #0e3360;
    --debt: #e53935;
    --debt-soft: #4a1515;
    --pay: #00a854;
    --pay-soft: #083b22;
    --warning: #fb8c00;
    --warning-soft: #4a2c00;
    --shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 28px rgba(0, 0, 0, 0.5);
    --gradient-hero: linear-gradient(135deg, #0d3b66 0%, #08233d 100%);
  }
}

/* Global Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font);
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

input, button, select, textarea {
  font: inherit;
  color: inherit;
}

/* Typography & Utilities */
.text-muted { color: var(--text-muted); }
.text-debt { color: var(--debt); font-weight: 700; }
.text-pay { color: var(--pay); font-weight: 700; }
.fw-bold { font-weight: 700; }
.fw-medium { font-weight: 500; }
.tabular-nums { font-variant-numeric: tabular-nums; }

/* Status / Sync Banner */
.banner {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}
.banner-offline { background: var(--debt); color: #fff; }
.banner-syncing { background: var(--warning); color: #ffffff; }
.banner-warning { background: #fff6ee; color: #b45309; border-bottom-color: #fde68a; }
.banner-danger { background: #fdf0ed; color: #991b1b; border-bottom-color: #fecaca; }
.banner-link { color: inherit; text-decoration: underline; cursor: pointer; }

/* Layout App Shell */
.app-shell {
  display: flex;
  flex-direction: column;
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  position: relative;
  padding-bottom: calc(72px + var(--safe-bottom));
}

@media (min-width: 900px) {
  .app-shell {
    padding-bottom: 24px;
    padding-top: 16px;
  }
}

/* Header */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: var(--shadow-sm);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
}
.brand-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 16px;
}
.brand-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.2px;
}
.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

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

/* Top Sticky Search Bar */
.search-wrapper {
  padding: 12px 16px;
  background: var(--bg);
  position: sticky;
  top: 53px;
  z-index: 30;
}
.search-box {
  position: relative;
  display: flex;
  align-items: center;
}
.search-box input {
  width: 100%;
  height: 44px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 0 40px 0 42px;
  font-size: 15px;
  outline: none;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.search-box input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
}
.search-icon {
  position: absolute;
  left: 14px;
  font-size: 16px;
  color: var(--text-muted);
  pointer-events: none;
}
.search-clear {
  position: absolute;
  right: 12px;
  background: none;
  border: none;
  font-size: 16px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: none;
}

/* Hero Cards (Sapo Navy Style) */
.hero-card {
  background: var(--gradient-hero);
  color: #ffffff;
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin: 4px 16px 14px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.12);
}
.hero-card::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 120px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.04));
  pointer-events: none;
}
.hero-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  opacity: 0.85;
}
.hero-value {
  font-size: 30px;
  font-weight: 800;
  margin: 3px 0 5px;
  letter-spacing: -0.5px;
}
.hero-sub {
  font-size: 12.5px;
  opacity: 0.92;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.hero-badge {
  background: rgba(255, 255, 255, 0.16);
  padding: 2px 7px;
  border-radius: var(--radius-xs);
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Filter Chips (Cứng cáp, bo nhẹ 4px) */
.chip-row {
  display: flex;
  gap: 8px;
  padding: 0 16px 10px;
  overflow-x: auto;
  scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.15s ease;
}
.chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

/* Customer List */
.list-group {
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.customer-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s ease, background-color 0.15s ease, transform 0.1s ease;
  cursor: pointer;
}
.customer-card:hover {
  border-color: var(--border-dark);
  background: #fafbfc;
}
.customer-card:active {
  transform: scale(0.99);
  background: var(--surface-2);
}
.cust-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 16px;
  flex-shrink: 0;
  border: 1px solid rgba(0, 72, 153, 0.15);
}
.cust-info {
  flex: 1;
  min-width: 0;
}
.cust-name {
  font-size: 15.5px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.cust-meta {
  font-size: 12.5px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.cust-balance {
  text-align: right;
  flex-shrink: 0;
}
.cust-balance-amt {
  font-size: 16px;
  font-weight: 800;
}
.cust-balance-sub {
  font-size: 11px;
  color: var(--text-muted);
}

/* Empty States */
.empty-box {
  text-align: center;
  padding: 44px 20px;
  color: var(--text-muted);
}
.empty-icon {
  font-size: 40px;
  margin-bottom: 10px;
}
.empty-title {
  font-size: 16.5px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}

/* Floating Action Button (FAB - Cứng cáp) */
.fab {
  position: fixed;
  bottom: calc(76px + var(--safe-bottom));
  right: 18px;
  background: var(--debt);
  color: #ffffff;
  padding: 12px 18px;
  border-radius: var(--radius);
  box-shadow: 0 4px 14px rgba(222, 54, 24, 0.35);
  font-size: 15px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 8px;
  border: none;
  cursor: pointer;
  z-index: 50;
  transition: transform 0.15s ease, background-color 0.15s ease;
}
.fab:hover {
  background: var(--debt-hover);
}
.fab:active {
  transform: scale(0.96);
  background: var(--debt-hover);
}

@media (min-width: 900px) {
  .fab {
    bottom: 28px;
    right: 28px;
  }
}

/* Bottom Navigation (Mobile) */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(60px + var(--safe-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: var(--safe-bottom);
  z-index: 45;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.04);
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  gap: 3px;
  transition: color 0.15s ease;
  position: relative;
}
.nav-item.active {
  color: var(--primary);
  font-weight: 700;
}
.nav-icon {
  font-size: 18px;
}
.badge-count {
  position: absolute;
  top: 4px;
  right: 25%;
  background: var(--debt);
  color: #fff;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: var(--radius-xs);
  font-weight: 800;
}

/* Desktop 2-Column Layout */
@media (min-width: 900px) {
  .desktop-layout {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 20px;
    padding: 0 16px;
  }
  .desktop-sidebar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    height: calc(100vh - 100px);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 76px;
    box-shadow: var(--shadow-sm);
  }
  .desktop-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 22px;
    min-height: calc(100vh - 100px);
    box-shadow: var(--shadow-sm);
  }
}

/* Buttons (Cứng cáp, bo nhẹ 4px) */
.btn {
  height: 44px;
  border-radius: var(--radius);
  padding: 0 16px;
  font-size: 14.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-debt { background: var(--debt); color: #fff; }
.btn-debt:hover { background: var(--debt-hover); }
.btn-pay { background: var(--pay); color: #fff; }
.btn-pay:hover { background: var(--pay-hover); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-3); border-color: var(--border-dark); }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--surface-2); border-color: var(--border-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; pointer-events: none; }

/* Forms & Inputs */
.form-group {
  margin-bottom: 14px;
}
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 5px;
}
.form-input {
  width: 100%;
  height: 44px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 0 14px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
}

/* Big Money Input in Entry Sheet */
.money-input-wrapper {
  position: relative;
  margin: 10px 0;
}
.money-input {
  width: 100%;
  height: 58px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  background: var(--surface);
  padding: 0 44px 0 14px;
  font-size: 30px;
  font-weight: 800;
  text-align: right;
  font-variant-numeric: tabular-nums;
  outline: none;
  transition: border-color 0.15s ease;
}
.money-input:focus {
  border-color: var(--primary);
}
.money-unit {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 18px;
  font-weight: 700;
  color: var(--text-muted);
}

/* Quick Add Money Chips */
.quick-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.quick-chip {
  padding: 6px 11px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.1s ease;
}
.quick-chip:hover {
  border-color: var(--border-dark);
}
.quick-chip:active {
  background: var(--primary-soft);
  color: var(--primary);
  transform: scale(0.96);
}

/* Bottom Sheet Modal (Bo góc nhẹ 8px) */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 34, 0.5);
  backdrop-filter: blur(2px);
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}
.sheet-backdrop.open {
  opacity: 1;
  visibility: visible;
}
.sheet-content {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 560px;
  margin: 0 auto;
  background: var(--surface);
  border-radius: 8px 8px 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
  padding: 14px 18px calc(18px + var(--safe-bottom));
  box-shadow: var(--shadow-sheet);
  z-index: 201;
  transform: translateY(100%);
  transition: transform 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
  max-height: 90vh;
  overflow-y: auto;
}
.sheet-backdrop.open .sheet-content {
  transform: translateY(0);
}
.sheet-bar {
  width: 36px;
  height: 4px;
  background: var(--border-dark);
  border-radius: 2px;
  margin: 0 auto 12px;
}

/* Segmented Toggle (Bo góc nhẹ 4px) */
.segmented {
  display: flex;
  background: var(--surface-2);
  padding: 3px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 14px;
}
.segmented-btn {
  flex: 1;
  height: 38px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  color: var(--text-muted);
}
.segmented-btn.active-debt {
  background: var(--debt);
  color: #ffffff;
  box-shadow: var(--shadow-sm);
}
.segmented-btn.active-pay {
  background: var(--pay);
  color: #ffffff;
  box-shadow: var(--shadow-sm);
}

/* Modals & Dialogs (Bo góc nhẹ 6px) */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 34, 0.55);
  backdrop-filter: blur(2px);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  visibility: hidden;
  transition: all 0.18s ease;
}
.modal-backdrop.open {
  opacity: 1;
  visibility: visible;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  max-width: 440px;
  width: 100%;
  padding: 20px;
  box-shadow: var(--shadow-lg);
  transform: scale(0.95);
  transition: transform 0.18s ease;
}
.modal-backdrop.open .modal-box {
  transform: scale(1);
}
.modal-title {
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 6px;
}
.modal-body {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 18px;
  line-height: 1.5;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Toast Notifications (Bo nhẹ 4px) */
.toast-container {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 90%;
  max-width: 380px;
  pointer-events: none;
}
.toast {
  background: #182538;
  color: #ffffff;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  pointer-events: auto;
  border: 1px solid rgba(255, 255, 255, 0.1);
  animation: toastIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.toast-success { background: #00703c; color: #ffffff; }
.toast-error { background: #c42b10; color: #ffffff; }
.toast-info { background: #004899; color: #ffffff; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Print Preview Box */
.receipt-preview-wrap {
  background: var(--surface-2);
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: flex;
  justify-content: center;
  margin: 14px 0;
  overflow-x: auto;
}
