/* ===== Base ===== */
:root {
  /* Bảng màu lấy từ logo Tấn Hưng:
     #00a651 xanh lá đậm (chủ đạo) · #a6ce39 xanh lá nhạt · #00aeef xanh cyan ·
     #ed1c24 đỏ (cảnh báo) */
  --bg:#f4f7f4; --surface:#fff; --border:#dde4dd; --text:#1f2933;
  --muted:#6b7480;
  --primary:#00a651; --primary-dark:#007d3d;
  --accent:#a6ce39; --info:#00aeef;
  --ok:#00a651; --err:#ed1c24;
  --shadow:0 1px 3px rgba(0,0,0,.06);
}
* { box-sizing: border-box; }
html, body { margin:0; padding:0; }
/* Ép attribute `hidden` luôn ẩn — class có display:flex/grid sẽ ko override được. */
[hidden] { display: none !important; }
/* Mọi <dialog> phải ẩn khi không có [open] — bảo hiểm trường hợp CSS đè default UA */
dialog:not([open]) { display: none !important; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Topbar ===== */
.topbar {
  display:flex; align-items:center; gap:1.5rem;
  padding: .6rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow); position: sticky; top:0; z-index: 50;
}
.topbar .brand {
  display:flex; align-items:center; gap:.85rem;
  color: var(--text); text-decoration:none;
}
.topbar .brand:hover { text-decoration:none; opacity:.85; }
.topbar .brand-logo {
  height: 44px; width:auto; display:block;
}
.topbar .brand-sep {
  width:1px; height:28px; background: var(--border); display:inline-block;
}
.topbar .brand-title {
  font-weight: 600; font-size: 1rem; color: var(--primary-dark);
  letter-spacing: .01em;
}
.topbar nav { display:flex; gap: .25rem; margin-left: .5rem; }
.topbar nav a {
  color: var(--text); padding: .4rem .75rem; border-radius:6px;
  font-weight: 500; white-space: nowrap;
}
.topbar nav a:hover { background: var(--bg); text-decoration: none; color: var(--primary-dark); }
.topbar .user-box { margin-left:auto; display:flex; gap: .85rem; align-items:center; color: var(--muted); white-space: nowrap; }

.main { max-width: 1280px; margin: 0 auto; padding: 1.25rem; }

