:root {
  color-scheme: dark;
  --bg: #0f1419;
  --panel: #1a2332;
  --panel-inset: #141c28;
  --border: #2d3a4d;
  --text: #e8eef7;
  --muted: #8b9cb3;
  --accent: #3d8bfd;
  --accent-hover: #5ca0ff;
  --accent-dim: rgba(61, 139, 253, 0.15);
  --danger: #f07178;
  --radius: 8px;
  --font: "Segoe UI", system-ui, sans-serif;
  --nav-compact-max: 760px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
}

html, body {
  height: 100%;
  overscroll-behavior-y: contain;
}
#app { min-height: 100%; }

h1, h2, h3 { margin: 0; font-weight: 600; }
h3 { font-size: 0.95rem; }
.subtitle, .hint, .muted { color: var(--muted); }
.subtitle { margin: 0; font-size: 0.9rem; }
.hint, .empty-inline { margin: 0.25rem 0 0; font-size: 0.8rem; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.center { max-width: 480px; margin: 3rem auto; padding: 1rem; }

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

label.check {
  flex-direction: row;
  align-items: center;
  color: var(--text);
}

input, select, textarea, button {
  font: inherit;
  border-radius: 6px;
  border: 1px solid var(--border);
}

input, select, textarea {
  background-color: var(--bg);
  color: var(--text);
  padding: 0.55rem 0.65rem;
}

select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b9cb3' d='M2.5 4.5 6 8 9.5 4.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
}

select option,
select optgroup {
  background-color: var(--panel);
  color: var(--text);
}

input:read-only, textarea:read-only, select:disabled {
  opacity: 0.92;
  cursor: default;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

input:disabled { opacity: 0.5; }
select:disabled { opacity: 0.5; }

button {
  cursor: pointer;
  padding: 0.55rem 1rem;
  background: var(--border);
  color: var(--text);
  white-space: nowrap;
}

button:disabled {
  cursor: wait;
  opacity: 0.75;
}

button:hover { filter: brightness(1.08); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-hover); }
button.ghost { background: transparent; }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
button.small { padding: 0.3rem 0.55rem; font-size: 0.78rem; }

#unlock-form { display: flex; flex-direction: column; gap: 1rem; margin-top: 1.5rem; }
.unlock-status { color: var(--muted); font-size: 0.9rem; margin: 0; text-align: center; }
.error { color: var(--danger); font-size: 0.9rem; margin: 0; }
.empty { color: var(--muted); text-align: center; padding: 2rem; }

#toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: #243044;
  border: 1px solid var(--border);
  padding: 0.65rem 1.1rem;
  border-radius: 999px;
  z-index: 9999;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
}


#unlock-screen[hidden],
#vault-screen[hidden] {
  display: none !important;
}

#vault-screen {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.5rem;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.vault-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.vault-panel[hidden] { display: none !important; }

.vault-sticky {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.vault-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Main navigation */
.main-nav.panel {
  padding: 0.125rem 0.5rem;
}

.main-nav {
  margin-bottom: 0;
}

.main-nav-inner {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.35rem;
  min-width: 0;
  height: 2rem;
}

#credentials-panel .main-nav-inner,
#settings-panel .main-nav-inner,
#admin-panel .main-nav-inner {
  height: 3rem;
}

.main-nav-links,
.nav-btn-row {
  display: inline-flex;
  flex: 0 0 auto;
  width: max-content;
  max-width: calc(100% - 2rem - 0.7rem);
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
}

.main-nav-inner > .nav-menu-toggle {
  flex: 0 0 auto;
  margin-left: auto;
}

.brand-logo-nav {
  width: 2rem;
  height: 2rem;
  object-fit: contain;
  flex-shrink: 0;
  display: block;
}

.nav-btn, .admin-tab, .settings-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2rem;
  height: 2rem;
  padding: 0 0.65rem;
  font-size: 0.8rem;
  line-height: 1;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text);
  flex-shrink: 0;
}

.nav-btn:hover, .admin-tab:hover, .settings-tab:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border);
}

.nav-btn.active, .admin-tab.active, .settings-tab.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent-hover);
}

.nav-back {
  flex-shrink: 0;
  white-space: nowrap;
}

.nav-menu-toggle {
  display: none;
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  min-width: 2rem;
  min-height: 2rem;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  line-height: 1;
}

