/* ── CSS Custom Properties ─────────────────────────────────────────────── */
:root {
  --bg: #1a1a1a;
  --surface: #2a2a2a;
  --surface2: #333333;
  --accent: #e84c1e;
  --accent-dark: #c0381a;
  --success: #2ecc71;
  --info: #3498db;
  --warning: #f39c12;
  --danger: #e74c3c;
  --text: #f0f0f0;
  --text-muted: #999;
  --border: #444;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 2px 8px rgba(0,0,0,.4);
  --topbar-h: 56px;
}

/* ── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
button { cursor: pointer; font: inherit; }
input, select, textarea { font: inherit; }
ul { list-style: none; }

/* ── Utilities ─────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.text-right { text-align: right; }
.hint { font-size: .8em; color: var(--text-muted); }
.error-msg { color: var(--danger); padding: .5rem; background: rgba(231,76,60,.15); border-radius: var(--radius-sm); }
.no-results { color: var(--text-muted); padding: 2rem; text-align: center; }

/* ── Topbar ────────────────────────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  z-index: 100;
  gap: 1rem;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 1rem; }
.logo-sm { font-weight: 700; font-size: 1.1rem; color: var(--accent); letter-spacing: .05em; }
.page-title { color: var(--text-muted); font-size: .95rem; }

/* ── Logo image ────────────────────────────────────────────────────────── */
/* Logo is black-on-white → invert to white-on-transparent for dark theme  */
.logo-img {
  display: block;
  filter: invert(1);
  object-fit: contain;
}
.logo-img-topbar {
  height: 32px;
  width: auto;
  max-width: 140px;
}
.logo-img-login {
  height: 72px;
  width: auto;
  max-width: 260px;
  margin-bottom: .25rem;
}
.nav-links { display: flex; gap: .75rem; }
.nav-link { color: var(--text-muted); font-size: .9rem; transition: color .2s; }
.nav-link:hover { color: var(--text); text-decoration: none; }
.event-select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: .35rem .75rem;
  border-radius: var(--radius-sm);
  font-size: .9rem;
}

/* ── User badge ────────────────────────────────────────────────────────── */
.user-badge { display: flex; align-items: center; gap: .5rem; }
.user-name { font-weight: 600; }
.user-role { font-size: .75rem; color: var(--text-muted); background: var(--surface2); padding: .1rem .5rem; border-radius: 99px; }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .5rem 1.2rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 500;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { filter: brightness(1.1); }
.btn-info { background: var(--info); color: #fff; }
.btn-info:hover:not(:disabled) { filter: brightness(1.1); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.1); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface2); color: var(--text); }
.btn-sm { padding: .3rem .7rem; font-size: .8rem; }
.btn-lg { padding: .8rem 2rem; font-size: 1.1rem; }
.btn-full { width: 100%; }

/* ── Forms ─────────────────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-group label { font-size: .85rem; color: var(--text-muted); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-check-group { justify-content: flex-end; flex-direction: row; align-items: center; }
.form-check-group label { display: flex; align-items: center; gap: .5rem; color: var(--text); }
input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="search"],
input[type="email"],
select,
textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: .5rem .75rem;
  border-radius: var(--radius-sm);
  transition: border-color .15s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}
input[type="file"] {
  padding: .4rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  width: 100%;
}

/* ── Modals ────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-wide { max-width: 640px; }
.modal-title { font-size: 1.2rem; margin-bottom: 1.25rem; }
.modal-form { display: flex; flex-direction: column; gap: 1rem; }
.modal-footer { display: flex; gap: .75rem; justify-content: flex-end; margin-top: .5rem; }

/* ── Badges ────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .15rem .6rem;
  border-radius: 99px;
  font-size: .78rem;
  font-weight: 600;
}
.badge-cash { background: rgba(46,204,113,.2); color: var(--success); }
.badge-card { background: rgba(52,152,219,.2); color: var(--info); }
.badge-active { background: rgba(46,204,113,.2); color: var(--success); }
.badge-inactive { background: rgba(231,76,60,.2); color: var(--danger); }
.badge-role-admin { background: rgba(232,76,30,.2); color: var(--accent); }
.badge-role-owner { background: rgba(243,156,18,.2); color: var(--warning); }
.badge-role-seller { background: rgba(153,153,153,.2); color: var(--text-muted); }

/* ── Tables ────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.data-table th {
  background: var(--surface2);
  padding: .6rem 1rem;
  text-align: left;
  font-weight: 600;
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.data-table td { padding: .7rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--surface2); }
.tx-row { cursor: pointer; }
.tx-detail-row td { background: var(--bg); padding: 0; }
.detail-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.detail-table th, .detail-table td { padding: .5rem 1.5rem; border-bottom: 1px solid var(--border); }
.detail-table th { background: transparent; text-transform: none; font-size: .85rem; }

/* ── LOGIN PAGE ────────────────────────────────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-container {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 380px;
}
.login-logo { display: flex; flex-direction: column; align-items: center; margin-bottom: 2rem; gap: .5rem; }
.logo-sub { font-size: .8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .15em; }
.login-form { display: flex; flex-direction: column; gap: 1rem; }

/* ── POS PAGE ──────────────────────────────────────────────────────────── */
.pos-page { padding-top: var(--topbar-h); height: 100vh; display: flex; flex-direction: column; }
.barcode-input {
  position: absolute;
  top: -9999px;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}