/* ===== Atoms ===== */
.muted { color: var(--muted); }
.small { font-size: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 1rem; box-shadow: var(--shadow);
}
.alert { padding: .6rem .8rem; border-radius:6px; margin-bottom: 1rem; }
.alert.ok  { background:#e6f7ee; color: var(--ok);  border:1px solid #b7e4c7; }
.alert.err { background:#fdecea; color: var(--err); border:1px solid #fbb4ad; }

.btn {
  display:inline-block; padding:.5rem .9rem; border:1px solid var(--border);
  background: #fff; color: var(--text); border-radius:6px; cursor:pointer;
  font-size: 14px; font-family: inherit;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn.primary { background: var(--primary); color:#fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn.muted   { color: var(--muted); }
.btn.danger  { background:#fdecea; color: var(--err); border-color:#fbb4ad; }
.btn.small   { padding:.3rem .6rem; font-size:13px; }
.btn.tiny    { padding:.15rem .5rem; font-size:12px; }

/* ===== Forms ===== */
.form .row { display:grid; grid-template-columns: 180px 1fr; gap: 1rem; align-items:center; margin-bottom:.85rem; }
.form .row > span:first-child { color: var(--muted); }
.form .row em { color: var(--err); }
.form input[type=text], .form input[type=date], .form input[type=password],
.form input[type=file], .form select, .form textarea {
  width: 100%; padding: .5rem .65rem; border:1px solid var(--border);
  border-radius:6px; background:#fff; font: inherit; color: inherit;
}
.form textarea { resize: vertical; }
.form .form-actions { display:flex; gap:.5rem; margin-top: 1rem; }
.combo { display:flex; gap:.5rem; align-items:center; }
.combo select { flex: 1; }

fieldset.files { border:1px solid var(--border); border-radius:6px; padding: .85rem; margin-bottom: .85rem; }
fieldset.files legend { padding: 0 .35rem; color: var(--muted); }
.file-row { display:flex; gap:.5rem; margin-bottom:.5rem; align-items:center; }
.file-row input[type=file] { flex: 2; }
.file-row input[type=text] { flex: 1; }
.file-row .remove { line-height:1; padding:.15rem .45rem; font-size:14px; }

/* ===== Login ===== */
.login-body {
  display:flex; align-items:center; justify-content:center;
  min-height:100vh; padding: 1rem;
  background: linear-gradient(135deg, #e8f4ec 0%, #f4f7f4 60%, #e6f4eb 100%);
}
.login-card { width: 380px; padding: 1.75rem; }
.login-logo { display:block; height: 60px; width:auto; margin: 0 auto .75rem; }
.login-card h1 { margin: 0 0 .25rem; font-size: 1.15rem; text-align:center; color: var(--primary-dark); }
.login-card > .muted { text-align:center; margin: 0 0 1.25rem; }
.login-card label { display:block; margin-top: .75rem; font-size: 13px; color: var(--muted); }
.login-card input { width:100%; padding:.55rem .65rem; border:1px solid var(--border); border-radius:6px; margin-top: .2rem; font: inherit; }
.login-card input:focus { outline:none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0,166,81,.15); }
.login-card .btn { width:100%; margin-top: 1.25rem; padding: .65rem; font-weight: 600; }

/* ===== Tra cứu (layout) ===== */
.layout { display:grid; grid-template-columns: 260px 1fr; gap: 1.25rem; }
@media (max-width: 800px) { .layout { grid-template-columns: 1fr; } }
.filter { background: var(--surface); border:1px solid var(--border); border-radius:8px; padding: 1rem; height: fit-content; box-shadow: var(--shadow); }
.filter h3 { margin: 0 0 .75rem; font-size: 1rem; }
.filter .block { margin-bottom: 1rem; border:none; padding:0; }
.filter .block legend { color: var(--muted); margin-bottom:.35rem; font-size: 12px; text-transform: uppercase; letter-spacing:.04em; }
.filter input[type=text], .filter input[type=date] { width:100%; padding:.4rem .55rem; border:1px solid var(--border); border-radius:6px; }
.filter .checklist { max-height: 200px; overflow:auto; border:1px solid var(--border); border-radius:6px; padding:.5rem; background:#fafbfc; }
.filter .checklist label { display:block; padding:.15rem 0; cursor:pointer; }
.filter .inline { display:flex; align-items:center; gap:.4rem; margin-bottom:.35rem; }
.filter .inline input { flex:1; }

.results-head { display:flex; justify-content:space-between; align-items:center; margin-bottom: .75rem; }

/* ===== Filter bar (horizontal) ===== */
.filter-bar {
  display:flex; flex-wrap:wrap; gap:.5rem; align-items:center;
  padding: .75rem .9rem; margin-bottom: 1rem;
  background: var(--surface); border:1px solid var(--border); border-radius:8px;
  box-shadow: var(--shadow); position: relative; z-index: 20;
}
.filter-search {
  width: 280px; padding: .55rem .75rem;
  border:1px solid var(--border); border-radius:6px; font: inherit;
}
.filter-spacer { flex: 1; }   /* đẩy nút "+ Tải lên" sang phải cùng hàng */
.filter-search:focus { outline:none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0,166,81,.12); }

.filter-date-label { display:flex; align-items:center; gap:.35rem; color: var(--muted); font-size:13px; }
.filter-date { padding: .45rem .55rem; border:1px solid var(--border); border-radius:6px; font: inherit; }

.filter-drop { position: relative; }
.filter-drop summary {
  display:inline-flex; align-items:center; gap:.4rem;
  list-style: none; cursor: pointer; user-select:none;
  padding: .5rem .85rem; background:#fff;
  border:1px solid var(--border); border-radius:6px; font-weight:500;
}
.filter-drop summary::-webkit-details-marker { display:none; }
.filter-drop summary::marker { content: ''; }
.filter-drop summary:hover { border-color: var(--primary); }
.filter-drop[open] summary { border-color: var(--primary); background: rgba(0,166,81,.06); }
.filter-drop .caret { color: var(--muted); font-size: 11px; transition: transform .15s; }
.filter-drop[open] .caret { transform: rotate(180deg); }
.filter-count {
  background: var(--primary); color:#fff;
  padding: 0 .45rem; border-radius: 999px; font-size: 11px;
  min-width: 18px; text-align:center; line-height: 18px;
}

.drop-panel {
  position:absolute; top: calc(100% + 6px); left: 0; z-index: 25;
  background:#fff; border:1px solid var(--border); border-radius:8px;
  box-shadow: 0 8px 22px rgba(0,0,0,.14);
  min-width: 280px; max-width: 360px;
  max-height: 360px; overflow:hidden;
  display:flex; flex-direction:column;
}
.drop-search {
  border:none; border-bottom: 1px solid var(--border);
  padding: .55rem .85rem; outline:none; font:inherit;
  background:#fafbfa;
}
.drop-search:focus { background:#fff; border-bottom-color: var(--primary); }
.drop-checklist {
  list-style:none; margin:0; padding:.25rem 0;
  overflow:auto; max-height: 280px;
}
.drop-checklist li { padding: 0; }
.drop-checklist label {
  display:flex; align-items:center; gap:.55rem;
  padding: .35rem .85rem; cursor: pointer; line-height: 1.3;
}
.drop-checklist label:hover { background: var(--bg); }
.drop-checklist input[type=checkbox] { flex-shrink:0; }

/* ===== Grid card ===== */
.grid { display:grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap:.85rem; }
.design-card {
  background: var(--surface); border: 1px solid var(--border); border-radius:8px;
  overflow: hidden; box-shadow: var(--shadow); color: var(--text);
  display:flex; flex-direction:column; transition: transform .12s, box-shadow .12s;
}
.design-card:hover { transform: translateY(-2px); text-decoration:none; box-shadow: 0 4px 10px rgba(0,0,0,.08); }
.design-card .thumb { aspect-ratio: 4 / 3; background: #f1f4f7; display:flex; align-items:center; justify-content:center; overflow:hidden; }
.design-card .thumb img { width:100%; height:100%; object-fit:contain; background:#fff; }
.design-card .thumb .placeholder { color: var(--muted); font-size: 12px; padding: .5rem; text-align:center; }
.design-card .info { padding: .55rem .65rem; }
.design-card .product { font-weight: 600; margin-bottom:.25rem; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.design-card .meta { color: var(--muted); font-size: 12px; display:flex; flex-direction:column; gap:.15rem; }

.pager { display:flex; gap:1rem; align-items:center; justify-content:center; margin: 1.25rem 0 0; }

/* ===== Design detail modal (image-first layout) =====
   Modal shrink-wrap theo ảnh — chỉ to bằng ảnh + chrome (header + foot).
   PHẢI dùng fit-content (không phải auto) vì <dialog> default có
   left:0;right:0 khiến width:auto bị stretch full viewport. */
.design-dialog {
  width: -moz-fit-content;
  width: fit-content;
  height: -moz-fit-content;
  height: fit-content;
  min-width: 480px;
  max-width: 95vw;
  max-height: 95vh;
  padding: 0;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #fff;
}
.design-dialog[open] { display: flex; flex-direction: column; }

/* Header gọn */
.design-dialog .design-dialog-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .55rem 1rem;
  border-bottom: 1px solid var(--border);
  background: #fff;
  flex-shrink: 0;
}
.design-dialog .design-dialog-head h2 {
  margin: 0; font-size: 1rem; color: var(--primary-dark); font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding-right: .75rem;
}
.design-dialog .dlg-close {
  border: none; background: transparent; cursor: pointer;
  font-size: 22px; line-height: 1; padding: .1rem .55rem;
  color: var(--muted); border-radius: 6px; flex-shrink: 0;
}
.design-dialog .dlg-close:hover { background: rgba(0,0,0,.06); color: var(--err); }

/* Body: hero ảnh + strip + foot */
.design-dialog-body {
  display: flex; flex-direction: column;
  flex: 1; min-height: 0;
  background: #fafbfa;
}

/* HERO: viền đen mỏng xung quanh ảnh, không có khoảng trống thừa.
   Ảnh giới hạn theo viewport — trừ chrome (header ~45px + foot ~85px + strip 0/72px). */
.design-hero {
  display: flex; align-items: center; justify-content: center;
  background: #2a2e33;
  padding: 6px;
}
.design-hero-img {
  display: block;
  width: auto; height: auto;
  max-width: calc(95vw - 14px);
  max-height: calc(95vh - 145px);     /* trừ header + foot + chừa biên */
  object-fit: contain;
  box-shadow: 0 2px 12px rgba(0,0,0,.3);
}
.design-hero-empty {
  color: #aab2bd; font-size: 14px;
  min-width: 480px; min-height: 240px;
  display: flex; align-items: center; justify-content: center;
}

/* STRIP: chỉ hiện khi có >1 file. Hàng ngang scrollable */
.design-thumb-strip {
  display: flex; gap: .4rem; padding: .5rem .75rem;
  overflow-x: auto; background: #1d2025;
  border-top: 1px solid #000;
  flex-shrink: 0;
}
.design-thumb-strip .strip-item {
  flex-shrink: 0;
  width: 70px; height: 56px;
  border: 2px solid transparent; border-radius: 4px;
  background: #2a2e33; padding: 0;
  cursor: pointer; overflow: hidden;
  transition: border-color .12s, opacity .12s;
  opacity: .65;
}
.design-thumb-strip .strip-item:hover { opacity: 1; }
.design-thumb-strip .strip-item.active {
  border-color: var(--primary); opacity: 1;
}
.design-thumb-strip .strip-item img {
  width: 100%; height: 100%; object-fit: contain; background: #fff;
}
.design-thumb-strip .strip-placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  color: #aab2bd; font-size: 16px;
}

/* FOOT: thanh thông tin + nút Tải về + xoá */
.design-foot {
  background: #fff;
  border-top: 1px solid var(--border);
  padding: .65rem 1rem .75rem;
  flex-shrink: 0;
}
.design-foot .design-meta-line {
  display: flex; gap: .85rem; flex-wrap: wrap;
  color: var(--muted); font-size: 12.5px;
  margin-bottom: .45rem;
}
.design-foot .design-meta-line strong { color: var(--text); }
.design-foot .design-note-inline {
  max-width: 360px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.design-foot-bar {
  display: flex; align-items: center; gap: .75rem;
}
.design-foot-bar .design-file-info {
  flex: 1; min-width: 0;
}
.design-foot-bar .design-file-name {
  font-weight: 600; font-size: 13.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.design-foot-bar .btn { flex-shrink: 0; padding: .45rem .9rem; }
.design-foot-bar .design-delete-form { margin: 0; flex-shrink: 0; }
.design-foot-bar .btn.danger {
  padding: .45rem .65rem; font-size: 16px; line-height: 1;
}

/* Mobile/tablet: upload modal cũng dùng block layout (cùng lý do với design modal) */
@media (max-width: 720px) {
  .upload-dialog {
    width: 100vw !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
  }
  .upload-dialog[open] {
    display: block !important;
  }
  .upload-form {
    flex: none !important;
    min-height: auto !important;
    overflow-y: auto;
    max-height: calc(100dvh - 60px);   /* trừ header sticky */
    padding: 1rem 1rem 1.25rem !important;
  }
  .upload-dialog .upload-dialog-head {
    padding-top: max(.75rem, env(safe-area-inset-top)) !important;
    padding-right: max(.5rem, env(safe-area-inset-right)) !important;
    padding-left:  max(1.1rem, env(safe-area-inset-left)) !important;
    position: sticky; top: 0; z-index: 5;
  }
  .upload-dialog .dlg-close {
    min-width: 44px !important;
    min-height: 44px !important;
    display: flex !important;
    align-items: center; justify-content: center;
    font-size: 26px !important;
  }
  .upload-form .form-actions { padding-bottom: env(safe-area-inset-bottom); }
}

/* Mobile/tablet: dùng BLOCK layout đơn giản (iOS Safari xử lý flex+fit-content
   không nhất quán, body bị collapse). Block stack tự nhiên từ trên xuống. */
@media (max-width: 720px) {
  .design-dialog {
    width: 100vw !important;
    min-width: 0 !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
    padding: 0 !important;
    border-radius: 0 !important;
  }
  /* Override flex column của desktop bằng block */
  .design-dialog[open] {
    display: block !important;
  }
  .design-dialog-body {
    display: block !important;
    flex: none !important;
    min-height: auto !important;
    overflow-y: auto;
    max-height: calc(100dvh - 50px);    /* body scroll nếu quá dài, head ~50px */
  }
  /* Header sticky để khi scroll body vẫn thấy × */
  .design-dialog .design-dialog-head {
    padding-top: max(.6rem, env(safe-area-inset-top)) !important;
    padding-right: max(.5rem, env(safe-area-inset-right)) !important;
    padding-left:  max(1rem, env(safe-area-inset-left)) !important;
    position: sticky; top: 0; z-index: 5;
  }
  .design-dialog .dlg-close {
    min-width: 44px !important;
    min-height: 44px !important;
    display: flex !important;
    align-items: center; justify-content: center;
    font-size: 26px !important;
  }
  .design-hero-img {
    max-width: 100% !important;
    max-height: calc(100dvh - 220px) !important;
  }
  .design-foot {
    padding-bottom: max(.75rem, env(safe-area-inset-bottom)) !important;
  }
  .design-foot-bar { flex-wrap: wrap; }
  .design-foot-bar .design-file-info { flex-basis: 100%; }
  .design-foot-bar .btn.primary { flex: 1; text-align: center; }
}

/* ===== Detail (legacy design.php) ===== */
.design-detail h1 { margin: .5rem 0; }
.design-detail .meta-line { display:flex; gap: 1.25rem; color: var(--muted); margin-bottom: 1rem; flex-wrap:wrap; }
.design-detail .meta-line strong { color: var(--text); }
.notes-box { background:#fffbe6; border:1px solid #f6e58d; padding: .65rem .85rem; border-radius:6px; margin-bottom: 1.5rem; }

.file-list { display:grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.file-item { padding: 0; overflow:hidden; }
.file-item .thumb { aspect-ratio: 4 / 3; background:#f1f4f7; display:flex; align-items:center; justify-content:center; }
.file-item .thumb img { width:100%; height:100%; object-fit:contain; background:#fff; }
.file-item .file-info { padding: .65rem; display:flex; flex-direction:column; gap:.35rem; }
.file-item .filename { font-weight:600; word-break: break-all; }
.label-tag { background: var(--bg); padding: .1rem .45rem; border-radius:4px; font-size:12px; display:inline-block; align-self: flex-start; }

/* ===== Admin ===== */
.admin-grid { display:grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin-top:1rem; }
.stat { text-align:center; padding: 1.25rem; }
.stat .num { font-size: 1.7rem; font-weight:700; color: var(--primary); }
.stat .lbl { color: var(--muted); }
table.data { width:100%; border-collapse: collapse; background: var(--surface); margin-top: 1rem; box-shadow: var(--shadow); border-radius:8px; overflow:hidden; }
table.data th, table.data td { padding: .55rem .75rem; border-bottom: 1px solid var(--border); text-align:left; }
table.data th { background:#fafbfc; color: var(--muted); font-weight:600; font-size:12px; text-transform: uppercase; letter-spacing: .04em; }
.role-admin { background:#fdecea; color: var(--err); padding: .1rem .45rem; border-radius:4px; font-size:12px; }
.role-staff { background:#e6f7ff; color: var(--info); padding: .1rem .45rem; border-radius:4px; font-size:12px; }

/* ===== Dialog ===== */
dialog { border:none; border-radius:10px; padding: 1.5rem; box-shadow: 0 12px 30px rgba(0,0,0,.22); min-width: 380px; }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog h3 { margin:0 0 .85rem; }
dialog label { display:block; margin-bottom: .6rem; }
dialog input { width:100%; padding:.5rem; border:1px solid var(--border); border-radius:6px; margin-top:.25rem; font: inherit; }

/* ============================================================
   Upload modal (dropzone + searchable select + progress)
   ============================================================ */
.upload-wrap { max-width: 720px; margin: 1rem auto; }
.upload-wrap h1 { margin: 0 0 1rem; }

/* Modal upload — to hơn dialog mặc định, có scroll khi form dài.
   CHỈ display khi có attribute [open] — tránh đè rule mặc định
   `dialog:not([open]) { display:none }` của browser. */
.upload-dialog {
  width: 640px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  padding: 0;
  border-radius: 12px;
  overflow: hidden;
}
.upload-dialog[open] {
  display: flex;
  flex-direction: column;
}
.upload-dialog .upload-dialog-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  cursor: move;          /* gợi ý kéo thả */
  user-select: none;
}
.upload-dialog .upload-dialog-head:active { cursor: grabbing; }
.upload-dialog .upload-dialog-head .dlg-close { cursor: pointer; }
.upload-dialog .upload-dialog-head h2 {
  margin: 0; font-size: 1.1rem; color: var(--primary-dark);
}
.upload-dialog .dlg-close {
  border: none; background: transparent; cursor: pointer;
  font-size: 22px; line-height: 1; padding: 0 .5rem;
  color: var(--muted); border-radius: 6px;
}
.upload-dialog .dlg-close:hover { background: rgba(0,0,0,.06); color: var(--err); }

.upload-form { padding: 1.25rem 1.5rem; overflow-y: auto; flex: 1; min-height: 0; }
.upload-form .field { margin-bottom: 1.5rem; }
.upload-form .field-label { display:block; color: var(--muted); font-size: 13px; margin-bottom: .4rem; }
.upload-form .field-label em { color: var(--err); }
.upload-form .form-actions { display:flex; gap: .75rem; justify-content:center; margin-top:1rem; }
.upload-form .btn.big { font-size: 1rem; padding: .75rem 2rem; font-weight: 600; min-width: 180px; }
.upload-form .center { text-align: center; }

/* --- Searchable product dropdown (inline expand, không overlay) --- */
.product-picker { position: relative; }
.picker-trigger {
  display:flex; align-items:center; justify-content:space-between; gap:.5rem;
  width:100%; padding: .6rem .85rem;
  background: #fff; border:1px solid var(--border); border-radius:8px;
  font: inherit; cursor: pointer; text-align:left;
}
.picker-trigger:hover { border-color: var(--primary); }
.picker-trigger[aria-expanded="true"] {
  border-color: var(--primary);
  border-bottom-left-radius: 0; border-bottom-right-radius: 0;
}
.picker-current { color: var(--text); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.picker-current.placeholder { color: var(--muted); }
.picker-caret { color: var(--muted); font-size: 12px; flex-shrink:0; transition: transform .15s; }
.picker-trigger[aria-expanded="true"] .picker-caret { transform: rotate(180deg); }

/* Panel inline (không position:absolute) — đẩy dropzone xuống thay vì đè lên */
.picker-panel {
  border:1px solid var(--primary);
  border-top: none;
  border-radius: 0 0 8px 8px;
  background: #fff;
  display: flex; flex-direction: column; overflow: hidden;
  max-height: 280px;
  margin-bottom: .25rem;
}
.picker-search {
  border:none; border-bottom:1px solid var(--border);
  padding: .55rem .85rem; font:inherit; outline:none; width:100%;
  background: #fafbfa;
}
.picker-search:focus { background: #fff; border-bottom-color: var(--primary); }
.picker-options { list-style:none; margin:0; padding:.25rem 0; overflow:auto; max-height: 180px; }
.picker-options li {
  padding: .45rem .85rem; cursor: pointer; line-height:1.3;
}
.picker-options li:hover, .picker-options li.hl { background: var(--bg); }
.picker-options li.selected { background: rgba(0,166,81,.08); color: var(--primary-dark); font-weight: 500; }
.picker-options li::before { content: '○'; color: var(--border); margin-right:.5rem; }
.picker-options li.selected::before { content: '✓'; color: var(--primary); }
.picker-add {
  border:none; border-top:1px solid var(--border); background:#fafbfa;
  padding: .55rem .85rem; cursor:pointer; font:inherit; text-align:center;
  color: var(--primary-dark); font-weight: 500;
}
.picker-add:hover { background: rgba(0,166,81,.06); }

/* --- Dropzone (compact) --- */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 1rem .75rem;
  text-align: center;
  background: #fafbfa;
  cursor: pointer;
  transition: all .15s ease;
}
.dropzone:hover, .dropzone:focus {
  border-color: var(--primary);
  background: #f0f8f3;
  outline: none;
}
.dropzone.dragover {
  border-color: var(--primary);
  background: #e6f4eb;
  transform: scale(1.005);
}
.dz-icon    { font-size: 1.75rem; line-height: 1; margin-bottom: .25rem; }
.dz-title   { font-size: .95rem;  font-weight: 600; color: var(--text); }
.dz-hint    { color: var(--muted); margin-top: .15rem; font-size: 13px; }
.dz-formats { color: var(--muted); font-size: 11px; margin-top: .35rem; letter-spacing: .04em; }

/* --- Ghi chú --- */
.notes-input {
  width:100%; padding: .6rem .85rem;
  border:1px solid var(--border); border-radius:8px;
  background:#fff; font: inherit; resize: vertical;
  min-height: 60px;
}
.notes-input:focus {
  outline:none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0,166,81,.12);
}

.picked-files { list-style:none; margin: .85rem 0 0; padding: 0; }
.picked-item {
  display:flex; align-items:center; gap:.65rem;
  padding: .55rem .75rem;
  background: #fff; border:1px solid var(--border); border-radius:6px;
  margin-bottom: .35rem;
}
.pf-icon { font-size: 1.1rem; }
.pf-name { flex:1; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-weight: 500; }
.pf-size { white-space:nowrap; }
.pf-remove {
  border:none; background: transparent; color: var(--err); font-size: 16px;
  cursor:pointer; padding: .15rem .45rem; border-radius:4px; line-height:1;
}
.pf-remove:hover { background: #fdecea; }

/* --- Progress --- */
.progress { margin-top: 1rem; }
.progress-bar {
  height: 10px; background: var(--bg); border-radius: 999px; overflow: hidden;
  border: 1px solid var(--border);
}
.progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--primary) 0%, var(--accent) 100%);
  transition: width .15s ease;
}
.progress-meta { display:flex; justify-content:space-between; margin-top: .35rem; font-size:13px; color: var(--text); }

/* --- Global drop overlay (kéo file vào bất kỳ chỗ nào trên trang) --- */
.global-drop-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(0, 166, 81, .82);
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;          /* không chặn drop event bubble */
  animation: gdo-fade .12s ease;
}
.global-drop-box {
  border: 4px dashed rgba(255,255,255,.85);
  border-radius: 20px;
  padding: 2.5rem 3.5rem;
  text-align: center; color: #fff;
  background: rgba(0,0,0,.08);
  box-shadow: 0 0 0 4px rgba(255,255,255,.1);
}
.global-drop-icon { font-size: 4rem; line-height: 1; margin-bottom: .85rem; }
.global-drop-text { font-size: 1.5rem; font-weight: 700; letter-spacing: .02em; }
@keyframes gdo-fade { from { opacity: 0 } to { opacity: 1 } }
@media (max-width: 720px) {
  .global-drop-box { padding: 1.5rem 2rem; }
  .global-drop-icon { font-size: 3rem; }
  .global-drop-text { font-size: 1.15rem; }
}

/* --- Success modal --- */
.success-modal { text-align:center; padding: .5rem; }
.success-icon {
  width: 64px; height: 64px; line-height: 64px;
  margin: 0 auto .75rem;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff; font-size: 2.5rem; font-weight: bold;
}
.success-modal h3 { margin: 0 0 .25rem; color: var(--primary-dark); }
.success-modal p  { margin: 0 0 1.25rem; }

/* ============================================================
   Mobile (≤ 720px) — overrides
   ============================================================ */
@media (max-width: 720px) {
  /* Layout chung */
  .main { padding: .75rem; }

  /* Topbar: logo nhỏ, ẩn chữ phụ, tên người dùng rút thành icon */
  .topbar { padding: .5rem .75rem; gap: .5rem; }
  .topbar .brand-title, .topbar .brand-sep { display:none; }
  .topbar .brand-logo { height: 32px; }
  .topbar nav { gap: 0; margin-left: 0; }
  .topbar nav a { padding: .35rem .55rem; font-size: 13px; }
  .topbar .user-box { gap: .4rem; }
  .topbar .user-box span { display:none; }  /* ẩn "👤 Vũ Nguyễn Anh Tuấn" */
  .topbar .user-box a { padding: .3rem .55rem; font-size: 13px; }
  .topbar .user-box a::before { content: '⇲ '; }

  /* Filter bar: search full-width khi xuống dòng */
  .filter-bar { padding: .6rem; gap: .4rem; }
  .filter-search { width: 100%; }
  .filter-spacer { display:none; }
  .filter-bar .btn {
    flex: 1; min-width: 0; text-align: center;
    white-space: nowrap;            /* không vỡ chữ "+ Tải lên" thành 2 dòng */
  }
  /* "+ Tải lên" chiếm 1 hàng riêng full-width — dễ tap trên mobile */
  .filter-bar .btn[data-open-upload] {
    flex-basis: 100%;
    padding: .65rem;
    font-weight: 600;
  }
  .filter-date-label { font-size: 12px; }
  .filter-date { padding: .4rem .5rem; }
  .drop-panel { min-width: 240px; max-width: calc(100vw - 24px); }

  /* Grid 2 cột trên mobile, gap nhỏ hơn */
  .grid { grid-template-columns: repeat(2, 1fr); gap: .6rem; }
  .design-card .info { padding: .45rem .55rem; }
  .design-card .product { font-size: 13px; }
  .design-card .meta { font-size: 11px; }

  /* Detail page: file list 1 cột */
  .file-list { grid-template-columns: 1fr; }

  /* Upload form */
  .upload-wrap { margin: .25rem auto; }
  .upload-form { padding: 1rem; }
  .dropzone   { padding: .85rem .75rem; }
  .dz-icon    { font-size: 1.6rem; }
  .dz-title   { font-size: .9rem; }
  .dz-formats { font-size: 10.5px; }

  /* Dialog nhỏ (success / add product) — full-width nhỏ gọn trên mobile.
     KHÔNG đụng đến design-dialog và upload-dialog (có layout riêng). */
  #dlg-add-product, #dlg-success {
    min-width: 0; width: calc(100vw - 32px); padding: 1rem;
  }
  .form .row { grid-template-columns: 1fr; gap: .25rem; }
  .form .row > span:first-child { font-size: 12px; }

  /* Admin */
  .admin-grid { grid-template-columns: repeat(2, 1fr); }
  table.data { font-size: 12px; }
  table.data th, table.data td { padding: .4rem .5rem; }
}

/* Rất hẹp (≤ 400px): grid 1 cột để card đủ to thấy thumbnail rõ */
@media (max-width: 400px) {
  .grid { grid-template-columns: 1fr; }
}
