/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --border: #e0e3e8;
  --text: #1a1d23;
  --text-muted: #8a8f9a;
  --accent: #4f6ef7;
  --accent-hover: #3d5ce5;
  --danger: #e5534b;
  --success: #3fb950;
  --warning: #d29922;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --transition: 0.18s ease;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --border: #30363d;
    --text: #e6edf3;
    --text-muted: #7d8590;
    --accent: #6e8efb;
    --accent-hover: #8aa3fc;
    --shadow: 0 1px 3px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  }
}

[data-theme="light"] {
  --bg: #f0f2f5; --surface: #ffffff; --border: #e0e3e8;
  --text: #1a1d23; --text-muted: #8a8f9a;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
}
[data-theme="dark"] {
  --bg: #0d1117; --surface: #161b22; --border: #30363d;
  --text: #e6edf3; --text-muted: #7d8590;
  --shadow: 0 1px 3px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
}

html, body { height: 100%; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  transition: background var(--transition), color var(--transition);
}

/* ── Auth Overlay ─────────────────────────────────────────────────────────── */
#auth-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.3s ease;
}
#auth-overlay.hidden { opacity: 0; pointer-events: none; }

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.auth-card .logo {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
  color: var(--text);
}
.auth-card .logo span { color: var(--accent); }

.auth-card .subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 28px;
}

.auth-card .input-group {
  position: relative;
  margin-bottom: 14px;
}

.auth-card input[type="password"],
.auth-card input[type="text"] {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 15px;
  font-family: var(--font-sans);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.auth-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79,110,247,.15);
}

.auth-card .btn-primary {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform 0.1s;
  margin-top: 4px;
}
.auth-card .btn-primary:hover { background: var(--accent-hover); }
.auth-card .btn-primary:active { transform: scale(0.98); }

.auth-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 10px;
  min-height: 18px;
  text-align: center;
}

/* ── Note Editor ──────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  opacity: 0;
  transition: opacity 0.3s ease;
}
#app.visible { opacity: 1; }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: 52px;
  flex-shrink: 0;
  transition: background var(--transition), border-color var(--transition);
}

.topbar .logo-small {
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.3px;
  flex-shrink: 0;
}
.topbar .logo-small span { color: var(--accent); }

.topbar .note-id {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 10px;
  flex-shrink: 0;
}

.topbar .spacer { flex: 1; }

.save-status {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 5px;
  transition: color 0.3s;
  flex-shrink: 0;
}
.save-status.saving { color: var(--warning); }
.save-status.saved  { color: var(--success); }
.save-status.error  { color: var(--danger); }

.save-status .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.save-status.saving .dot { animation: pulse 1s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Icon buttons */
.icon-btn {
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  flex-shrink: 0;
}
.icon-btn:hover {
  background: var(--bg);
  border-color: var(--border);
  color: var(--text);
}
.icon-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.icon-btn svg { width: 16px; height: 16px; }

/* Editor area */
.editor-wrap {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

#editor {
  flex: 1;
  padding: 32px;
  font-family: var(--font-mono);
  font-size: 15px;
  line-height: 1.75;
  color: var(--text);
  background: var(--surface);
  border: none;
  outline: none;
  resize: none;
  width: 100%;
  transition: background var(--transition), color var(--transition), font-size var(--transition);
}

#editor::placeholder { color: var(--text-muted); }

/* Markdown preview */
#preview {
  flex: 1;
  padding: 32px;
  overflow-y: auto;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: none;
  font-size: 15px;
  line-height: 1.75;
}
#preview.visible { display: block; }

#preview h1, #preview h2, #preview h3 { margin: 1em 0 0.5em; font-weight: 600; }
#preview h1 { font-size: 1.6em; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
#preview h2 { font-size: 1.3em; border-bottom: 1px solid var(--border); padding-bottom: 0.2em; }
#preview p { margin: 0.75em 0; }
#preview code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}
#preview pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  overflow-x: auto;
  margin: 1em 0;
}
#preview pre code { background: none; border: none; padding: 0; }
#preview blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 16px;
  color: var(--text-muted);
  margin: 1em 0;
}
#preview a { color: var(--accent); }
#preview ul, #preview ol { padding-left: 1.5em; margin: 0.75em 0; }
#preview li { margin: 0.25em 0; }
#preview hr { border: none; border-top: 1px solid var(--border); margin: 1.5em 0; }
#preview table { border-collapse: collapse; width: 100%; margin: 1em 0; }
#preview th, #preview td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
#preview th { background: var(--bg); font-weight: 600; }

