/* Dark theme — Sabaidee warehouse */
:root {
  --bg: #0f1419;
  --bg2: #1a222d;
  --bg3: #242f3d;
  --border: #2d3a4a;
  --text: #e8edf4;
  --muted: #8b9aad;
  --accent: #3d9cf4;
  --accent2: #2b7fd4;
  --success: #3ecf8e;
  --warn: #f0b429;
  --danger: #e85d6a;
  --font: "Segoe UI", system-ui, sans-serif;
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body.app {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  display: flex;
  min-height: 100vh;
  flex-direction: row;
  align-items: stretch;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: none; }
.sidebar a:hover { color: var(--text); }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Sidebar */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--bg2) 0%, #131a22 100%);
  border-right: 1px solid var(--border);
  z-index: 200;
  min-height: 100vh;
}
.sidebar__brand {
  padding: 1.1rem 1rem 0.9rem;
  border-bottom: 1px solid var(--border);
}
.sidebar__logo {
  display: block;
  line-height: 0;
  color: var(--text) !important;
}
.app-logo--sidebar {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: 8px;
  background: #fff;
  padding: 0.4rem 0.55rem;
  box-sizing: content-box;
}
.guestbar__logo {
  display: block;
  line-height: 0;
}
.app-logo--guestbar {
  max-width: 120px;
  width: 100%;
  height: auto;
  display: block;
  border-radius: 6px;
  background: #fff;
  padding: 0.2rem 0.35rem;
}
.login-card__logo {
  margin: 0 0 1.25rem;
  text-align: center;
  line-height: 0;
  font-size: 0;
}
.app-logo--login {
  max-width: 100%;
  height: auto;
  max-height: 5.5rem;
  width: auto;
}
.sidebar__nav {
  flex: 1;
  padding: 0.6rem 0.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.sidebar__link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  color: var(--text) !important;
  font-size: 0.9rem;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.sidebar__link:hover {
  background: var(--bg3);
  border-color: var(--border);
}
.sidebar__link.is-active {
  background: rgba(61, 156, 244, 0.12);
  border-color: rgba(61, 156, 244, 0.35);
  color: #b8d9fb !important;
  box-shadow: 0 0 0 1px rgba(61, 156, 244, 0.08) inset;
}
.sidebar__ic {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  opacity: 0.9;
  color: var(--accent);
}
.sidebar__link.is-active .sidebar__ic {
  color: var(--accent);
  opacity: 1;
}
.sidebar__tx { flex: 1; min-width: 0; }
.sidebar__link--quit {
  margin-top: 0.25rem;
}
.sidebar__link--quit .sidebar__ic {
  color: var(--muted);
}
.sidebar__link--quit:hover {
  color: #ffb4bc !important;
  border-color: rgba(232, 93, 106, 0.35);
  background: rgba(232, 93, 106, 0.08);
}
.sidebar__footer {
  padding: 0.75rem 0.5rem 1rem;
  border-top: 1px solid var(--border);
  margin-top: auto;
}
.sidebar__user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem 0.75rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.sidebar__user-ic {
  display: flex;
  color: var(--accent);
  opacity: 0.85;
}
.sidebar__user-tx {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 500;
}
.sidebar__lang {
  display: flex;
  gap: 0.35rem;
  padding: 0 0.35rem 0.6rem;
}
.sidebar__lang-btn {
  padding: 0.25rem 0.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  border-radius: 4px;
  color: var(--muted) !important;
  background: var(--bg3);
  border: 1px solid var(--border);
}
.sidebar__lang-btn:hover { color: var(--text) !important; }
.sidebar__lang-btn.is-on {
  color: var(--accent) !important;
  border-color: var(--accent);
  background: rgba(61, 156, 244, 0.1);
}

.layout__body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg);
}
.layout__scrim {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 199;
  background: rgba(0, 0, 0, 0.45);
  cursor: default;
  margin: 0;
  padding: 0;
  border: 0;
  appearance: none;
}
#sidebar-toggle:checked ~ .layout__body .layout__scrim {
  display: block;
}
.layout__inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Mobile top bar = menu trigger + title */
.topbar-mobile {
  display: none;
  flex-shrink: 0;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.9rem;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  min-height: 3rem;
}
.topbar-mobile__menu {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  color: var(--text);
  background: var(--bg3);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.topbar-mobile__menu:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--bg2);
}
.topbar-mobile__title {
  font-weight: 600;
  font-size: 0.95rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Trang login: ẩn thanh trên cùng (1) class app--login (2) :has nếu chỉ tải CSS cũ / thiếu class */
body.app--login .guestbar,
body.app--guest:has(.login-wrap .login-card) .guestbar {
  display: none !important;
  height: 0 !important;
  min-height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  visibility: hidden !important;
  position: absolute !important;
  width: 1px !important;
}

/* Guest = login (no sidebar) */
body.app .guestbar,
body.app .main--guest { margin-left: 0; }
.guestbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.1rem;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  width: 100%;
  flex: 0 0 auto;
}
.guestbar__nav {
  display: flex;
  gap: 0.4rem;
}
.guestbar__lang {
  padding: 0.3rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 4px;
  color: var(--muted) !important;
  background: var(--bg3);
  border: 1px solid var(--border);
}
.guestbar__lang:hover { color: var(--text) !important; }
body.app--guest {
  flex-direction: column;
}
.main--guest {
  max-width: 100%;
  margin: 0 auto;
}

