/* Shared light / dark schemes — brand files only set accent/font accents */
html[data-scheme="dark"] {
  --bg: #0b0d12;
  --surface: #12151c;
  --surface2: #1a1f2a;
  --border: #2a3142;
  --text: #e8edf5;
  --muted: #94a3b8;
  --danger: #f07178;
  --input-bg: #0b0d12;
  --shadow: none;
  --login-bg: var(--bg);
  --badge-bg: var(--surface2);
}
html[data-scheme="light"] {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface2: #eef1f6;
  --border: #d5dbe6;
  --text: #1a2332;
  --muted: #5c6b7a;
  --danger: #c0392b;
  --input-bg: #ffffff;
  --shadow: 0 8px 24px rgba(20, 30, 45, 0.06);
  --login-bg: var(--bg);
  --badge-bg: var(--surface2);
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0; min-height: 100%;
  font-family: var(--font, system-ui, sans-serif);
  color: var(--text);
  background: var(--bg);
}
a { color: var(--accent, #3b82f6); text-decoration: none; }
a:hover { text-decoration: underline; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.75rem 1.25rem; border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 0.75rem; color: inherit; text-decoration: none; }
.brand-logo { height: 40px; width: auto; max-width: 140px; object-fit: contain; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text small { color: var(--muted); font-size: 0.8rem; }
.nav { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.container { max-width: 1800px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.page-head h1 { margin: 0 0 0.25rem; font-size: 1.5rem; }
.muted { color: var(--muted); }
.btn {
  border: 1px solid var(--border); background: var(--surface2); color: var(--text);
  border-radius: 8px; padding: 0.45rem 0.8rem; cursor: pointer; font: inherit;
}
.btn:hover { border-color: var(--accent, #3b82f6); }
.btn-primary {
  background: var(--accent, #3b82f6);
  border-color: var(--accent, #3b82f6);
  color: var(--accent-text, #fff);
}
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-ghost { background: transparent; }
.btn-tiny { padding: 0.2rem 0.45rem; font-size: 0.8rem; }
.btn-block { width: 100%; }
.inline { display: inline; }
.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 1rem;
  background: var(--login-bg, var(--bg));
  position: relative;
}
.login-theme {
  position: absolute; top: 1rem; right: 1rem;
}
.login-card {
  width: min(400px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 2rem 1.5rem; box-shadow: var(--shadow, none);
}
.login-logo { display: block; height: 72px; width: auto; max-width: 100%; margin: 0 auto 1rem; object-fit: contain; }
.login-card h1 { text-align: center; margin: 0 0 0.25rem; font-size: 1.4rem; }
.login-card .muted { text-align: center; margin-bottom: 1.25rem; }
.login-card label { display: block; margin-bottom: 0.85rem; font-size: 0.9rem; }
.login-card input, .form-grid input, .form-grid select, .form-grid textarea {
  width: 100%; margin-top: 0.3rem; padding: 0.55rem 0.65rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--input-bg, var(--bg)); color: var(--text); font: inherit;
}
.alert {
  background: color-mix(in srgb, var(--danger) 15%, transparent);
  border: 1px solid var(--danger); color: var(--text); padding: 0.6rem 0.75rem; border-radius: 8px; margin-bottom: 1rem;
}
.cards {
  /* width 21.4rem; expanded height 21.2rem (0.2rem shorter than former square) */
  --card-width: calc(10.6rem * 2 + 0.2rem);
  --card-height: calc(10.6rem * 2);
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
  align-items: flex-start;
  align-content: flex-start;
}
.card {
  --card-bg: var(--surface);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0;
  width: var(--card-width);
  height: auto;
  flex: 0 0 var(--card-width);
  max-width: 100%;
  overflow: auto;
  box-sizing: border-box;
}
details.card:not([open]) {
  height: auto;
  min-height: 0;
}
details.card[open] {
  height: auto;
  min-height: var(--card-height);
}
html[data-scheme="light"] .cards .card:nth-child(odd) { --card-bg: #ffffff; }
html[data-scheme="light"] .cards .card:nth-child(even) { --card-bg: #e9edf3; }
html[data-scheme="dark"] .cards .card:nth-child(odd) { --card-bg: #0a0c10; }
html[data-scheme="dark"] .cards .card:nth-child(even) { --card-bg: #171b24; }
.card-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  gap: 0.5rem;
  padding: 0.85rem 0.95rem;
  user-select: none;
  box-sizing: border-box;
}
details.card[open] > .card-summary {
  margin-bottom: 0.35rem;
}
.card-summary::-webkit-details-marker { display: none; }
.card-summary::before {
  content: "▸";
  color: var(--muted);
  width: 1rem;
  flex: 0 0 1rem;
  transition: transform 0.15s ease;
}
details.card[open] > .card-summary::before { transform: rotate(90deg); }
.card-summary h2 { margin: 0; font-size: 1.15rem; }
.card-body { padding: 0 0.95rem 0.85rem; }
.badge {
  display: inline-block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 0.15rem 0.45rem; border-radius: 999px; background: var(--badge-bg, var(--surface2)); color: var(--muted);
}
.field-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin: 0.4rem 0; }
.field-row .label { min-width: 4.5rem; color: var(--muted); font-size: 0.85rem; }
code.secret {
  background: var(--surface2); padding: 0.2rem 0.45rem; border-radius: 6px; font-size: 0.95rem;
  word-break: break-all;
}
.note { margin: 0.6rem 0 0; color: var(--muted); white-space: pre-wrap; }
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 1.1rem; margin-bottom: 1.25rem;
}
.panel h2 { margin-top: 0; font-size: 1.1rem; }
.form-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0.75rem;
}
.form-grid .full { grid-column: 1 / -1; }
.form-grid label { display: block; font-size: 0.9rem; }
fieldset.full { border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem; }
.check { display: flex; align-items: center; gap: 0.45rem; margin: 0.35rem 0; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 0.55rem 0.4rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.nowrap { white-space: nowrap; }
.sep { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }
.entry-edit { margin-bottom: 0.5rem; }
.empty { color: var(--muted); padding: 2rem 0; }
.folder {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  margin-bottom: 1rem;
  padding: 0 0 0.85rem;
}
.folder-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  user-select: none;
}
.folder-summary::-webkit-details-marker { display: none; }
.folder-summary::before {
  content: "▸";
  color: var(--muted);
  width: 1rem;
  transition: transform 0.15s ease;
}
details.folder[open] > .folder-summary::before { transform: rotate(90deg); }
.folder .cards { padding: 0.15rem 1rem 0.35rem; }
.folder-empty { padding: 0 1rem 0.5rem; }
.folder-icon {
  width: 1.1rem; height: 0.85rem; border: 2px solid var(--accent, #3b82f6); border-radius: 2px 2px 0 0;
  border-bottom-width: 3px; display: inline-block; position: relative; top: 1px;
}
.folder-icon-flat {
  border-color: var(--muted); border-radius: 2px; height: 0.95rem;
}
.folder-admin-list { list-style: none; padding: 0; margin: 1rem 0 0; }
.folder-admin-list li {
  display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center;
  padding: 0.45rem 0; border-bottom: 1px solid var(--border);
}
.inline-form { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; flex: 1; }
.inline-form input { flex: 1; min-width: 140px; padding: 0.4rem 0.55rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--input-bg, var(--bg)); color: var(--text); font: inherit; }
.folder-edit-title { margin: 1.25rem 0 0.5rem; font-size: 1rem; }

/* Editor: add form toggle */
.add-entry-head { margin-bottom: 0.25rem; }
.add-entry-form { margin-top: 1rem; }
.add-entry-form[hidden] { display: none !important; }

/* Editor: Guacamole-like connection tree */
.guac-tree {
  margin-top: 0.75rem;
  padding: 0.75rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}
.guac-group { margin: 0.15rem 0 0.55rem; }
/* Hairline between folder groups (editor + home tree) */
.guac-group + .guac-group {
  border-top: 1px solid color-mix(in srgb, var(--border) 90%, var(--muted));
  margin-top: 0.55rem;
  padding-top: 0.55rem;
}
.guac-group-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.25rem;
  user-select: none;
  font-size: 0.95rem;
}
.guac-group-summary::-webkit-details-marker { display: none; }
.guac-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.15rem;
  height: 1.15rem;
  border: 1px solid var(--text);
  border-radius: 2px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.72rem;
  line-height: 1;
  flex-shrink: 0;
  color: var(--text);
  background: var(--surface);
}
.guac-toggle::before { content: "+"; }
.guac-group[open] > .guac-group-summary .guac-toggle::before { content: "−"; }
.guac-group-name { font-weight: 600; }
.guac-count { font-size: 0.85rem; }
.guac-empty { margin: 0.15rem 0 0.35rem 1.6rem; font-size: 0.9rem; }
.guac-children {
  list-style: none;
  margin: 0.2rem 0 0.35rem 0.55rem;
  padding: 0 0 0 0.85rem;
  border-left: 1px solid color-mix(in srgb, var(--border) 85%, var(--muted));
  column-count: 3;
  column-gap: 1.25rem;
}
.guac-children > li {
  break-inside: avoid;
  margin: 0;
  padding: 0;
}
.guac-entry {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.18rem 0.4rem;
  margin: 0.05rem 0;
  color: inherit;
  text-decoration: none;
  border-radius: 2px;
  max-width: 100%;
  font-size: 0.92rem;
}
.guac-entry:hover {
  background: color-mix(in srgb, var(--accent, #90b090) 18%, transparent);
  text-decoration: none;
}
.guac-entry.is-active {
  background: color-mix(in srgb, #9fc49f 55%, var(--surface));
  color: var(--text);
}
html[data-scheme="dark"] .guac-entry.is-active {
  background: color-mix(in srgb, #5a7a5a 45%, var(--surface2));
}
.guac-entry-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.guac-monitor {
  position: relative;
  width: 14px;
  height: 11px;
  border: 1.5px solid currentColor;
  border-radius: 1px;
  flex-shrink: 0;
  opacity: 0.9;
}
.guac-monitor::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -4px;
  width: 8px;
  height: 2px;
  background: currentColor;
  transform: translateX(-50%);
  border-radius: 1px;
}
@media (max-width: 1100px) {
  .guac-children { column-count: 2; }
}
@media (max-width: 640px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .brand-logo { height: 32px; }
  .guac-children { column-count: 1; }
}

/* Vault home (Guacamole-inspired) */
.vault-section-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text);
}
.vault-recent {
  margin: 0 0 1.25rem;
}
.vault-recent-grid {
  --recent-tile-w: 10rem;
  --recent-tile-h: 5rem;
  --recent-gap: 0.75rem;
  display: flex;
  flex-wrap: nowrap;
  gap: var(--recent-gap);
  margin-top: 0.75rem;
  overflow: hidden;
}
.vault-recent-empty {
  margin: 0.65rem 0 0;
  font-size: 0.9rem;
}
.vault-recent-empty[hidden],
.vault-recent-grid:empty + .vault-recent-empty[hidden] { display: none; }
.vault-recent-card {
  display: block;
  flex: 0 0 var(--recent-tile-w);
  width: var(--recent-tile-w);
  height: var(--recent-tile-h);
  padding: 0;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  text-align: center;
}
.vault-recent-thumb {
  width: 100%;
  height: 100%;
  border-radius: 2px;
  box-shadow: 0 2px 8px rgba(20, 30, 45, 0.14);
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  overflow: hidden;
  position: relative;
  padding: 0.35rem 0.4rem;
  box-sizing: border-box;
}
.vault-recent-thumb::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(160deg, rgba(255,255,255,0.18), transparent 42%),
    repeating-linear-gradient(
      -18deg,
      transparent,
      transparent 10px,
      rgba(0,0,0,0.035) 10px,
      rgba(0,0,0,0.035) 11px
    );
  pointer-events: none;
}
html[data-scheme="dark"] .vault-recent-thumb {
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}
.vault-recent-kind,
.vault-recent-name {
  position: relative;
  z-index: 1;
  display: block;
  max-width: 100%;
  width: 100%;
  text-align: center;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.45);
}
.vault-recent-kind {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.15;
  opacity: 0.95;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.vault-recent-name {
  font-size: 0.7rem;
  font-weight: 500;
  line-height: 1.15;
  overflow: hidden;
  white-space: normal;
  word-break: break-word;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  max-height: 2.3em;
}
.vault-recent-card:hover .vault-recent-thumb {
  outline: 2px solid color-mix(in srgb, var(--accent, #3b82f6) 65%, transparent);
  outline-offset: 1px;
}
.vault-recent-card:focus-visible {
  outline: none;
}
.vault-recent-card:focus-visible .vault-recent-thumb {
  outline: 2px solid var(--accent, #3b82f6);
  outline-offset: 2px;
}

.vault-all-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.55rem 0.85rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
}
.vault-filter {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.vault-filter-label { white-space: nowrap; }
.vault-filter-field {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.vault-filter-field input {
  width: 11rem;
  padding: 0.28rem 1.7rem 0.28rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--input-bg, var(--surface));
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
}
.vault-filter-field input:focus {
  outline: 2px solid color-mix(in srgb, var(--accent, #3b82f6) 45%, transparent);
  outline-offset: 0;
}
.vault-filter-icon {
  position: absolute;
  right: 0.4rem;
  width: 0.85rem;
  height: 0.85rem;
  border: 1.6px solid var(--muted);
  border-radius: 50%;
  pointer-events: none;
  opacity: 0.85;
}
.vault-filter-icon::after {
  content: "";
  position: absolute;
  width: 0.35rem;
  height: 1.6px;
  background: var(--muted);
  right: -0.22rem;
  bottom: -0.05rem;
  transform: rotate(42deg);
  border-radius: 1px;
}

.vault-home-tree {
  margin-top: 0;
  border-radius: 0 0 8px 8px;
  font-family: "Lucida Grande", "Lucida Sans Unicode", "DejaVu Sans", Tahoma, sans-serif;
  font-size: 0.84rem;
}
.vault-home-tree .guac-group-summary { font-size: 0.88rem; }
.vault-home-tree .guac-entry {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  cursor: pointer;
  font: inherit;
  font-size: 0.84rem;
}
.vault-home-tree .guac-entry:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent, #3b82f6) 55%, transparent);
  outline-offset: 1px;
}
.vault-home-tree [data-vault-item][hidden],
.vault-home-tree [data-vault-group][hidden] { display: none; }

.vault-tip {
  position: fixed;
  z-index: 40;
  max-width: 18rem;
  padding: 0.55rem 0.7rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(20, 30, 45, 0.16);
  font-size: 0.8rem;
  line-height: 1.35;
  pointer-events: none;
}
html[data-scheme="dark"] .vault-tip {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
.vault-tip[hidden] { display: none !important; }
.vault-tip-row {
  display: grid;
  grid-template-columns: 4.2rem 1fr;
  gap: 0.25rem 0.45rem;
  margin: 0.15rem 0;
}
.vault-tip-row dt {
  margin: 0;
  color: var(--muted);
  font-weight: 500;
}
.vault-tip-row dd {
  margin: 0;
  overflow-wrap: anywhere;
}
.vault-tip-title {
  font-weight: 700;
  margin: 0 0 0.35rem;
  font-size: 0.86rem;
}

.vault-detail-dialog {
  width: min(36rem, calc(100vw - 2rem));
  max-height: calc(100vh - 3rem);
  margin: auto;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 16px 40px rgba(20, 30, 45, 0.18);
}
.vault-detail-dialog::backdrop {
  background: rgba(12, 16, 24, 0.45);
}
.vault-detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}
.vault-detail-body {
  padding: 0.85rem;
  overflow: auto;
}
.vault-detail-body .card {
  width: 100%;
  max-width: none;
  height: auto;
  min-height: 0;
  border-radius: 8px;
}
.vault-detail-body .card-summary {
  cursor: default;
}
.vault-detail-body .card-summary::before { display: none; }
.vault-card-store { display: none !important; }

@media (max-width: 640px) {
  .vault-filter-field input { width: 8.5rem; }
  .vault-all-bar { align-items: stretch; }
}
