:root {
  --bg: #000000;
  --bg-elev: #0e0e10;
  --bg-card: #141417;
  --border: #26262b;
  --text: #ffffff;
  --muted: #9a9a9a;
  --accent: #ffffff;
  --accent-ink: #000000;
  --danger: #ff5a5a;
  --radius: 18px;
  --radius-sm: 12px;
}

*,
*::before,
*::after { box-sizing: border-box; }

/* Das [hidden]-Attribut muss alle display-Regeln überschreiben
   (sonst bleiben Modal/Logout trotz hidden sichtbar). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text);
}
.brand img { width: 40px; height: 40px; object-fit: contain; }
.brand span { font-size: 20px; font-weight: 700; letter-spacing: 0.02em; }
.brand em { font-style: normal; color: var(--muted); font-weight: 600; }

.app { min-height: calc(100vh - 77px); }
.view { padding: 40px 24px 80px; }
.container { max-width: 1080px; margin: 0 auto; }

h1 { font-size: clamp(2rem, 6vw, 3rem); font-weight: 800; letter-spacing: -0.02em; margin: 0 0 8px; }
h2 { font-size: clamp(1.5rem, 4vw, 2rem); font-weight: 700; letter-spacing: -0.01em; margin: 0 0 4px; }
.muted { color: var(--muted); line-height: 1.5; margin: 0 0 20px; }
.small { font-size: 13px; }
.error { color: var(--danger); margin-top: 14px; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; margin-top: 18px; line-height: 1.5; }
.empty { color: var(--muted); text-align: center; padding: 60px 0; }

/* Buttons */
.primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 28px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.primary-btn:hover { transform: translateY(-2px); background: #e6e6e6; }
.primary-btn:active { transform: translateY(0); }
.primary-btn:disabled { opacity: 0.5; cursor: default; transform: none; }

.ghost-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.ghost-btn:hover { border-color: #3a3a40; background: var(--bg-elev); }
.ghost-btn.solid { background: var(--bg-card); }

/* Login */
.login-card {
  max-width: 460px;
  margin: 6vh auto 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
}
.field-label { display: block; font-size: 13px; color: var(--muted); margin: 22px 0 8px; }
.key-input {
  width: 100%;
  padding: 15px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 18px;
  letter-spacing: 0.08em;
  font-family: "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;
  text-transform: uppercase;
}
.key-input:focus { outline: none; border-color: #4a4a52; }
.login-card .primary-btn { width: 100%; margin-top: 22px; }

/* Devices */
.device-list { display: grid; gap: 14px; }
.device-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
}
.device-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.device-id { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; color: var(--muted); }
.device-id strong { color: var(--text); display: block; font-size: 16px; margin-bottom: 2px; letter-spacing: 0.02em; }
.device-form { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.pass-input {
  flex: 1 1 220px;
  padding: 13px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 15px;
}
.pass-input:focus { outline: none; border-color: #4a4a52; }
.device-error { color: var(--danger); font-size: 13px; margin-top: 10px; }

/* Notes */
.notes-toolbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 28px; }
.toolbar-right { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.search-input {
  padding: 11px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 14px;
  min-width: 180px;
}
.search-input:focus { outline: none; border-color: #4a4a52; }

.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 18px;
}
.note-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
  display: flex;
  flex-direction: column;
}
.note-card:hover { transform: translateY(-3px); border-color: #3a3a40; }
.note-thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #1b1b1f;
  display: block;
}
.note-thumb.placeholder { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; }
.note-title {
  padding: 14px 16px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  border-top: 1px solid var(--border);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Modal */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 24px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.78); backdrop-filter: blur(4px); }
.modal-card {
  position: relative;
  z-index: 1;
  width: min(720px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
}
.modal-close {
  position: absolute; top: 14px; right: 16px;
  background: transparent; border: none; color: var(--muted);
  font-size: 28px; line-height: 1; cursor: pointer;
}
.modal-close:hover { color: var(--text); }
.modal-img { width: 100%; border-radius: var(--radius-sm); background: #1b1b1f; display: block; }
.modal-card h3 { margin: 18px 0 4px; font-size: 20px; }
.modal-actions { display: flex; gap: 12px; margin-top: 22px; flex-wrap: wrap; }

/* Toast */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 13px 22px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  z-index: 60;
  box-shadow: 0 12px 32px rgba(0,0,0,0.5);
}

@media (max-width: 520px) {
  .topbar { padding: 14px 16px; }
  .view { padding: 28px 16px 60px; }
  .login-card { padding: 30px 22px; }
  .notes-toolbar { align-items: stretch; }
  .toolbar-right { width: 100%; }
  .search-input { flex: 1; }
  .notes-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