.nav-menu-drawer {
  display: none;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.35rem;
  padding-top: 0.35rem;
  border-top: 1px solid var(--border);
}

.nav-menu-drawer .nav-btn,
.nav-menu-drawer .admin-tab,
.nav-menu-drawer .settings-tab {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
}

@media (max-width: 760px) {
  .main-nav .main-nav-links { display: none; }
  .main-nav .nav-menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .main-nav.nav-open .nav-menu-drawer { display: flex; }
}

.session-bar {
  padding: 0.35rem 0.75rem;
  margin-bottom: 0;
}

.session-warn {
  margin: 0 0 0.35rem;
  padding: 0.45rem 0.75rem;
  border-color: #9a7b1a;
  background: rgba(210, 170, 50, 0.12);
  font-size: 0.85rem;
  text-align: center;
}

.session-warn strong { font-weight: 600; }

.session-chip {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.35;
}

.filters-compact {
  margin-bottom: 0;
}

.filters-primary {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.5rem;
  align-items: end;
  width: 100%;
}

.filters-primary .filter-search {
  flex: 1;
  min-width: 8rem;
  margin: 0;
}

.filters-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  grid-column: 1 / -1;
  margin: 0 0 0.35rem;
  padding: 0.15rem 0;
  background: transparent;
  border: none;
  color: var(--text);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}

.filters-toggle:hover { color: var(--accent-hover); }

.filters-chevron {
  color: var(--muted);
  font-size: 0.7rem;
  transition: transform 0.15s ease;
}

.filters-body {
  display: contents;
}

#filters-card {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr));
  gap: 0.45rem 0.65rem;
  align-items: end;
  padding: 0.5rem 0.65rem;
  margin-bottom: 0;
}

#filters-card.collapsed .filters-body { display: none; }
#filters-card.collapsed .filters-toggle { margin-bottom: 0; }
#filters-card.collapsed .filters-chevron { transform: rotate(-90deg); }
#filters-card.collapsed { padding-bottom: 0.35rem; }

.filters-compact label {
  font-size: 0.72rem;
  gap: 0.2rem;
  min-width: 0;
}

.filters-compact input,
.filters-compact select {
  padding: 0.35rem 0.45rem;
  font-size: 0.85rem;
}

.filter-search { min-width: 0; }

.filter-actions {
  display: flex;
  gap: 0.35rem;
  align-items: end;
  flex-shrink: 0;
}

.filter-actions button { padding: 0.35rem 0.65rem; }

.filter-sort-mobile { display: none; }

.filter-pulldown select {
  width: 100%;
}

.table-panel { padding: 0; border: none; background: transparent; }

.settings-view h2 { font-size: 1.1rem; margin-bottom: 0.35rem; }

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 28rem;
  margin-top: 0.75rem;
}

.settings-form .full { width: 100%; }

.backup-block {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.backup-block:first-of-type {
  margin-top: 0.75rem;
  padding-top: 0;
  border-top: none;
}

.backup-subhead {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0 0 0.25rem;
}

.backup-mode-fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem 0.75rem;
  margin: 0;
}

.backup-mode-legend {
  font-size: 0.8rem;
  color: var(--muted);
  padding: 0 0.25rem;
}

.backup-mode-option {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  font-size: 0.85rem;
  margin-top: 0.35rem;
}

.backup-mode-option:first-of-type { margin-top: 0; }

.vault-retention-form { max-width: 22rem; margin-top: 1rem; }

.backup-mode-option input { margin-top: 0.15rem; flex-shrink: 0; }

#admin-panel { margin-top: 0; }
.admin-content { min-height: 120px; margin-top: 0; }

