:root {
  --primary: #c0392b;
  --primary-dark: #922b21;
  --accent: #d35400;
  --bg: #faf6f2;
  --card: #ffffff;
  --text: #2c1810;
  --muted: #7f6b62;
  --border: #e8ddd6;
  --success: #27ae60;
  --shadow: 0 2px 12px rgba(44, 24, 16, 0.08);
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  width: 100%;
  max-width: none;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  width: 100%;
  max-width: none;
}

/* Chặn CSS hoá đơn (nếu lỡ inject) làm vỡ layout */
@media print {
  html, body {
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
  }
}

#print-sandbox {
  position: fixed;
  left: -10000px;
  top: 0;
  width: 1px;
  height: 1px;
  overflow: hidden;
  visibility: hidden;
  pointer-events: none;
  border: 0;
}

.navbar {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar-brand { font-weight: 700; font-size: 1.1rem; }
.navbar-brand small { display: block; font-size: 0.75rem; opacity: 0.85; font-weight: 400; }

.navbar-nav { display: flex; gap: 0.25rem; align-items: center; }

.nav-link {
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  transition: background 0.2s;
}
.nav-link:hover, .nav-link.active { background: rgba(255,255,255,0.2); color: #fff; }

.nav-user { font-size: 0.85rem; opacity: 0.9; margin-right: 0.5rem; }

.container { max-width: 1400px; margin: 0 auto; padding: 1.25rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--bg); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #219a52; }
.btn-danger { background: #e74c3c; color: #fff; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.85rem; }
.btn-lg { padding: 0.85rem 1.5rem; font-size: 1.05rem; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.35rem; font-weight: 600; font-size: 0.9rem; }
.form-control {
  width: 100%;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  background: #fff;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(192,57,43,0.15); }

.tabs { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.tab {
  padding: 0.5rem 1.25rem;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.2s;
}
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.search-box { margin-bottom: 1rem; }
.search-box input { max-width: 320px; }

/* POS Layout */
.pos-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 1.25rem;
  align-items: start;
}
.pos-menu-col {
  grid-column: 1;
  min-width: 0;
}
@media (max-width: 900px) {
  .pos-layout { grid-template-columns: 1fr; }
  .pos-menu-col { grid-column: 1; }
  .cart-panel { grid-column: 1; }
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.75rem;
}

.menu-item {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
}
.menu-item:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: var(--shadow); }
.menu-item .name { font-weight: 600; font-size: 0.95rem; margin-bottom: 0.35rem; }
.menu-item .price { color: var(--primary); font-weight: 700; }

.cart-panel {
  display: flex;
  flex-direction: column;
  height: fit-content;
  position: sticky;
  top: 76px;
  grid-column: 2;
  min-width: 380px;
  max-width: 380px;
}
.cart-panel .card-body { padding: 1rem; }
.cart-items { max-height: 400px; overflow-y: auto; margin-bottom: 1rem; }
.cart-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}
.cart-item:last-child { border-bottom: none; }
.cart-item-info { flex: 1; min-width: 0; }
.cart-item-name { font-weight: 600; font-size: 0.9rem; }
.cart-item-price { font-size: 0.8rem; color: var(--muted); }
.qty-control { display: flex; align-items: center; gap: 0.25rem; }
.qty-btn {
  width: 28px; height: 28px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 700;
}
.qty-btn:hover { background: var(--bg); }
.qty-num { min-width: 24px; text-align: center; font-weight: 600; }

.cart-total {
  display: flex;
  justify-content: space-between;
  font-size: 1.25rem;
  font-weight: 700;
  padding: 0.75rem 0;
  border-top: 2px solid var(--border);
  margin-top: 0.5rem;
}
.cart-total span:last-child { color: var(--primary); }

.discount-block {
  margin-bottom: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--border);
}
.discount-block label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  display: block;
  margin-bottom: 0.35rem;
}
.discount-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
.cart-summary {
  font-size: 0.9rem;
  margin-top: 0.25rem;
}
.cart-summary-row {
  display: flex;
  justify-content: space-between;
  padding: 0.2rem 0;
  color: var(--muted);
}
.cart-discount-row {
  color: #c0392b;
  font-weight: 600;
}

.cart-actions { display: flex; flex-direction: column; gap: 0.5rem; }

