/**
 * components.css
 * ─────────────────────────────────────────────────────
 * Buttons, inputs, cards, modals, toasts, table items
 * ─────────────────────────────────────────────────────
 */

/* ══════════════════════════════════════════════════
   BUTTONS
══════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--r);
  font-weight: 700;
  font-size: .8rem;
  font-family: inherit;
  letter-spacing: .02em;
  transition: all .15s;
  cursor: pointer;
  border: none;
  line-height: 1;
}

.btn:disabled { opacity: .35; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: scale(.96); }

.btn-full  { width: 100%; }
.btn-sm    { padding: 6px 12px; font-size: .7rem; border-radius: var(--r-sm); }
.btn-lg    { padding: 14px 20px; font-size: .95rem; }

/* Màu sắc */
.btn-orange { background: var(--orange);   color: #fff; }
.btn-orange:hover:not(:disabled) { background: var(--orange2); }

.btn-green  { background: var(--green);    color: #fff; }
.btn-green:hover:not(:disabled)  { background: var(--green2); }

.btn-blue   { background: var(--blue);     color: #fff; }
.btn-blue:hover:not(:disabled)   { background: var(--blue2); }

.btn-red    { background: var(--red);      color: #fff; }
.btn-red:hover:not(:disabled)    { background: var(--red2); }

.btn-amber  { background: var(--amber);    color: #fff; }
.btn-amber:hover:not(:disabled)  { filter: brightness(1.1); }

.btn-slate  { background: var(--bg3);      color: var(--text); }
.btn-slate:hover:not(:disabled)  { background: var(--bg4); }

.btn-purple { background: var(--purple);   color: #fff; }
.btn-purple:hover:not(:disabled) { filter: brightness(1.1); }

.btn-teal   { background: var(--teal);     color: #fff; }
.btn-teal:hover:not(:disabled)   { filter: brightness(1.1); }

/* ══════════════════════════════════════════════════
   INPUTS
══════════════════════════════════════════════════ */
.inp {
  background: var(--bg3);
  color: var(--text);
  border: 1.5px solid var(--border);
  border-radius: var(--r);
  padding: 10px 14px;
  font-size: .85rem;
  width: 100%;
  transition: border-color .15s;
}

.inp:focus { border-color: var(--orange); }

.inp-sm {
  padding: 6px 10px;
  font-size: .75rem;
  border-radius: var(--r-sm);
}

select.inp {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M0 0l6 8 6-8z' fill='%2394a3b8'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-color: var(--bg3);
  padding-right: 32px;
}

/* Checkbox */
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.checkbox-row input[type=checkbox] {
  width: 16px;
  height: 16px;
  accent-color: var(--orange);
  cursor: pointer;
}

/* ══════════════════════════════════════════════════
   TABLE CARDS (sơ đồ bàn)
══════════════════════════════════════════════════ */
.table-card {
  background: var(--bg3);
  border: 2px solid var(--dim);
  border-radius: var(--r-lg);
  padding: 14px 8px;
  text-align: center;
  cursor: pointer;
  transition: all .15s;
  position: relative;
  min-height: 95px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.table-card:hover { filter: brightness(1.18); }
.table-card:active { transform: scale(.96); }

.table-card.status-serving {
  background: var(--amber-bg);
  border-color: #f59e0b;
}

.table-card.status-waiting {
  background: var(--red-bg);
  border-color: #f87171;
}

.table-num {
  font-size: 2.2rem;
  font-weight: 900;
  color: var(--text);
  line-height: 1;
}

.table-id {
  font-size: .62rem;
  color: var(--muted);
  margin-top: 3px;
}

.table-status-label {
  font-size: .62rem;
  font-weight: 700;
  margin-top: 4px;
}

.table-total {
  font-size: .72rem;
  font-weight: 900;
  color: #fbbf24;
  margin-top: 5px;
  background: rgba(0,0,0,.35);
  padding: 2px 8px;
  border-radius: 20px;
}

/* Ping dot (chờ TT) */
.ping-dot {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #ef4444;
}

.ping-dot::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid #ef4444;
  animation: ping 1.2s ease-in-out infinite;
}

@keyframes ping {
  0%   { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.8); }
}

/* ══════════════════════════════════════════════════
   CATEGORY BAR (order)
══════════════════════════════════════════════════ */
.cat-bar {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  overflow-x: auto;
  background: rgba(30,41,59,.7);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.cat-bar::-webkit-scrollbar { height: 2px; }
.cat-bar::-webkit-scrollbar-thumb { background: var(--bg3); }

.cat-btn {
  padding: 6px 14px;
  border-radius: var(--r-sm);
  font-size: .7rem;
  font-weight: 700;
  background: var(--bg3);
  color: var(--muted);
  white-space: nowrap;
  transition: all .15s;
  cursor: pointer;
  border: none;
  font-family: inherit;
}

.cat-btn:hover { color: var(--text); background: var(--bg4); }
.cat-btn.active { background: var(--orange); color: #fff; }

/* ══════════════════════════════════════════════════
   MENU CARDS (order)
══════════════════════════════════════════════════ */
.order-search-bar {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.menu-grid {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  align-content: start;
}

.menu-card {
  background: var(--bg3);
  border: 1.5px solid transparent;
  border-radius: var(--r);
  padding: 12px;
  cursor: pointer;
  transition: all .15s;
  text-align: left;
  font-family: inherit;
}

.menu-card:hover  { background: #3f4f61; border-color: rgba(249,115,22,.2); }
.menu-card:active { background: #7c2d12; transform: scale(.97); }

.mc-name  { color: var(--text);   font-weight: 700; font-size: .8rem; line-height: 1.3; }
.mc-desc  { color: var(--dim);    font-size: .65rem; margin-top: 3px; }
.mc-price { color: var(--orange); font-weight: 900; font-size: 1rem;  margin-top: 6px; }

/* ══════════════════════════════════════════════════
   ORDER PANEL (phải)
══════════════════════════════════════════════════ */
.order-panel-header {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.order-table-label {
  font-size: 1.2rem;
  font-weight: 900;
  color: var(--orange);
}

.status-badge {
  font-size: .6rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 20px;
  margin-left: 8px;
  border: 1px solid currentColor;
}

.order-items-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.empty-hint {
  color: var(--dim);
  padding: 40px 10px;
  font-size: .85rem;
}

/* Order item */
.order-item {
  background: rgba(51,65,85,.7);
  border: 1px solid rgba(51,65,85,.5);
  border-radius: var(--r);
  padding: 10px;
}

.oi-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 8px;
}

.oi-name  { color: var(--text);   font-weight: 700; font-size: .75rem; flex: 1; line-height: 1.3; }
.oi-price { color: var(--orange); font-weight: 900; font-size: .75rem; flex-shrink: 0; }

.oi-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 7px;
}

.qty-btn {
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
  font-weight: 900;
  font-size: 1rem;
  background: var(--bg3);
  color: var(--text);
  transition: background .15s;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qty-btn.minus:hover { background: var(--red); }
.qty-btn.plus:hover  { background: var(--green); }

.qty-num {
  color: var(--text);
  font-weight: 900;
  width: 22px;
  text-align: center;
  font-size: .9rem;
}

.oi-note {
  flex: 1;
  min-width: 0;
  background: var(--bg3) !important;
}

.oi-disc {
  display: flex;
  align-items: center;
  gap: 6px;
}

.disc-label { color: var(--muted); font-size: .7rem; }
.disc-inp   { width: 72px !important; background: var(--bg3) !important; }
.disc-unit  { color: var(--muted); font-size: .7rem; }

/* Order footer */
.order-footer {
  padding: 10px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.vat-row {
  margin-bottom: 8px;
  font-size: .78rem;
}

.total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  margin-bottom: 10px;
}

.total-label  { font-weight: 900; font-size: 1rem; }
.total-amount { color: var(--orange); font-weight: 900; font-size: 1.5rem; }

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.action-grid .btn {
  font-size: .65rem;
  padding: 11px 4px;
  letter-spacing: 0;
}

/* ══════════════════════════════════════════════════
   MENU TABLE
══════════════════════════════════════════════════ */
.menu-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.menu-filters {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.table-wrap {
  border-radius: var(--r);
  border: 1px solid var(--border);
  overflow: hidden;
  overflow-x: auto;
}

table  { width: 100%; border-collapse: collapse; font-size: .8rem; }
thead  { background: var(--bg2); }
th     { padding: 12px 16px; text-align: left; color: var(--muted); font-weight: 700; white-space: nowrap; }
td     { padding: 10px 16px; border-top: 1px solid var(--border); vertical-align: middle; }
tr:hover td { background: rgba(30,41,59,.5); }
tr.row-even td { background: rgba(30,41,59,.25); }

.item-name-main { color: var(--text);   font-weight: 700; }
.item-name-desc { color: var(--dim);    font-size: .68rem; margin-top: 2px; }
.td-cat         { color: var(--muted); }
.td-price       { color: var(--orange); font-weight: 900; white-space: nowrap; }
.row-actions    { display: flex; gap: 6px; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .65rem;
  font-weight: 700;
  cursor: pointer;
  transition: filter .15s;
}

.badge:hover { filter: brightness(1.15); }
.badge.on    { background: var(--green-bg); color: #86efac; }
.badge.off   { background: var(--bg3);      color: var(--dim); }

/* ══════════════════════════════════════════════════
   HISTORY
══════════════════════════════════════════════════ */
.hist-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px;
  margin-bottom: 12px;
}

.hist-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.hist-table-id { font-size: 1.1rem; font-weight: 900; }
.hist-time     { color: var(--muted); font-size: .78rem; margin-left: 10px; }
.hist-total    { color: var(--orange); font-weight: 900; font-size: 1.2rem; }
.method-qr     { color: #38bdf8; font-size: .7rem; font-weight: 700; }
.method-cash   { color: #4ade80; font-size: .7rem; font-weight: 700; }

.hist-items { border-top: 1px solid var(--border); padding-top: 10px; }

.hist-item-row {
  display: flex;
  justify-content: space-between;
  font-size: .78rem;
  color: var(--muted);
  padding: 2px 0;
}

.hist-bills       { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.hist-bills-label { color: var(--dim); font-size: .68rem; margin-bottom: 6px; }
.hist-bills-imgs  { display: flex; gap: 8px; flex-wrap: wrap; }

.bill-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform .15s;
}

.bill-thumb:hover { transform: scale(1.08); }

/* ══════════════════════════════════════════════════
   REPORTS
══════════════════════════════════════════════════ */
.rep-period-btn {
  padding: 8px 20px;
  border-radius: var(--r);
  font-size: .8rem;
  font-weight: 700;
  background: var(--bg3);
  color: var(--muted);
  transition: all .15s;
  border: none;
  font-family: inherit;
  cursor: pointer;
}

.rep-period-btn:hover { color: var(--text); }
.rep-period-btn.active { background: var(--orange); color: #fff; box-shadow: 0 4px 12px var(--orange-glow); }

.top-item-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  border-top: 1px solid var(--border);
}

.top-item-row:first-child { border-top: none; }
.top-rank { color: var(--orange); font-weight: 900; width: 22px; text-align: right; }
.top-name { color: var(--text);   font-weight: 700; font-size: .82rem; flex: 1; }

.top-bar-wrap {
  width: 100px;
  height: 7px;
  background: var(--bg3);
  border-radius: 10px;
  overflow: hidden;
}

.top-bar {
  height: 100%;
  background: var(--orange);
  border-radius: 10px;
  transition: width .4s ease;
}

.top-qty { color: var(--orange); font-weight: 900; width: 30px; text-align: right; font-size: .9rem; }

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

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

.modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 24px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  position: relative;
}

.modal-box.sm { max-width: 420px; }
.modal-box.md { max-width: 520px; }

.modal-title {
  font-size: 1.2rem;
  font-weight: 900;
  margin-bottom: 20px;
}

.modal-footer {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

/* QR Modal */
#modal-qr .modal-box { border-color: var(--orange); max-width: 380px; }

.qr-amount {
  color: #fff;
  font-weight: 900;
  font-size: 2.4rem;
  text-align: center;
  margin-bottom: 16px;
}

.qr-image-wrap {
  background: #fff;
  border-radius: var(--r);
  padding: 12px;
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}

#qr-image { width: 220px; height: 220px; object-fit: contain; }

.qr-info { text-align: center; font-size: .82rem; margin-bottom: 20px; }
.qr-info p { color: var(--muted); margin-bottom: 4px; }
.qr-info strong { color: var(--orange); font-size: 1.2rem; }
.qr-info b { color: var(--text); }

/* Camera Modal */
.cam-stage { display: none; }
.cam-stage.show { display: block; }

#cam-video {
  width: 100%;
  border-radius: var(--r);
  background: #000;
  aspect-ratio: 16/9;
  display: block;
  margin-bottom: 12px;
  object-fit: cover;
}

#cam-preview {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border-radius: var(--r);
  background: #000;
  margin-bottom: 12px;
  display: block;
}

.cam-btn-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.cam-error-msg {
  background: var(--red-bg);
  color: #fca5a5;
  padding: 16px;
  border-radius: var(--r);
  text-align: center;
  margin-bottom: 12px;
  font-size: .85rem;
}

/* Confirm Modal */
#modal-confirm .modal-box { max-width: 380px; }

.confirm-msg {
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 28px;
  line-height: 1.5;
}

/* Menu form Modal */
#modal-menu-form .modal-box { max-width: 440px; }

.form-row {
  margin-bottom: 14px;
}

.form-row label {
  display: block;
  color: var(--muted);
  font-size: .72rem;
  margin-bottom: 5px;
}

/* ══════════════════════════════════════════════════
   TOAST
══════════════════════════════════════════════════ */
#toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 18px;
  border-radius: var(--r);
  font-weight: 700;
  font-size: .82rem;
  color: #fff;
  box-shadow: 0 8px 24px rgba(0,0,0,.3);
  opacity: 0;
  transform: translateX(20px);
  transition: all .25s ease;
  pointer-events: auto;
}

.toast.show {
  opacity: 1;
  transform: translateX(0);
}

.toast-success { background: var(--green); }
.toast-error   { background: var(--red);   }
.toast-info    { background: var(--blue);  }
