/* AV_RESPONSIVE_2026_V5 — Account Vault visual & responsive enhancement
 * Layered after style.css. No functional/authentication/cryptography code modified.
 * Breakpoints: wide / desktop / tablet / phone / compact phone.
 */

/* 01 — Harmonized light/dark design tokens */
:root {
  --bg: #f5f7fc;
  --surface: #ffffff;
  --surface-alt: #f8faff;
  --border: #e4e9f3;
  --text: #1d2942;
  --muted: #7f8ba2;
  --subtle: #63718a;
  --primary: #6456e8;
  --primary-dark: #5244d9;
  --primary-soft: #f0edff;
  --radius: 16px;
  --shadow: 0 9px 34px rgba(24, 38, 78, .045);
}
:root[data-theme="dark"] {
  --bg: #0f1728;
  --surface: #18233a;
  --surface-alt: #212f47;
  --border: #344158;
  --text: #f0f3ff;
  --muted: #9eabc0;
  --subtle: #bdc8d8;
  --primary: #a399ff;
  --primary-dark: #8b7dfa;
  --primary-soft: #302b59;
  --shadow: 0 8px 26px rgba(0, 0, 0, .10);
}
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-behavior: smooth; }
body { min-width: 0; font-size: 14px; line-height: 1.58; -webkit-font-smoothing: antialiased; }
#app, .shell, .workspace, .content { min-width: 0; }
img, svg, video, canvas { max-width: 100%; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button, .btn, .icon-button, .mini-btn { touch-action: manipulation; }
:where(button, a, input, select, textarea, [tabindex]):focus-visible {
  outline: 3px solid #8274f8; outline-offset: 3px;
}
:where(.panel, .service-card, .stat-card, .center-card, .modal, .drawer) { color: var(--text); }
:where(.panel, .service-card, .stat-card) { border-color: var(--border); box-shadow: var(--shadow); }
:where(.panel, .service-card, .stat-card) { transition: box-shadow .18s ease, border-color .18s ease; }
:where(.panel, .service-card, .stat-card):hover { border-color: color-mix(in srgb, var(--border) 65%, var(--primary) 35%); }
::selection { background: #cbc5ff; color: #17223b; }

/* 02 — App shell, fluid spacing and navigation */
.shell { min-height: 100vh; min-height: 100dvh; }
.sidebar {
  width: 248px; min-width: 248px;
  height: 100vh; height: 100dvh;
  padding-top: max(22px, env(safe-area-inset-top));
  scrollbar-width: thin; scrollbar-color: #50607d transparent;
  overscroll-behavior: contain;
}
.sidebar-head { padding-bottom: 28px; }
.nav-link, .service-nav-link { min-height: 39px; }
.sidebar-bottom { padding-bottom: max(2px, env(safe-area-inset-bottom)); }
.workspace { flex: 1 1 0; width: 0; }
.topbar { height: 72px; gap: 12px; padding-inline: clamp(16px, 2.8vw, 44px); }
.topbar-left, .topbar-right, .breadcrumbs { min-width: 0; }
.topbar-left { flex: 1 1 0; overflow: hidden; }
.topbar-right { flex: 0 0 auto; gap: 9px; }
.breadcrumbs { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.breadcrumbs > * { min-width: 0; }
.content { max-width: 1540px; padding: clamp(20px, 3vw, 38px) clamp(16px, 3vw, 44px) 72px; }
.page-head { gap: 16px; }
.page-head > :first-child { min-width: 0; }
.page-head h1 { font-size: clamp(23px, 2.3vw, 31px); overflow-wrap: anywhere; }
.page-head p { overflow-wrap: anywhere; }
.page-actions { flex-wrap: wrap; justify-content: flex-end; max-width: 100%; }
.btn { min-height: 41px; padding-inline: 15px; border-radius: 10px; }
.btn-primary { box-shadow: 0 6px 15px rgba(98, 84, 232, .17); }
.icon-button { flex: 0 0 auto; }
.logo-text strong, .stat-value, .page-head h1 { text-wrap: balance; }

/* 03 — Dashboard cards, sections, long text safety */
.stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: clamp(11px, 1.35vw, 19px); }
.stat-card { min-width: 0; padding: clamp(15px, 1.7vw, 24px); }
.stat-value { font-size: clamp(27px, 2.5vw, 34px); }
.stat-top { min-width: 0; }
.stat-top span, .stat-sub, .panel-head p { overflow-wrap: anywhere; }
.dashboard-grid { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 18px; }
.dashboard-grid > *, .settings-grid > *, .service-grid > * { min-width: 0; }
.panel { min-width: 0; }
.panel-head { align-items: flex-start; }
.quick-list button, .recent-row { min-width: 0; }
.quick-list button > span, .recent-main { min-width: 0; }
.quick-list strong, .quick-list small, .recent-main strong { overflow-wrap: anywhere; }
.service-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.service-card { display: flex; flex-direction: column; min-width: 0; }
.service-card h3, .service-card p { overflow-wrap: anywhere; }
.service-card-link { margin-top: auto; }
.service-card .field-chips { margin-bottom: 13px; }

/* 04 — Table: large data sets, sticky header, touch scrolling and safe secrets */
.table-panel { overflow: hidden; min-width: 0; }
.table-toolbar { display: flex; flex-wrap: wrap; gap: 10px; padding: 17px clamp(14px, 1.9vw, 23px); }
.table-toolbar > * { min-width: 0; }
.table-toolbar .search-input { width: min(100%, 450px); max-width: 450px; min-width: 190px; }
.table-toolbar select { max-width: 100%; }
.table-count { white-space: nowrap; }
.table-wrap {
  width: 100%; max-width: 100%; overflow-x: auto; overflow-y: auto;
  overscroll-behavior-inline: contain; -webkit-overflow-scrolling: touch;
  scrollbar-width: thin; scrollbar-color: #b9bdd4 transparent;
}
.table-wrap:focus-visible { outline-offset: -3px; }
.table-wrap::-webkit-scrollbar { height: 10px; width: 8px; }
.table-wrap::-webkit-scrollbar-thumb { background: #b9bdd4; border-radius: 20px; border: 2px solid var(--surface); }
.data-table { width: 100%; min-width: 740px; border-collapse: separate; border-spacing: 0; }
.data-table th {
  position: sticky; top: 0; z-index: 2; background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  font-size: 11px; letter-spacing: .01em;
}
.data-table th, .data-table td { padding: 13px clamp(10px, 1.15vw, 17px); vertical-align: middle; }
.data-table th:first-child, .data-table td:first-child { padding-left: clamp(12px, 1.6vw, 22px); }
.data-table td { background: var(--surface); }
.data-table tbody tr:hover td { background: var(--surface-alt); }
.data-table td:last-child, .data-table th:last-child { white-space: nowrap; }
.table-actions { gap: 1px; }
.table-actions .mini-btn, .table-secret-controls .mini-btn, .av-username-copy {
  min-width: 32px; min-height: 32px; display: inline-flex;
  align-items: center; justify-content: center;
}
.av-username-cell { display: flex; align-items: center; gap: 6px; min-width: 185px; max-width: 360px; }
.av-username-cell .cell-entry { min-width: 0; max-width: 100%; }
.av-username-copy { opacity: .88; flex: none; }
.cell-entry { min-width: 0; }
.entry-title { min-width: 0; max-width: 290px; }
.table-secret-cell { min-width: 164px; max-width: 430px; gap: 9px; }
.table-secret-value { flex: 0 1 auto; min-width: 70px; max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-secret-controls { gap: 2px; flex: 0 0 auto; }
.table-footer { flex-wrap: wrap; padding: 13px clamp(12px, 1.7vw, 22px); }
.pagination { margin-left: auto; white-space: nowrap; }

/* 05 — Modals, dynamic field builder, inputs and drawer */
.modal-backdrop { padding: 18px; }
.modal { max-width: 100%; overscroll-behavior: contain; max-height: calc(100vh - 36px); max-height: calc(100dvh - 36px); }
.modal-wide { width: min(100%, 960px); }
.modal-top { min-width: 0; }
.modal-top h2 { font-size: clamp(19px, 2vw, 23px); overflow-wrap: anywhere; }
.modal-footer { flex-wrap: wrap; }
.form-grid { grid-template-columns: minmax(0, 1fr) minmax(110px, 140px) minmax(112px, 145px); }
.form-grid.extra-fields { grid-template-columns: minmax(0, 1fr) minmax(130px, 170px); }
.form-grid > label, .entry-fields > *, .entry-field { min-width: 0; }
.builder-row { min-width: 0; grid-template-columns: 22px minmax(120px, 1.6fr) minmax(110px, 1fr) 96px 65px 92px; }
.builder-row .builder-label, .builder-row select { min-width: 0; }
.builder-moves { justify-content: flex-end; }
.builder-moves button { min-width: 25px; min-height: 32px; }
.field-options { overflow-wrap: anywhere; }
.drawer { max-width: 100%; height: 100vh; height: 100dvh; overscroll-behavior: contain; }
.drawer-head h2 { overflow-wrap: anywhere; }
.detail-text, .recovery-value, .note-box, .info-panel p { overflow-wrap: anywhere; }
.center-page, .auth-page { min-height: 100vh; min-height: 100dvh; }
.center-card { max-width: min(100%, 490px); }
:where(input, textarea, select):not([type="checkbox"]) { max-width: 100%; }
#toast-root { z-index: 120; bottom: max(16px, env(safe-area-inset-bottom)); right: max(16px, env(safe-area-inset-right)); }

/* 06 — Medium laptop and narrow desktop */
@media (max-width: 1280px) {
  .sidebar { width: 226px; min-width: 226px; }
  .content { padding-inline: clamp(18px, 2vw, 28px); }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .service-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}
@media (max-width: 1050px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .builder-row { grid-template-columns: 20px minmax(100px, 1.3fr) minmax(104px, 1fr) 88px 61px 90px; }
}

/* 07 — Tablet: off-canvas menu, wrapping action toolbar */
@media (max-width: 900px) {
  .sidebar {
    position: fixed; top: 0; left: 0; width: min(310px, 88vw); min-width: 0;
    height: 100vh; height: 100dvh;
    padding-top: max(20px, env(safe-area-inset-top));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    z-index: 45; box-shadow: 15px 0 55px rgba(0,0,0,.3);
    transform: translateX(-105%); transition: transform .22s ease;
  }
  .sidebar.mobile-open { transform: translateX(0); }
  .mobile-scrim { z-index: 44; background: rgba(10, 16, 34, .58); }
  .workspace { width: 100%; }
  .topbar { height: 66px; padding-inline: 17px; }
  .mobile-menu { display: inline-flex; }
  .content { padding: 26px 22px 60px; }
  .page-head { align-items: flex-start; }
  .page-actions { flex: 1 1 auto; }
  .modal-backdrop, .drawer-backdrop { z-index: 65; }
}

/* 08 — Phones: single-column panels, flexible forms, compact header */
@media (max-width: 700px) {
  .auth-page { display: block; min-height: 100dvh; }
  .auth-visual { display: none; }
  .auth-content { padding: max(26px, env(safe-area-inset-top)) 20px max(30px, env(safe-area-inset-bottom)); min-height: 100dvh; }
  .auth-card { width: min(100%, 440px); }
  .mobile-brand { margin-bottom: clamp(24px, 7vh, 60px); }
  .auth-card h2, .center-card h2 { font-size: clamp(23px, 6vw, 29px); }
  .center-page { min-height: 100dvh; padding: max(24px, env(safe-area-inset-top)) 15px max(25px, env(safe-area-inset-bottom)); }
  .center-card { padding: 24px 19px; border-radius: 18px; }
  .center-brand { margin-bottom: 20px; }
  .security-foot { flex-wrap: wrap; text-align: center; }
  .content { padding: 21px 13px 52px; }
  .topbar { height: 61px; gap: 6px; padding-inline: 12px; }
  .topbar-right { gap: 2px; }
  .topbar-right .topbar-security { display: none; }
  .topbar .icon-button { width: 33px; height: 36px; }
  .topbar .av-top-action { padding: 7px; min-height: 36px; }
  .topbar .av-top-action span { display: none; }
  .breadcrumbs { font-size: 12px; gap: 6px; }
  .page-head { flex-direction: column; gap: 14px; margin-bottom: 21px; }
  .page-head h1 { font-size: clamp(23px, 6vw, 29px); }
  .page-head p { line-height: 1.6; font-size: 12px; }
  .page-actions { flex: initial; width: 100%; justify-content: stretch; gap: 8px; }
  .page-actions .btn { flex: 1 1 auto; white-space: normal; text-align: center; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat-card { padding: 15px 13px; }
  .stat-top { font-size: 11px; }
  .stat-icon { width: 34px; height: 34px; }
  .stat-value { font-size: 27px; }
  .dashboard-grid, .service-grid, .settings-grid { grid-template-columns: 1fr; gap: 13px; }
  .panel { padding: 18px 16px; }
  .recent-panel { margin-top: 13px; }
  .table-panel { padding: 0; }
  .table-toolbar { padding: 13px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(100px, auto); }
  .table-toolbar .search-input { grid-column: 1 / -1; max-width: none; width: 100%; min-width: 0; }
  .table-toolbar select { grid-column: 1; width: 100%; }
  .table-toolbar .table-count { grid-column: 2; justify-self: end; align-self: center; }
  .data-table { min-width: 780px; }
  .table-wrap { overflow-x: auto; }
  .data-table th, .data-table td { padding: 12px 11px; }
  .table-secret-cell { min-width: 175px; }
  .table-footer { gap: 8px; padding: 11px 12px; }
  .bulk-actions { flex-wrap: wrap; }
  .entry-fields, .form-grid.extra-fields { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid > label:first-child { grid-column: 1 / -1; }
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal { width: 100%; max-width: 100%; max-height: 92vh; max-height: 92dvh; padding: 20px 16px max(18px, env(safe-area-inset-bottom)); border-radius: 20px 20px 0 0; }
  .modal-wide { width: 100%; }
  .modal-top { margin-bottom: 18px; }
  .modal-footer { justify-content: flex-end; }
  .modal-footer .btn { min-height: 42px; }
  .field-builder { margin-top: 18px; padding-top: 16px; }
  .section-row { flex-wrap: wrap; gap: 4px 12px; }
  /* Field editor becomes a vertical mini-card; nothing escapes the viewport. */
  .builder-row {
    display: grid; width: 100%; min-width: 0;
    grid-template-columns: 25px minmax(0, 1fr) minmax(0, 1fr);
    gap: 9px 8px; align-items: center;
    padding: 12px 9px; border: 1px solid var(--border);
    border-radius: 12px; background: var(--surface-alt); margin-bottom: 10px;
  }
  .builder-index { grid-column: 1; grid-row: 1; }
  .builder-row > input.builder-label { grid-column: 2 / -1; grid-row: 1; width: 100%; }
  .builder-row > select { grid-column: 2 / -1; grid-row: 2; width: 100%; }
  .builder-row > .builder-check { grid-row: auto; grid-column: 2; }
  .builder-row > .builder-check + .builder-check { grid-column: 3; }
  .builder-row > .builder-moves { grid-column: 2 / -1; grid-row: auto; display: flex; justify-content: flex-start; gap: 13px; }
  .builder-row > .builder-moves button { min-width: 36px; min-height: 36px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); }
  .builder-row > .field-options { grid-column: 2 / -1; width: 100%; }
  .builder-row input, .builder-row select { font-size: 14px; }
  .drawer { width: 100%; height: 100dvh; padding: 20px 16px max(20px, env(safe-area-inset-bottom)); }
  .drawer-footer .btn { min-width: 0; flex: 1; }
  #toast-root { bottom: max(12px, env(safe-area-inset-bottom)); right: 12px; left: 12px; max-width: none; }
}

/* 09 — Small phones and narrow landscape */
@media (max-width: 430px) {
  .topbar-right .avatar { display: none; }
  .topbar .icon-button { width: 31px; }
  .topbar-right { gap: 0; }
  .breadcrumbs .crumb-home { max-width: 55px; overflow: hidden; text-overflow: ellipsis; }
  .content { padding-inline: 10px; }
  .page-actions .btn { padding: 8px 10px; font-size: 12px; }
  .stats-grid { gap: 8px; }
  .stat-card { padding: 13px 11px; }
  .stat-top { align-items: flex-start; flex-wrap: wrap; gap: 5px; }
  .stat-value { font-size: 24px; }
  .service-card { padding: 18px; }
  .center-card { padding: 22px 16px; }
  .center-actions { gap: 7px; }
  .center-actions button { font-size: 12px; }
  .modal-footer { gap: 7px; }
  .modal-footer > .spacer { display: none; }
  .modal-footer .btn { flex: 1 1 auto; min-width: 100px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid > label:first-child { grid-column: auto; }
  .drawer-footer { flex-direction: column; }
  .drawer-footer .btn { width: 100%; }
}
@media (max-width: 350px) {
  .topbar .icon-button { width: 29px; }
  .page-actions { flex-direction: column; }
  .page-actions .btn { width: 100%; }
  .stats-grid { grid-template-columns: 1fr; }
  .breadcrumbs { font-size: 11px; }
}
@media (max-height: 520px) and (max-width: 900px) {
  .modal { max-height: 98dvh; }
  .center-page { justify-content: flex-start; }
  .auth-content { align-items: flex-start; }
}

/* 10 — Fine/coarse pointer, motion and contrast accessibility */
@media (pointer: coarse) {
  .nav-link, .service-nav-link, .sidebar-lock, .add-nav { min-height: 44px; }
  .btn { min-height: 44px; }
  .table-actions .mini-btn, .table-secret-controls .mini-btn, .av-username-copy { min-width: 38px; min-height: 38px; }
}
@media (pointer: coarse) and (max-width: 700px) {
  input:not([type="checkbox"]), textarea, select, .search-input input,
  .form-grid input, .form-grid select, .builder-row input, .builder-row select { font-size: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto !important; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
@media (prefers-contrast: more) {
  :root { --border: #9ca6b9; --muted: #536079; --subtle: #44516b; }
  :root[data-theme="dark"] { --border: #a8b4cc; --muted: #e0e6f4; --subtle: #e6ecf8; }
  .btn, .icon-button, input, select, textarea { border-width: 2px; }
}
@media print {
  /* Prevent accidental plaintext vault printing (e.g. while eye-toggle is active). */
  #app, #toast-root { display: none !important; }
  body::before { content: 'Account Vault: vi ly do bao mat, vui long khong in noi dung kho mat khau.'; display: block; padding: 32px; font: 16px/1.5 sans-serif; }
}

/* Component-level enhancement only where supported */
@supports (container-type: inline-size) {
  .table-panel { container-type: inline-size; }
  @container (max-width: 620px) {
    .table-toolbar { display: grid; grid-template-columns: minmax(0, 1fr) minmax(100px, auto); }
    .table-toolbar .search-input { grid-column: 1 / -1; max-width: none; width: 100%; min-width: 0; }
    .table-toolbar select { grid-column: 1; max-width: 100%; }
    .table-toolbar .table-count { grid-column: 2; justify-self: end; margin-left: 0; }
  }
}
/* END AV_RESPONSIVE_2026_V5 */

/* AV_LOGOUT_ALIGN_FIX_V1 */
.sidebar-bottom .sidebar-logout,
.sidebar-bottom [data-action="logout"],
.sidebar-bottom button[data-action="logout"],
.sidebar-bottom a[data-action="logout"]{
  width:100%;
  display:flex !important;
  align-items:center !important;
  justify-content:center !important;
  gap:9px !important;
  margin:10px auto 0 !important;
  padding:9px 12px !important;
  min-height:40px !important;
  border:1px solid transparent !important;
  border-radius:10px !important;
  background:transparent !important;
  color:#b7c4dc !important;
  font-size:12px !important;
  font-weight:650 !important;
  line-height:1 !important;
  text-align:center !important;
  white-space:nowrap !important;
  box-sizing:border-box !important;
}

.sidebar-bottom .sidebar-logout:hover,
.sidebar-bottom [data-action="logout"]:hover,
.sidebar-bottom button[data-action="logout"]:hover,
.sidebar-bottom a[data-action="logout"]:hover{
  color:#ffffff !important;
  background:#ffffff10 !important;
}

.sidebar-bottom .sidebar-logout svg,
.sidebar-bottom [data-action="logout"] svg,
.sidebar-bottom button[data-action="logout"] svg,
.sidebar-bottom a[data-action="logout"] svg{
  width:16px !important;
  height:16px !important;
  flex:none !important;
  display:block !important;
}

.sidebar-bottom .sidebar-logout span,
.sidebar-bottom [data-action="logout"] span,
.sidebar-bottom button[data-action="logout"] span,
.sidebar-bottom a[data-action="logout"] span{
  display:inline-flex !important;
  align-items:center !important;
  line-height:1 !important;
}

@media (max-width:660px){
  .sidebar-bottom .sidebar-logout,
  .sidebar-bottom [data-action="logout"],
  .sidebar-bottom button[data-action="logout"],
  .sidebar-bottom a[data-action="logout"]{
    min-height:42px !important;
    font-size:12px !important;
  }
}
