/* ==========================================================================
   SÓNG ÂM — BASE / COMPONENT LIBRARY (bản dựng thật)
   Port từ thiet-ke/base.css: giữ nguyên mọi token, tên class, trạng thái
   của thư viện component (4.3). Bỏ phần chỉ phục vụ khung trình diễn mockup
   tĩnh (.mock-stage/.phone-frame/.desktop-frame/.dev-note — không phải UI
   thật, xem 4.1 quy tắc #2) để giảm dung lượng trang người nhận.
   Mục lục:
     1. Reset & nền tảng
     2. Tiện ích chữ
     3. Nút bấm
     4. Thẻ (card)
     5. Biểu mẫu (input, label, field)
     6. Huy hiệu trạng thái & nhãn độ tin cậy
     7. Tiến trình (progress / spinner)
     8. Công tắc khoá/mở (toggle)
     9. Banner cảnh báo
     10. Bảng dữ liệu
     11. Đồng hồ khả năng quét
     12. Hộp thoại xác nhận (modal) & tấm trượt đáy (sheet)
     13. Điều hướng xưởng (sidebar/topbar)
     14. Khung chứa sóng âm
     15. Tiện ích khả năng tiếp cận
     16. Chuyển động & prefers-reduced-motion
   ========================================================================== */

/* ---------- 1. Reset & nền tảng ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-family-base);
  font-size: var(--font-size-body);
  line-height: var(--line-height-body);
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4, p, figure { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
button, input, select, textarea { font-family: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
::selection { background: #F6CCDDF0; color: #4C2638; }
img, svg { display: block; max-width: 100%; }
a { color: inherit; }

/* Một phần tử có cả class đặt display:flex/grid (banner, modal-overlay,
   sheet-overlay…) VÀ thuộc tính hidden vẫn hiện ra nếu không có dòng này —
   quy tắc UA mặc định [hidden]{display:none} có độ ưu tiên thấp hơn bất kỳ
   rule display nào trong CSS tác giả, bất kể selector cụ thể hơn hay không.
   Phát hiện khi chụp ảnh màn hình nhan-5 (tấm trượt đáy hiện sẵn dù hidden). */
[hidden] { display: none !important; }

