:root {
  --bg: #0b0e14;
  --panel: #141a24;
  --panel2: #1b2330;
  --line: #263042;
  --text: #e6ebf2;
  --muted: #8a97a8;
  --accent: #4c8dff;
  /* Filled-button blues/reds: --accent and --danger are tuned for borders and
     glyphs, where WCAG's 4.5:1 text rule does not apply. White label text on
     them measures 3.20:1 and 3.79:1, so filled buttons use these darker
     variants instead (4.70:1 and 4.80:1). Same hue family, AA-compliant. */
  --accent-strong: #2f6fe0;
  --accent2: #3aa776;
  --danger: #e05260;
  --danger-strong: #cf3b48;
  --radius: 12px;
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    sans-serif;
}
.hidden {
  display: none !important;
}
.center {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px 28px;
  text-align: center;
}
.logo,
.brand {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.logo span,
.brand span {
  color: var(--accent);
}
.muted {
  color: var(--muted);
}
.fine {
  color: var(--muted);
  font-size: 12.5px;
  margin: 14px 0;
}
input,
textarea {
  width: 100%;
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 9px;
  padding: 11px 12px;
  margin: 7px 0;
  font: inherit;
  outline: none;
}
input:focus,
textarea:focus {
  border-color: var(--accent);
}
input::placeholder,
textarea::placeholder {
  /* The UA default placeholder colour on these dark fields lands near 3:1.
     #9aa7b8 on --panel2 is 6.46:1. */
  color: #9aa7b8;
  opacity: 1;
}
button {
  cursor: pointer;
  font: inherit;
  border: none;
  border-radius: 9px;
}
/* Keyboard focus was invisible on every button: only inputs changed on focus. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button.primary {
  width: 100%;
  background: var(--accent-strong);
  color: #fff;
  padding: 11px;
  font-weight: 600;
  margin-top: 8px;
}
button.primary:hover {
  filter: brightness(1.08);
}
button.primary:disabled {
  /* Not opacity: fading the whole button dropped its label to 3.33:1.
     This pair is 7.06:1. */
  background: #2a3a55;
  color: #c3ccd9;
  cursor: default;
}
button.secondary {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--line);
  padding: 10px 16px;
  font-weight: 600;
}
button.secondary:hover {
  border-color: var(--accent);
}
button.primary.small {
  width: auto;
  padding: 8px 16px;
  margin: 0;
}
button.link,
button.ghost {
  background: transparent;
  color: var(--muted);
}
button.link {
  margin-top: 12px;
  text-decoration: underline;
  width: 100%;
}
button.ghost {
  padding: 7px 9px;
  font-size: 16px;
}
button.ghost:hover {
  color: var(--text);
}
button.danger {
  background: var(--danger-strong);
  color: #fff;
  padding: 9px 16px;
  font-weight: 600;
}
button.danger:hover {
  filter: brightness(1.08);
}
button.mini {
  background: var(--panel2);
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 4px 8px;
  font-size: 12px;
}
button.mini:hover {
  color: var(--text);
  border-color: var(--accent);
}

/* topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}
.spacer {
  flex: 1;
}
.who {
  color: var(--muted);
  font-size: 13px;
  margin-right: 6px;
}
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
}
.search {
  flex: 1;
  margin: 0;
}
.count {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}
.list {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 20px 60px;
}
.empty {
  color: var(--muted);
  text-align: center;
  padding: 48px 0;
}
.item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 8px;
  cursor: pointer;
}
.item:hover,
.item:focus-visible {
  border-color: var(--accent);
}
.ico {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--panel2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--accent);
  overflow: hidden;
  flex: none;
}
.ico img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.meta {
  flex: 1;
  min-width: 0;
}
.title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.title .star {
  color: #f2c14e;
}
.sub {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-actions {
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.12s;
}
/* focus-within keeps these from being focusable-but-invisible when tabbing. */
.item:hover .row-actions,
.item:focus-visible .row-actions,
.item:focus-within .row-actions {
  opacity: 1;
}
/* Touch devices have no hover, so the row actions were unreachable there. */
@media (hover: none) {
  .row-actions {
    opacity: 1;
  }
}
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}
.check input {
  width: auto;
  margin: 0;
}

