/* Trang quản lý — giao diện SÁNG (mặc định, tông cam ấm) và TỐI (bấm nút ☀️/🌙). Không dùng font/CDN ngoài. */
:root {
  --bg: #f7f3ee;
  --panel: #ffffff;
  --panel-2: #fbf7f2;
  --line: #efe5da;
  --text: #221c17;
  --muted: #8b7f74;
  --accent: #f26b1d;
  --accent-2: #ff9a3d;
  --accent-soft: #fff0e5;
  --accent-text: #e35f12;
  --ok: #16a34a;
  --ok-bg: #e9f8ef;
  --bad: #e5484d;
  --bad-bg: #fdeeee;
  --warn: #d97706;
  --warn-bg: #fff4e0;
  --shadow: 0 1px 2px rgba(60, 40, 20, .05), 0 6px 18px rgba(60, 40, 20, .05);
  --input-bg: #fffdfb;
  --radius: 16px;
}
:root[data-theme="dark"] {
  --bg: #0b0f1c;
  --panel: #111729;
  --panel-2: #151c31;
  --line: #222b45;
  --text: #e8ebf3;
  --muted: #8b93ad;
  --accent: #ff7a2f;
  --accent-2: #ffa24d;
  --accent-soft: rgba(255, 122, 47, .14);
  --accent-text: #ffb27a;
  --ok: #34d399;
  --ok-bg: rgba(52, 211, 153, .14);
  --bad: #f87171;
  --bad-bg: rgba(248, 113, 113, .14);
  --warn: #fbbf24;
  --warn-bg: rgba(251, 191, 36, .14);
  --shadow: none;
  --input-bg: #0b0f1c;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent-text); }
code { background: var(--panel-2); border: 1px solid var(--line); padding: 1px 6px; border-radius: 6px; font-size: 13px; }
h1, h2, h3 { margin: 0 0 8px; }
h3 { font-size: 17px; }
h4 { margin: 8px 0 0; color: var(--accent-text); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ── Bố cục ── */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 264px; flex: 0 0 264px; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 12px; padding: 20px; }
.brand-logo { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 20px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 6px 16px rgba(242, 107, 29, .3); }
.brand-name { font-weight: 800; font-size: 17px; letter-spacing: -.01em; }
.nav { flex: 1; overflow-y: auto; padding: 4px 12px 12px; }
.nav-group { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin: 16px 10px 6px; font-weight: 700; }
.nav-item { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 12px; color: var(--text); margin-bottom: 2px; font-weight: 500; }
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 700; box-shadow: inset 3px 0 0 var(--accent); }
.nav-icon { width: 22px; text-align: center; }
.sidebar-foot { border-top: 1px solid var(--line); padding: 14px; }
.who { color: var(--muted); font-size: 13px; margin-bottom: 10px; display: flex; justify-content: space-between; gap: 8px; }
.who-role { color: var(--accent-text); font-weight: 600; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.content { flex: 1; min-width: 0; padding: 24px 36px 40px; }

/* Thanh trên cùng: đường dẫn trang + người dùng + đổi sáng/tối */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 36px;
  border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; }