/* Bottom bar */
.bottombar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 6px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  height: 36px;
  flex-shrink: 0;
  transition: background var(--transition), border-color var(--transition);
}

.bottombar .stat {
  font-size: 12px;
  color: var(--text-muted);
}

.font-size-control {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}
.font-size-control label {
  font-size: 12px;
  color: var(--text-muted);
}
.font-size-control input[type="range"] {
  width: 80px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Focus mode */
body.focus-mode .topbar,
body.focus-mode .bottombar { opacity: 0; pointer-events: none; transition: opacity 0.4s; }
body.focus-mode:hover .topbar,
body.focus-mode:hover .bottombar { opacity: 1; pointer-events: auto; }
body.focus-mode #editor { padding: 60px max(60px, calc(50% - 380px)); }

/* ── Admin Panel ──────────────────────────────────────────────────────────── */
.admin-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.admin-sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
}

.admin-sidebar .logo {
  font-size: 18px;
  font-weight: 700;
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
  color: var(--text);
}
.admin-sidebar .logo span { color: var(--accent); }

.admin-sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  border-radius: 0;
  transition: background var(--transition), color var(--transition);
}
.admin-sidebar nav a:hover { background: var(--bg); color: var(--text); }
.admin-sidebar nav a.active { color: var(--accent); background: var(--bg); }
.admin-sidebar nav a svg { width: 16px; height: 16px; flex-shrink: 0; }

.admin-sidebar .logout-btn {
  margin-top: auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--danger);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  transition: background var(--transition);
}
.admin-sidebar .logout-btn:hover { background: var(--bg); }
.admin-sidebar .logout-btn svg { width: 16px; height: 16px; }

.admin-main {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
  background: var(--bg);
}

.admin-section { display: none; }
.admin-section.active { display: block; }

.admin-section h1 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 24px;
  color: var(--text);
}

/* Stats cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.stat-card .label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}
.stat-card .value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
}
.stat-card .unit {
  font-size: 13px;
  color: var(--text-muted);
  margin-left: 4px;
}

/* Table */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.table-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.table-toolbar input[type="search"] {
  flex: 1;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition);
}
.table-toolbar input[type="search"]:focus { border-color: var(--accent); }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
thead th {
  padding: 10px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg); }
tbody td { padding: 12px 16px; color: var(--text); vertical-align: middle; }
tbody td.mono { font-family: var(--font-mono); font-size: 13px; }
tbody td.muted { color: var(--text-muted); font-size: 13px; }
tbody td.preview { color: var(--text-muted); font-size: 13px; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background var(--transition), color var(--transition), border-color var(--transition), transform 0.1s;
  text-decoration: none;
}
.btn:active { transform: scale(0.97); }
.btn svg { width: 14px; height: 14px; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-ghost { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }

.btn-sm { padding: 5px 10px; font-size: 12px; }

/* Form */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  max-width: 520px;
}
.form-card + .form-card { margin-top: 20px; }

.form-group { margin-bottom: 18px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.form-group .hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}
.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition);
}
.form-group input:focus,
.form-group select:focus { border-color: var(--accent); }

.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

.section-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

/* Invite tokens */
.invite-list { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.invite-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
}
.invite-item .token {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent);
  flex: 1;
}
.invite-item .meta { font-size: 12px; color: var(--text-muted); }
.invite-item .expired { color: var(--danger); }

/* Toast */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 999;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 14px;
  box-shadow: var(--shadow);
  animation: toastIn 0.25s ease;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 320px;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.info    { border-left: 3px solid var(--accent); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* Responsive */
@media (max-width: 640px) {
  #editor { padding: 20px 16px; font-size: 14px; }
  .topbar { padding: 8px 12px; gap: 8px; }
  .admin-layout { flex-direction: column; }
  .admin-sidebar { width: 100%; height: auto; flex-direction: row; padding: 0; border-right: none; border-bottom: 1px solid var(--border); overflow-x: auto; }
  .admin-sidebar nav { display: flex; flex-direction: row; }
  .admin-sidebar nav a { padding: 12px 16px; white-space: nowrap; }
  .admin-main { padding: 16px; }
}

/* Print */
@media print {
  .topbar, .bottombar { display: none; }
  #editor { padding: 0; font-family: var(--font-sans); }
}

/* ── Modals ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 8px 40px rgba(0,0,0,.2);
  animation: slideUp 0.22s ease;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}
.modal-title code {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
}

.modal-close {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); border-radius: 6px;
  transition: background var(--transition), color var(--transition);
}
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-close svg { width: 16px; height: 16px; }

.modal-body {
  padding: 20px;
}
.modal-body .form-group { margin-bottom: 16px; }
.modal-body .form-group:last-child { margin-bottom: 0; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.modal-body code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}

/* ── Contenteditable Editor ───────────────────────────────────────────────── */
#editor {
  flex: 1;
  padding: 32px;
  font-family: var(--font-mono);
  font-size: 15px;
  line-height: 1.75;
  color: var(--text);
  background: var(--surface);
  border: none;
  outline: none;
  overflow-y: auto;
  word-break: break-word;
  white-space: pre-wrap;
  transition: background var(--transition), color var(--transition), font-size var(--transition);
  cursor: text;
}