table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { text-align: left; padding: 0.5rem 0.45rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
th.sort-asc::after { content: " \2191"; opacity: 0.85; }
th.sort-desc::after { content: " \2193"; opacity: 0.85; }
.actions-col { width: 9rem; }
.actions-col-header { display: inline-flex; align-items: center; gap: 0.45rem; white-space: nowrap; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: rgba(255,255,255,0.03); }
tbody tr td.actions-col { cursor: default; }

.cred-meta { font-size: 0.72rem; color: var(--muted); white-space: nowrap; }

.brand-logo {
  width: 160px;
  height: 160px;
  object-fit: contain;
  flex-shrink: 0;
  display: block;
}

.brand-logo-lg {
  width: 180px;
  height: 180px;
}

.nav-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

.nav-header-center {
  flex-direction: column;
  text-align: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.lookup-type-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  margin-bottom: 0.5rem;
}

.lookup-tabs-spacer { flex: 1; }

.lookup-refresh-btn {
  flex-shrink: 0;
}

.lookups-hint { margin: 0 0 0.75rem; }

.table-scroll { overflow-x: auto; }

.icon-group { display: flex; gap: 0.2rem; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--muted);
}

.icon-btn:hover {
  color: var(--text);
  border-color: var(--border);
  background: rgba(255,255,255,0.04);
}

#admin-panel { margin-top: 0; }