:focus-visible {
  outline: 2.5px solid var(--color-focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
/* Programmatic headings orient screen readers without looking like inputs. */
h1[tabindex="-1"]:focus-visible, h2[tabindex="-1"]:focus-visible { outline: none; }

/* ---------- 2. Tiện ích chữ ---------- */
.text-display  { font-size: var(--font-size-display);  line-height: var(--line-height-display);  font-weight: var(--font-weight-bold); }
.text-title    { font-size: var(--font-size-title);    line-height: var(--line-height-title);    font-weight: var(--font-weight-semibold); }
.text-subtitle { font-size: var(--font-size-subtitle); line-height: var(--line-height-subtitle); font-weight: var(--font-weight-medium); }
.text-body     { font-size: var(--font-size-body);     line-height: var(--line-height-body); }
.text-caption  { font-size: var(--font-size-caption);  line-height: var(--line-height-caption); }
.text-muted    { color: var(--color-text-muted); }
.text-faint    { color: var(--color-text-faint); }
.text-text     { color: var(--color-text); }
.weight-medium   { font-weight: var(--font-weight-medium); }
.weight-semibold { font-weight: var(--font-weight-semibold); }
.weight-bold     { font-weight: var(--font-weight-bold); }

/* Trang dành cho người nhận quà dùng cỡ chữ lớn hơn một bậc. */
.scale-nguoi-nhan {
  --font-size-body: 1.125rem;
  --line-height-body: 1.75rem;
  --font-size-caption: 1rem;
  --line-height-caption: 1.5rem;
  --tap-target-min: 48px;
}

/* ---------- 3. Nút bấm ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap-target-min);
  padding: 0 var(--space-5);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: var(--font-size-body);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
  transition: background-color var(--duration-micro) var(--ease-emphasized),
              border-color var(--duration-micro) var(--ease-emphasized),
              transform var(--duration-micro) var(--ease-emphasized);
  text-decoration: none;
  user-select: none;
}
.btn:not(:disabled):hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0) scale(0.98); }
.btn-primary { background: var(--color-primary); color: var(--color-on-primary); }
.btn-primary:not(:disabled):hover { background: var(--color-primary-strong); }
.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border-strong); }
.btn-secondary:not(:disabled):hover { background: var(--color-surface-alt); }
.btn-ghost { background: transparent; color: var(--color-primary); }
.btn-ghost:not(:disabled):hover { background: var(--color-primary-soft); }
.btn-danger { background: var(--color-danger); color: var(--color-on-danger); }
.btn-danger:hover { filter: brightness(0.92); }
.btn-block { width: 100%; }
.btn-lg { min-height: 56px; font-size: var(--font-size-subtitle); padding: 0 var(--space-6); border-radius: var(--radius-lg); }
.btn-compact { min-height: 44px; padding: 0 var(--space-4); font-size: var(--font-size-caption); border-radius: var(--radius-sm); }
.btn-icon { padding: 0; width: var(--tap-target-min); min-height: var(--tap-target-min); border-radius: var(--radius-full); }
.btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; }
.btn svg { width: 20px; height: 20px; flex: none; }

/* ---------- 4. Thẻ (card) ---------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
}
.card-pad { padding: var(--space-5); }

/* ---------- 5. Biểu mẫu ---------- */
.field { display: flex; flex-direction: column; gap: var(--space-2); }
.field label {
  font-size: var(--font-size-caption);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-muted);
}
.input, .select, textarea.input {
  font-family: inherit;
  font-size: var(--font-size-body);
  color: var(--color-text);
  background: var(--color-surface);
  border: 1.5px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  padding: 0 var(--space-4);
  min-height: var(--tap-target-min);
  transition: border-color var(--duration-micro) var(--ease-emphasized), background-color var(--duration-micro) var(--ease-emphasized);
}
.input:focus, .select:focus { border-color: var(--color-primary); background: #FFFBFD; }
input::placeholder, textarea::placeholder { color: var(--color-text-faint); opacity: 1; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--color-primary); width: 18px; height: 18px; }
.field-hint { font-size: var(--font-size-caption); color: var(--color-text-faint); }
textarea.input { min-height: 88px; padding: var(--space-3) var(--space-4); line-height: var(--line-height-body); resize: vertical; }

/* ---------- 6. Huy hiệu trạng thái ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--font-size-caption);
  font-weight: var(--font-weight-semibold);
  padding: 3px var(--space-3);
  border-radius: var(--radius-full);
  line-height: var(--line-height-caption);
}
.badge::before {
  content: '';
  width: 7px; height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.badge-success { background: var(--color-success-soft); color: var(--color-success); }
.badge-warning { background: var(--color-warning-soft); color: var(--color-warning); }
.badge-danger  { background: var(--color-danger-soft);  color: var(--color-danger); }
.badge-neutral { background: var(--color-surface-alt); color: var(--color-text-muted); }

/* ---------- 7. Tiến trình ---------- */
.progress {
  width: 100%;
  height: 10px;
  border-radius: var(--radius-full);
  background: var(--color-surface-alt);
  overflow: hidden;
}
.progress__bar {
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--color-primary);
  transition: width var(--duration-base) var(--ease-emphasized);
}
.spinner {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 3px solid var(--color-surface-alt);
  border-top-color: var(--color-primary);
  animation: spin 900ms linear infinite;
}
.spinner-sm { width: 12px; height: 12px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 8. Công tắc khoá/mở ---------- */
.toggle { display: inline-flex; align-items: center; gap: var(--space-3); min-height: 44px; cursor: pointer; }
.toggle__track {
  width: 46px; height: 28px;
  border-radius: var(--radius-full);
  background: var(--color-border-strong);
  position: relative;
  transition: background-color var(--duration-micro) var(--ease-emphasized);
  flex: none;
}
.toggle__thumb {
  position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--color-surface);
  box-shadow: var(--shadow-card);
  transition: transform var(--duration-micro) var(--ease-emphasized);
}
.toggle.is-on .toggle__track { background: var(--color-success); }
.toggle.is-on .toggle__thumb { transform: translateX(18px); }
.toggle.is-locked .toggle__track { background: var(--color-danger); }

/* ---------- 9. Banner ---------- */
.banner {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--color-warning-soft);
  color: var(--color-on-warning);
  font-size: var(--font-size-caption);
  font-weight: var(--font-weight-medium);
  border-bottom: 1px solid rgba(0,0,0,.06);
  position: relative;
  z-index: var(--z-banner);
}
.banner svg { flex: none; width: 20px; height: 20px; }
.banner__close {
  margin-left: auto;
  background: none; border: none; cursor: pointer;
  width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: inherit;
}
.banner__close:hover { background: rgba(0,0,0,.06); }

