:root {
  --bg: #0d1017;
  --surface: #151a22;
  --surface-2: #1b212b;
  --surface-3: #222a36;
  --border: #28303d;
  --text: #e6eaf2;
  --muted: #8b95a7;
  --accent: #5b8cff;
  --accent-soft: rgba(91, 140, 255, 0.14);
  --danger: #ff6b6b;
  --danger-soft: rgba(255, 107, 107, 0.12);
  --radius: 10px;
  --shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}

h1 {
  font-size: 20px;
  margin-bottom: 12px;
}

h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  text-transform: none;
}

h3 {
  font-size: 16px;
  margin-bottom: 14px;
}

p {
  margin: 0 0 10px;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.brand.large {
  font-size: 26px;
  margin-bottom: 18px;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12px;
}

.hint {
  color: var(--muted);
  font-size: 12px;
  margin-top: 8px;
}

.warn {
  color: #ffb86b;
  background: rgba(255, 184, 107, 0.08);
  border: 1px solid rgba(255, 184, 107, 0.25);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13px;
  margin: 12px 0 18px;
}

.error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 10px;
}

/* ---------------------------------------------------------------- 屏幕 */

.screen {
  min-height: 100vh;
}

.screen.center {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.boot {
  text-align: center;
}

.card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}

.card.narrow {
  max-width: 360px;
}

/* ---------------------------------------------------------------- 表单 */

label {
  display: block;
  margin-bottom: 14px;
}

label > span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

input,
select,
textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea {
  resize: vertical;
  min-height: 72px;
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

button {
  font-family: inherit;
  font-size: 13px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 9px 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button.primary {
  background: var(--accent);
  color: #0b0f16;
  font-weight: 600;
}

button.primary:hover:not(:disabled) {
  background: #7aa2ff;
}

button.ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}

button.ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: #3a4453;
  background: var(--surface-2);
}

button.danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: rgba(255, 107, 107, 0.28);
}

button.danger:hover:not(:disabled) {
  background: rgba(255, 107, 107, 0.2);
}

button.small-btn {
  padding: 6px 12px;
  font-size: 12px;
}

button.tiny {
  padding: 3px 8px;
  font-size: 11px;
  border-radius: 6px;
}

.danger-text {
  color: var(--danger) !important;
}

#init-form button[type="submit"],
#login-form button[type="submit"] {
  width: 100%;
  margin-top: 6px;
  padding: 11px;
  font-size: 14px;
}

/* ---------------------------------------------------------------- 主界面 */

#vault-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.topbar {
  flex: 0 0 auto;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  min-height: 0;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-head,
.content-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
}

.content-head {
  padding: 16px 24px;
}

.content-head h2 {
  font-size: 16px;
  color: var(--text);
  font-weight: 600;
}

.category-list,
.item-list {
  list-style: none;
  margin: 0;
  padding: 0 10px 16px;
  overflow-y: auto;
  flex: 1 1 auto;
}

.category-item {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 8px;
  margin-bottom: 2px;
}

.category-item.is-active {
  background: var(--accent-soft);
}

.category-item.is-active .category-name {
  color: var(--text);
  font-weight: 600;
}

.category-select {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: transparent;
  border: none;
  color: var(--muted);
  text-align: left;
  padding: 9px 10px;
  font-size: 13px;
  border-radius: 8px;
}

.category-select:hover {
  color: var(--text);
  background: var(--surface-2);
}

.category-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-count {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--muted);
  background: var(--surface-3);
  border-radius: 20px;
  padding: 1px 8px;
}

.category-tools {
  display: none;
  gap: 2px;
  padding-right: 6px;
}

/* ---------------------------------------------------------------- 拖动排序 */

.category-item[draggable="true"],
.item-row[draggable="true"] {
  cursor: grab;
}

.category-item.is-dragging,
.item-row.is-dragging {
  opacity: 0.45;
  outline: 1px dashed var(--accent);
  outline-offset: -1px;
  border-radius: 8px;
  cursor: grabbing;
}

.item-row.is-dragging {
  border-radius: var(--radius);
}

.category-item:hover .category-tools {
  display: flex;
}

.content {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.item-list {
  padding: 0 24px 24px;
}

.item-row {
  margin-bottom: 8px;
}

.item-open {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 16px;
  color: var(--text);
  font-size: 14px;
}

.item-open:hover {
  border-color: #3a4453;
  background: var(--surface-2);
}

.item-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-time {
  flex: 0 0 auto;
}

.center-text {
  text-align: center;
  padding: 40px 0;
}

/* ---------------------------------------------------------------- 对话框 */

.dialog {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  padding: 24px;
  width: min(460px, calc(100vw - 32px));
  box-shadow: var(--shadow);
}

.dialog::backdrop {
  background: rgba(6, 9, 14, 0.72);
  backdrop-filter: blur(3px);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.detail .field {
  margin-bottom: 14px;
}

.field-label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 5px;
}

.field-value {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}

.field-value code {
  flex: 1 1 auto;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Courier New", monospace;
  font-size: 13px;
  word-break: break-all;
  letter-spacing: 0.02em;
}

.note {
  margin: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  max-height: 180px;
  overflow-y: auto;
}

/* ---------------------------------------------------------------- 提示 */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 22px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 50;
}

/* ---------------------------------------------------------------- 响应式 */

@media (max-width: 760px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 38vh;
  }

  .category-list {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0 12px 12px;
  }

  .category-item {
    flex: 0 0 auto;
    background: var(--surface-2);
  }

  .category-tools {
    display: flex;
  }

  .category-count {
    margin-left: 6px;
  }

  .content-head,
  .item-list {
    padding-left: 14px;
    padding-right: 14px;
  }
}