.lookups-panel { margin-top: 0; }
.admin-table { font-size: 0.85rem; }
.admin-toolbar { margin-bottom: 0.75rem; display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.admin-user-list { display: flex; flex-direction: column; gap: 0.35rem; }
.admin-user-card {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.5rem 0.35rem 0.65rem;
  background: var(--surface);
  min-height: 2.25rem;
  cursor: pointer;
}
.admin-user-card:focus-visible {
  outline: 2px solid var(--accent, #8ab4ff);
  outline-offset: 1px;
}
.admin-user-card.is-disabled { opacity: 0.85; }
.admin-user-info {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem 0.45rem;
}
.admin-user-name {
  font-size: 0.9rem;
  white-space: nowrap;
}
.admin-user-login {
  font-size: 0.72rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-left: auto;
}
.badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  background: var(--border);
  color: var(--text-muted);
  line-height: 1.3;
}
.badge.disabled { background: #5a2a2a; color: #ffb4b4; }
.badge.locked { background: #5a4a2a; color: #ffe0a8; }
.badge.role { background: var(--accent-dim, #2a3a5a); color: var(--accent, #8ab4ff); }
.admin-user-card .user-edit,
.admin-user-card .rate-reset-btn,
.admin-user-card .revoke-btn {
  flex-shrink: 0;
  margin-left: 0.25rem;
}
.admin-data-card { cursor: default; }
.admin-data-card:focus-visible { outline: none; }
.admin-record-detail {
  font-size: 0.72rem;
  min-width: 0;
  flex: 1 1 6rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.badge.ok { background: #2a4a3a; color: #b4ffcc; }
.badge.fail { background: #5a2a2a; color: #ffb4b4; }
.admin-master-section { margin-top: 0.75rem; }
.admin-master-section.fold-card {
  padding: 0.55rem 0.65rem;
}
.admin-master-section.collapsed { padding-bottom: 0.35rem; }
.admin-master-section.collapsed .admin-master-body { display: none; }
.admin-master-section .admin-master-body { margin-top: 0.5rem; }
.admin-master-section .admin-master-body .hint:first-child { margin-top: 0; }
@media (min-width: 721px) {
  .admin-master-section.fold-card.collapsed .admin-master-body { display: block; }
  .admin-master-section.fold-card.collapsed { padding-bottom: 0.55rem; }
  .admin-master-section.fold-card .fold-toggle {
    pointer-events: none;
    cursor: default;
    padding-bottom: 0.35rem;
  }
  .admin-master-section.fold-card .fold-chevron { display: none; }
}
.user-pw-reset {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  margin: 0.5rem 0 0;
}
.user-pw-reset legend { font-size: 0.85rem; padding: 0 0.25rem; }
.user-lock-wrap { margin: 0.35rem 0 0.5rem; }
.user-lock-wrap .hint { margin: 0 0 0.35rem; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 0.8rem; }
button.tiny { padding: 0.15rem 0.35rem; font-size: 0.7rem; margin-left: 0.25rem; }

.lookup-type-tab {
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
}
.lookup-type-tab.active { background: var(--accent-dim); color: var(--text); border-color: var(--accent); }
.confirm-word { font-size: 1rem; margin: 0.75rem 0; }
.confirm-word strong { color: var(--accent); font-family: ui-monospace, Consolas, monospace; }

.totp-qr-wrap { text-align: center; margin: 0.75rem 0; }
.totp-qr { width: 256px; height: 256px; background: #fff; border-radius: 8px; padding: 0.5rem; }

.detail-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.2rem 0.65rem;
  margin: 0;
  font-size: 0.85rem;
  align-items: baseline;
}

.detail-list dt {
  color: var(--muted);
  margin: 0;
  white-space: nowrap;
}

.detail-list dd {
  margin: 0;
  min-width: 0;
  word-break: break-word;
}

.row-actions-inline { white-space: nowrap; }

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  padding: 0;
  max-width: 700px;
  width: calc(100% - 2rem);
  max-height: calc(100dvh - 2rem);
  overflow: auto;
}

#cred-dialog:not([open]) {
  display: none;
}

#cred-dialog[open] {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

dialog form:not(.cred-dialog-form) {
  padding: 1.25rem;
}

dialog::backdrop { background: rgba(0,0,0,0.65); }

.cred-dialog-form {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  max-height: calc(100dvh - 2rem);
}

.cred-dialog-header {
  flex-shrink: 0;
  padding: 1rem 1.25rem 0.35rem;
}

.cred-dialog-header h2 {
  margin: 0;
}

.cred-dialog-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 1.25rem 0.5rem;
  -webkit-overflow-scrolling: touch;
}

.cred-dialog-actions {
  flex-shrink: 0;
  margin-top: 0;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

#cred-form .form-grid {
  gap: 0.5rem;
  margin: 0.35rem 0 0.5rem;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
  margin: 1rem 0;
}

.form-grid .full { grid-column: 1 / -1; }

.field-row {
  display: flex;
  gap: 0.45rem;
  align-items: center;
  flex-wrap: wrap;
}

.field-row input, .field-row select { flex: 1; min-width: 0; }

.pw-gen {
  background: var(--panel-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.55rem 0.65rem;
}

.fold-card .fold-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin: 0;
  padding: 0.15rem 0;
  background: transparent;
  border: none;
  color: var(--text);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}

.fold-card .fold-toggle:hover { color: var(--accent-hover); }

.fold-chevron {
  color: var(--muted);
  font-size: 0.7rem;
  transition: transform 0.15s ease;
  flex-shrink: 0;
}

.fold-card.collapsed .fold-chevron { transform: rotate(-90deg); }

.pw-gen-dialog-form {
  box-sizing: border-box;
  min-width: 0;
  width: 100%;
}

.pw-gen-panel {
  margin-top: 0.75rem;
  min-width: 0;
}

.pw-gen-panel input,
.pw-gen-panel select {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.pw-gen-preview {
  display: block;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  font-family: ui-monospace, monospace;
  font-size: clamp(0.85rem, 3.5vw, 1rem);
  line-height: 1.35;
  padding: 0.65rem 0.75rem;
  background: var(--panel-inset);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  word-break: break-all;
  overflow-wrap: anywhere;
  min-height: 2.75rem;
}

#pw-gen-dialog:not([open]) {
  display: none;
}

#pw-gen-dialog[open] {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-width: min(520px, calc(100% - 2rem));
}

#pw-gen-dialog[open] .pw-gen-dialog-form {
  overflow-y: auto;
  max-height: calc(100dvh - 2rem);
  -webkit-overflow-scrolling: touch;
}

.pw-gen-hint { margin: 0.35rem 0 0.5rem; }

.section-head { margin-bottom: 0.65rem; }

.preset-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.35rem;
  margin-bottom: 0.55rem;
}

.preset-chip {
  padding: 0.35rem 0.35rem;
  font-size: 0.75rem;
  line-height: 1.15;
  text-align: center;
  white-space: normal;
  background: transparent;
  border: 1px solid var(--border);
  min-width: 0;
}

.preset-chip.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent-hover);
}

.rule-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.45rem;
  margin-bottom: 0.45rem;
}

.rule-grid .full { grid-column: 1 / -1; }