/* drawer */
.drawer {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  justify-content: flex-end;
  z-index: 20;
}
.drawer.open {
  display: flex;
}
.drawer-inner {
  width: 100%;
  max-width: 420px;
  height: 100%;
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 20px;
  overflow-y: auto;
}
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.drawer-head h3 {
  margin: 0;
}
.drawer label {
  display: block;
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 12px;
}
.pass-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.pass-row input {
  flex: 1;
}
.drawer-actions {
  display: flex;
  align-items: center;
  margin-top: 22px;
}

/* misc */
.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(560px, calc(100vw - 32px));
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 12px 10px 18px;
  border-radius: 9px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s;
  z-index: 50;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  /* Persistent toasts carry a dismiss/action button, so they must be
     clickable — the base rule turns pointer events off. */
  pointer-events: auto;
}
.toast:not(.show) .toast-action,
.toast:not(.show) .toast-close {
  display: none;
}
.toast-msg {
  flex: 1;
  min-width: 0;
}
.toast-action {
  flex: none;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--line);
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.toast-action:hover {
  border-color: var(--accent);
}
.toast-close {
  flex: none;
  background: transparent;
  color: var(--muted);
  padding: 4px 7px;
  font-size: 14px;
  line-height: 1;
}
.toast-close:hover {
  color: var(--text);
}
.toast.ok {
  border-color: var(--accent2);
}
.toast.err {
  border-color: var(--danger);
}
.toast.warn {
  border-color: #d9a441;
}

/* modal (confirmations + passphrase rotation) */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 60;
}
.modal.open {
  display: flex;
}
.modal-card {
  width: 100%;
  max-width: 420px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
}
.modal-title {
  margin: 0 0 8px;
  font-size: 18px;
}
.modal-desc {
  margin: 0 0 14px;
  font-size: 13.5px;
}
.modal-fields label {
  display: block;
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 12px;
}
.modal-error {
  margin: 12px 0 0;
  color: #ff9aa4;
  font-size: 13px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}
.modal-actions button {
  width: auto;
  margin: 0;
}

/* ---- responsive ---------------------------------------------------------- */
@media (max-width: 640px) {
  .topbar {
    flex-wrap: wrap;
    gap: 4px 6px;
    padding: 10px 14px;
  }
  .brand {
    font-size: 19px;
  }
  .spacer {
    /* Stop the flexible gap from forcing the icon row off-screen. */
    flex: 1 1 0;
    min-width: 0;
  }
  .who {
    order: 3;
    flex: 1 0 100%;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .toolbar {
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 14px;
  }
  .search {
    flex: 1 1 100%;
    order: 1;
  }
  .count {
    order: 2;
    flex: 1;
  }
  button.primary.small {
    order: 3;
  }
  .list {
    padding: 0 14px 48px;
  }
  .card {
    padding: 26px 20px;
  }
  .drawer-inner {
    max-width: 100%;
    border-left: none;
  }
  .modal-card {
    padding: 18px;
  }
}
@media (max-width: 400px) {
  .item {
    /* Below ~400px the actions cannot share a line with the title without
       squeezing it to nothing, so they wrap under it. */
    flex-wrap: wrap;
  }
  .meta {
    flex: 1 1 auto;
  }
  .row-actions {
    flex: 1 0 100%;
    opacity: 1;
    justify-content: flex-end;
  }
  .toast {
    left: 12px;
    right: 12px;
    bottom: 12px;
    max-width: none;
    transform: translateY(20px);
  }
  .toast.show {
    transform: translateY(0);
  }
  .modal-actions {
    flex-direction: column-reverse;
  }
  .modal-actions button {
    width: 100%;
  }
}
@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 2.4s;
  }
  .toast,
  .row-actions {
    transition: none;
  }
  .toast,
  .toast.show {
    transform: translateX(-50%);
  }
}
@media (prefers-reduced-motion: reduce) and (max-width: 400px) {
  .toast,
  .toast.show {
    transform: none;
  }
}
