:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1a1d23;
  --muted: #5f6775;
  --primary: #2563eb;
  --primary-text: #ffffff;
  --danger: #c62828;
  --ok: #2e7d32;
  --warn: #ef8a00;
  --focus: #93b4f8;
  --radius: 8px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 6%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111318;
    --surface: #1a1d24;
    --surface-2: #232731;
    --border: #2f3542;
    --text: #e6e8ec;
    --muted: #9aa3b2;
    --primary: #4f8cff;
    --danger: #ef5350;
    --ok: #66bb6a;
    --warn: #ffa726;
    --focus: #35589c;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 4px 16px rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
a { color: var(--primary); }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* ---------- controls ---------- */

input, select, textarea {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  width: 100%;
}
textarea { resize: vertical; }
input:disabled, textarea:disabled { background: var(--surface-2); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }

label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-weight: 500; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 500;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-outline { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: .85rem; }
.btn.wide { width: 100%; padding: 10px; }

.icon-btn {
  font: inherit; background: none; border: none; color: var(--muted);
  cursor: pointer; padding: 4px 8px; border-radius: 6px; font-size: 1.05rem;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.link-btn {
  font: inherit; font-size: .85rem; background: none; border: none; padding: 0 4px;
  color: var(--primary); cursor: pointer;
}
.link-btn:hover { text-decoration: underline; }

.input-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.input-row input { flex: 1 1 200px; width: auto; }
.input-row select { width: auto; }

.check { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; }
.check input { width: auto; }

.badge {
  font-size: .75rem; background: var(--surface-2); color: var(--muted);
  border-radius: 999px; padding: 0 8px;
}
.role { font-size: .75rem; font-weight: 600; border-radius: 999px; padding: 2px 8px; vertical-align: middle; }
.role-viewer { background: var(--surface-2); color: var(--muted); }
.role-editor { background: color-mix(in srgb, var(--primary) 15%, transparent); color: var(--primary); }
.role-manager { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

/* ---------- sign in / simple pages ---------- */

.center-card {
  min-height: 100vh; display: grid; place-items: center; padding: 16px;
}
.center-card .card { width: 100%; max-width: 420px; }
.signin { text-align: center; }
.signin .logo { font-size: 2.5rem; }
.signin .local-login { text-align: left; }
.form-error { color: var(--danger); font-weight: 500; }
.signin .break-glass { margin-top: 20px; }
.signin .break-glass summary { cursor: pointer; margin-bottom: 12px; }

/* ---------- layout ---------- */

.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.nav-btn {
  font: inherit; background: none; border: none; color: var(--muted);
  padding: 6px 12px; border-radius: 6px; cursor: pointer;
}
.nav-btn:hover { background: var(--surface-2); color: var(--text); }
.nav-btn.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.user { display: flex; align-items: center; gap: 10px; }

.layout { display: grid; grid-template-columns: 260px 1fr; min-height: calc(100vh - 57px); }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 16px; }
.sidebar-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sidebar-head h2 { margin: 0; }
.vault-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.vault-item {
  width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 8px;
  font: inherit; text-align: left; color: inherit; background: none; border: none;
  padding: 8px 10px; border-radius: 6px; cursor: pointer;
}
.vault-item:hover { background: var(--surface-2); }
.vault-item.active { background: color-mix(in srgb, var(--primary) 14%, transparent); font-weight: 600; }
.vault-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.content { padding: 24px; min-width: 0; }
.content.single { max-width: 1200px; margin: 0 auto; }
.content.narrow { max-width: 640px; }

.empty { text-align: center; padding: 64px 16px; max-width: 480px; margin: 0 auto; }

.vault-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; }
.search { flex: 1; }

/* ---------- entries ---------- */

.entries { display: flex; flex-direction: column; gap: 10px; }
.empty-list { padding: 24px 0; }
.entry {
  display: grid;
  grid-template-columns: minmax(160px, 1.2fr) minmax(160px, 1fr) minmax(200px, 1.2fr) auto;
  grid-template-areas: "main user pass actions" "meta meta meta actions";
  gap: 4px 16px; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px;
}
.entry-main { grid-area: main; min-width: 0; }
.entry-main h3 { margin: 0; overflow-wrap: anywhere; }
.entry-main a { overflow-wrap: anywhere; }
.entry-field { display: flex; align-items: baseline; gap: 6px; min-width: 0; flex-wrap: wrap; }
.entry-user { grid-area: user; }
.entry-pass { grid-area: pass; }
.entry-field .label { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; width: 100%; }
.entry-field .mono { overflow-wrap: anywhere; }
.entry-meta { grid-area: meta; }
.entry-actions { grid-area: actions; display: flex; gap: 6px; }

/* ---------- generator ---------- */