.pos-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  flex: 1;
  overflow: hidden;
}

/* Products panel */
.pos-products {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--border);
}
.search-bar { padding: .75rem 1rem; border-bottom: 1px solid var(--border); }
.search-bar input { background: var(--surface2); }
.category-tabs {
  display: flex;
  gap: .5rem;
  padding: .5rem 1rem;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
}
.tab-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: .35rem .9rem;
  border-radius: 99px;
  font-size: .85rem;
  white-space: nowrap;
  transition: all .15s;
}
.tab-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.tab-btn:hover:not(.active) { background: var(--surface); color: var(--text); }

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(202px, 1fr));
  grid-auto-rows: min-content;
  gap: .75rem;
  padding: 1rem;
  overflow-y: auto;
  align-content: start;
  flex: 1;
}
.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform .1s, border-color .15s;
  display: flex;
  flex-direction: column;
  aspect-ratio: 1 / 1;
}
.product-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.product-card.out-of-stock { opacity: .5; cursor: not-allowed; }
.product-img-wrap { flex: 1; background: var(--surface2); display: flex; align-items: center; justify-content: center; overflow: hidden; min-height: 0; }
.product-img-wrap img { width: 100%; height: 100%; object-fit: cover; }
.no-img { font-size: 2rem; }
.product-info { padding: .4rem .5rem; display: flex; flex-direction: column; gap: .1rem; flex-shrink: 0; }
.product-name { font-size: .8rem; font-weight: 600; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.product-price { font-size: .95rem; color: var(--accent); font-weight: 700; }
.product-stock { font-size: .7rem; color: var(--text-muted); }
.product-stock.low-stock { color: var(--warning); }

/* Cart */
.pos-cart {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  overflow: hidden;
}
.cart-title { padding: 1rem; font-size: 1rem; font-weight: 700; border-bottom: 1px solid var(--border); }
.cart-items { flex: 1; overflow-y: auto; padding: .5rem; display: flex; flex-direction: column; gap: .5rem; }
.cart-empty { color: var(--text-muted); text-align: center; padding: 2rem; }
.cart-item {
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: .5rem .75rem;
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: .5rem;
  font-size: .9rem;
}
.cart-item-name { font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cart-item-controls { display: flex; align-items: center; gap: .25rem; }
.cart-item-price { font-weight: 600; color: var(--accent); white-space: nowrap; }
.qty-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  line-height: 1;
}
.qty-btn:hover { background: var(--accent); border-color: var(--accent); }
.qty-val { min-width: 24px; text-align: center; }
.remove-btn { background: none; border: none; color: var(--text-muted); font-size: 1rem; line-height: 1; padding: .25rem; }
.remove-btn:hover { color: var(--danger); }
.cart-footer { padding: 1rem; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: .75rem; }
.cart-total { display: flex; justify-content: space-between; align-items: center; font-size: 1.1rem; }
.cart-total strong { font-size: 1.4rem; color: var(--accent); }
.btn-pay { padding: .9rem; font-size: 1.1rem; font-weight: 700; letter-spacing: .05em; }

/* Checkout modal */
.checkout-items { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1rem; }
.checkout-item { display: flex; justify-content: space-between; padding: .35rem 0; border-bottom: 1px solid var(--border); }
.checkout-event-row { font-size: .9rem; color: var(--text-muted); margin-bottom: .75rem; }
.checkout-total { font-size: 1.3rem; font-weight: 700; text-align: right; }
#checkout-modal .modal-footer { justify-content: center; gap: 1rem; flex-wrap: wrap; }

/* Flash success */
.flash-success {
  position: fixed;
  inset: 0;
  background: rgba(46,204,113,.25);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  pointer-events: none;
  animation: flash-fade 1.5s ease forwards;
}
.flash-content { font-size: 3rem; font-weight: 800; color: var(--success); }
@keyframes flash-fade { 0% { opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; } }

/* ── INVENTORY PAGE ────────────────────────────────────────────────────── */
.inventory-page { padding-top: var(--topbar-h); }
.inventory-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: calc(100vh - var(--topbar-h));
  overflow: hidden;
}
.inv-categories {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.inv-panel-header {
  padding: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  gap: .5rem;
}
.inv-panel-header h2 { font-size: 1rem; font-weight: 600; }
.category-list { flex: 1; overflow-y: auto; }
.cat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.cat-item:hover { background: var(--surface2); }
.cat-item.active { background: var(--surface2); border-left: 3px solid var(--accent); }
.cat-actions { display: flex; gap: .25rem; opacity: 0; transition: opacity .15s; }
.cat-item:hover .cat-actions { opacity: 1; }

.inv-products { overflow-y: auto; }
.product-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  padding: 1rem;
}
.inv-product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  gap: .75rem;
  padding: .75rem;
  align-items: flex-start;
}
.inv-product-card.inactive { opacity: .6; }
.inv-product-img { width: 70px; height: 70px; flex-shrink: 0; background: var(--surface2); border-radius: var(--radius-sm); overflow: hidden; display: flex; align-items: center; justify-content: center; }
.prod-image-preview { width: 80px; height: 80px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border); margin-bottom: .4rem; display: block; }
.inv-product-img img { width: 100%; height: 100%; object-fit: cover; }
.inv-product-details { flex: 1; display: flex; flex-direction: column; gap: .2rem; min-width: 0; }
.inv-product-name { font-weight: 600; font-size: .95rem; }
.inv-product-cat { font-size: .75rem; color: var(--text-muted); }
.inv-barcode { font-size: .75rem; color: var(--text-muted); font-family: monospace; }
.inv-price { font-size: 1rem; color: var(--accent); font-weight: 700; }
.stock-control { display: flex; align-items: center; gap: .35rem; margin-top: .25rem; }
.stock-val { min-width: 30px; text-align: center; font-weight: 600; }
.inv-product-actions { display: flex; flex-direction: column; gap: .35rem; flex-shrink: 0; }