/* ---------- 10. Bảng dữ liệu ---------- */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left;
  font-size: var(--font-size-caption);
  color: var(--color-text-muted);
  font-weight: var(--font-weight-semibold);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
.data-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  font-size: var(--font-size-body);
  vertical-align: middle;
}
.data-table tbody tr { transition: background-color var(--duration-micro) var(--ease-emphasized); }
.data-table tbody tr:hover { background: var(--color-surface-alt); }
.row-thumb {
  width: 56px; height: 32px;
  border-radius: var(--radius-sm);
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  color: var(--color-wave-theu);
}
.row-thumb svg { width: 100%; height: 100%; }

/* ---------- 11. Đồng hồ khả năng quét ---------- */
.scan-meter { display: flex; flex-direction: column; gap: var(--space-2); }
.scan-meter__track {
  position: relative;
  height: 14px;
  border-radius: var(--radius-full);
  display: flex;
  overflow: visible;
}
.scan-meter__zone { height: 100%; }
.scan-meter__zone:first-child { border-radius: var(--radius-full) 0 0 var(--radius-full); }
.scan-meter__zone:last-child { border-radius: 0 var(--radius-full) var(--radius-full) 0; }
.scan-meter__zone--safe { background: var(--color-success); flex: 1 1 50%; }
.scan-meter__zone--warn { background: var(--color-warning); flex: 1 1 30%; }
.scan-meter__zone--risk { background: var(--color-danger); flex: 1 1 20%; }
.scan-meter__pointer {
  position: absolute;
  top: -5px;
  width: 2px; height: 24px;
  background: var(--color-text);
  border-radius: 2px;
  transform: translateX(-1px);
}
.scan-meter__pointer::after {
  content: '';
  position: absolute; top: -6px; left: 50%;
  transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--color-text);
}
.scan-meter__labels { display: flex; justify-content: space-between; font-size: var(--font-size-caption); color: var(--color-text-faint); }
.scan-meter__note {
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-caption);
}
.scan-meter__note--safe { background: var(--color-success-soft); color: var(--color-success); }
.scan-meter__note--warn { background: var(--color-warning-soft); color: var(--color-warning); }
.scan-meter__note--risk { background: var(--color-danger-soft); color: var(--color-danger); }
.scan-meter__note svg { flex: none; width: 18px; height: 18px; margin-top: 1px; }

/* ---------- 12. Hộp thoại xác nhận & tấm trượt đáy ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: var(--color-overlay);
  display: flex; align-items: center; justify-content: center;
  padding: var(--space-5);
  z-index: var(--z-modal);
}
.modal {
  width: 100%; max-width: 400px;
  background: var(--color-surface-raised);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  padding: var(--space-5);
  display: flex; flex-direction: column; gap: var(--space-4);
}
.modal__actions { display: flex; gap: var(--space-3); justify-content: flex-end; }
.sheet-overlay {
  position: fixed; inset: 0;
  background: var(--color-overlay);
  display: flex; align-items: flex-end;
  z-index: var(--z-modal);
}
.sheet {
  width: 100%;
  background: var(--color-surface-raised);
  border-radius: 24px 24px 0 0;
  box-shadow: var(--shadow-modal);
  padding: var(--space-3) var(--space-5) var(--space-6);
  display: flex; flex-direction: column; gap: var(--space-4);
  max-height: 80%;
  overflow: auto;
}
.sheet__handle {
  width: 40px; height: 4px; border-radius: var(--radius-full);
  background: var(--color-border-strong);
  margin: 0 auto;
}

/* ---------- 13. Điều hướng xưởng ---------- */
.app-sidebar {
  width: 240px;
  flex: none;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  padding: var(--space-5) var(--space-3);
  gap: var(--space-6);
}
.app-sidebar__brand {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 0 var(--space-3);
}
.app-sidebar__brand-mark {
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  background: var(--color-primary); color: var(--color-on-primary);
  display: flex; align-items: center; justify-content: center;
}
.app-nav { display: flex; flex-direction: column; gap: var(--space-1); }
.app-nav__link {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-weight: var(--font-weight-medium);
  text-decoration: none;
  transition: background-color var(--duration-micro) var(--ease-emphasized);
}
.app-nav__link svg { width: 20px; height: 20px; flex: none; }
.app-nav__link:hover { background: var(--color-surface-alt); color: var(--color-text); }
.app-nav__link.is-active { background: var(--color-primary-soft); color: var(--color-primary-strong); }
.app-topbar {
  flex: none;
  min-height: 64px;
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-6);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-wrap: wrap;
}
.app-body { display: flex; min-height: 100vh; }
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-content { flex: 1; overflow: auto; padding: var(--space-6); }
.avatar-chip {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--color-primary-soft); color: var(--color-primary-strong);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; flex: none;
}
.user-chip { display: flex; align-items: center; gap: var(--space-3); }
.user-chip .role { font-size: var(--font-size-caption); color: var(--color-text-faint); }