/* Desktop: always show sidebar, hide scrim, hide mobile top */
@media (min-width: 901px) {
  .layout__scrim { display: none !important; }
  .topbar-mobile { display: none !important; }
  #sidebar-toggle:checked ~ .layout__body .layout__scrim { display: none !important; }
}

/* Mobile: drawer sidebar */
@media (max-width: 900px) {
  body.app { flex-direction: row; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    height: 100%;
    min-height: 100%;
    max-height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 6px 0 24px rgba(0, 0, 0, 0.35);
  }
  #sidebar-toggle:checked + .sidebar {
    transform: translateX(0);
  }
  .layout__body {
    width: 100%;
    margin-left: 0;
  }
  .topbar-mobile { display: flex; }
  .footer {
    margin-left: 0;
  }
}

.main {
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  padding: 1.5rem 1.25rem 3rem;
  flex: 1;
}
.main--guest { padding: 1.5rem 1.25rem 2rem; }

.footer {
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
  padding: 0.9rem 1rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  width: 100%;
}
.layout__body .footer { margin-top: auto; }

h1 { font-size: 1.5rem; font-weight: 600; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; font-weight: 600; margin: 1.5rem 0 0.75rem; }

.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.card--tight { padding: 0.9rem; }
input[readonly] {
  background: var(--bg3);
  cursor: default;
  opacity: 0.95;
}

.form-row { margin-bottom: 1rem; }
label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 0.35rem; }
input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  max-width: 28rem;
  padding: 0.5rem 0.65rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.95rem;
}
textarea { min-height: 80px; max-width: 100%; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(61, 156, 244, 0.25);
}
.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
}
.btn:hover { background: var(--border); }
.btn--primary {
  background: var(--accent2);
  border-color: var(--accent2);
  color: #fff;
}
.btn--primary:hover { filter: brightness(1.05); }
.btn--danger { background: #5c2a32; border-color: var(--danger); color: #fff; }

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  border: 1px solid var(--border);
}
.alert--ok { background: #153428; border-color: var(--success); color: #c8f5df; }
.alert--err { background: #3a1f24; border-color: var(--danger); color: #ffd0d5; }
.alert--warn { background: #3a3218; border-color: var(--warn); color: #fff4d0; }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
table.data th,
table.data td {
  padding: 0.5rem 0.65rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
table.data th { color: var(--muted); font-weight: 500; }
table.data tr:hover td { background: var(--bg3); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.badge { display: inline-block; padding: 0.2rem 0.5rem; border-radius: 4px; font-size: 0.8rem; }
.badge--ok { background: #153428; color: var(--success); }
.badge--wait { background: #3a3218; color: var(--warn); }
.badge--no { background: #3a1f24; color: var(--danger); }

.suggest { position: relative; }
.suggest__list {
  position: absolute;
  z-index: 20;
  left: 0;
  right: 0;
  max-width: 28rem;
  max-height: 220px;
  overflow: auto;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-top: 2px;
  display: none;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.suggest__list.is-open { display: block; }
.suggest__item { padding: 0.4rem 0.65rem; cursor: pointer; }
.suggest__item:hover, .suggest__item.is-active { background: var(--bg3); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 720px) { .grid2 { grid-template-columns: 1fr; } }

.login-wrap {
  min-height: 70vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.login-card { width: 100%; max-width: 380px; }
.login-card__lang {
  display: flex;
  justify-content: center;
  gap: 0.4rem;
  margin: 0 0 1rem;
}

.row-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* Hộp thoại chụp hóa đơn (getUserMedia) */
.ref-cam-dlg {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.ref-cam-dlg[hidden] { display: none !important; }
.ref-cam-dlg__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
}
.ref-cam-dlg__panel {
  position: relative;
  z-index: 1;
  width: min(32rem, 100%);
  max-width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
}
.ref-cam-dlg__title { margin: 0 0 0.5rem; font-size: 1rem; }
.ref-cam-dlg__hint { color: var(--muted); font-size: 0.88rem; margin: 0 0 0.75rem; }
.ref-cam-dlg__frame {
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  max-height: 60vh;
  aspect-ratio: 4 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ref-cam-dlg__video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.ref-cam-dlg__actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.9rem; }
