/*
 * Electro Live Tech — Hulimavu Offline Stocks & POS
 * Clean, Pale Color Palette, No Emojis, Minimal Contrast
 */

:root {
  --bg-app: #f8fafc;
  --bg-surface: #ffffff;
  --bg-muted: #f1f5f9;
  --bg-subtle: #f8fafc;
  --border-light: #e2e8f0;
  --border-medium: #cbd5e1;
  --border-focus: #94a3b8;
  
  --text-main: #1e293b;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  
  --pale-teal: #0f766e;
  --pale-teal-bg: #f0fdfa;
  --pale-teal-border: #ccfbf1;
  
  --pale-blue: #2563eb;
  --pale-blue-bg: #eff6ff;
  --pale-blue-border: #dbeafe;
  
  --pale-green: #047857;
  --pale-green-bg: #ecfdf5;
  --pale-green-border: #a7f3d0;
  
  --pale-amber: #b45309;
  --pale-amber-bg: #fffbeb;
  --pale-amber-border: #fde68a;
  
  --pale-rose: #be123c;
  --pale-rose-bg: #fff1f2;
  --pale-rose-border: #fecdd3;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.03);
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  background-color: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header & Top Bar */
.header-bar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-light);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
  gap: 14px;
}

@media (min-width: 861px) {
  .header-main-row {
    display: contents;
  }
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-main);
}

.brand-badge {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  background: var(--pale-teal-bg);
  color: var(--pale-teal);
  border: 1px solid var(--pale-teal-border);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  letter-spacing: 0.04em;
}

.nav-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-tab-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-size: 0.86rem;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.nav-tab-btn:hover {
  background: var(--bg-muted);
  color: var(--text-main);
}

.nav-tab-btn.active {
  background: var(--pale-teal-bg);
  border-color: var(--pale-teal-border);
  color: var(--pale-teal);
  font-weight: 600;
}

.user-status {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-badge {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--bg-muted);
  padding: 4px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
}

.btn-secondary {
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  color: var(--text-main);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

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

.btn-primary {
  background: var(--pale-teal);
  border: 1px solid var(--pale-teal);
  color: #ffffff;
  font-size: 0.84rem;
  font-weight: 600;
  padding: 7px 15px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.btn-primary:hover {
  background: #0d655f;
}

.btn-danger {
  background: var(--pale-rose-bg);
  border: 1px solid var(--pale-rose-border);
  color: var(--pale-rose);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-danger:hover {
  background: #ffe4e6;
}

/* Layout Container */
.main-content {
  flex: 1;
  padding: 16px 20px;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}

/* Tab Panels */
.tab-panel {
  display: none;
}
.tab-panel.active {
  display: block;
}

/* Cards & Containers */
.panel-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: 16px;
}

.card-header {
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface);
}

.card-title {
  font-size: 0.94rem;
  font-weight: 600;
  color: var(--text-main);
  letter-spacing: -0.01em;
}

.card-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.card-body {
  padding: 16px 18px;
}

/* POS Layout Grid */
.pos-grid {
  display: grid;
  grid-template-columns: 1fr 390px;
  gap: 16px;
  align-items: start;
}

@media (max-width: 980px) {
  .pos-grid {
    grid-template-columns: 1fr;
  }
}

/* Scanner Bar / Gun Input */
.scan-bar-container {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 14px;
}

.scan-input {
  flex: 1;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  padding: 9px 12px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s ease;
  background: var(--bg-subtle);
}

.scan-input:focus {
  border-color: var(--pale-teal);
  background: #ffffff;
}

.sound-toggle-btn {
  background: var(--bg-muted);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

.sound-toggle-btn.sound-on {
  background: var(--pale-teal-bg);
  color: var(--pale-teal);
  border-color: var(--pale-teal-border);
}

/* Cart Table */
.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.86rem;
}

.data-table th {
  background: var(--bg-muted);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-light);
}

.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-main);
  vertical-align: middle;
}

.data-table tr:hover td {
  background: #fafbfd;
}

.table-empty {
  text-align: center;
  padding: 36px 14px;
  color: var(--text-muted);
  font-size: 0.88rem;
}

/* Quantity Adjuster */
.qty-controller {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-surface);
}

