:root {
  --bg: #f4f5f8;
  --panel: #ffffff;
  --panel-2: #fafbfc;
  --border: #e6e8ee;
  --text: #1f2430;
  --muted: #8b93a5;
  --primary: #4f6ef7;
  --primary-600: #3d5be0;
  --primary-soft: #eef2ff;
  --danger: #e5484d;
  --danger-soft: #fdecec;
  --success: #12b76a;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .06);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--primary); }

.hidden { display: none !important; }

/* ---------- generic controls ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-weight: 500;
  transition: background .15s, border-color .15s, transform .06s, box-shadow .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--panel-2); border-color: #d7dbe4; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-600); border-color: var(--primary-600); }
.btn.danger { color: var(--danger); border-color: #f2c9ca; background: #fff; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: rgba(0,0,0,.05); }
.btn.icon { padding: 8px; width: 36px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }

.input, .select, .textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #fff;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 110, 247, .15);
}
.textarea { resize: vertical; min-height: 76px; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; min-width: 0; }

/* ---------- auth ---------- */
#auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 500px at 50% -10%, #e6ecff 0%, rgba(230,236,255,0) 60%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 34px 30px 30px;
}
.auth-logo {
  width: 62px; height: 62px;
  border-radius: 17px;
  display: grid; place-items: center;
  background: linear-gradient(150deg, #5b7bff, #3d5be0);
  color: #fff;
  margin: 0 auto 18px;
  box-shadow: 0 10px 24px rgba(79,110,247,.35);
}
.auth-logo svg { width: 32px; height: 32px; }
.auth-card h1 { text-align: center; font-size: 21px; margin: 0 0 6px; }
.auth-card p.sub { text-align: center; color: var(--muted); margin: 0 0 24px; font-size: 13px; }
.auth-hint { font-size: 12px; color: var(--muted); margin-top: 10px; }
.auth-error { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ---------- app shell ---------- */
#app-screen { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 12px 18px;
  background: rgba(255,255,255,.85);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 16px; }
.brand .mark {
  width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(150deg, #5b7bff, #3d5be0);
}
.brand .mark svg { width: 19px; height: 19px; }
.search-wrap { flex: 1; max-width: 460px; position: relative; }
.search-wrap svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); }
.search-wrap .input { padding-left: 35px; background: var(--panel-2); }
.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.layout { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: 244px; flex: none;
  border-right: 1px solid var(--border);
  background: var(--panel);
  padding: 14px 12px;
  overflow-y: auto;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 8px 10px; }