.crumbs { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.crumbs b { color: var(--text); }
.top-actions { display: flex; align-items: center; gap: 8px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel); font-size: 13px; font-weight: 600; }
.pill-accent { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
.theme-toggle { width: 36px; height: 36px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-size: 16px; }

/* ── Đầu trang ── */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-title { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.page-sub { margin: 0; color: var(--muted); }

/* ── Thẻ, thống kê, bảng ── */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; box-shadow: var(--shadow);
  border-top: 3px solid var(--accent); }
.grid .stat:nth-child(4n+1) { border-top-color: #3b82f6; }
.grid .stat:nth-child(4n+2) { border-top-color: var(--accent); }
.grid .stat:nth-child(4n+3) { border-top-color: #22c55e; }
.grid .stat:nth-child(4n+4) { border-top-color: #ef4444; }
.stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; }
.stat-value { font-size: 26px; font-weight: 800; margin-top: 6px; letter-spacing: -.02em; }
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; margin-bottom: 18px; box-shadow: var(--shadow); }
.card .table-wrap { box-shadow: none; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
  font-weight: 700; padding: 14px 18px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--panel-2); }
td { padding: 14px 18px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--panel-2); }
.cell-title { font-weight: 600; }
.cell-sub { color: var(--muted); font-size: 13px; margin-top: 2px; max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.empty { padding: 36px; text-align: center; color: var(--muted); }

/* Biểu đồ doanh thu (SVG vẽ sẵn từ máy chủ) */
.chart { width: 100%; height: 220px; display: block; }
.chart .bar { fill: var(--accent); opacity: .85; }
.chart .bar:hover { opacity: 1; }
.chart .axis { stroke: var(--line); }
.chart text { fill: var(--muted); font-size: 11px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg a { padding: 6px 12px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg a.on { background: var(--accent-soft); color: var(--accent-text); }

/* ── Chip trạng thái ── */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.chip-ok { color: var(--ok); background: var(--ok-bg); }
.chip-bad { color: var(--bad); background: var(--bad-bg); }
.chip-warn { color: var(--warn); background: var(--warn-bg); }
.chip-info { color: var(--accent-text); background: var(--accent-soft); }
.chip-muted { color: var(--muted); background: var(--panel-2); border: 1px solid var(--line); }

/* ── Nút ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer; font: inherit; font-weight: 700; }
.btn:hover { border-color: var(--accent); color: var(--accent-text); }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: 0; color: #fff; box-shadow: 0 6px 16px rgba(242, 107, 29, .28); }
.btn-primary:hover { color: #fff; filter: brightness(1.05); }
.btn-danger { color: var(--bad); }
.btn-danger:hover { border-color: var(--bad); color: var(--bad); }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 10px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
td .actions { flex-wrap: nowrap; }
.product-thumb { max-width: 220px; max-height: 220px; border-radius: 12px; border: 1px solid var(--line); object-fit: cover; }
.product-thumb[hidden] { display: none; }
.thumb-xs { width: 38px; height: 38px; border-radius: 10px; object-fit: cover; border: 1px solid var(--line); }
.icon-btn { width: 38px; height: 38px; display: inline-grid; place-items: center; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); cursor: pointer; font-size: 16px; color: var(--text); }
.icon-btn:hover { border-color: var(--accent); }
.inline { display: inline; margin: 0; }

/* ── Biểu mẫu ── */
.form { display: grid; gap: 14px; }
.form-row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.form-row > label { align-self: start; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 14px; font-weight: 600; }
input, select, textarea { width: 100%; padding: 10px 13px; border-radius: 12px; border: 1px solid var(--line); background: var(--input-bg);
  color: var(--text); font: inherit; font-weight: 400; }
input:focus, select:focus, textarea:focus { outline: 3px solid var(--accent-soft); border-color: var(--accent); }
textarea { min-height: 130px; resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.checkbox { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 500; }
.checkbox input { width: auto; accent-color: var(--accent); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; align-items: center; }
.toolbar input, .toolbar select { width: auto; min-width: 200px; }
.input-xs { width: 70px !important; min-width: 0 !important; }
.qr-preview { width: 180px; height: 180px; background: #fff; border-radius: 12px; padding: 6px; border: 1px solid var(--line); }

/* ── Thông báo ── */
.alert { padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; border: 1px solid transparent; }
.alert-ok { color: var(--ok); background: var(--ok-bg); }
.alert-bad { color: var(--bad); background: var(--bad-bg); }
.alert-warn { color: var(--warn); background: var(--warn-bg); }

/* ── Đăng nhập ── */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 500px at 15% 0%, var(--accent-soft), transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 32px; box-shadow: var(--shadow); }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.auth-card h1 { font-size: 22px; margin-bottom: 18px; font-weight: 800; }
.error-card h1 { font-size: 22px; }

.pager { display: flex; gap: 8px; justify-content: flex-end; align-items: center; color: var(--muted); }

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; }
  .nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .nav-group { display: none; }
  .content, .topbar { padding-left: 16px; padding-right: 16px; }
}

/* Trang đăng nhập: cách đăng nhập khác (mật khẩu) */
.login-alt { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }
.login-alt summary { cursor: pointer; color: var(--muted); font-weight: 600; font-size: 14px; }
.login-alt[open] summary { margin-bottom: 10px; }
.input-sm { width: 160px !important; min-width: 0 !important; }

/* Ô xác nhận thao tác quan trọng (mã Telegram hoặc mật khẩu) */
.confirm-field { display: grid; gap: 6px; }
.confirm-field .btn { justify-self: start; }

.menu-section > summary { cursor: pointer; padding: 8px 0; font-weight: 600; }
.menu-section[open] > summary { margin-bottom: 16px; }
[data-menu-list] tr[hidden] { display: none; }

.settings-section > summary { cursor: pointer; padding: 8px 0; font-weight: 600; }
.settings-summary { display: block; margin: 6px 0 0 18px; font-weight: 400; }
.settings-section[open] > summary { margin-bottom: 18px; }
.settings-section[hidden] { display: none; }