.history-section {
  margin-top: 0.35rem;
  padding: 0.55rem 0.65rem;
  background: var(--panel-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.pw-gen-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.history-cap-note { margin: 0.35rem 0 0; font-size: 0.8rem; }

.history-section.collapsed { padding-bottom: 0.35rem; }
.history-section.collapsed .history-body { display: none; }

.history-list { list-style: none; margin: 0.5rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }

.history-item {
  background: var(--panel-inset);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.65rem 0.75rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: center;
}

.history-meta { display: flex; flex-direction: column; gap: 0.15rem; font-size: 0.85rem; }
.history-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.pw-mask { font-family: ui-monospace, monospace; font-size: 0.8rem; color: var(--muted); }

.dialog-actions { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.5rem; }
.spacer { flex: 1; }

/* View vs edit mode */
.mode-view .edit-only { display: none !important; }
.mode-edit .view-only { display: none !important; }

.mode-view #cred-form .form-grid input,
.mode-view #cred-form .form-grid select,
.mode-view #cred-form .form-grid textarea {
  border-color: transparent;
  background: transparent;
  padding: 0.2rem 0;
  box-shadow: none;
}

.mode-view #cred-form .form-grid label {
  gap: 0.15rem;
}

.mode-view #cred-form .form-grid label.field-empty-hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .brand-logo { width: 120px; height: 120px; }
  .brand-logo-lg { width: 140px; height: 140px; }
  #vault-screen { padding: 0.35rem; }
}

@media (max-width: 760px) {
  .form-grid { grid-template-columns: 1fr; }
  .rule-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #pw-gen-dialog {
    width: calc(100% - 0.75rem);
    max-width: none;
    max-height: calc(100dvh - 0.75rem);
  }
  #pw-gen-dialog .rule-grid label:first-child { grid-column: 1 / -1; }
  #pw-gen-dialog .dialog-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }
  .detail-list {
    grid-template-columns: auto 1fr;
    gap: 0.15rem 0.45rem;
    font-size: 0.8rem;
  }
  .filters-compact,
  #filters-card {
    grid-template-columns: 1fr 1fr 1fr;
    padding: 0.4rem 0.5rem;
    gap: 0.35rem;
  }
  .filter-category,
  .filter-person,
  .filter-sort-mobile {
    display: flex;
    grid-column: span 1;
  }
  .filter-date { grid-column: span 1; }
  .filters-primary { flex-direction: column; align-items: stretch; }
  .filters-primary .filter-actions { justify-content: flex-start; flex-wrap: wrap; }
  .panel { padding: 0.65rem; }
  .main-nav.panel { padding: 0.125rem 0.4rem; }
  .session-bar { padding: 0.3rem 0.55rem; }
  th, td { padding: 0.35rem 0.3rem; }

  #cred-table thead { display: none; }
  #cred-table tbody tr {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto minmax(0, 1fr);
    grid-template-areas:
      "cat site person url"
      "updated updated actions actions";
    gap: 0.2rem 0.45rem;
    padding: 0.45rem 0.35rem;
    align-items: center;
  }
  #cred-table tbody td {
    border-bottom: none;
    padding: 0.1rem 0;
  }
  #cred-table tbody tr {
    border-bottom: 1px solid var(--border);
  }
  #cred-table tbody td:nth-child(1) { grid-area: cat; font-size: 0.72rem; color: var(--muted); white-space: nowrap; }
  #cred-table tbody td:nth-child(2) { grid-area: site; font-size: 0.95rem; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #cred-table tbody td:nth-child(3) { grid-area: person; font-size: 0.78rem; color: var(--muted); white-space: nowrap; }
  #cred-table tbody td:nth-child(4) {
    grid-area: url;
    font-size: 0.85rem;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #cred-table tbody td:nth-child(4) a {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #cred-table tbody td:nth-child(5) {
    grid-area: updated;
    font-size: 0.72rem;
    color: var(--muted);
  }
  #cred-table tbody td:nth-child(6) {
    grid-area: actions;
    justify-self: end;
  }
  #cred-table tbody td:nth-child(6) .icon-group { justify-content: flex-end; }
}

@media (max-width: 420px) {
  #vault-screen { padding: 0.25rem; }
  .filters-compact { padding: 0.35rem; }
  .nav-btn, .admin-tab, .settings-tab { padding: 0.35rem 0.6rem; font-size: 0.8rem; }
  #cred-table tbody tr { padding: 0.35rem 0.25rem; gap: 0.1rem 0.35rem; }
  #pw-gen-dialog { width: calc(100% - 0.5rem); }
  #pw-gen-dialog .rule-grid { grid-template-columns: 1fr; }
  dialog form:not(.cred-dialog-form) { padding: 0.85rem; }
}
