:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --success: #16a34a;
  --error: #dc2626;
  --bg: #f4f5f9;
  --card-bg: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* Login / setup / 2FA pages */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 55%, var(--primary-dark) 100%);
  background-attachment: fixed;
  position: relative;
  overflow: hidden;
}

.auth-body::before,
.auth-body::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  z-index: 0;
}

.auth-body::before {
  width: 420px;
  height: 420px;
  top: -160px;
  right: -140px;
}

.auth-body::after {
  width: 320px;
  height: 320px;
  bottom: -140px;
  left: -120px;
}

.auth-card {
  background: var(--card-bg);
  border: none;
  border-radius: 18px;
  padding: 2.2rem 1.9rem 1.9rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 25px 60px rgba(30, 20, 80, 0.35);
  position: relative;
  z-index: 1;
}

.auth-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.7rem;
  margin: -3.7rem auto 1rem;
  box-shadow: 0 10px 22px rgba(79, 70, 229, 0.45);
  border: 4px solid var(--card-bg);
}

.auth-title {
  font-size: 1.2rem;
  margin: 0 0 0.3rem;
  text-align: center;
  color: var(--text);
}

.auth-hint {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 1.4rem;
  line-height: 1.4;
}

.auth-submit {
  width: 100%;
  margin-top: 0.5rem;
  background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
  border: none;
  box-shadow: 0 8px 18px rgba(79, 70, 229, 0.35);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.auth-submit:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(79, 70, 229, 0.45);
}

.auth-code-input {
  text-align: center;
  font-size: 1.3rem;
  letter-spacing: 0.4em;
}

.auth-qr {
  display: block;
  margin: 0 auto 0.8rem;
  width: 200px;
  height: 200px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.auth-secret {
  text-align: center;
  font-family: monospace;
  font-size: 0.85rem;
  background: var(--bg);
  padding: 0.5rem;
  border-radius: 6px;
  margin: 0 0 0.5rem;
  word-break: break-all;
}

/* Compact top bar (replaces the old tall gradient banner) */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  background: var(--primary);
  color: white;
  padding: 0.6rem 1rem;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.topbar-title {
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
}

.version-badge {
  background: rgba(255, 255, 255, 0.18);
  color: white;
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
  vertical-align: middle;
}

.version-log-link {
  color: white;
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 6px;
  padding: 0.15rem 0.55rem;
  white-space: nowrap;
  transition: background 0.15s ease;
}

.version-log-link:hover {
  background: rgba(255, 255, 255, 0.18);
}

.changelog-list {
  margin: 0;
  padding-left: 1.2rem;
  font-size: 0.88rem;
}

.changelog-list li {
  margin-bottom: 0.4rem;
}

.topbar-nav {
  display: flex;
  gap: 0.4rem;
}

.topbar-nav a {
  color: white;
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 6px;
  padding: 0.3rem 0.65rem;
  transition: background 0.15s ease;
  white-space: nowrap;
}

.topbar-btn {
  background: white;
  color: var(--primary-dark);
  border: 1px solid white;
  font-size: 0.85rem;
  font-weight: 700;
  border-radius: 6px;
  padding: 0.35rem 0.8rem;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.topbar-nav a:hover, .topbar-nav a.active {
  background: rgba(255, 255, 255, 0.18);
}

.topbar-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
}

@media (max-width: 640px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    padding: 0.6rem 0.8rem;
  }

  .topbar-left {
    flex-wrap: wrap;
    justify-content: center;
    text-align: center;
  }

  .topbar-nav {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.4rem;
  }

  .topbar-nav a,
  .topbar-nav .topbar-btn {
    justify-content: center;
    text-align: center;
    padding: 0.45rem 0.5rem;
  }
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0.9rem;
}

.container-wide {
  max-width: 1600px;
}

.search-bar {
  margin-bottom: 0.7rem;
  display: flex;
  gap: 0.5rem;
}

.search-bar input[type="search"] {
  flex: 1;
  min-width: 0;
}

.search-bar input, .search-bar select {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  background: var(--card-bg);
  font-family: inherit;
}

.search-bar select {
  max-width: 220px;
}

@media (max-width: 560px) {
  .search-bar {
    flex-direction: column;
  }
  .search-bar select {
    max-width: none;
  }
}

.filter-toggle {
  display: inline-flex;
  gap: 0.25rem;
  background: var(--bg);
  border-radius: 999px;
  padding: 0.2rem;
  margin-bottom: 0.7rem;
}

.filter-btn {
  border: none;
  background: none;
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.filter-btn.active {
  background: var(--primary);
  color: white;
}

/* Collapsible sections */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 0.7rem;
  overflow: hidden;
}

.card > summary {
  list-style: none;
  cursor: pointer;
  padding: 0.65rem 0.9rem;
  font-weight: 700;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  user-select: none;
}

.card > summary::-webkit-details-marker {
  display: none;
}

.card > summary::before {
  content: "▸";
  display: inline-block;
  color: var(--muted);
  transition: transform 0.15s ease;
  font-size: 0.75rem;
}

.card[open] > summary::before {
  transform: rotate(90deg);
}

.card > summary:hover {
  background: #fafafa;
}

.card-body {
  padding: 0 0.9rem 0.9rem;
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
}

.count-badge {
  background: var(--bg);
  color: var(--muted);
  border-radius: 999px;
  padding: 0.05rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 700;
}

.card-hint {
  color: var(--muted);
  font-size: 0.82rem;
  margin: 0 0 0.6rem;
}

