/* ── Variables ───────────────────────────────────────────── */
:root {
  --primary:      #1d4ed8;
  --primary-h:    #1e40af;
  --success:      #16a34a;
  --success-h:    #15803d;
  --danger:       #dc2626;
  --danger-h:     #b91c1c;
  --warning:      #d97706;
  --bg:           #f1f5f9;
  --card:         #ffffff;
  --text:         #1e293b;
  --text-muted:   #64748b;
  --border:       #e2e8f0;
  --radius:       8px;
  --shadow:       0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --nav-h:        56px;
  --cart-w:       320px;
  --cats-w:       180px;
}

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; border: none; background: none; font-family: inherit; font-size: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; }
a { color: inherit; text-decoration: none; }

/* ── Splash / Loading ────────────────────────────────────── */
.splash { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; gap: 12px; }
.splash-icon { font-size: 64px; }

/* ── App layout ──────────────────────────────────────────── */
#app { height: 100%; display: flex; flex-direction: column; }

/* ── Navigation bar ──────────────────────────────────────── */
.navbar {
  height: var(--nav-h); min-height: var(--nav-h);
  background: var(--primary); color: #fff;
  display: flex; align-items: center; gap: 4px;
  padding: 0 8px; box-shadow: 0 2px 4px rgba(0,0,0,.2);
  position: sticky; top: 0; z-index: 100;
}
.navbar-brand { font-size: 18px; font-weight: 700; padding: 0 8px; white-space: nowrap; }
.navbar-nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.navbar-nav::-webkit-scrollbar { display: none; }
.nav-btn {
  padding: 8px 14px; border-radius: var(--radius); font-size: 14px; font-weight: 500;
  color: rgba(255,255,255,.8); white-space: nowrap; transition: background .15s, color .15s;
  min-height: 40px;
}
.nav-btn:hover { background: rgba(255,255,255,.15); color: #fff; }
.nav-btn.active { background: rgba(255,255,255,.2); color: #fff; }
.navbar-user { margin-left: auto; display: flex; align-items: center; gap: 8px; padding: 0 4px; white-space: nowrap; font-size: 13px; }
.navbar-user span { opacity: .8; }
.btn-logout { padding: 6px 12px; border-radius: var(--radius); background: rgba(255,255,255,.15); color: #fff; font-size: 13px; transition: background .15s; min-height: 36px; }
.btn-logout:hover { background: rgba(255,255,255,.25); }

/* ── View container ──────────────────────────────────────── */
.view { flex: 1; overflow: hidden; display: flex; flex-direction: column; }

/* ── ════ LOGIN ════ ──────────────────────────────────────── */
.login-view {
  display: flex; align-items: center; justify-content: center;
  flex: 1; padding: 16px; background: var(--bg);
}
.login-card {
  background: var(--card); border-radius: 16px; padding: 40px 32px;
  width: 100%; max-width: 380px; box-shadow: 0 8px 24px rgba(0,0,0,.12);
  text-align: center;
}
.login-logo { font-size: 48px; margin-bottom: 8px; }
.login-title { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.login-subtitle { color: var(--text-muted); font-size: 14px; margin-bottom: 28px; }
.login-card .form-group { text-align: left; margin-bottom: 16px; }
.login-card .form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text-muted); }
.login-card input {
  width: 100%; padding: 12px 14px; border: 2px solid var(--border);
  border-radius: var(--radius); font-size: 16px; transition: border-color .15s;
}
.login-card input:focus { outline: none; border-color: var(--primary); }
.login-card .btn-primary { width: 100%; margin-top: 8px; }
.login-hint { font-size: 12px; color: var(--text-muted); margin-top: 16px; }
.login-error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; border-radius: var(--radius); padding: 10px 14px; font-size: 14px; margin-bottom: 16px; }

/* ── ════ POS LAYOUT ════ ─────────────────────────────────── */
.pos-view {
  flex: 1; display: grid; overflow: hidden;
  grid-template-columns: var(--cats-w) 1fr var(--cart-w);
  grid-template-rows: 1fr;
}

/* Categories sidebar */
.pos-categories {
  background: var(--card); border-right: 1px solid var(--border);
  overflow-y: auto; padding: 8px;
  display: flex; flex-direction: column; gap: 4px;
}
.cat-btn {
  padding: 12px 10px; border-radius: var(--radius); font-size: 14px; font-weight: 500;
  text-align: left; transition: background .15s, color .15s;
  min-height: 48px; display: flex; align-items: center; gap: 8px;
  color: var(--text);
}
.cat-btn:hover { background: var(--bg); }
.cat-btn.active { background: var(--primary); color: #fff; }
.cat-color-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* Items grid */
.pos-items {
  overflow-y: auto; padding: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  grid-auto-rows: min-content;
  gap: 8px; align-content: start;
}
.item-btn {
  padding: 12px 8px; border-radius: var(--radius); font-size: 14px; font-weight: 600;
  color: #fff; text-align: center; min-height: 80px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  transition: opacity .1s, transform .1s; box-shadow: var(--shadow);
  word-break: break-word; line-height: 1.3;
}
.item-btn:active { opacity: .85; transform: scale(.97); }
.item-btn .item-price { font-size: 12px; opacity: .85; font-weight: 400; }
.items-empty { grid-column: 1/-1; text-align: center; padding: 40px; color: var(--text-muted); }

/* Cart panel */
.pos-cart {
  background: var(--card); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
.cart-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.cart-header h3 { font-size: 15px; font-weight: 700; }
.cart-items { flex: 1; overflow-y: auto; padding: 8px; }
.cart-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--text-muted); gap: 8px; }
.cart-empty-icon { font-size: 40px; }
.cart-item {
  display: grid; grid-template-columns: 1fr auto;
  gap: 4px 8px; align-items: center;
  padding: 8px; border-radius: var(--radius); border: 1px solid var(--border);
  margin-bottom: 6px; background: var(--bg);
}
.cart-item-name { font-size: 14px; font-weight: 600; grid-column: 1; }
.cart-item-price { font-size: 12px; color: var(--text-muted); grid-column: 1; }
.cart-item-controls { display: flex; align-items: center; gap: 4px; grid-column: 2; grid-row: 1 / span 2; }
.qty-btn {
  width: 30px; height: 30px; border-radius: 6px; font-size: 16px; font-weight: 700;
  background: var(--border); color: var(--text); display: flex; align-items: center; justify-content: center;
  transition: background .1s;
}
.qty-btn:hover { background: #cbd5e1; }
.qty-input {
  width: 36px; height: 30px; text-align: center; border: 2px solid var(--border);
  border-radius: 6px; font-size: 14px; font-weight: 600;
}
.qty-input:focus { outline: none; border-color: var(--primary); }
.cart-item-remove {
  width: 28px; height: 28px; border-radius: 6px; color: var(--danger);
  display: flex; align-items: center; justify-content: center; font-size: 16px;
  transition: background .1s;
}
.cart-item-remove:hover { background: #fef2f2; }
.cart-footer {
  border-top: 1px solid var(--border); padding: 12px 14px; flex-shrink: 0;
}
.cart-total { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.cart-total-label { font-size: 14px; color: var(--text-muted); }
.cart-total-amount { font-size: 22px; font-weight: 800; color: var(--success); }
.cart-subtotal { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }

/* Mobile cart toggle */
.cart-mobile-bar { display: none; }

/* ── ════ MANAGEMENT VIEWS ════ ───────────────────────────── */
.mgmt-view { flex: 1; overflow-y: auto; padding: 16px; }
.view-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; gap: 12px; flex-wrap: wrap;
}
.view-header h2 { font-size: 20px; font-weight: 700; }

/* Table */
.table-wrap { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 400px; }
thead { background: var(--bg); }
th { padding: 10px 14px; text-align: left; font-size: 13px; font-weight: 600; color: var(--text-muted); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }

.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-success { background: #dcfce7; color: #15803d; }
.badge-danger  { background: #fef2f2; color: var(--danger); }
.badge-muted   { background: var(--bg); color: var(--text-muted); }

.color-swatch { display: inline-block; width: 20px; height: 20px; border-radius: 4px; vertical-align: middle; margin-right: 6px; border: 1px solid rgba(0,0,0,.1); }

/* ── ════ TRANSACTIONS ════ ───────────────────────────────── */
.filter-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; background: var(--card); padding: 12px 14px; border-radius: var(--radius); box-shadow: var(--shadow); }
.filter-bar label { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.filter-bar input[type="date"] { padding: 8px 10px; border: 2px solid var(--border); border-radius: var(--radius); font-size: 14px; }
.filter-bar input[type="date"]:focus { outline: none; border-color: var(--primary); }

/* ── ════ DAILY SUMMARY ════ ──────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card { background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.stat-label { font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
.stat-value { font-size: 26px; font-weight: 800; color: var(--text); }
.stat-card.primary .stat-value { color: var(--primary); }
.stat-card.success .stat-value { color: var(--success); }

.section-title { font-size: 16px; font-weight: 700; margin-bottom: 12px; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: var(--radius); font-size: 14px; font-weight: 600;
  transition: background .15s, opacity .15s; min-height: 44px; white-space: nowrap;
  border: 2px solid transparent;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-h); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: var(--success-h); }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled)  { background: var(--danger-h); }
.btn-outline { background: transparent; color: var(--text); border-color: var(--border); }
.btn-outline:hover:not(:disabled) { background: var(--bg); }
.btn-sm { padding: 6px 12px; font-size: 13px; min-height: 34px; }
.btn-lg { padding: 14px 22px; font-size: 16px; min-height: 56px; width: 100%; }
.btn-icon { width: 36px; height: 36px; padding: 0; border-radius: var(--radius); display: inline-flex; align-items: center; justify-content: center; font-size: 18px; }
.btn-icon:hover { background: var(--bg); }
.btn-danger-outline { background: transparent; color: var(--danger); border-color: #fecaca; }
.btn-danger-outline:hover:not(:disabled) { background: #fef2f2; }

/* ── Forms ───────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.form-control {
  width: 100%; padding: 10px 12px; border: 2px solid var(--border);
  border-radius: var(--radius); font-size: 15px; transition: border-color .15s;
  background: var(--card); color: var(--text);
}
.form-control:focus { outline: none; border-color: var(--primary); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-check { display: flex; align-items: center; gap: 8px; }
.form-check input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; }

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 16px; animation: fadeIn .15s;
}
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
.modal {
  background: var(--card); border-radius: 12px; width: 100%; max-width: 480px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3); max-height: 90vh; display: flex; flex-direction: column;
  animation: slideUp .15s;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0 } to { transform: none; opacity: 1 } }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.modal-header h3 { font-size: 17px; font-weight: 700; }
.modal-close { width: 32px; height: 32px; border-radius: var(--radius); display: flex; align-items: center; justify-content: center; font-size: 18px; transition: background .1s; }
.modal-close:hover { background: var(--bg); }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; flex-shrink: 0; }

/* Receipt detail */
.receipt-detail { }
.receipt-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; margin-bottom: 16px; font-size: 14px; }
.receipt-meta dt { color: var(--text-muted); font-size: 13px; }
.receipt-meta dd { font-weight: 600; }
.receipt-items-list { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 16px; }
.receipt-item-row { display: grid; grid-template-columns: 1fr auto auto; gap: 4px 12px; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 14px; align-items: center; }
.receipt-item-row:last-child { border-bottom: none; }
.receipt-item-name { font-weight: 600; }
.receipt-item-qty { color: var(--text-muted); font-size: 13px; }
.receipt-total { display: flex; justify-content: space-between; font-size: 16px; font-weight: 700; }

/* Toast notifications */
.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 18px; border-radius: var(--radius); font-size: 14px; font-weight: 500;
  box-shadow: 0 4px 12px rgba(0,0,0,.15); min-width: 240px; max-width: 380px;
  animation: slideInRight .2s; color: #fff;
}
@keyframes slideInRight { from { transform: translateX(100%); opacity: 0 } to { transform: none; opacity: 1 } }
.toast-success { background: var(--success); }
.toast-error   { background: var(--danger); }
.toast-info    { background: var(--primary); }
.toast-warning { background: var(--warning); }

/* Confirm dialog */
.confirm-message { font-size: 15px; line-height: 1.6; margin-bottom: 4px; }

/* Settings view */
.settings-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; max-width: 480px; }
.settings-card h3 { font-size: 16px; font-weight: 700; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }

/* Misc */
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.gap-2 { gap: 8px; }
.flex { display: flex; }
.items-center { align-items: center; }
.w-full { width: 100%; }
.d-none { display: none !important; }

/* ── ════ MOBILE ════ ─────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --cats-w: 0px; --cart-w: 0px; --nav-h: 50px; }

  .pos-view { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }

  /* Categories horizontal scroll on mobile */
  .pos-categories {
    flex-direction: row; overflow-x: auto; overflow-y: hidden;
    padding: 8px; gap: 6px; border-right: none; border-bottom: 1px solid var(--border);
  }
  .cat-btn { white-space: nowrap; min-width: auto; padding: 8px 14px; min-height: 40px; }

  /* Items 2-col grid on mobile */
  .pos-items { grid-template-columns: repeat(2, 1fr); padding: 8px; gap: 6px; }
  .item-btn { min-height: 70px; font-size: 13px; }

  /* Cart as bottom drawer */
  .pos-cart {
    position: fixed; inset: 0; top: auto;
    background: var(--card); z-index: 200;
    max-height: 80vh; border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,.15);
    transform: translateY(100%); transition: transform .25s ease;
  }
  .pos-cart.open { transform: translateY(0); }

  .cart-mobile-bar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 14px; background: var(--success); color: #fff;
    cursor: pointer; flex-shrink: 0;
  }
  .cart-mobile-bar-left { display: flex; align-items: center; gap: 8px; font-weight: 600; }
  .cart-badge { background: #fff; color: var(--success); width: 22px; height: 22px; border-radius: 50%; font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
  .cart-mobile-bar-total { font-size: 18px; font-weight: 800; }

  .navbar-brand { font-size: 16px; }
  .mgmt-view { padding: 10px; }
  .form-row { grid-template-columns: 1fr; }
  .view-header { flex-direction: column; align-items: flex-start; }
  td, th { padding: 8px 10px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 20px; }
}

@media (max-width: 480px) {
  .pos-items { grid-template-columns: repeat(2, 1fr); }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .modal { max-width: 100%; margin: 0; border-radius: 16px 16px 0 0; position: fixed; bottom: 0; left: 0; right: 0; max-height: 95vh; }
  .modal-overlay { align-items: flex-end; padding: 0; }
}
