:root {
  --bg: #0b0a12;
  --text: #eceaf3;
  --muted: #a5a1b8;
  --line: rgba(255,255,255,.10);
  --glass: rgba(255,255,255,.055);
  --glass-hi: rgba(255,255,255,.10);
  --primary: #8a5cff;
  --primary-soft: rgba(138,92,255,.20);
  --accent: #6ee7f2;
  --on-primary: #ffffff;
  --error: #ff8a8a;
  --sidebar-w: 244px;
  --detail-w: 400px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic", sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

/* ── 배경 (홈페이지와 같은 오로라) ── */
.aurora { position: fixed; inset: -20% -10%; z-index: -2; filter: blur(72px); opacity: .62; pointer-events: none; }
.aurora span { position: absolute; display: block; border-radius: 50%; mix-blend-mode: screen; animation: drift 24s ease-in-out infinite alternate; }
.aurora span:nth-child(1) { width: 46vw; height: 46vw; left: 2%;  top: 0%;   background: #7b3ff2; }
.aurora span:nth-child(2) { width: 38vw; height: 38vw; right: 4%; top: 10%;  background: #2f7cf6; animation-delay: -6s; }
.aurora span:nth-child(3) { width: 34vw; height: 34vw; left: 24%; bottom: 0%; background: #17b8a6; animation-delay: -12s; }
.aurora span:nth-child(4) { width: 24vw; height: 24vw; right: 18%; bottom: 4%; background: #e0479e; animation-delay: -3s; opacity: .7; }
@keyframes drift { from { transform: translate3d(0,0,0) scale(1); } to { transform: translate3d(4vw,-4vh,0) scale(1.16); } }

.grid-overlay {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: radial-gradient(ellipse 80% 60% at 50% 25%, #000 40%, transparent 100%);
  -webkit-mask-image: radial-gradient(ellipse 80% 60% at 50% 25%, #000 40%, transparent 100%);
  opacity: .45;
}
@media (prefers-reduced-motion: reduce) { .aurora span { animation: none; } }

/* ── 로그인 · 금고 ── */

.center-view {
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

.card { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 14px; }
.card.glass {
  padding: 34px 28px 30px;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: var(--glass);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 24px 60px rgba(0,0,0,.45);
}

.lock-badge {
  align-self: center;
  width: 62px; height: 62px;
  display: grid; place-items: center;
  font-size: 28px;
  border-radius: 20px;
  background: linear-gradient(140deg, #8a5cff, #4527a0);
  box-shadow: 0 10px 26px rgba(90,40,200,.45);
}

.brand {
  margin: 6px 0 0;
  text-align: center;
  font-size: 32px; font-weight: 800; letter-spacing: -.01em;
  background: linear-gradient(100deg, #c9b7ff 0%, #6ee7f2 60%, #c9b7ff 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand-sub { margin-top: -6px; letter-spacing: .08em; }

.vault-owner {
  margin: -6px 0 0;
  font-size: 16px; font-weight: 700;
  color: #ded5ff;
}
.vault-owner .who {
  display: inline-block;
  padding: 5px 12px; margin-right: 4px;
  background: var(--primary-soft);
  border: 1px solid rgba(138,92,255,.35);
  border-radius: 999px;
}
.center-btn { align-self: center; margin-top: 2px; }

.field { display: flex; flex-direction: column; gap: 6px; }

.check-row {
  display: flex; align-items: center; gap: 9px;
  font-size: 14px; color: var(--muted);
  cursor: pointer;
}
.check-row input { width: 18px; height: 18px; accent-color: var(--primary); }
.field > span { font-size: 13px; color: var(--muted); }

input[type="text"], input[type="password"], input[type="search"], select, textarea {
  width: 100%;
  padding: 13px 15px;
  font-size: 16px; /* 16px 미만이면 iOS가 확대한다 */
  font-family: inherit;
  color: var(--text);
  background: rgba(255,255,255,.06);
  border: 1px solid var(--line);
  border-radius: 12px;
}
input::placeholder, textarea::placeholder { color: #7d7a8c; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: rgba(138,92,255,.75);
  box-shadow: 0 0 0 3px rgba(138,92,255,.18);
}
textarea { resize: vertical; }
select option { background: #1a1822; color: var(--text); }

button { font-size: 16px; font-weight: 600; border: none; cursor: pointer; font-family: inherit; }
button:disabled { opacity: .45; cursor: default; }

.primary {
  padding: 14px; border-radius: 999px;
  color: var(--on-primary);
  background: linear-gradient(100deg, #8a5cff, #5b32d6);
  box-shadow: 0 10px 24px rgba(90,40,200,.4);
  transition: transform .15s ease, box-shadow .15s ease;
}
.primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 14px 30px rgba(90,40,200,.5); }
.secondary { padding: 12px 18px; border-radius: 999px; background: var(--glass-hi); color: var(--text); border: 1px solid var(--line); }
.link-btn { padding: 7px 12px; font-size: 14px; background: none; color: #c8bcff; border-radius: 10px; }
.link-btn:hover { background: var(--glass-hi); }
.link-btn.danger { color: var(--error); }

.icon-btn {
  width: 40px; height: 40px; flex: none;
  font-size: 17px; background: none; color: var(--text); border-radius: 999px;
}
.icon-btn:hover { background: var(--glass-hi); }

/* 홈으로 (topbar 오른쪽 끝) */
.home-btn {
  display: inline-flex; align-items: center; justify-content: center;
  text-decoration: none; color: #c8bcff;
}
.home-btn svg { width: 20px; height: 20px; fill: currentColor; }

.error { margin: 0; color: var(--error); font-size: 14px; }
.muted { margin: 0; color: var(--muted); font-size: 14px; }
.center-text { text-align: center; line-height: 1.55; }

/* ── 메인 ── */

.app-view { display: flex; flex-direction: column; height: 100dvh; }

.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: rgba(11,10,18,.62);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.app-title {
  margin: 0; font-size: 20px; font-weight: 800; white-space: nowrap;
  background: linear-gradient(100deg, #c9b7ff, #6ee7f2);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.search { flex: 1; min-width: 0; max-width: 460px; }

.body-grid { flex: 1; display: flex; min-height: 0; position: relative; }

/* 구분 */
.sidebar {
  width: var(--sidebar-w); flex: none;
  display: flex; flex-direction: column;
  padding: 14px 10px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: rgba(255,255,255,.03);
}
.cat-nav { flex: 1; display: flex; flex-direction: column; gap: 3px; }
.cat-item {
  padding: 12px 15px;
  font-size: 15px; text-align: left;
  background: none; color: var(--text);
  border-radius: 12px; width: 100%;
  transition: background .15s ease;
}
.cat-item:hover { background: var(--glass-hi); }
.cat-item.active {
  font-weight: 700;
  color: #fff;
  background: linear-gradient(100deg, rgba(138,92,255,.45), rgba(110,231,242,.18));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.12);
}
.manage-btn { margin-top: 10px; text-align: left; }

/* 목록 */
.list-pane { flex: 1; min-width: 0; overflow-y: auto; padding: 0 12px; }
.list-info { padding: 14px 6px 10px; }
.list { margin: 0; padding: 0 0 90px; list-style: none; display: flex; flex-direction: column; gap: 8px; }

.list-item {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--glass);
  cursor: pointer;
  transition: transform .14s ease, background .14s ease, border-color .14s ease;
}
.list-item:hover { transform: translateY(-2px); background: var(--glass-hi); border-color: rgba(255,255,255,.2); }
.list-item.selected {
  border-color: rgba(138,92,255,.6);
  background: linear-gradient(100deg, rgba(138,92,255,.22), rgba(110,231,242,.08));
}
.item-main { flex: 1; min-width: 0; }
.item-title { font-size: 16px; font-weight: 600; overflow-wrap: anywhere; }
.item-sub { font-size: 13.5px; color: var(--muted); overflow-wrap: anywhere; }

.chip {
  padding: 5px 11px; font-size: 12px; white-space: nowrap;
  color: #ded5ff;
  background: var(--primary-soft);
  border: 1px solid rgba(138,92,255,.35);
  border-radius: 999px;
}

/* 상세 · 편집 · 구분 관리 패널 */
.detail-pane {
  width: var(--detail-w); flex: none;
  display: flex; flex-direction: column;
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: rgba(16,14,24,.86);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
}
.detail-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 8px;
  padding: 12px 12px;
  background: rgba(16,14,24,.9);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.detail-head h2 { flex: 1; margin: 0; font-size: 18px; overflow-wrap: anywhere; }
.detail-body { padding: 18px; display: flex; flex-direction: column; gap: 20px; }

.detail-section > h3 {
  margin: 0 0 10px;
  font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted);
}
.value-row {
  display: flex; align-items: center; gap: 8px;
  padding: 11px 13px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 13px;
}
.value-text {
  flex: 1; min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 15px; overflow-wrap: anywhere;
}
.cred-block { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.cred-label { font-size: 12px; color: var(--muted); }
.memo-text { white-space: pre-wrap; overflow-wrap: anywhere; font-family: inherit; }
.detail-body a { color: #9fd8ff; overflow-wrap: anywhere; }

/* 편집 */
.cred-edit {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 12px; padding: 12px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.cred-edit .inputs { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }

.url-row { display: flex; align-items: center; gap: 6px; }
.url-row input { flex: 1; min-width: 0; }

/* 구분 관리 */
.cat-add-row { display: flex; gap: 8px; }
.cat-add-row input { flex: 1; min-width: 0; }
.cat-manage-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.cat-manage-item {
  display: flex; align-items: center; gap: 4px;
  padding: 8px 6px 8px 14px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: 13px;
}
.cat-manage-item .name { flex: 1; min-width: 0; overflow-wrap: anywhere; }

/* 좁은 화면 */
.scrim { position: absolute; inset: 0; background: rgba(0,0,0,.55); z-index: 8; }
.only-narrow { display: none; }

@media (max-width: 820px) {
  .only-narrow { display: inline-flex; }
  .only-wide { display: none; }
  .app-title { display: none; }

  .sidebar {
    position: absolute; inset: 0 auto 0 0; z-index: 9;
    background: rgba(16,14,24,.94);
    backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
    box-shadow: 0 0 40px rgba(0,0,0,.5);
    transform: translateX(-100%);
    transition: transform .22s ease;
  }
  .sidebar.open { transform: none; }

  .detail-pane { position: absolute; inset: 0; width: auto; z-index: 10; border-left: none; }
}

/* 추가 버튼 */
.fab {
  position: fixed;
  right: 22px;
  bottom: max(22px, env(safe-area-inset-bottom));
  z-index: 15;
  width: 58px; height: 58px;
  font-size: 28px; line-height: 1;
  color: var(--on-primary);
  background: linear-gradient(140deg, #8a5cff, #4527a0);
  border-radius: 20px;
  box-shadow: 0 12px 30px rgba(90,40,200,.5);
  transition: transform .15s ease;
}
.fab:hover { transform: translateY(-2px) scale(1.03); }

/* 알림 */
.toast {
  position: fixed;
  left: 50%; bottom: max(26px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 20;
  padding: 12px 20px;
  font-size: 14px; color: #fff;
  background: linear-gradient(100deg, #8a5cff, #5b32d6);
  border-radius: 999px;
  box-shadow: 0 10px 28px rgba(0,0,0,.45);
}

/* 편집·상세 패널이 열려 있으면 + 버튼을 숨긴다 (저장 버튼과 헷갈리지 않게) */
body.panel-open .fab { display: none; }