.instructions {
  font-size: 0.82rem;
  color: var(--text);
  margin: 0 0 0.9rem;
  padding-left: 1.2rem;
}

.instructions li {
  margin-bottom: 0.35rem;
}

.instructions code {
  background: var(--bg);
  border-radius: 4px;
  padding: 0.05rem 0.35rem;
  font-size: 0.8rem;
}

.category-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.category-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.category-swatch {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
}

.category-name {
  flex: 1;
  font-size: 0.85rem;
  font-weight: 600;
}

.category-edit-form, .category-item form {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.category-edit-form input[type="color"], .category-add-form input[type="color"] {
  width: 40px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}

.contact-item {
  flex-wrap: wrap;
}

.contact-edit-form {
  flex: 1;
  min-width: 220px;
}

.contact-edit-form input {
  min-width: 120px;
}

.category-add-form {
  align-items: flex-end;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.category-add-form .form-group {
  margin-bottom: 0;
}

/* Form elements */
.note-form .form-group {
  margin-bottom: 0.7rem;
}

.form-row {
  display: flex;
  gap: 0.75rem;
}

.form-row .form-group {
  flex: 1;
}

.form-row .form-group-wide {
  flex: 2;
}

.form-row .form-group-narrow {
  flex: 1;
  max-width: 130px;
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.3rem;
  font-size: 0.82rem;
}

.form-checkbox label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 500;
  cursor: pointer;
}

.form-checkbox input[type="checkbox"] {
  width: auto;
}

.form-checkbox-row {
  display: flex;
  gap: 1.2rem;
}

.form-checkbox-row label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 500;
  cursor: pointer;
}

.form-checkbox-row input[type="checkbox"] {
  width: auto;
}

input, textarea, .note-form select {
  width: 100%;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--card-bg);
}

input:focus, textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.btn {
  border: none;
  border-radius: 6px;
  padding: 0.45rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.btn:hover {
  opacity: 0.9;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-success {
  background: var(--success);
  color: white;
}

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.link-btn {
  background: none;
  border: none;
  padding: 0;
  margin-top: 0.3rem;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.link-btn:hover {
  text-decoration: underline;
}

/* Modal dialogs (native <dialog>) */
.note-dialog {
  border: none;
  border-radius: 12px;
  padding: 1.1rem;
  width: 90%;
  max-width: 440px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.note-dialog::backdrop {
  background: rgba(17, 24, 39, 0.5);
}

.note-dialog h3 {
  margin: 0 0 0.8rem;
  font-size: 1rem;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.4rem;
}

@media (max-width: 560px) {
  .form-row {
    flex-direction: column;
    gap: 0;
  }
  .form-row .form-group-narrow {
    max-width: none;
  }
}

/* Note lists */
.note-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  align-content: start;
  gap: 0.6rem;
  max-height: 520px;
  overflow-y: auto;
}

.note-item {
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.note-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.note-pending {
  border-left: 3px solid var(--primary);
}

.note-done {
  border-left: 3px solid var(--success);
  opacity: 0.7;
}

.note-edit {
  margin-top: 0.35rem;
}

.note-edit > summary {
  list-style: none;
  cursor: pointer;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 600;
}

.note-edit > summary::-webkit-details-marker {
  display: none;
}

.note-edit .note-form {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--border);
}

.note-content p {
  margin: 0.15rem 0;
  font-size: 0.9rem;
}

.note-id {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
}

.note-meta {
  font-size: 0.75rem;
  color: var(--muted);
}

.empty-state {
  color: var(--muted);
  font-style: italic;
  font-size: 0.85rem;
  margin: 0.2rem 0;
}

/* Flash messages */
.flash-container {
  margin-bottom: 0.7rem;
}

.flash {
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  margin-bottom: 0.4rem;
  font-weight: 500;
  font-size: 0.85rem;
}

.flash-success {
  background: #dcfce7;
  color: #166534;
}

.flash-error {
  background: #fee2e2;
  color: #991b1b;
}

/* History table */
.table-wrapper {
  overflow-y: auto;
  overflow-x: hidden;
  max-height: 480px;
}

.log-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.log-table th, .log-table td {
  text-align: left;
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid var(--border);
  white-space: normal;
  overflow-wrap: break-word;
}

.log-table thead th {
  position: sticky;
  top: 0;
  background: var(--card-bg);
  z-index: 1;
}

.log-table th:nth-child(1), .log-table td:nth-child(1) { width: 14%; }
.log-table th:nth-child(2), .log-table td:nth-child(2) { width: 10%; }
.log-table th:nth-child(3), .log-table td:nth-child(3) { width: 6%; }
.log-table th:nth-child(4), .log-table td:nth-child(4) { width: 18%; }
.log-table th:nth-child(5), .log-table td:nth-child(5) { width: 18%; }
.log-table th:nth-child(6), .log-table td:nth-child(6) { width: 10%; }
.log-table th:nth-child(7), .log-table td:nth-child(7) { width: 24%; }

.log-table th {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
}

.badge {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
}

.badge-success {
  background: #dcfce7;
  color: #166534;
}

.badge-error {
  background: #fee2e2;
  color: #991b1b;
}

.badge-pending {
  background: #fef3c7;
  color: #92400e;
  margin-left: 0.3rem;
}

.badge-category {
  background: var(--bg);
  color: var(--text);
  margin-left: 0.3rem;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.badge-category::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--cat-color, var(--primary));
}

.back-link {
  display: inline-block;
  margin-top: 0.4rem;
  font-size: 0.85rem;
  color: var(--primary);
  text-decoration: none;
}

.back-link:hover {
  text-decoration: underline;
}
