:root {
  --primary: #d6a814;
  --primary-dark: #b68b08;
  --primary-soft: #fff8d9;
  --sidebar: #111827;
  --sidebar-muted: #9ca3af;
  --ok: #067647;
  --warn: #b42318;
  --muted: #667085;
  --bg: #f5f7fa;
  --card: #ffffff;
  --border: #e4e7ec;
  --text: #101828;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --radius: 12px;
  --sidebar-width: 260px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: Inter, "Segoe UI", Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
button, input, select { font: inherit; }
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: none; }

/* App shell */
.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 50; width: var(--sidebar-width);
  display: flex; flex-direction: column; background: var(--sidebar); color: #fff;
  transform: translateX(-100%); transition: transform .22s ease;
}
.sidebar-brand { min-height: 72px; padding: 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-brand > a { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mark { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; flex: 0 0 auto; background: var(--primary); color: #111827; font-size: 20px; font-weight: 900; }
.brand-copy { display: flex; flex-direction: column; line-height: 1.05; letter-spacing: .04em; }
.brand-copy b { color: #fff; font-size: 16px; }
.brand-copy small { margin-top: 4px; color: var(--primary); font-size: 10px; font-weight: 700; letter-spacing: .16em; }
.sidebar-close { width: 36px; height: 36px; border: 0; border-radius: 8px; background: transparent; color: #d0d5dd; font-size: 26px; cursor: pointer; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 16px 12px; }
.nav-label { margin: 18px 10px 8px; color: #667085; font-size: 10px; font-weight: 800; letter-spacing: .12em; }
.nav-label:first-child { margin-top: 4px; }
.nav-item { display: flex; align-items: center; gap: 11px; min-height: 44px; margin: 3px 0; padding: 10px 12px; border-radius: 9px; color: #d0d5dd; font-weight: 600; transition: background .15s, color .15s; }
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: var(--primary); color: #111827; }
.nav-icon { width: 22px; text-align: center; font-size: 18px; line-height: 1; }
.sidebar-footer { padding: 14px; border-top: 1px solid rgba(255,255,255,.08); }
.user-card { display: flex; gap: 10px; align-items: center; min-width: 0; }
.user-avatar, .mobile-avatar { display: grid; place-items: center; border-radius: 50%; background: var(--primary); color: #111827; font-weight: 800; }
.user-avatar { width: 38px; height: 38px; flex: 0 0 auto; }
.user-info { min-width: 0; display: flex; flex-direction: column; }
.user-info b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.user-info small { margin-top: 2px; color: var(--sidebar-muted); font-size: 11px; }
.logout-link { display: block; margin-top: 12px; padding: 9px 10px; border: 1px solid rgba(255,255,255,.12); border-radius: 8px; color: #d0d5dd; text-align: center; font-size: 13px; }
.logout-link:hover { color: #fff; border-color: rgba(255,255,255,.3); }
.sidebar-overlay { position: fixed; inset: 0; z-index: 40; visibility: hidden; opacity: 0; background: rgba(16,24,40,.52); transition: opacity .2s; }
.sidebar-open { overflow: hidden; }
.sidebar-open .sidebar { transform: translateX(0); }
.sidebar-open .sidebar-overlay { visibility: visible; opacity: 1; }
.app-main { min-width: 0; min-height: 100vh; }
.mobile-header { position: sticky; top: 0; z-index: 30; height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 14px; background: #fff; border-bottom: 1px solid var(--border); }
.menu-toggle { width: 38px; height: 38px; border: 1px solid var(--border); border-radius: 9px; background: #fff; color: var(--text); cursor: pointer; font-size: 20px; }
.mobile-brand { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 13px; letter-spacing: .04em; }
.mobile-brand b { color: var(--primary-dark); }
.mobile-avatar { width: 34px; height: 34px; flex: 0 0 auto; }

.container { width: 100%; max-width: 1440px; margin: 0 auto; padding: 18px 14px 36px; }
h1 { margin: 0; font-size: clamp(22px, 4vw, 30px); line-height: 1.25; letter-spacing: -.02em; }
h2 { margin: 0 0 14px; font-size: 16px; line-height: 1.35; }
.page-head { display: flex; flex-direction: column; align-items: stretch; gap: 14px; margin-bottom: 18px; }
.page-head > div { display: flex; flex-wrap: wrap; gap: 8px; }

.card, .color-form, .table-wrap { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card { padding: 16px; margin-bottom: 14px; }
.detail-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }

.flash { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 13px; border: 1px solid transparent; border-radius: 10px; margin-bottom: 14px; font-size: 13px; font-weight: 600; transition: opacity .35s ease, transform .35s ease; }
.flash-hide { opacity: 0; transform: translateY(-6px); pointer-events: none; }
.flash-close { flex: 0 0 auto; border: 0; background: transparent; color: inherit; font-size: 17px; line-height: 1; opacity: .55; cursor: pointer; padding: 0 2px; }
.flash-close:hover { opacity: 1; }
.flash-success { background: #ecfdf3; border-color: #abefc6; color: var(--ok); }
.flash-error { background: #fef3f2; border-color: #fecdca; color: var(--warn); }
.flash-warning { background: #fffaeb; border-color: #fedf89; color: #93370d; }

.btn { display: inline-flex; justify-content: center; align-items: center; gap: 6px; min-height: 40px; padding: 9px 13px; border: 1px solid var(--border); border-radius: 9px; background: #fff; color: #344054; cursor: pointer; font-size: 13px; font-weight: 700; box-shadow: 0 1px 2px rgba(16,24,40,.04); transition: background .15s, border-color .15s, transform .05s; }
.btn:hover { background: #f9fafb; border-color: #d0d5dd; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #111827; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }
.btn-sm { min-height: 34px; padding: 6px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-danger { background: #fff; border-color: #fda29b; color: var(--warn); }
.btn-danger:hover { background: #fef3f2; }

.table-wrap { overflow-x: auto; margin-bottom: 14px; }
.data-table { width: 100%; min-width: 640px; border-collapse: separate; border-spacing: 0; background: var(--card); font-size: 13px; }
.card > .data-table { display: block; overflow-x: auto; min-width: 0; }
.card > .data-table thead, .card > .data-table tbody { display: table; width: 100%; min-width: 540px; table-layout: auto; }
.data-table th, .data-table td { padding: 11px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.data-table thead th { background: #f9fafb; color: #475467; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: #fcfcfd; }
.data-table .num { text-align: right; white-space: nowrap; }
.data-table .total-row td { border-top: 2px solid #d0d5dd; background: #f9fafb; }
.note-cell, .detail-cell { max-width: 300px; font-size: 12px; color: var(--muted); word-break: break-word; }

.pagination { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; margin: 6px 0 14px; }
.pagination-pages { display: flex; flex-wrap: wrap; gap: 6px; }
.pagination .btn-sm { min-width: 40px; padding: 6px 8px; }
.pagination-current { cursor: default; }
.pagination-ellipsis { display: inline-flex; align-items: center; padding: 0 4px; color: var(--muted); font-weight: 700; }
.btn-disabled { opacity: .45; pointer-events: none; box-shadow: none; }

.badge { display: inline-flex; align-items: center; padding: 4px 8px; border-radius: 999px; font-size: 10px; font-weight: 800; letter-spacing: .02em; white-space: nowrap; }
.badge-ok { background: #dcfae6; color: var(--ok); }
.badge-warn { background: #fee4e2; color: var(--warn); }
.badge-muted { background: #f2f4f7; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }

label { display: block; margin-bottom: 13px; color: #344054; font-size: 13px; font-weight: 700; }
input[type=text], input[type=number], input[type=password], select, input[type=file] {
  display: block; width: 100%; min-height: 42px; margin-top: 6px; padding: 9px 11px; border: 1px solid #d0d5dd; border-radius: 9px; background: #fff; color: var(--text); font-size: 14px; font-weight: 400; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { border-color: var(--primary-dark); box-shadow: 0 0 0 3px rgba(214,168,20,.18); }
input[readonly] { background: #f2f4f7; color: #667085; cursor: not-allowed; }
input[readonly]:focus { border-color: #d0d5dd; box-shadow: none; }
input[readonly]:hover { cursor: not-allowed; }
.form-grid, .pigment-grid { display: grid; grid-template-columns: 1fr; gap: 0; }
.color-form { padding: 16px; }
.total-bar { position: sticky; bottom: 10px; z-index: 5; margin: 16px 0; padding: 12px 14px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 4px 14px rgba(16,24,40,.12); }
.form-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.inline-form { display: grid; grid-template-columns: 1fr; gap: 8px; margin-bottom: 14px; }
.inline-form input, .inline-form select { width: 100%; margin-top: 0; }
.filter-form { margin-bottom: 16px; }

/* Authentication */
.auth-body { min-height: 100vh; background: radial-gradient(circle at top right, rgba(214,168,20,.18), transparent 30%), #111827; }
.auth-main { min-height: 100vh; display: grid; align-content: center; justify-items: center; padding: 20px 14px; }
.auth-main .flash { width: 100%; max-width: 420px; }
.login-box { width: 100%; max-width: 420px; margin: 0 auto; padding: 24px 18px; background: #fff; border: 1px solid rgba(255,255,255,.5); border-radius: 16px; box-shadow: 0 20px 45px rgba(0,0,0,.3); }
.login-box::before { content: "BRICON COLOR LAB"; display: block; margin-bottom: 20px; color: var(--primary-dark); font-size: 13px; font-weight: 900; letter-spacing: .12em; }
.login-box h1 { margin-bottom: 22px; }
.login-box .btn { width: 100%; margin-top: 4px; }

.qr-img { width: min(180px, 100%); aspect-ratio: 1; display: block; margin: 0 auto 12px; object-fit: contain; }
.color-swatch-big { width: min(220px, 100%); aspect-ratio: 1; margin: 0 auto; border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.color-swatch-empty { background: repeating-linear-gradient(45deg, #f2f4f7, #f2f4f7 10px, #e4e7ec 10px, #e4e7ec 20px); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; text-align: center; }
.gallery { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.gallery figure { min-width: 0; margin: 0; }
.gallery img { width: 100%; height: 120px; object-fit: cover; border: 1px solid var(--border); border-radius: 9px; }
.gallery figcaption { margin-top: 5px; font-size: 11px; line-height: 1.4; word-break: break-word; }
.gallery figcaption .small { display: block; }
.note { padding: 10px 12px; border-left: 3px solid var(--primary); border-radius: 7px; background: var(--primary-soft); color: #704f00; font-size: 13px; }

.color-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.color-card { display: block; min-width: 0; overflow: hidden; background: var(--card); border: 1px solid var(--border); border-radius: 12px; color: var(--text); box-shadow: var(--shadow); transition: box-shadow .15s, transform .15s; }
.color-card:hover { box-shadow: 0 8px 20px rgba(16,24,40,.12); transform: translateY(-2px); }
.swatch { height: 86px; display: flex; align-items: center; justify-content: center; border-bottom: 1px solid rgba(0,0,0,.05); }
.swatch-empty { padding: 3px 7px; border-radius: 999px; background: rgba(255,255,255,.8); color: #667085; font-size: 10px; }
.card-body { padding: 11px; }
.card-title { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.card-title b { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-sub { margin-top: 5px; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.card-note { margin-top: 7px; overflow: hidden; color: #854a0e; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.hex-row { display: grid; grid-template-columns: 48px 1fr; gap: 8px; align-items: center; margin-top: 6px; }
.hex-row input[type=color] { width: 48px; height: 42px; padding: 2px; border: 1px solid #d0d5dd; border-radius: 9px; cursor: pointer; background: #fff; }
.hex-row input[type=text] { width: 100%; margin-top: 0; }
.hex-row .small { grid-column: 1 / -1; }
.swatch-dot { display: inline-block; width: 22px; height: 22px; margin-right: 8px; border: 1px solid var(--border); border-radius: 6px; vertical-align: -5px; }

.print-only { display: none; }

/* Lightbox xem ảnh full-size */
.lightbox-overlay { position: fixed; inset: 0; z-index: 200; display: none; align-items: center; justify-content: center; background: rgba(16,24,40,.88); padding: 30px; }
.lightbox-img { max-width: 92vw; max-height: 92vh; object-fit: contain; border-radius: 8px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.lightbox-close { position: fixed; top: 18px; right: 22px; z-index: 201; width: 42px; height: 42px; border: 0; border-radius: 50%; background: rgba(255,255,255,.14); color: #fff; font-size: 26px; line-height: 1; cursor: pointer; }
.lightbox-close:hover { background: rgba(255,255,255,.26); }
body.lightbox-open { overflow: hidden; }
.sign-row { display: flex; justify-content: space-around; margin-top: 50px; text-align: center; }

@media (min-width: 560px) {
  .container { padding: 24px 20px 40px; }
  .page-head { flex-direction: row; align-items: center; justify-content: space-between; }
  .form-grid { grid-template-columns: 1fr 1fr; gap: 14px; }
  .pigment-grid { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 0 14px; }
  .form-actions { flex-direction: row; }
  .inline-form { display: flex; flex-wrap: wrap; align-items: center; }
  .inline-form input, .inline-form select { width: auto; min-width: 160px; flex: 1 1 180px; }
  .inline-form .btn { flex: 0 0 auto; }
  .gallery { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .color-grid { grid-template-columns: repeat(auto-fill, minmax(190px,1fr)); gap: 14px; }
  .card-title { flex-direction: row; align-items: center; justify-content: space-between; }
}

@media (min-width: 960px) {
  .sidebar { transform: translateX(0); }
  .sidebar-close, .mobile-header, .sidebar-overlay { display: none; }
  .app-main { margin-left: var(--sidebar-width); }
  .container { padding: 30px 28px 48px; }
  .detail-grid { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 18px; }
  .card, .color-form { padding: 20px; }
  .pigment-grid { grid-template-columns: repeat(auto-fill, minmax(190px,1fr)); gap: 0 14px; }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(180px,1fr)); }
  .sidebar-open { overflow: auto; }
}

@media print {
  .no-print, .sidebar, .mobile-header { display: none !important; }
  .print-only { display: block; }
  .sign-row.print-only { display: flex; }
  body { background: #fff; }
  .app-main { margin-left: 0; }
  .container { max-width: 100%; margin: 0; padding: 0; }
  .print-sheet { font-size: 13px; }
  .sign-row div { padding-bottom: 70px; }
  .card, .table-wrap { box-shadow: none; }
}


/* =========================================================
   MOBILE TABLE FIX — không cuộn ngang, bảng chuyển thành card
   ========================================================= */
html, body { max-width: 100%; overflow-x: hidden; }
.app-shell, .app-main, .container, main, section, .card, .table-wrap,
.page-head, .detail-grid, .color-form, form { min-width: 0; max-width: 100%; }
img, svg, video, canvas { max-width: 100%; }
h1, h2, p, td, th, .note, .flash, .detail-cell { overflow-wrap: anywhere; word-break: break-word; }
.card, .table-wrap { overflow: hidden; }
.form-actions, .page-head > div { min-width: 0; }
.form-actions > *, .page-head > div > * { max-width: 100%; }

@media (max-width: 559px) {
  .container { overflow: hidden; }

  /* Bảng công thức 2 cột vẫn giữ dạng bảng nhưng co vừa màn hình */
  .formula-table,
  .card > .formula-table { display: table; width: 100%; min-width: 0; table-layout: fixed; overflow: visible; }
  .card > .formula-table thead,
  .card > .formula-table tbody { display: table-row-group; width: auto; min-width: 0; }
  .card > .formula-table thead { display: table-header-group; }
  .formula-table th,
  .formula-table td { padding: 10px 8px; }
  .formula-table th:first-child,
  .formula-table td:first-child { width: 68%; }
  .formula-table th:last-child,
  .formula-table td:last-child { width: 32%; }

  /* Các bảng nhiều cột chuyển thành từng card, tuyệt đối không scroll ngang */
  .table-wrap { overflow: visible; border: 0; box-shadow: none; background: transparent; }
  .responsive-stack,
  .card > .responsive-stack { display: block; width: 100%; min-width: 0; background: transparent; overflow: visible; }
  .responsive-stack thead { display: none !important; }
  .responsive-stack tbody { display: grid !important; width: 100% !important; min-width: 0 !important; gap: 10px; }
  .responsive-stack tr { display: block; width: 100%; min-width: 0; padding: 12px; border: 1px solid var(--border); border-radius: 11px; background: #fff; box-shadow: var(--shadow); }
  .responsive-stack tr:hover { background: #fff; }
  .responsive-stack td { display: grid; grid-template-columns: minmax(92px, 36%) minmax(0, 1fr); align-items: start; gap: 10px; width: 100%; min-width: 0; padding: 8px 0; border-bottom: 1px dashed var(--border); text-align: left !important; white-space: normal !important; }
  .responsive-stack td:last-child { border-bottom: 0; }
  .responsive-stack td::before { color: #667085; font-size: 10px; font-weight: 800; line-height: 1.45; text-transform: uppercase; letter-spacing: .04em; }
  .responsive-stack td[colspan] { display: block; padding: 8px 0; border: 0; }
  .responsive-stack td[colspan]::before { display: none; }
  .responsive-stack .btn { width: 100%; }
  .responsive-stack form { width: 100%; }
  .responsive-stack input,
  .responsive-stack select { min-width: 0; width: 100%; }
  .responsive-stack details, .responsive-stack pre { max-width: 100%; white-space: pre-wrap !important; overflow-wrap: anywhere; }

  /* Nhãn từng loại bảng */
  .versions-table td:nth-child(1)::before { content: "Phiên bản"; }
  .versions-table td:nth-child(2)::before { content: "Trạng thái"; }
  .versions-table td:nth-child(3)::before { content: "Ghi chú"; }
  .versions-table td:nth-child(4)::before { content: "Ngày tạo"; }
  .versions-table td:nth-child(5)::before { content: "Thao tác"; }

  .logs-table td:nth-child(1)::before { content: "Thời gian"; }
  .logs-table td:nth-child(2)::before { content: "Người dùng"; }
  .logs-table td:nth-child(3)::before { content: "Hành động"; }
  .logs-table td:nth-child(4)::before { content: "Đối tượng"; }
  .logs-table td:nth-child(5)::before { content: "Chi tiết"; }

  .mine-table td:nth-child(1)::before { content: "Màu"; }
  .mine-table td:nth-child(2)::before { content: "Phiên bản"; }
  .mine-table td:nth-child(3)::before { content: "Trạng thái"; }
  .mine-table td:nth-child(4)::before { content: "Lý do từ chối"; }
  .mine-table td:nth-child(5)::before { content: "Thao tác"; }

  .pending-table td:nth-child(1)::before { content: "Màu"; }
  .pending-table td:nth-child(2)::before { content: "Phiên bản"; }
  .pending-table td:nth-child(3)::before { content: "Ghi chú"; }
  .pending-table td:nth-child(4)::before { content: "Cập nhật lúc"; }
  .pending-table td:nth-child(5)::before { content: "Thao tác"; }

  .pigments-table td:nth-child(1)::before { content: "STT"; }
  .pigments-table td:nth-child(2)::before { content: "Tên pigment"; }
  .pigments-table td:nth-child(3)::before { content: "Số màu dùng"; }
  .pigments-table td:nth-child(4)::before { content: "Trạng thái"; }

  .roles-table td:nth-child(1)::before { content: "Vai trò"; }
  .roles-table td:nth-child(2)::before { content: "Được phép làm"; }

  .users-table td:nth-child(1)::before { content: "Tài khoản"; }
  .users-table td:nth-child(2)::before { content: "Họ tên"; }
  .users-table td:nth-child(3)::before { content: "Vai trò"; }
  .users-table td:nth-child(4)::before { content: "Trạng thái"; }
  .users-table td:nth-child(5)::before { content: "Quyền riêng"; }
  .users-table td:nth-child(6)::before { content: "Mật khẩu"; }
  .users-table td:nth-child(7)::before { content: "Khóa / Xóa"; }

  /* Header và nút thao tác không làm rộng trang */
  .page-head h1 { max-width: 100%; }
  .page-head > div { width: 100%; }
  .page-head > div .btn,
  .page-head > div form { flex: 1 1 auto; }
  .page-head > div form .btn { width: 100%; }

  /* Form lọc nhật ký */
  .filter-form { width: 100%; }
  .filter-form select,
  .filter-form .btn { width: 100%; }
}