.empty-cart { text-align: center; color: var(--muted); padding: 2rem 1rem; }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 0.75rem 1rem; text-align: left; border-bottom: 1px solid var(--border); }
th { background: var(--bg); font-weight: 600; font-size: 0.85rem; color: var(--muted); }
tr:hover td { background: #fdfaf8; }

.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-success { background: #d5f5e3; color: #1e8449; }
.badge-muted { background: #eee; color: #666; }

/* Dashboard */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.kpi-card { padding: 1.25rem; }
.kpi-card .label { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.25rem; }
.kpi-card .value { font-size: 1.75rem; font-weight: 700; color: var(--primary); }

.chart-bars { display: flex; align-items: flex-end; gap: 4px; height: 160px; padding: 1rem 0; }
.chart-bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.chart-bar {
  width: 100%;
  max-width: 40px;
  background: linear-gradient(to top, var(--primary), var(--accent));
  border-radius: 4px 4px 0 0;
  min-height: 4px;
}
.chart-label { font-size: 0.65rem; color: var(--muted); writing-mode: vertical-rl; transform: rotate(180deg); max-height: 50px; overflow: hidden; }

.section-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 1rem; }
.page-header { margin-bottom: 1.25rem; }
.page-header h1 { font-size: 1.5rem; margin-bottom: 0.25rem; }
.page-header p { color: var(--muted); font-size: 0.9rem; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
@media (min-width: 900px) {
  .grid-3-admin { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 768px) { .grid-2 { grid-template-columns: 1fr; } }

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 1rem;
}
.modal {
  background: #fff;
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal h2 { margin-bottom: 1rem; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }

.alert {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.alert-error { background: #fdecea; color: #c0392b; border: 1px solid #f5c6cb; }
.alert-success { background: #d5f5e3; color: #1e8449; border: 1px solid #a9dfbf; }
.alert-info { background: #ebf5fb; color: #2471a3; border: 1px solid #aed6f1; }

.hidden { display: none !important; }

.input-with-btn { display: flex; gap: 0.5rem; }
.input-with-btn .form-control { flex: 1; }

.reprint-quick {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border);
}
.reprint-quick label {
  font-size: 0.8rem;
  font-weight: 600;
  display: block;
  margin-bottom: 0.35rem;
  color: var(--muted);
}

.action-btns { display: flex; gap: 0.35rem; flex-wrap: wrap; }

.perms-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.5rem;
}
.perm-item {
  font-size: 0.9rem;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.perm-yes { background: #eafaf1; color: #1e8449; }
.perm-no { background: #f8f9fa; color: #7f6b62; }
.perm-item span { font-weight: 700; }

.modal-lg { max-width: 720px; }

.print-lang-group { margin: 0.75rem 0; }
.print-lang-group label { font-size: 0.85rem; font-weight: 600; margin-bottom: 0.35rem; display: block; }

.print-preview-modal { max-width: 380px; }
.print-preview-modal h2 { margin-bottom: 0.25rem; }
.preview-hint { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.75rem; }
.print-preview-body {
  background: #f5f5f5;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem;
  max-height: 65vh;
  overflow: auto;
  min-height: 200px;
}
.print-preview-body iframe {
  box-shadow: 0 1px 6px rgba(0,0,0,0.12);
}

.bulk-table input.form-control,
.bulk-table select.form-control {
  padding: 0.4rem 0.5rem;
  font-size: 0.9rem;
}
.bulk-table td { padding: 0.35rem 0.25rem; vertical-align: middle; }
.bulk-tabs { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.bulk-tabs .tab { padding: 0.4rem 1rem; font-size: 0.85rem; }

.names-i18n-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
}
.names-i18n-hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
  line-height: 1.4;
}
.name-lang-badge {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.field-hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.35rem;
}
.cat-id-code {
  font-size: 0.8rem;
  background: var(--bg);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

.danger-link {
  display: block;
  margin-top: 0.65rem;
  font-size: 0.8rem;
  color: var(--muted);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
}
.danger-link:hover { color: #c0392b; }

.danger-panel {
  margin-top: 0.75rem;
  padding: 0.85rem;
  border: 1px solid #f5c6cb;
  background: #fdf2f2;
  border-radius: 8px;
}
.danger-warn {
  font-size: 0.85rem;
  color: #922b21;
  margin-bottom: 0.75rem;
  line-height: 1.45;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.modal-header h2 { margin: 0; font-size: 1.2rem; }
.modal-close {
  background: none; border: none; font-size: 1.5rem;
  cursor: pointer; color: var(--muted); line-height: 1;
}
