/* ── Variables ──────────────────────────────────────────────────────────── */
:root {
  --bg:        #0f0e0c;
  --bg2:       #1a1814;
  --bg3:       #252220;
  --border:    #302d28;
  --text:      #e8e0d0;
  --text-muted:#8a8070;
  --accent:    #d4a853;
  --accent-dim:#a07830;
  --danger:    #e05555;
  --radius:    10px;
  --shadow:    0 4px 24px rgba(0,0,0,0.5);
  --font-display: 'Playfair Display', Georgia, serif;
  --font-body:    'DM Sans', system-ui, sans-serif;
  --sidebar-w: 260px;
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { cursor: pointer; border: none; background: none; font: inherit; }
input { font: inherit; }
a { color: var(--accent); }

/* ── Login ──────────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse 60% 50% at 50% 0%, rgba(212,168,83,0.12) 0%, transparent 70%),
    var(--bg);
  padding: 2rem;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow);
}
.login-brand {
  text-align: center;
  margin-bottom: 2rem;
}
.brand-icon { font-size: 2.5rem; display: block; margin-bottom: .5rem; }
.login-brand h1 {
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent);
}
.login-brand p { color: var(--text-muted); font-size: .85rem; margin-top: .25rem; }
.login-form { display: flex; flex-direction: column; gap: 1rem; }
.field-group { display: flex; flex-direction: column; gap: .4rem; }
.field-group label { font-size: .8rem; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.field-group input, .modal-input {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: .7rem 1rem;
  font-size: 1rem;
  width: auto;
  transition: border-color .2s;
  outline: none;
}
.field-group input:focus, .modal-input:focus {
  border-color: var(--accent);
}
.totp-input {
  font-size: 1.8rem !important;
  letter-spacing: .4em;
  text-align: center;
  font-family: var(--font-display);
}
.totp-prompt {
  background: var(--bg3);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  text-align: center;
  border: 1px solid var(--border);
}
.totp-icon { font-size: 2rem; margin-bottom: .5rem; }
.totp-prompt p { font-size: .9rem; color: var(--text-muted); }
.totp-prompt strong { color: var(--text); }
.login-error {
  background: rgba(224,85,85,.15);
  border: 1px solid rgba(224,85,85,.35);
  border-radius: var(--radius);
  color: #f08080;
  padding: .6rem 1rem;
  font-size: .875rem;
}
.btn-primary {
  background: var(--accent);
  color: #0f0e0c;
  font-weight: 600;
  padding: .75rem 1.5rem;
  border-radius: var(--radius);
  font-size: 1rem;
  transition: background .2s, transform .1s;
}
.btn-primary:hover { background: #e8bc6a; }
.btn-primary:active { transform: scale(.98); }
.btn-secondary {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  padding: .7rem 1.4rem;
  border-radius: var(--radius);
  font-size: .95rem;
  transition: border-color .2s;
}
.btn-secondary:hover { border-color: var(--text-muted); }

/* ── App shell ──────────────────────────────────────────────────────────── */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.sidebar-header {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: 1.2rem 1rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg2);
  z-index: 2;
}
.brand-mark { font-size: 1.4rem; }
.brand-name { font-family: var(--font-display); font-size: 1.1rem; font-weight: 600; color: var(--accent); }
.btn-logout {
  padding: .3rem .5rem;
  color: var(--text-muted);
  font-size: 1rem;
  border-radius: 6px;
  transition: color .2s, background .2s;
}
.btn-logout:hover { color: var(--danger); background: rgba(224,85,85,.1); }
.sidebar-section {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-label {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  margin-bottom: .6rem;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.tag-filter-list { display: flex; flex-direction: column; gap: .2rem; }
.tag-filter {
  text-align: left;
  padding: .45rem .7rem;
  border-radius: 7px;
  font-size: .875rem;
  color: var(--text-muted);
  transition: background .15s, color .15s;
  border-left: 3px solid transparent;
}
.tag-filter:hover { background: var(--bg3); color: var(--text); }
.tag-filter.active {
  background: var(--bg3);
  color: var(--text);
  border-left-color: var(--tc, var(--accent));
}
.sidebar-tags { flex: 1; }
.tag-manager-row {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .3rem 0;
}
.tag-chip {
  flex: 1;
  font-size: .8rem;
  padding: .2rem .6rem;
  border-radius: 20px;
  color: #fff;
  font-weight: 500;
  text-shadow: 0 1px 2px rgba(0,0,0,.3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.btn-icon {
  color: var(--text-muted);
  font-size: 1rem;
  padding: .1rem .3rem;
  border-radius: 5px;
  transition: color .15s, background .15s;
  line-height: 1;
}
.btn-icon:hover { color: var(--accent); background: rgba(212,168,83,.1); }
.btn-icon-sm {
  color: var(--text-muted);
  font-size: .8rem;
  padding: .15rem .3rem;
  border-radius: 4px;
  transition: color .15s, background .15s;
  flex-shrink: 0;
}
.btn-icon-sm:hover { color: var(--accent); background: rgba(212,168,83,.1); }
.btn-icon-sm.danger:hover { color: var(--danger); background: rgba(224,85,85,.1); }
.sidebar-footer {
  padding: .8rem 1rem;
  font-size: .78rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}
.sidebar-footer strong { color: var(--text); }

/* ── Main content ───────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}
.search-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: .9rem;
  font-size: 1rem;
  pointer-events: none;
}
.search-input {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 24px;
  color: var(--text);
  padding: .6rem 1rem .6rem 2.5rem;
  font-size: 1rem;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.search-input:focus {
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px rgba(212,168,83,.1);
}
.search-hint {
  position: absolute;
  right: 1rem;
  font-size: .75rem;
  color: var(--text-muted);
}
.btn-add-book {
  background: var(--accent);
  color: #0f0e0c;
  font-weight: 600;
  padding: .6rem 1.2rem;
  border-radius: 24px;
  font-size: .9rem;
  white-space: nowrap;
  transition: background .2s;
  flex-shrink: 0;
}
.btn-add-book:hover { background: #e8bc6a; }

/* ── Books grid ─────────────────────────────────────────────────────────── */
.books-grid {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
  align-content: start;
}
.loading-books {
  grid-column: 1/-1;
  text-align: center;
  color: var(--text-muted);
  padding: 3rem;
}
.book-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  transition: border-color .2s, box-shadow .2s, transform .15s;
  position: relative;
  animation: fadeIn .2s ease;
}
.book-card:hover {
  border-color: var(--accent-dim);
  box-shadow: 0 4px 20px rgba(0,0,0,.4);
  transform: translateY(-1px);
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.book-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
  flex: 1;
}
.book-tags {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
}
.book-tag {
  font-size: .72rem;
  padding: .18rem .55rem;
  border-radius: 20px;
  color: #fff;
  font-weight: 500;
  text-shadow: 0 1px 2px rgba(0,0,0,.3);
}
.book-meta {
  font-size: .72rem;
  color: var(--text-muted);
}
.book-actions {
  display: flex;
  gap: .3rem;
  opacity: 0;
  transition: opacity .15s;
}
.book-card:hover .book-actions { opacity: 1; }
.book-top {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
}
.empty-state {
  grid-column: 1/-1;
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}
.empty-state h3 { font-family: var(--font-display); font-size: 1.4rem; margin-bottom: .5rem; color: var(--text); }

/* ── Modals ─────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(3px);
  padding: 1rem;
  animation: overlayIn .15s ease;
}
.modal-overlay[hidden] { display: none !important; }
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 500px;
  box-shadow: var(--shadow);
  animation: modalIn .2s ease;
}
.modal-sm { max-width: 360px; }
@keyframes modalIn { from { opacity: 0; transform: scale(.95) translateY(10px); } to { opacity: 1; transform: none; } }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.2rem 1.5rem 1rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 600;
}
.modal-close {
  color: var(--text-muted);
  font-size: 1.1rem;
  padding: .2rem .5rem;
  border-radius: 6px;
  transition: color .15s, background .15s;
}
.modal-close:hover { color: var(--text); background: var(--bg3); }
.modal-body {
  padding: 1.2rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: .7rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
}
.tag-selector {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  min-height: 40px;
  padding: .5rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  align-content: flex-start;
}
.tag-selector:empty::before {
  content: 'No tags yet — create one below';
  color: var(--text-muted);
  font-size: .8rem;
  line-height: 2;
}
.tag-option {
  padding: .28rem .75rem;
  border-radius: 20px;
  font-size: .8rem;
  font-weight: 500;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform .1s, box-shadow .1s, opacity .1s;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,.3);
  opacity: .55;
  line-height: 1.4;
}
.tag-option:hover { transform: scale(1.05); opacity: .8; }
.tag-option.selected {
  opacity: 1;
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px rgba(255,255,255,.15);
  transform: scale(1.05);
}
.tag-create-inline {
  display: flex;
  gap: .5rem;
  margin-top: .5rem;
  align-items: stretch;
  height: 36px;
}
.modal-input-sm {
  flex: 1;
  min-width: 0;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0 .75rem;
  font-size: .875rem;
  outline: none;
  transition: border-color .2s;
  height: 100%;
}
.modal-input-sm:focus { border-color: var(--accent); }
.color-picker {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  background: var(--bg3);
  cursor: pointer;
  flex-shrink: 0;
  -webkit-appearance: none;
  appearance: none;
  align-self: center;
}
.color-picker::-webkit-color-swatch-wrapper { padding: 0; border-radius: 5px; }
.color-picker::-webkit-color-swatch { border: none; border-radius: 5px; }
.btn-sm {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0 1rem;
  border-radius: 8px;
  font-size: .85rem;
  font-weight: 500;
  transition: border-color .15s, color .15s;
  flex-shrink: 0;
  height: 100%;
  display: inline-flex;
  align-items: center;
}
.btn-sm:hover { border-color: var(--accent); color: var(--accent); }
.color-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-bottom: .4rem;
}
.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform .15s, border-color .15s;
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.selected { border-color: var(--text); transform: scale(1.15); }

/* ── Scrollbars ─────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Autocomplete ────────────────────────────────────────────────────────── */
.autocomplete-wrap {
  position: relative;
}
.suggest-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg2);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,.6);
  list-style: none;
  margin: 0;
  padding: .3rem 0;
  z-index: 200;
  max-height: 280px;
  overflow-y: auto;
}
.suggest-dropdown[hidden] { display: none !important; }
.suggest-item {
  display: flex;
  flex-direction: column;
  gap: .1rem;
  padding: .55rem 1rem;
  cursor: pointer;
  transition: background .1s;
  border-left: 2px solid transparent;
}
.suggest-item:hover,
.suggest-item.active {
  background: var(--bg3);
  border-left-color: var(--accent);
}
.suggest-item-title {
  font-family: var(--font-display);
  font-size: .95rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.suggest-item-meta {
  font-size: .75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.suggest-loading {
  padding: .7rem 1rem;
  font-size: .85rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: .5rem;
}
.suggest-loading::before {
  content: '';
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