.generator { display: flex; flex-direction: column; gap: 14px; }
.gen-row { display: flex; gap: 6px; align-items: center; }
.gen-output {
  flex: 1; min-width: 0; font-size: 1.15rem; padding: 10px 12px;
  background: var(--surface-2); border-radius: 6px; overflow-wrap: anywhere; min-height: 48px;
}
.meter-row { display: flex; align-items: center; gap: 10px; }
.meter { flex: 0 0 140px; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; transition: width .2s, background .2s; }
.meter[data-level="1"] span { width: 25%; background: var(--danger); }
.meter[data-level="2"] span { width: 50%; background: var(--warn); }
.meter[data-level="3"] span { width: 75%; background: var(--ok); }
.meter[data-level="4"] span { width: 100%; background: var(--ok); }
.range { font-weight: 400; }
.range input { padding: 0; accent-color: var(--primary); }
.checks { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.dialog .generator { border: 1px dashed var(--border); border-radius: var(--radius); padding: 14px; }

/* ---------- dialogs ---------- */

.dialog {
  border: 1px solid var(--border); border-radius: 10px; padding: 0;
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.dialog.wide { width: min(1000px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgb(0 0 0 / 45%); }
.dialog-inner { display: flex; flex-direction: column; max-height: calc(100vh - 34px); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px 8px; }
.dialog-head h2 { margin: 0; }
.dialog-body { padding: 8px 20px 16px; overflow: auto; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); }

/* ---------- sharing ---------- */

.members { display: flex; flex-direction: column; gap: 6px; }
.member { display: flex; align-items: center; gap: 10px; padding: 8px; border: 1px solid var(--border); border-radius: 6px; }
.member-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.member select { width: auto; }
.add-member { display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--border); padding-top: 14px; }
.search-results { display: flex; flex-direction: column; }
.result {
  font: inherit; text-align: left; color: inherit; background: none; border: none;
  padding: 6px 8px; border-radius: 6px; cursor: pointer;
}
.result:hover { background: var(--surface-2); }

/* ---------- audit ---------- */

.table-wrap { overflow-x: auto; }
.audit { width: 100%; border-collapse: collapse; font-size: .9rem; }
.audit th, .audit td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.audit th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.action-tag { font-family: ui-monospace, Consolas, monospace; font-size: .8rem; background: var(--surface-2); padding: 1px 6px; border-radius: 4px; }

/* ---------- toast ---------- */

#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 8px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 1000;
  max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); color: #fff; }

/* ---------- small screens ---------- */

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); }
  .content { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .entry {
    grid-template-columns: 1fr;
    grid-template-areas: "main" "user" "pass" "meta" "actions";
  }
  .toolbar { flex-wrap: wrap; }
  .toolbar .search { flex: 1 1 100%; }
  .toolbar .sort-select { flex: 1; }
}

/* ---------- sidebar sections ---------- */

.vault-section + .vault-section { margin-top: 16px; }
.vault-section-title { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 6px; }

/* ---------- admin ---------- */

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 8px 0 20px; flex-wrap: wrap; }
.tab {
  font: inherit; color: var(--muted); background: none; border: 0; border-bottom: 2px solid transparent;
  padding: 8px 12px; margin-bottom: -1px; cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.grow { flex: 1; margin: 0; }
.users td { vertical-align: top; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.disabled-row td { opacity: .55; }
.temp-password, .redirect-uri {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px;
  overflow-wrap: anywhere;
}
.temp-password { font-size: 1.1rem; letter-spacing: .04em; }
.settings { max-width: 720px; }
.settings .card h2 { margin: 0; font-size: 1.1rem; }
.status { font-weight: 600; margin: 0; }
.status.ok { color: var(--ok); }

/* ---------- entry types ---------- */

.type-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.type-btn {
  font: inherit; font-size: .9rem; cursor: pointer; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px;
}
.type-btn:hover:not(:disabled) { background: var(--surface-2); }
.type-btn.active { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 12%, transparent); color: var(--primary); font-weight: 600; }
.type-btn:disabled { cursor: default; }
.two-col { display: flex; gap: 12px; align-items: flex-start; }
.two-col > label { flex: 1; min-width: 0; }
.type-icon { font-size: .95em; }
.sort-select { width: auto; }

/* ---------- filters ---------- */

.filter-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: -6px 0 12px; }
.chip {
  font: inherit; font-size: .85rem; cursor: pointer; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip:hover { background: var(--surface-2); }
.chip.active { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 12%, transparent); color: var(--primary); font-weight: 600; }
.chip-count { font-size: .75rem; color: var(--muted); background: var(--surface-2); border-radius: 999px; padding: 0 6px; min-width: 1.4em; text-align: center; }
.chip.active .chip-count { color: inherit; }
.result-count { margin: -6px 0 10px; }
.result-count:empty { display: none; }

