/* Personal Vault — minimal, clean, responsive */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e3e6eb;
  --text: #1c2430;
  --muted: #667085;
  --primary: #1f3a5f;
  --primary-hover: #284b78;
  --primary-soft: #e8eef6;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --success: #067647;
  --warn: #b54708;
  --radius: 8px;
  --sidebar: 236px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.5;
}
[hidden] { display: none !important; }
a { color: var(--primary); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.45rem; font-weight: 600; }
h2 { font-size: 1.1rem; font-weight: 600; }
h3 { font-size: .95rem; font-weight: 600; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.noscript { padding: 2rem; text-align: center; }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .5rem .9rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #f0f2f5; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { color: var(--danger); border-color: #f3c7c2; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-solid:hover { background: #912018; }
.btn-sm { padding: .3rem .6rem; font-size: .85rem; }
.btn-block { width: 100%; }
.btn-link { background: none; border: none; color: var(--primary); padding: 0; cursor: pointer; font: inherit; text-decoration: underline; }

label { display: block; font-weight: 500; font-size: .9rem; margin-bottom: .3rem; }
input[type=text], input[type=password], input[type=search], input[type=email], input[type=date],
input[type=datetime-local], input[type=file], select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: #fff; color: var(--text); font: inherit;
}
textarea { min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible {
  outline: 2px solid #9db4d3; outline-offset: 1px; border-color: var(--primary);
}
.field { margin-bottom: 1rem; }
.field-hint { font-size: .8rem; color: var(--muted); margin-top: .25rem; }
.check { display: flex; align-items: center; gap: .45rem; font-weight: 400; margin: 0; }
.check input { width: auto; margin: 0; }
.row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; }
.row > .grow { flex: 1 1 200px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.error-box { background: var(--danger-soft); color: var(--danger); padding: .6rem .8rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .9rem; }
.notice { background: var(--primary-soft); padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .9rem; }
.notice.warn { background: #fef6ee; color: #7a2e0e; }

/* ---------- Auth screens ---------- */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 2rem; box-shadow: var(--shadow); }
.auth-card.wide { max-width: 540px; }
.auth-head { text-align: center; margin-bottom: 1.5rem; }
.auth-head .brand-mark { margin: 0 auto .75rem; width: 40px; height: 40px; }
.auth-foot { text-align: center; margin-top: 1rem; font-size: .9rem; }
.strength { height: 5px; border-radius: 3px; background: var(--border); margin-top: .4rem; overflow: hidden; }
.strength > span { display: block; height: 100%; width: 0; transition: width .2s; }
.recovery-key { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.05rem; letter-spacing: .04em;
  background: #f7f8fa; border: 1px dashed #b8c2d0; border-radius: var(--radius); padding: 1rem; text-align: center; word-break: break-all; margin-bottom: 1rem; user-select: all; }

/* ---------- Layout ---------- */
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 600; font-size: 1.05rem; padding: 1.1rem 1.2rem; }
.brand-mark { display: inline-block; width: 28px; height: 28px; border-radius: 7px; background: var(--primary) url(/img/favicon.svg) center/cover; }
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar); flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.nav { display: flex; flex-direction: column; padding: .5rem .75rem; gap: 2px; flex: 1; }
.nav a { padding: .55rem .8rem; border-radius: var(--radius); color: var(--text); text-decoration: none; font-weight: 500; }
.nav a:hover { background: #f0f2f5; }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.sidebar-foot { padding: 1rem; border-top: 1px solid var(--border); }
.session-info { font-size: .8rem; color: var(--muted); margin-bottom: .6rem; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: .75rem; padding: .8rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.search { flex: 1; max-width: 560px; }
.view { padding: 1.5rem; max-width: 1180px; width: 100%; outline: none; }
.menu-btn { display: none; }
.icon-btn { background: none; border: 1px solid var(--border); border-radius: var(--radius); width: 38px; height: 38px; cursor: pointer; padding: 9px 8px; flex-direction: column; justify-content: space-between; }
.icon-btn span { display: block; height: 2px; background: var(--text); border-radius: 2px; }
.sidebar-backdrop { display: none; }

.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head p { margin: .2rem 0 0; }

/* ---------- Cards, stats, lists ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1.25rem; box-shadow: var(--shadow); margin-bottom: 1.25rem; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .9rem; gap: .5rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1rem 1.2rem; text-decoration: none; color: inherit; box-shadow: var(--shadow); }
.stat:hover { border-color: #c5cfdc; }
.stat-label { color: var(--muted); font-size: .85rem; }
.stat-value { font-size: 1.7rem; font-weight: 600; margin-top: .15rem; }
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1.25rem; }

.list { list-style: none; margin: 0; padding: 0; }
.list-item { display: flex; align-items: center; gap: .9rem; padding: .7rem 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: none; }
.list-item .grow { flex: 1; min-width: 0; }
.list-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; color: var(--text); text-decoration: none; }
a.list-title:hover { color: var(--primary); text-decoration: underline; }
.list-sub { font-size: .82rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-actions { display: flex; gap: .4rem; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }

.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; background: #f0f2f5; color: #475467; font-size: .75rem; font-weight: 500; white-space: nowrap; }
.badge.primary { background: var(--primary-soft); color: var(--primary); }
.badge.ok { background: #ecfdf3; color: var(--success); }
.badge.warn { background: #fef6ee; color: var(--warn); }
.filetype { width: 40px; height: 40px; border-radius: 8px; background: var(--primary-soft); color: var(--primary); font-size: .68rem; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; text-transform: uppercase; }

.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip { display: inline-flex; gap: .4rem; align-items: center; padding: .4rem .8rem; border: 1px solid var(--border); border-radius: 999px; text-decoration: none; color: var(--text); background: #fff; font-size: .9rem; }
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip .count { color: var(--muted); font-size: .8rem; }

.toolbar { display: flex; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar > * { flex: 1 1 200px; max-width: 320px; }

/* Record detail */
.kv { display: grid; grid-template-columns: minmax(140px, 220px) 1fr auto; gap: 0; border-top: 1px solid var(--border); }
.kv > div { padding: .7rem .25rem; border-bottom: 1px solid var(--border); }
.kv .k { color: var(--muted); font-size: .9rem; }
.kv .v { word-break: break-word; white-space: pre-wrap; }
.kv .a { display: flex; gap: .35rem; justify-content: flex-end; align-items: flex-start; }
.masked { letter-spacing: .15em; color: var(--muted); }
.field-row { display: grid; grid-template-columns: 1fr 1.6fr auto auto; gap: .5rem; align-items: center; margin-bottom: .5rem; }
.field-row .check { font-size: .85rem; }
.pre { white-space: pre-wrap; word-break: break-word; }

/* Notes */
.notes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 1rem; }
.note-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1rem; cursor: pointer; display: flex; flex-direction: column; gap: .5rem; min-height: 140px; text-align: left; font: inherit; color: inherit; box-shadow: var(--shadow); }
.note-card:hover { border-color: #c5cfdc; }
.note-card.pinned { border-left: 3px solid var(--primary); }
.note-body { color: #475467; font-size: .9rem; white-space: pre-wrap; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; flex: 1; }
.note-meta { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; font-size: .78rem; color: var(--muted); }

/* Settings */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1.25rem; align-items: start; }
.qr { display: block; margin: .5rem 0 1rem; border: 1px solid var(--border); border-radius: 8px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .88rem; }
.tbl th, .tbl td { text-align: left; padding: .55rem .4rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl th { color: var(--muted); font-weight: 500; }
.table-wrap { overflow-x: auto; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 1rem; z-index: 50; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 560px; box-shadow: 0 12px 32px rgba(16, 24, 40, .18); }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.modal-body { padding: 1.25rem; }
.modal-foot { display: flex; justify-content: flex-end; gap: .5rem; padding: 1rem 1.25rem; border-top: 1px solid var(--border); flex-wrap: wrap; }
.close-x { background: none; border: none; font-size: 1.4rem; line-height: 1; cursor: pointer; color: var(--muted); padding: .2rem .4rem; }
.preview-img { max-width: 100%; max-height: 70vh; display: block; margin: 0 auto; border-radius: 6px; }

/* Toasts */
.toasts { position: fixed; bottom: 1rem; right: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 60; }
.toast { background: #1c2430; color: #fff; padding: .7rem 1rem; border-radius: var(--radius); font-size: .9rem; max-width: 340px; box-shadow: 0 6px 16px rgba(0,0,0,.18); }
.toast.error { background: var(--danger); }

.progress { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; margin-top: .5rem; }
.progress > span { display: block; height: 100%; background: var(--primary); width: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .dash-grid, .settings-grid { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  .menu-btn { display: flex; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 24px rgba(0,0,0,.2); }
  .sidebar-backdrop.open { display: block; position: fixed; inset: 0; background: rgba(16,24,40,.35); z-index: 30; }
  .topbar { padding: .7rem 1rem; }
  .view { padding: 1rem; }
  .grid-2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr auto; }
  .kv .k { grid-column: 1 / -1; border-bottom: none !important; padding-bottom: 0 !important; }
  .field-row { grid-template-columns: 1fr 1fr; }
  .list-item { flex-wrap: wrap; }
  .list-actions { width: 100%; justify-content: flex-start; }
  .toolbar > * { max-width: none; }
}
@media (max-width: 480px) {
  .auth-card { padding: 1.4rem; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 1.4rem; }
}