/* ---------- 14. Khung chứa sóng âm ---------- */
.wf-svg { width: 100%; height: auto; display: block; }
.waveform-box {
  width: 100%;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}
.wf-bar, .wf-dot { transition: fill var(--duration-base) var(--ease-emphasized); }

/* ---------- 14b. Tiện ích khoảng cách (thay cho thuộc tính "style" nội tuyến —
   CSP style-src 'self' không cho phép đặt kiểu nội tuyến trực tiếp trong HTML) ---------- */
.mt-1 { margin-top: var(--space-1); } .mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); } .mt-4 { margin-top: var(--space-4); }
.mt-5 { margin-top: var(--space-5); } .mt-6 { margin-top: var(--space-6); }
.mb-1 { margin-bottom: var(--space-1); } .mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); } .mb-4 { margin-bottom: var(--space-4); }
.ml-auto { margin-left: auto; }
.mr-auto { margin-right: auto; }
.flex-row { display: flex; align-items: center; }
.flex-col { display: flex; flex-direction: column; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-5 { gap: var(--space-5); }
.gap-6 { gap: var(--space-6); }

/* ---------- 15. Tiện ích khả năng tiếp cận ---------- */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: var(--space-3); top: -48px;
  background: var(--color-primary); color: var(--color-on-primary);
  padding: var(--space-2) var(--space-4); border-radius: var(--radius-sm);
  transition: top var(--duration-micro) var(--ease-emphasized);
  z-index: 100;
}
.skip-link:focus { top: var(--space-3); }

/* ---------- 16. Chuyển động trang trí — tôn trọng prefers-reduced-motion ---------- */
@keyframes breathe {
  0%, 100% { transform: scaleY(1); opacity: .85; }
  50% { transform: scaleY(1.12); opacity: 1; }
}
.is-breathing .wf-bar, .is-breathing .wf-dot {
  animation: breathe 1600ms var(--ease-emphasized) infinite;
}
@media (prefers-reduced-motion: reduce) {
  .is-breathing .wf-bar, .is-breathing .wf-dot { animation: none; }
  .spinner { animation-duration: 1600ms; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Shared blush identity: legible ink, soft borders, visible interaction. */
.card { transition: border-color var(--duration-base) var(--ease-emphasized); }
.card:focus-within { border-color: var(--color-border-strong); }
.modal, .sheet { border: 1px solid var(--color-border); animation: rose-enter 260ms var(--ease-emphasized) both; }
.data-table thead { background: #FCF1F6; }
.data-table th { padding-top: 18px; padding-bottom: 18px; }
.data-table td { padding-top: 16px; padding-bottom: 16px; }
.app-sidebar { width: 248px; background: #FFFCFD; padding: 32px 18px; gap: 40px; }
.app-sidebar__brand { font-size: 20px; letter-spacing: -.04em; }
.app-sidebar__brand-mark { width: 40px; height: 40px; border-radius: 15px; transform: rotate(-5deg); }
.app-nav { gap: 8px; }
.app-nav__link { min-height: 48px; padding: 13px 16px; font-size: 14px; }
.app-nav__link.is-active { background: #F9E2EC; font-weight: 600; }
.app-nav__link svg { stroke-linecap: round; stroke-linejoin: round; }
.app-topbar { min-height: 92px; background: #FFFCFD; padding: 22px 36px; }
.app-topbar h1 { letter-spacing: -.04em; }
.app-content { padding: 32px 36px; }
.avatar-chip { border: 1px solid var(--color-border); }
.waveform-box { background: #FFFAFC; border-style: dashed; padding: 24px; }
@keyframes rose-enter { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@media (max-width: 760px) {
  .app-content { padding: 24px 18px; }
  .app-topbar { min-height: 76px; padding: 18px; }
}