.qty-btn {
  background: var(--bg-muted);
  border: none;
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: bold;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
}

.qty-btn:hover {
  background: var(--border-light);
}

.qty-input {
  width: 42px;
  height: 28px;
  border: none;
  text-align: center;
  font-size: 0.86rem;
  font-weight: 600;
  outline: none;
  background: #ffffff;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
}

.badge-in-stock {
  background: var(--pale-green-bg);
  color: var(--pale-green);
  border-color: var(--pale-green-border);
}

.badge-low-stock {
  background: var(--pale-amber-bg);
  color: var(--pale-amber);
  border-color: var(--pale-amber-border);
}

.badge-out-stock {
  background: var(--pale-rose-bg);
  color: var(--pale-rose);
  border-color: var(--pale-rose-border);
}

.badge-special-price {
  background: var(--pale-teal-bg);
  color: var(--pale-teal);
  border-color: var(--pale-teal-border);
}

/* Checkout Summary Card */
.checkout-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  position: sticky;
  top: 76px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 0.86rem;
  color: var(--text-muted);
}

.summary-row.total-row {
  border-top: 1px dashed var(--border-medium);
  margin-top: 8px;
  padding-top: 12px;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
}

.field-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 5px;
  margin-top: 12px;
}

.form-control {
  width: 100%;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  font-size: 0.88rem;
  outline: none;
  background: var(--bg-surface);
  color: var(--text-main);
}

.form-control:focus {
  border-color: var(--pale-teal);
}

.payment-method-group {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin-top: 4px;
}

.payment-option-btn {
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 8px 4px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  text-align: center;
  transition: all 0.15s ease;
}

.payment-option-btn:hover {
  background: var(--bg-muted);
  color: var(--text-main);
}

.payment-option-btn.active {
  background: var(--pale-teal-bg);
  border-color: var(--pale-teal-border);
  color: var(--pale-teal);
  font-weight: 600;
}

