*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #0f1020;
  color: #e8e8f0;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid #7ab8ff; outline-offset: 2px; }

.hidden, [hidden] { display: none !important; }

/* === Bildschirme === */
.screen.center {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.card {
  background: #1a1a2e;
  border: 1px solid #2a2b45;
  border-radius: 14px;
  padding: 28px;
  max-width: 460px;
  width: 100%;
  box-shadow: 0 10px 40px rgba(0,0,0,0.4);
}
.card.wide { max-width: 560px; }
.card h1 { margin: 0 0 6px; font-size: 22px; }
.card .subtitle { margin: 0 0 22px; color: #9a9ab2; font-size: 14px; line-height: 1.5; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; margin-bottom: 6px; font-size: 13px; color: #b8b8cc; }
.field input, .field textarea, .field select {
  width: 100%;
  padding: 10px 12px;
  background: #0f1020;
  border: 1px solid #2a2b45;
  border-radius: 8px;
  font-size: 15px;
}
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: #7ab8ff; outline: none;
}
.pw { position: relative; display: block; }
.pw input { padding-right: 42px; }
.pw-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  background: transparent; border: none; padding: 6px 10px; color: #b8b8cc; font-size: 16px;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px;
  border: 1px solid #2a2b45;
  background: #232442; color: #e8e8f0;
  border-radius: 8px; font-size: 14px; font-weight: 500;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: #2c2d52; }
.btn.primary { background: #4a6fdc; border-color: #4a6fdc; }
.btn.primary:hover { background: #5a7fec; }
.btn.danger { background: #c2384a; border-color: #c2384a; }
.btn.danger:hover { background: #d04859; }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: #232442; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.full { width: 100%; }

.error {
  margin-top: 12px;
  padding: 10px 12px;
  background: rgba(194,56,74,0.15);
  border: 1px solid rgba(194,56,74,0.4);
  border-radius: 6px;
  color: #ff8a98;
  font-size: 13px;
}
.info {
  margin-top: 12px;
  padding: 10px 12px;
  background: rgba(74,111,220,0.12);
  border: 1px solid rgba(74,111,220,0.35);
  border-radius: 6px;
  color: #b8c8ee;
  font-size: 13px;
  line-height: 1.5;
}

.strength { margin-top: 8px; margin-bottom: 6px; }
.strength .bar { height: 4px; background: #2a2b45; border-radius: 2px; overflow: hidden; }
.strength .fill { height: 100%; width: 0; background: #c2384a; transition: width 0.2s, background 0.2s; }
.strength .label { font-size: 12px; margin-top: 4px; color: #9a9ab2; }

.qr-wrap {
  display: flex; gap: 16px; align-items: center;
  margin: 4px 0 18px;
  flex-wrap: wrap;
}
#totp-qr { width: 168px; height: 168px; background: white; border-radius: 8px; padding: 6px; flex-shrink: 0; }
.qr-secret { font-size: 13px; color: #b8b8cc; }
.qr-secret code {
  display: inline-block;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; letter-spacing: 0.05em;
  padding: 4px 6px;
  background: #0f1020; border: 1px solid #2a2b45;
  border-radius: 4px;
  margin-top: 4px;
  word-break: break-all;
}
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9em;
  padding: 1px 5px;
  background: rgba(255,255,255,0.08);
  border-radius: 4px;
}

/* === MAIN APP === */
.app-header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(15,16,32,0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid #2a2b45;
  padding: 12px 20px;
  display: flex; gap: 10px; align-items: center;
}
.app-title { font-size: 18px; font-weight: 600; margin-right: auto; }
.dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: #6ad48f; margin-right: 8px; vertical-align: middle;
}
.dot.dirty { background: #f0b248; }
.search {
  width: 240px;
  padding: 8px 12px;
  background: #1a1a2e; border: 1px solid #2a2b45;
  border-radius: 8px; font-size: 14px;
}
.search:focus { border-color: #7ab8ff; outline: none; }

.app-body { max-width: 1100px; margin: 0 auto; padding: 24px 20px 80px; }

/* TOC */
.toc {
  background: linear-gradient(135deg, #1a1a2e 0%, #232442 100%);
  border: 1px solid #2a2b45;
  border-radius: 14px;
  padding: 22px;
  margin-bottom: 30px;
}
.toc h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.01em; }
.toc-sub { margin: 0 0 16px; font-size: 13px; color: #9a9ab2; }
.toc-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.toc-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  background: #0f1020;
  border: 1px solid #2a2b45;
  border-radius: 10px;
  text-decoration: none; color: inherit;
  transition: transform 0.1s, border-color 0.15s, background 0.15s;
}
.toc-item:hover {
  border-color: #4a6fdc;
  background: #14152c;
  transform: translateY(-1px);
}
.toc-icon {
  font-size: 22px;
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: #232442; border-radius: 8px; flex-shrink: 0;
}
.toc-name { font-weight: 500; font-size: 15px; }
.toc-count { font-size: 12px; color: #9a9ab2; margin-top: 2px; }

/* Groups */
.group { margin-bottom: 30px; scroll-margin-top: 80px; }
.group-header {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid #2a2b45;
}
.group-icon {
  font-size: 22px;
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  background: #232442; border-radius: 10px;
}
.group-name { font-size: 20px; font-weight: 600; flex-grow: 1; }
.group-actions { display: flex; gap: 6px; }
.entries {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.entry {
  background: #1a1a2e; border: 1px solid #2a2b45;
  border-radius: 12px; padding: 14px 16px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.entry:hover { border-color: #4a6fdc; transform: translateY(-1px); }
.entry-title { font-weight: 600; font-size: 15px; margin-bottom: 4px; }
.entry-sub { font-size: 13px; color: #9a9ab2; }
.entry-meta {
  display: flex; gap: 10px; margin-top: 8px;
  font-size: 12px; color: #6e6e88;
}
.empty-group {
  padding: 18px;
  background: #14152c; border: 1px dashed #2a2b45;
  border-radius: 10px; color: #9a9ab2; font-size: 13px;
  text-align: center;
}

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(3px);
  z-index: 100;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 20px;
  overflow-y: auto;
}
.modal {
  background: #1a1a2e; border: 1px solid #2a2b45;
  border-radius: 14px;
  width: 100%; max-width: 640px;
  margin: 40px auto;
  padding: 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal h3 { margin: 0 0 4px; font-size: 18px; }
.modal-sub { margin: 0 0 16px; color: #9a9ab2; font-size: 13px; }
.modal-actions {
  display: flex; gap: 8px; justify-content: flex-end;
  margin-top: 20px; padding-top: 16px; border-top: 1px solid #2a2b45;
  flex-wrap: wrap;
}
.section-label {
  font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: #9a9ab2;
  margin: 16px 0 8px;
}

/* Fields editor */
.fields-editor { display: flex; flex-direction: column; gap: 8px; }
.field-row {
  display: grid;
  grid-template-columns: 1fr 2fr auto auto;
  gap: 6px; align-items: center;
}
.field-row input {
  padding: 8px 10px;
  background: #0f1020; border: 1px solid #2a2b45;
  border-radius: 6px; font-size: 14px; min-width: 0;
}
.field-row input:focus { border-color: #7ab8ff; outline: none; }
.icon-btn {
  width: 34px; height: 34px;
  padding: 0; display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid #2a2b45;
  border-radius: 6px; color: #b8b8cc; font-size: 16px;
}
.icon-btn:hover { background: #232442; color: #fff; }
.icon-btn.danger:hover { background: rgba(194,56,74,0.2); color: #ff8a98; border-color: rgba(194,56,74,0.4); }

/* View entry */
.view-fields { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.view-field {
  display: grid;
  grid-template-columns: 140px 1fr auto;
  gap: 10px; align-items: center;
  padding: 8px 10px;
  background: #0f1020; border: 1px solid #2a2b45;
  border-radius: 8px;
}
.view-field-label { font-size: 13px; color: #9a9ab2; }
.view-field-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 14px; word-break: break-all; white-space: pre-wrap;
}
.view-field-value.secret { letter-spacing: 0.2em; }
.view-notes {
  background: #0f1020; border: 1px solid #2a2b45;
  border-radius: 8px; padding: 12px; font-size: 14px;
  white-space: pre-wrap; word-break: break-word;
  margin-bottom: 14px;
}
.attachments-list { display: flex; flex-direction: column; gap: 6px; }
.attachment {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  background: #0f1020; border: 1px solid #2a2b45;
  border-radius: 8px;
}
.attachment-name { flex-grow: 1; font-size: 14px; word-break: break-all; }
.attachment-size { font-size: 12px; color: #9a9ab2; flex-shrink: 0; }

/* Toast */
.toast-host {
  position: fixed; bottom: 20px; left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
.toast {
  background: #232442;
  border: 1px solid #4a6fdc;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
  animation: toast-in 0.2s ease-out;
}
.toast.error { border-color: #c2384a; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Mobile */
@media (max-width: 640px) {
  .app-header { padding: 10px 14px; gap: 8px; flex-wrap: wrap; }
  .search { width: 100%; order: 10; }
  .app-body { padding: 16px 14px 60px; }
  .toc { padding: 18px; }
  .toc-list { grid-template-columns: 1fr; }
  .entries { grid-template-columns: 1fr; }
  .modal { padding: 18px; margin: 0 0 20px; }
  .view-field { grid-template-columns: 1fr; gap: 4px; }
  .view-field-label { font-size: 12px; }
  .field-row { grid-template-columns: 1fr; gap: 4px; }
  .field-row .icon-btn { justify-self: end; }
  .modal-actions .btn { flex-grow: 1; }
}
