/* CH Inventory POS - Styles (fixed) */

/* =========================
   1) THEME VARIABLES
   ========================= */
:root {
  /* Palette */
  --primary-color: #667eea;
  --primary-dark: #5a67d8;

  --success-color: #48bb78;
  --success-dark: #2f855a;

  --danger-color: #f56565;
  --danger-dark: #c53030;

  --warning-color: #ed8936;
  --warning-dark: #dd6b20;

  --secondary-color: #6c757d;
  --secondary-dark: #495057;

  /* Surfaces */
  --bg-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --surface: #ffffff;         /* card-like surfaces */
  --card-bg: #ffffff;         /* compatibility with original */
  --background: #ffffff;      /* form inputs / cards */

  /* Text & borders */
  --text-primary: #333333;
  --text-secondary: #666666;
  --text-muted: #999999;
  --border-color: #e1e1e1;

  /* Component colors */
  --input-bg: #ffffff;
  --product-card-bg: #fafafa;
  --cart-item-bg: #f8f9fa;

  /* Alerts (light) */
  --alert-success-bg: #d4edda;
  --alert-success-color: #155724;
  --alert-success-border: #c3e6cb;

  --alert-error-bg: #f8d7da;
  --alert-error-color: #721c24;
  --alert-error-border: #f5c6cb;

  --alert-info-bg: #d1ecf1;
  --alert-info-color: #0c5460;
  --alert-info-border: #bee5eb;

  /* Shadows */
  --shadow: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.1);
}

/* Dark theme overrides */
[data-theme="dark"] {
  --bg-gradient: linear-gradient(135deg, #2c3e50 0%, #34495e 100%);
  --surface: #2c3e50;
  --card-bg: #2c3e50;
  --background: #34495e;

  --text-primary: #ecf0f1;
  --text-secondary: #bdc3c7;
  --text-muted: #95a5a6;
  --border-color: #34495e;

  --input-bg: #34495e;
  --product-card-bg: #34495e;
  --cart-item-bg: #34495e;

  /* Alerts (dark) */
  --alert-success-bg: #27ae60;
  --alert-success-color: #ffffff;
  --alert-success-border: #2ecc71;

  --alert-error-bg: #e74c3c;
  --alert-error-color: #ffffff;
  --alert-error-border: #c0392b;

  --alert-info-bg: #3498db;
  --alert-info-color: #ffffff;
  --alert-info-border: #2980b9;
}

/* =========================
   2) BASE / RESETS
   ========================= */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-gradient);
  color: var(--text-primary);
  line-height: 1.6;
  transition: all 0.3s ease;
}

/* =========================
   3) THEME TOGGLE (fixed top-right)
   ========================= */
.theme-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  background: var(--surface);
  border: 2px solid var(--border-color);
  border-radius: 25px;
  padding: 10px 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-primary);
  transition: all 0.3s ease;
  box-shadow: var(--shadow);
}
.theme-toggle:hover {
  background: var(--primary-color);
  color: #fff;
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}
.theme-toggle-text { font-weight: 500; }

/* Optional header layout wrapper used in your HTML */
.header-actions { display: flex; align-items: center; gap: 32px; position: static; z-index: 1001; }

/* Logout button (keep visible) */
#logout-btn {
  margin-left: 0;
  box-shadow: var(--shadow);
  background: var(--danger-color);
  color: #fff;
  border: 2px solid var(--danger-dark);
  font-weight: bold;
  text-shadow: 0 2px 4px rgba(0,0,0,0.18);
  letter-spacing: 0.5px;
  font-size: 1.1em;
}
.header-title {
  font-size: 2em;
  font-weight: bold;
  color: var(--primary-color);
  margin-bottom: 10px;
  margin-left: 20px;
}

/* =========================
   4) LAYOUT
   ========================= */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 30px;
  min-height: 100vh;
}

/* Sections */
.pos-section,
.cart-section {
  background: var(--surface);
  border-radius: 15px;
  padding: 25px;
  border: 1px solid var(--border-color);
}
.cart-section {
  height: fit-content;
  position: sticky;
  top: 20px;
}

/* =========================
   5) LOGIN FORM
   ========================= */
.login-form {
  max-width: 400px;
  margin: 100px auto;
  padding: 40px;
  background: var(--surface);
  border-radius: 15px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
}
.login-form h1 {
  text-align: center;
  margin-bottom: 30px;
  color: var(--primary-color);
}

/* =========================
   6) FORMS
   ========================= */
.form-group { margin-bottom: 20px; }
.form-group label {
  display: block;
  margin-bottom: 5px;
  font-weight: 500;
  color: var(--text-secondary);
}
.form-group input,
.form-group select {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-size: 16px;
  background: var(--background);
  color: var(--text-primary);
  transition: all 0.3s ease;
}
.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(102,126,234,0.1);
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
}