/* ── FINANCE PAGE ──────────────────────────────────────────────────────── */
.finance-page { padding-top: var(--topbar-h); }
.finance-content { padding: 1.5rem; max-width: 1200px; margin: 0 auto; }
.summary-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1.5rem; }
.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: .35rem;
}
.summary-label { font-size: .8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.summary-value { font-size: 1.8rem; font-weight: 700; color: var(--accent); }
.filter-bar { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; background: var(--surface); padding: 1rem; border-radius: var(--radius); border: 1px solid var(--border); }
.filter-bar label { display: flex; align-items: center; gap: .5rem; font-size: .9rem; }
.filter-bar input[type="date"], .filter-bar select { width: auto; }
.toggle-col { color: var(--text-muted); font-size: .75rem; }

/* ── ADMIN PAGE ────────────────────────────────────────────────────────── */
.admin-page { padding-top: var(--topbar-h); }
.admin-content { padding: 1.5rem; max-width: 1100px; margin: 0 auto; }
.admin-tabs { display: flex; gap: .5rem; margin-bottom: 1.5rem; border-bottom: 1px solid var(--border); padding-bottom: 1rem; }
.tab-content { animation: fadeIn .2s; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.tab-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.tab-header h2 { font-size: 1.1rem; }
.metrics-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-bottom: 1.5rem; }
.metrics-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }
.metrics-card h3 { margin-bottom: 1rem; font-size: 1rem; }
.metrics-total { font-size: 1.1rem; color: var(--text-muted); }
.metrics-total strong { color: var(--accent); font-size: 1.4rem; }
.metrics-hint { font-size: .8rem; color: var(--text-muted); margin-top: .4rem; }
.cash-balance { color: var(--accent); font-weight: 600; }

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .pos-layout { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .pos-cart { max-height: 45vh; border-right: none; border-top: 1px solid var(--border); }
  .product-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .inventory-layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .inv-categories { height: 200px; }
  .summary-cards { grid-template-columns: 1fr; }
  .metrics-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .filter-bar { flex-direction: column; align-items: flex-start; }
}
