:root {
  --bg: #0f1117;
  --bg-panel: #161922;
  --bg-card: #1b1f2a;
  --bg-hover: #232838;
  --border: #2a2f3d;
  --text: #e8eaf0;
  --text-muted: #9098ac;
  --accent: #6366f1;
  --accent-hover: #7c7ff5;
  --danger: #ef4444;
  --danger-hover: #f87171;
  --success: #22c55e;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }

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

.hidden { display: none !important; }

.screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.loader {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Autenticação --- */
.auth-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}
.brand {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.auth-card h1 { font-size: 20px; margin: 0 0 8px; }
.muted { color: var(--text-muted); font-size: 14px; line-height: 1.5; }
.muted.small { font-size: 12px; margin-top: 6px; }

label { display: block; font-size: 13px; color: var(--text-muted); margin: 14px 0 6px; }
input[type="text"], input[type="password"], input[type="search"], input[type="file"], textarea, select {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}
input[type="color"] {
  width: 60px; height: 36px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  margin: 16px 0;
}
.checkbox-line input { width: auto; margin: 0; }

.error {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  margin-top: 8px;
}

button { font-family: inherit; cursor: pointer; }
.btn-primary {
  width: 100%;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 600;
  margin-top: 14px;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  background: var(--bg-hover);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 13px;
  width: 100%;
  margin-top: 10px;
}
.btn-secondary:hover { border-color: var(--accent); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: none;
  padding: 9px 10px;
  font-size: 14px;
  text-align: left;
  border-radius: 8px;
  width: 100%;
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-ghost.danger:hover { color: var(--danger); }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  margin-top: 16px;
  width: 100%;
  text-align: center;
}
.link-btn:hover { text-decoration: underline; }

.recovery-code {
  background: var(--bg-card);
  border: 1px dashed var(--accent);
  border-radius: 8px;
  padding: 16px;
  font-family: "SF Mono", Consolas, monospace;
  font-size: 18px;
  letter-spacing: 1px;
  text-align: center;
  margin: 14px 0;
  word-break: break-all;
}

/* --- App shell --- */
.app-shell {
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  min-height: 100vh;
  padding: 0;
}
.sidebar {
  width: 250px;
  min-width: 250px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.category-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 8px;
}
.category-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 14px;
  position: relative;
}
.category-item:hover { background: var(--bg-hover); color: var(--text); }
.category-item.active { background: var(--bg-hover); color: var(--text); font-weight: 600; }
.category-item .cat-icon { font-size: 16px; }
.category-item .cat-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.category-item .cat-edit {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 2px 4px;
}
.category-item:hover .cat-edit { opacity: 1; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.main {
  flex: 1;
  padding: 24px 28px;
  overflow-y: auto;
  min-width: 0;
}
.topbar {
  display: flex;
  gap: 12px;
  margin-bottom: 18px;
}
.topbar input[type="search"] { flex: 1; }
.topbar .btn-primary { width: auto; margin-top: 0; white-space: nowrap; }

.category-header {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.items-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.item-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.15s;
}
.item-card:hover { border-color: #3a4055; }
.item-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.item-title { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 6px; }
.item-subtitle { color: var(--text-muted); font-size: 13px; }
.item-type-badge { font-size: 16px; }
.item-actions-top { display: flex; gap: 4px; }
.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  padding: 4px 6px;
  border-radius: 6px;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn.fav-active { color: #eab308; }

.item-field-row {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
}
.item-field-value {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: "SF Mono", Consolas, monospace;
  color: var(--text);
}
.item-field-label { color: var(--text-muted); min-width: 50px; font-family: inherit; }

.item-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
  flex-wrap: wrap;
}
.chip-btn {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 5px;
}
.chip-btn:hover { border-color: var(--accent); }
.chip-btn.primary { background: var(--accent); border-color: var(--accent); color: white; }
.chip-btn.primary:hover { background: var(--accent-hover); }

.item-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.tag { background: var(--bg-card); border: 1px solid var(--border); color: var(--text-muted); font-size: 11px; padding: 2px 8px; border-radius: 100px; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }

/* --- Modais --- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-box {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 420px;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-box-lg { max-width: 640px; }
.modal-box h2 { margin: 0 0 4px; font-size: 18px; }
.modal-header-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal-header-row h2 { margin: 0; }
.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 20px; }
.modal-actions .btn-primary, .modal-actions .btn-ghost, .modal-actions .btn-secondary { width: auto; margin-top: 0; }
.spacer { flex: 1; }
.modal-close-x {
  position: fixed;
  top: 24px; right: 28px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 16px;
}

.type-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.type-tab {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 8px 12px;
  border-radius: 100px;
  font-size: 13px;
}
.type-tab.active { background: var(--accent); border-color: var(--accent); color: white; }

.file-tabs { display: flex; gap: 6px; margin: 6px 0 12px; }
.file-tab {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 13px;
}
.file-tab.active { background: var(--bg-hover); color: var(--text); border-color: var(--accent); }

.code-textarea { font-family: "SF Mono", Consolas, monospace; font-size: 13px; }
.code-viewer {
  background: #0d1117;
  border-radius: 8px;
  padding: 16px;
  overflow: auto;
  max-height: 60vh;
  margin: 14px 0 0;
}
.code-viewer code { font-family: "SF Mono", Consolas, monospace; font-size: 13px; }

.pdf-images-preview { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.pdf-images-preview img { width: 70px; height: 70px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }

/* --- Toast --- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-hover);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 100px;
  font-size: 13px;
  z-index: 200;
  box-shadow: var(--shadow);
}

/* --- Mobile --- */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 14px; left: 14px;
  z-index: 50;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text);
  width: 40px; height: 40px;
  border-radius: 8px;
  font-size: 18px;
}

@media (max-width: 820px) {
  .mobile-menu-btn { display: block; }
  .sidebar {
    position: fixed;
    inset: 0 30% 0 0;
    z-index: 40;
    transform: translateX(-105%);
    transition: transform 0.2s;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .main { padding: 70px 16px 24px; }
  .topbar { flex-direction: column; }
  .topbar .btn-primary { width: 100%; }
}