/* =========================
   7) BUTTONS
   ========================= */
.btn {
  padding: 12px 20px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  text-decoration: none;
  display: inline-block;
  text-align: center;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--primary-color); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-success { background: var(--success-color); color: #fff; }
.btn-success:hover:not(:disabled) { background: var(--success-dark); transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-danger { background: var(--danger-color); color: #fff; border: 2px solid var(--danger-dark); font-weight: bold; text-shadow: 0 2px 4px rgba(0,0,0,0.18); }
.btn-danger:hover:not(:disabled) { background: var(--danger-dark); transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-warning { background: var(--warning-color); color: #fff; }
.btn-warning:hover:not(:disabled) { background: var(--warning-dark); transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-secondary { background: var(--secondary-color); color: #fff; }
.btn-secondary:hover:not(:disabled) { background: var(--secondary-dark); transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-info { background: #3182ce; color: #fff; }
.btn-info:hover:not(:disabled) { background: #2c5282; transform: translateY(-1px); box-shadow: var(--shadow); }

/* =========================
   8) TABS
   ========================= */
.tab-container {
  display: flex;
  background: var(--border-color);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 20px;
}
.tab-btn {
  flex: 1;
  padding: 12px 20px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 8px;
  font-weight: 500;
  transition: all 0.3s ease;
}
.tab-btn.active,
.tab-btn:hover {
  background: var(--primary-color);
  color: #fff;
  transform: translateY(-1px);
}
.tab-content { display: none; }
.tab-content.active { display: block; }

/* =========================
   9) SEARCH / FILTERS
   ========================= */
.search-bar { margin-bottom: 20px; }
.search-bar input {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-size: 16px;
  background: var(--background);
  color: var(--text-primary);
}
.category-filters {
  display: flex;
  gap: 10px;
  margin-bottom: 25px;
  flex-wrap: wrap;
}
.category-btn {
  padding: 8px 16px;
  border: 2px solid var(--border-color);
  background: var(--background);
  color: var(--text-secondary);
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 14px;
}
.category-btn.active,
.category-btn:hover {
  background: var(--primary-color);
  color: #fff;
  border-color: var(--primary-color);
  transform: translateY(-1px);
}

/* =========================
   10) PRODUCTS GRID
   ========================= */
.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px,1fr));
  gap: 15px;
}
.product-card {
  background: var(--background);
  border: 2px solid var(--border-color);
  border-radius: 12px;
  padding: 15px;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
}
.product-card:hover { border-color: var(--primary-color); transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.product-card.out-of-stock { opacity: 0.6; cursor: not-allowed; }
.product-card.virtual-product {
  border-color: var(--warning-color);
  background: linear-gradient(135deg, rgba(237,137,54,0.1), rgba(221,107,32,0.1));
}
.product-name { font-weight: 600; color: var(--text-primary); margin-bottom: 5px; }
.product-details { font-size: 12px; color: var(--text-secondary); margin-bottom: 8px; }
.product-price { font-size: 18px; font-weight: 700; color: var(--primary-color); margin-bottom: 8px; }
.product-stock {
  font-size: 11px; padding: 4px 8px; border-radius: 20px; font-weight: 500;
  position: absolute; top: 10px; right: 10px;
}
.stock-good { background: rgba(72,187,120,0.2); color: var(--success-color); }
.stock-low  { background: rgba(237,137,54,0.2); color: var(--warning-color); }
.stock-out  { background: rgba(245,101,101,0.2); color: var(--danger-color); }

/* =========================
   11) CART
   ========================= */
.cart { display: flex; flex-direction: column; height: 100%; }
.cart-items { flex: 1; max-height: 400px; overflow-y: auto; margin-bottom: 20px; }
.empty-cart { text-align: center; color: var(--text-secondary); padding: 40px 20px; font-size: 16px; }
.cart-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 15px; background: var(--cart-item-bg); border-radius: 10px;
  margin-bottom: 10px; border: 1px solid var(--border-color);
}
.cart-item-info { flex: 1; }
.cart-item-name { font-weight: 600; color: var(--text-primary); margin-bottom: 4px; }
.cart-item-details { font-size: 12px; color: var(--text-secondary); }
.cart-item-controls { display: flex; align-items: center; gap: 5px; }
.qty-btn {
  background: var(--primary-color); color: #fff; border: none; border-radius: 50%;
  width: 30px; height: 30px; cursor: pointer; font-weight: bold; transition: all 0.3s ease;
}
.qty-btn:hover { background: var(--primary-dark); transform: scale(1.1); }
.qty-display {
  background: var(--background); border: 2px solid var(--border-color); border-radius: 8px;
  padding: 5px 10px; min-width: 40px; text-align: center; font-weight: 600; color: var(--text-primary);
}

/* Cart totals */
.cart-total { border-top: 2px solid var(--border-color); padding-top: 15px; margin-bottom: 20px; }
.total-line { display: flex; justify-content: space-between; align-items: center; padding: 5px 0; color: var(--text-secondary); }
.total-final { font-size: 18px; font-weight: 700; color: var(--text-primary); border-top: 1px solid var(--border-color); padding-top: 10px; margin-top: 5px; }

/* Member balance block */
.member-balance {
  background: var(--cart-item-bg); border: 1px solid var(--border-color);
  border-radius: 8px; padding: 12px; margin-bottom: 15px;
}
.balance-info { font-weight: 600; text-align: center; }
.balance-status { display: block; font-size: 12px; margin-top: 4px; }
.balance-owed { color: var(--danger-color); }
.balance-credit { color: var(--success-color); }
.balance-even { color: var(--text-secondary); }

/* =========================
   12) ALERTS & LOADING
   ========================= */
.alert {
  padding: 15px; border-radius: 8px; margin-bottom: 20px; font-weight: 500;
}
.alert-success { background: var(--alert-success-bg); color: var(--alert-success-color); border: 1px solid var(--alert-success-border); }
.alert-error   { background: var(--alert-error-bg);   color: var(--alert-error-color);   border: 1px solid var(--alert-error-border); }
.alert-info    { background: var(--alert-info-bg);    color: var(--alert-info-color);    border: 1px solid var(--alert-info-border); }
.loading { text-align: center; color: var(--text-secondary); padding: 40px; font-size: 16px; }

/* =========================
   13) MEMBER MANAGEMENT
   ========================= */
.member-list { max-height: 600px; overflow-y: auto; }
.member-card {
  background: var(--background); border: 1px solid var(--border-color);
  border-radius: 10px; padding: 20px; margin-bottom: 15px; transition: all 0.3s ease;
}
.member-card:hover { border-color: var(--primary-color); box-shadow: var(--shadow); }
.member-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 15px; }
.member-name { font-size: 18px; font-weight: 600; color: var(--text-primary); margin-bottom: 5px; }
.member-details { font-size: 14px; color: var(--text-secondary); margin-bottom: 5px; }
.member-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.member-info { flex: 1; }

/* =========================
   14) MODALS
   ========================= */
.modal {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.5); display: flex; justify-content: center; align-items: center; z-index: 1000;
}
.modal-content {
  background: var(--surface); border-radius: 15px; padding: 30px; max-width: 500px; width: 90%;
  max-height: 80%; overflow-y: auto; border: 1px solid var(--border-color);
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 25px;
  padding-bottom: 15px; border-bottom: 1px solid var(--border-color);
}
.modal-header h3 { color: var(--text-primary); margin: 0; }
.modal-actions { display: flex; gap: 15px; justify-content: flex-end; margin-top: 25px; }

/* =========================
   15) SALES / CARDS
   ========================= */
.card {
  background: var(--surface); border: 1px solid var(--border-color); border-radius: 12px;
  padding: 20px; box-shadow: var(--shadow); color: var(--text-primary); transition: all 0.3s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.card h3 { margin: 0 0 15px 0; color: var(--text-primary); font-size: 1.1em; font-weight: 600; }

/* Gradient stat cards */
.gradient-green { background: linear-gradient(135deg, #4CAF50, #45a049); color: #fff !important; }
.gradient-blue  { background: linear-gradient(135deg, #2196F3, #1976D2); color: #fff !important; }
.gradient-orange{ background: linear-gradient(135deg, #FF9800, #F57C00); color: #fff !important; }
.gradient-purple{ background: linear-gradient(135deg, #9C27B0, #7B1FA2); color: #fff !important; }
.gradient-gray   { background: linear-gradient(135deg, #757575, #bdbdbd); color: #fff !important; }
.gradient-teal   { background: linear-gradient(135deg, #009688, #26a69a); color: #fff !important; }
.gradient-green h3, .gradient-blue h3, .gradient-orange h3, .gradient-purple h3 { color: #fff !important; margin: 0 0 10px 0; }
.gradient-gray h3, .gradient-teal h3 { color: #fff !important; margin: 0 0 10px 0; }
.stat-value { color: #fff !important; font-size: 2em; font-weight: bold; margin: 10px 0; }
.stat-label { color: rgba(255,255,255,0.8) !important; margin-top: 5px; font-size: 0.9em; }

/* Sales lists */
.sales-view { margin-top: 20px; animation: fadeIn 0.3s ease; }
.payment-methods, .top-products { max-height: 300px; overflow-y: auto; }
.payment-method-item, .top-product-item {
  display: flex; justify-content: space-between; align-items: center; padding: 12px;
  background: var(--cart-item-bg); border-radius: 8px; margin-bottom: 10px; border-left: 4px solid var(--primary-color);
}
.payment-method-item:hover, .top-product-item:hover { background: var(--border-color); }
.payment-method-name, .top-product-name { font-weight: 600; color: var(--text-primary); }
.payment-method-stats, .top-product-stats { text-align: right; font-size: 0.9em; color: var(--text-secondary); }
.payment-method-revenue, .top-product-revenue { font-weight: bold; color: var(--text-primary); margin-bottom: 2px; }
.top-product-category, .top-product-quantity { font-size: 12px; color: var(--text-secondary); }

/* =========================
   16) ANIMATIONS
   ========================= */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* =========================
   17) RESPONSIVE
   ========================= */
@media (max-width: 768px) {
  .container { grid-template-columns: 1fr; padding: 10px; gap: 20px; }
  .cart-section { position: relative; top: auto; }
  .products-grid { grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); }
  .form-row { grid-template-columns: 1fr; }
  .member-actions { flex-direction: column; }
  .modal-content { width: 95%; padding: 20px; }
  .theme-toggle { top: 10px; right: 10px; padding: 8px 12px; font-size: 13px; }
  .theme-toggle-text { display: none; }
}

/* =========================
   18) PERFORMANCE & A11Y
   ========================= */
.product-card, .cart-item, .member-card { contain: layout; }
.btn:focus, .tab-btn:focus, .category-btn:focus { outline: 2px solid var(--primary-color); outline-offset: 2px; }

/* =========================
   19) PRINT
   ========================= */
@media print {
  .theme-toggle, .modal, .cart-section { display: none !important; }
  body { background: #fff; color: #000; }
}

/* === Compat bridge for new index.html structure === */

/* Header */
.header {
  max-width: 1400px;
  margin: 20px auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header-title {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-primary);
}
.header-title .version {
  font-size: 0.75em;
  color: var(--text-secondary);
  margin-left: 8px;
}

/* Tabs wrapper (distinct from .tab-container used in Sales toggle) */
.tabs {
  max-width: 1400px;
  margin: 0 auto 20px;
  padding: 0 20px;
}
.tabs .tab-btn {
  margin-right: 8px;
}

/* POS layout columns */
.pos-layout {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px 30px;
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 30px;
}

/* New section names */
.products-section {
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: 15px;
  padding: 20px;
}
.section-title {
  font-weight: 700;
  font-size: 1.2rem;
  margin-bottom: 12px;
  color: var(--text-primary);
}
.product-controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 12px;
}
.search-group { width: 100%; }

/* Cart section already styled; ensure spacing is nice */
.cart-section .section-title { margin-bottom: 12px; }

/* Generic form control (used everywhere) */
.form-control {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-size: 16px;
  background: var(--background);
  color: var(--text-primary);
  transition: all 0.3s ease;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(102,126,234,0.1);
}

/* Full-width button helper */
.btn-block { width: 100%; }

/* Totals renamed from .total-line to .total-row in new HTML */
.total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  color: var(--text-secondary);
  font-weight: 500;
}
#cart-total { border-top: 2px solid var(--border-color); padding-top: 12px; }

/* Member section (dropdown + balance) */
.member-section { margin-bottom: 12px; }
.member-balance { margin-top: 10px; }

/* Login screen */
#login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
}
.login-container {
  width: min(420px, 92vw);
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 28px;
}
.logo {
  text-align: center;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--primary-color);
  margin-bottom: 18px;
}

/* Modals: close button */
.modal-close {
  background: transparent;
  border: none;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-secondary);
}
.modal-close:hover { color: var(--text-primary); }

/* Members tab header */
.member-header {
  max-width: 1400px;
  margin: 0 auto 16px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.member-search { width: 320px; }

/* Loading block inside lists/cards */
.loading { padding: 20px; font-style: italic; }

/* Responsive */
@media (max-width: 900px) {
  .pos-layout { grid-template-columns: 1fr; gap: 20px; }
  .member-search { width: 100%; }
  .header, .tabs { padding: 0 12px; }
}

/* --- Member card alignment fix --- */
.member-card {
  display: grid;
  grid-template-columns: 1fr auto; /* info | actions */
  gap: 12px;
  align-items: start;
}

.member-card .member-info {
  margin: 0;          /* kill any stray margins */
  justify-self: start;
}

.member-card .member-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-self: end;   /* push buttons to the right */
  justify-content: flex-end;
  align-items: flex-start;
  text-align: right;
}

/* If your markup wraps info + actions in .member-header, align that too */
.member-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: start;
}

/* Mobile: stack; buttons align left so they don’t look crammed */
@media (max-width: 768px) {
  .member-card,
  .member-header {
    grid-template-columns: 1fr;
  }
  .member-card .member-actions {
    justify-self: start;
    text-align: left;
  }
}