.btn-checkout {
  width: 100%;
  margin-top: 16px;
  padding: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  background: var(--pale-teal);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-checkout:hover {
  background: #0d655f;
}

.btn-checkout:disabled {
  background: var(--border-medium);
  cursor: not-allowed;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-overlay.active {
  display: flex;
}

.modal-container {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 0.96rem;
  font-weight: 600;
  color: var(--text-main);
}

.modal-close-btn {
  background: transparent;
  border: none;
  font-size: 1.1rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.modal-body {
  padding: 18px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  background: var(--bg-subtle);
}

/* Camera Scanner Viewport */
.camera-scanner-wrapper {
  background: #0f172a;
  border-radius: var(--radius-md);
  overflow: hidden;
  position: relative;
  min-height: 280px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#camera-reader {
  width: 100% !important;
  border: none !important;
}

/* Horizontal Mirror Flip for Front/Back Camera */
.camera-scanner-wrapper.is-mirrored video,
#camera-reader.is-mirrored video {
  transform: scaleX(-1) !important;
  -webkit-transform: scaleX(-1) !important;
}

.scanner-status-indicator {
  padding: 8px 12px;
  font-size: 0.8rem;
  color: #f1f5f9;
  background: rgba(15, 23, 42, 0.8);
  width: 100%;
  text-align: center;
}

/* Printable Bill / Thermal Receipt */
.receipt-wrapper {
  background: #ffffff;
  color: #000000;
  padding: 16px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 13px;
  line-height: 1.4;
  border: 1px dashed #cbd5e1;
  max-width: 380px;
  margin: 0 auto;
}

.receipt-header {
  text-align: center;
  border-bottom: 1px dashed #000000;
  padding-bottom: 8px;
  margin-bottom: 8px;
}

.receipt-title {
  font-size: 15px;
  font-weight: bold;
}

.receipt-table {
  width: 100%;
  margin: 8px 0;
  border-collapse: collapse;
}

.receipt-table th, .receipt-table td {
  padding: 3px 0;
  text-align: left;
}

.receipt-table .text-right {
  text-align: right;
}

.receipt-divider {
  border-top: 1px dashed #000000;
  margin: 6px 0;
}

/* Admin Dashboard KPI Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}

.kpi-label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.kpi-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-main);
  margin-top: 4px;
}

.kpi-subtext {
  font-size: 0.76rem;
  color: var(--text-subtle);
  margin-top: 2px;
}

/* Utilities */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.font-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
.gap-8 { gap: 8px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }

/* Mobile Responsive System */
@media (max-width: 860px) {
  .header-bar {
    display: flex;
    flex-direction: column;
    padding: 8px 12px;
    gap: 8px;
    position: sticky;
    top: 0;
  }
  .header-main-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    flex-wrap: wrap;
    gap: 8px;
  }
  .brand-title {
    font-size: 0.95rem;
  }
  .user-status {
    gap: 6px;
    flex-wrap: wrap;
  }
  .user-badge {
    padding: 3px 6px;
    font-size: 0.74rem;
  }
  .nav-tabs {
    display: flex;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    padding-bottom: 4px;
    gap: 6px;
    scrollbar-width: none;
  }
  .nav-tabs::-webkit-scrollbar {
    display: none;
  }
  .nav-tab-btn {
    flex-shrink: 0;
    padding: 7px 12px;
    font-size: 0.82rem;
  }
  .main-content {
    padding: 10px 10px;
  }
}

@media (max-width: 640px) {
  /* Prevent iOS Safari input zoom */
  input, select, textarea {
    font-size: 16px !important;
  }

  .main-content {
    padding: 8px 6px;
  }

  /* POS Scanner Bar */
  .scan-bar-container {
    flex-direction: column;
    align-items: stretch;
    padding: 10px;
    gap: 10px;
  }

  .scan-bar-container > div:first-child {
    flex-direction: column;
    gap: 8px;
  }

  .scan-input {
    width: 100%;
    min-height: 42px;
  }

  #pos-manual-add-btn {
    width: 100%;
    justify-content: center;
    min-height: 40px;
  }

  #pos-camera-scan-btn {
    width: 100%;
    justify-content: center;
    min-height: 42px;
    font-weight: 600;
  }

  /* Checkout summary panel */
  .checkout-panel {
    position: static;
    padding: 14px;
    margin-top: 10px;
  }

  .payment-method-group {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .payment-option-btn {
    padding: 10px 4px;
    font-size: 0.86rem;
    min-height: 40px;
  }

  .btn-checkout {
    padding: 14px;
    font-size: 1rem;
    min-height: 46px;
  }

  /* Modals: bottom-sheet on phone screens */
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .modal-container {
    max-width: 100% !important;
    width: 100% !important;
    max-height: 94vh !important;
    border-radius: 16px 16px 0 0 !important;
    margin: 0;
  }

  .modal-header {
    padding: 12px 16px;
  }

  .modal-body {
    padding: 14px 16px;
    -webkit-overflow-scrolling: touch;
  }

  .modal-footer {
    padding: 10px 16px;
    flex-wrap: wrap;
    gap: 6px;
  }

  .modal-footer button {
    flex: 1;
    min-height: 40px;
    justify-content: center;
  }

  /* Responsive Form Grids in Modals */
  div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  /* Tables horizontal scrolling */
  .data-table th, .data-table td {
    padding: 8px 10px;
    font-size: 0.8rem;
  }

  .kpi-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .kpi-card {
    padding: 10px 12px;
  }

  .kpi-value {
    font-size: 1.2rem;
  }

  .card-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .card-header > div:last-child {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .card-header > div:last-child button {
    flex: 1;
    justify-content: center;
    min-height: 38px;
  }

  #inv-search-input, #inv-filter-select, #inv-category-select,
  #inbound-search-input, #sales-search-input, #sales-method-select {
    max-width: 100% !important;
    width: 100% !important;
    min-height: 40px;
  }

  .qty-controller {
    min-height: 34px;
  }
  .qty-btn {
    width: 34px;
    height: 34px;
    font-size: 1.1rem;
  }
  .qty-input {
    width: 44px;
    height: 34px;
    font-size: 0.95rem;
  }
}

@media print {
  body * {
    visibility: hidden;
  }
  .receipt-wrapper, .receipt-wrapper * {
    visibility: visible;
  }
  .receipt-wrapper {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    max-width: 100%;
    border: none;
    padding: 0;
  }
}