/* ---------- entry details ---------- */

.entry-open {
  font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0;
  text-align: left; cursor: pointer; overflow-wrap: anywhere;
}
.entry-open:hover { color: var(--primary); text-decoration: underline; }
.details { margin: 0; display: flex; flex-direction: column; }
.detail-row {
  display: grid; grid-template-columns: 140px 1fr; gap: 4px 12px; align-items: baseline;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.detail-row dt { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.detail-row dd { margin: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; min-width: 0; }
.detail-value, .detail-secret { overflow-wrap: anywhere; min-width: 0; }
.detail-buttons { display: flex; gap: 6px; margin-left: auto; }
.detail-pre {
  margin: 0; flex: 1 1 100%; white-space: pre-wrap; overflow-wrap: anywhere; font-size: .85rem;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px;
  max-height: 260px; overflow: auto;
}
.detail-notes-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.detail-notes-head h3 { margin: 0; font-size: 1rem; }
.notes-text { font-family: inherit; font-size: .95rem; max-height: 320px; }
.push-left { margin-right: auto; }

/* ---------- expiry ---------- */

.nav-badge {
  display: inline-block; margin-left: 6px; min-width: 1.5em; padding: 0 6px; border-radius: 999px;
  font-size: .75rem; font-weight: 700; line-height: 1.5; text-align: center; color: #fff; background: var(--warn);
}
.nav-badge.bad { background: var(--danger); }
.expiry-row input[type=date] { flex: 1 1 160px; }
.expiry-row select { flex: 1 1 160px; width: auto; }
.preset-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.preset-row .chip { font-size: .8rem; padding: 2px 10px; }
.expiry-hint { margin: 6px 0 0; }
.expiring-group .entries { margin-top: 8px; }
.expiring-title { display: flex; align-items: center; gap: 8px; font-size: 1rem; margin: 0; }
.expiring-title.bad { color: var(--danger); }
.expiring-title.warn { color: var(--warn); }

/* ---------- delete confirmation / recycle bin ---------- */

.confirm-message { margin: 0; overflow-wrap: anywhere; }
.confirm-word {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; overflow-wrap: anywhere;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.trash td { vertical-align: top; }

/* ---------- MFA codes ---------- */

.totp { display: inline-flex; align-items: center; gap: 10px; }
.totp-code { font-size: 1.35rem; font-weight: 600; letter-spacing: .06em; color: var(--primary); }
.totp.compact .totp-code { font-size: 1rem; }
.totp-bar { width: 60px; height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.totp-bar > span { display: block; height: 100%; background: var(--primary); transition: width 1s linear; }
.totp.compact .totp-bar { width: 36px; }
.totp.ending .totp-code { color: var(--warn); }
.totp.ending .totp-bar > span { background: var(--warn); }
.totp-left { min-width: 2.5em; }
.totp-set { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.totp-set > span:first-child { margin-right: auto; }
.totp-status { margin: 4px 0 0; overflow-wrap: anywhere; }
.totp-status:empty { display: none; }
.totp-status.ok { color: var(--ok); }
.totp-status.bad { color: var(--danger); }
@media (max-width: 800px) {
  .detail-row { grid-template-columns: 1fr; }
}
.expiry.warn { color: var(--warn); font-weight: 600; }
.expiry.bad { color: var(--danger); font-weight: 600; }
.key-input { font-size: .8rem; white-space: pre; overflow-x: auto; }

/* departments */
.dept-tag {
  font: inherit; font-size: .75rem; font-weight: 600; vertical-align: middle; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); border-radius: 999px; padding: 1px 8px; margin-left: 4px;
}
.dept-tag::before { content: '🏢 '; }
.dept-tag:hover { color: var(--text); }
.dept-note { background: var(--surface-2); border-left: 3px solid var(--primary); border-radius: 4px; padding: 8px 10px; margin: 0; }
.dept-section { margin-top: 24px; display: flex; flex-direction: column; gap: 10px; }
.dept-section h2 { margin: 0; font-size: 1.1rem; }
.dept-section-head { display: flex; justify-content: space-between; align-items: center; }
.dept-vaults { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.dept-vault {
  width: 100%; display: flex; align-items: center; gap: 10px; text-align: left; font: inherit; color: inherit; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px;
}
.dept-vault:hover { border-color: var(--primary); }
.dept-vault .vault-name { flex: 1; }

/* automatic provisioning (SCIM) */
.scim-card { max-width: 720px; margin-top: 16px; }
.scim-card h2 { margin: 0; font-size: 1.1rem; }
.scim-card .steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; color: var(--muted); }