#editor:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  pointer-events: none;
}

#editor div, #editor p { min-height: 1.75em; }

/* Images inserted into editor */
.editor-img {
  display: block;
  max-width: 100%;
  max-height: 480px;
  border-radius: 8px;
  margin: 8px 0;
  border: 1px solid var(--border);
  cursor: default;
  object-fit: contain;
  background: var(--bg);
}

.editor-img:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(79,110,247,.15);
}

/* File attachment links */
.editor-file-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
  font-family: var(--font-sans);
  margin: 4px 0;
  transition: background var(--transition), border-color var(--transition);
}
.editor-file-link::before {
  content: '📎';
  font-size: 12px;
}
.editor-file-link:hover {
  background: var(--surface);
  border-color: var(--accent);
}

/* ── Drop Overlay ─────────────────────────────────────────────────────────── */
.editor-wrap {
  position: relative;
}

.drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  background: rgba(79, 110, 247, 0.08);
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.drop-overlay.active {
  opacity: 1;
  pointer-events: none; /* let drop event pass through to parent */
}

.drop-hint {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--accent);
  font-size: 16px;
  font-weight: 600;
}

.drop-hint svg {
  width: 40px;
  height: 40px;
  opacity: 0.7;
}

/* Preview image auth loading */
#preview img {
  max-width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin: 8px 0;
}

/* ── Attachments Page ─────────────────────────────────────────────────────── */

.attach-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.attach-toolbar input[type="search"] {
  flex: 1;
  min-width: 160px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition);
}
.attach-toolbar input[type="search"]:focus { border-color: var(--accent); }

.attach-toolbar select {
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  cursor: pointer;
}

.attach-stats {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
  min-height: 20px;
}

.attach-view-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.select-all-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  margin-left: 8px;
}

/* Grid */
.attach-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}

.attach-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-muted);
  padding: 48px 0;
  font-size: 14px;
}

.attach-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  transition: border-color var(--transition), box-shadow var(--transition);
  display: flex;
  flex-direction: column;
}

.attach-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 12px rgba(79,110,247,.12);
}

.attach-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(79,110,247,.25);
}

.attach-card.orphan {
  border-color: var(--warning);
}
.attach-card.orphan:hover {
  border-color: var(--warning);
  box-shadow: 0 2px 12px rgba(210,153,34,.15);
}

.attach-check {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  background: rgba(0,0,0,.35);
  border-radius: 4px;
  padding: 2px;
  line-height: 0;
  cursor: pointer;
}
.attach-check input { cursor: pointer; }

.attach-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.attach-badge.orphan     { background: var(--warning); color: #fff; }
.attach-badge.referenced { background: var(--success);  color: #fff; }

.attach-thumb {
  width: 100%;
  height: 120px;
  object-fit: cover;
  display: block;
  background: var(--bg);
  cursor: pointer;
  transition: opacity var(--transition);
}
.attach-thumb:hover { opacity: 0.85; }

.attach-thumb-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  cursor: default;
}

.attach-card-info {
  padding: 8px 10px 4px;
  flex: 1;
}

.attach-card-name {
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 4px;
}

.attach-card-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  overflow: hidden;
}
.attach-card-meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attach-card-actions {
  display: flex;
  gap: 6px;
  padding: 6px 8px 8px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.attach-card-actions .btn { flex: 1; justify-content: center; }

/* List view orphan row */
.orphan-row { background: rgba(210,153,34,.05); }
.orphan-row:hover { background: rgba(210,153,34,.1) !important; }

/* Image preview modal backdrop */
#modal-preview-image { background: rgba(0,0,0,.75); }