.sidebar-head span { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 9px;
  color: var(--text); cursor: pointer; user-select: none;
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--panel-2); }
.nav-item.active { background: var(--primary-soft); color: var(--primary-600); font-weight: 600; }
.nav-item .dot { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.nav-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .count { font-size: 12px; color: var(--muted); background: var(--bg); border-radius: 20px; padding: 1px 8px; }
.nav-item.active .count { background: #dfe6ff; color: var(--primary-600); }
.sidebar .empty { color: var(--muted); font-size: 12.5px; padding: 8px 10px; }

.content { flex: 1; min-width: 0; overflow-y: auto; padding: 22px 24px 90px; }
.content-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.content-head h2 { margin: 0; font-size: 19px; }
.content-head .meta { color: var(--muted); font-size: 13px; }
.content-head .spacer { flex: 1; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 15px 16px; box-shadow: var(--shadow-sm); cursor: pointer;
  transition: box-shadow .16s, transform .08s, border-color .16s;
  position: relative;
}
.card:hover { box-shadow: var(--shadow); border-color: #dbe0ea; transform: translateY(-1px); }
.card-top { display: flex; align-items: center; gap: 11px; margin-bottom: 12px; }
.avatar {
  width: 40px; height: 40px; border-radius: 11px; flex: none;
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 16px;
}
.card-top .titles { min-width: 0; flex: 1; }
.card-top .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-top .platform { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-top .fav { color: #f5a524; flex: none; }
.card-line { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-top: 6px; color: #4a5163; }
.card-line .k { color: var(--muted); flex: none; min-width: 40px; }
.card-line .v { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-line code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 1px; }
.copy-mini { margin-left: auto; color: var(--muted); border: none; background: transparent; padding: 3px; border-radius: 6px; flex: none; }
.copy-mini:hover { background: var(--primary-soft); color: var(--primary-600); }
.copy-mini svg { width: 15px; height: 15px; display: block; }

.empty-state { text-align: center; color: var(--muted); padding: 70px 20px; }
.empty-state svg { width: 46px; height: 46px; opacity: .5; margin-bottom: 12px; }
.empty-state .title { font-size: 15px; color: var(--text); font-weight: 600; margin-bottom: 6px; }

.fab {
  position: fixed; right: 26px; bottom: 26px; z-index: 30;
  height: 50px; padding: 0 20px; border-radius: 25px; border: none;
  background: var(--primary); color: #fff; font-weight: 600;
  display: inline-flex; align-items: center; gap: 8px;
  box-shadow: 0 10px 26px rgba(79,110,247,.42);
}
.fab:hover { background: var(--primary-600); }
.fab svg { width: 18px; height: 18px; }

/* ---------- modal ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(18, 22, 33, .45);
  backdrop-filter: blur(2px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 34px 16px; overflow-y: auto;
}
.modal {
  width: 100%; max-width: 560px;
  background: var(--panel); border-radius: 18px;
  box-shadow: 0 24px 60px rgba(16,24,40,.28);
  animation: pop .16s ease-out;
}
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; flex: 1; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 15px 20px; border-top: 1px solid var(--border); }

.pw-field { position: relative; }
.pw-field .input { padding-right: 82px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.pw-actions { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); display: flex; gap: 2px; }
.pw-actions button { border: none; background: transparent; color: var(--muted); padding: 5px; border-radius: 6px; }
.pw-actions button:hover { color: var(--primary-600); background: var(--primary-soft); }
.pw-actions svg { width: 16px; height: 16px; display: block; }

.strength { height: 5px; border-radius: 3px; background: var(--border); margin-top: 8px; overflow: hidden; }
.strength i { display: block; height: 100%; width: 0; transition: width .2s, background .2s; }
.strength-label { font-size: 12px; color: var(--muted); margin-top: 5px; }

.fields-head { display: flex; align-items: center; justify-content: space-between; margin: 20px 0 10px; }
.fields-head h4 { margin: 0; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.field-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.field-row .f-key { flex: 1; min-width: 0; }
.field-row .f-type { width: 108px; flex: none; }
.field-row .f-val { flex: 1.5; min-width: 0; }
.field-row .rm { flex: none; }
.hint { font-size: 12px; color: var(--muted); margin: -6px 0 14px; }

.platform-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px;
}
.platform-row .dot { width: 12px; height: 12px; border-radius: 4px; flex: none; }
.platform-row .pname { flex: 1; font-weight: 500; }
.platform-row .pcount { color: var(--muted); font-size: 12px; }
.template-tag { font-size: 11px; color: var(--muted); }

.tabs { display: flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 10px; margin-bottom: 18px; }
.tabs button { flex: 1; border: none; background: transparent; padding: 8px; border-radius: 7px; color: var(--muted); font-weight: 500; }
.tabs button.active { background: #fff; color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------- toast ---------- */
#toast-root { position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  background: #1f2430; color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: 13px; box-shadow: 0 10px 30px rgba(0,0,0,.25);
  animation: toast .18s ease-out;
  max-width: 80vw;
}
.toast.error { background: var(--danger); }
.toast.success { background: #101828; }
@keyframes toast { from { transform: translateY(10px); opacity: 0; } }

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  .sidebar { position: fixed; left: 0; top: 59px; bottom: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop { position: fixed; inset: 59px 0 0; background: rgba(0,0,0,.35); z-index: 39; }
  .search-wrap { max-width: none; }
  .content { padding: 16px 14px 90px; }
  .row { flex-direction: column; gap: 0; }
  .field-row { flex-wrap: wrap; }
  .field-row .f-key, .field-row .f-type, .field-row .f-val { flex: 1 1 40%; }
  .brand span { display: none; }
}
