/* ============================================================
   BOOKSHELF — PRIVATE LIBRARY AESTHETIC
   Dark academic palette, Bricolage Grotesque + Playfair Display
   ============================================================ */

/* --- Custom Properties ------------------------------------ */
:root {
  --bg-base:          #1c1917;
  --bg-surface:       #252019;
  --bg-elevated:      #312b24;
  --bg-input:         #1e1a16;
  --border:           rgba(212, 168, 83, 0.14);
  --border-strong:    rgba(212, 168, 83, 0.3);

  --text-primary:     #faf7f0;
  --text-secondary:   #c8bfaf;
  --text-muted:       #7d7268;
  --text-faint:       #4a443e;

  --accent:           #d4a853;
  --accent-dim:       #8c6d34;
  --accent-glow:      rgba(212, 168, 83, 0.12);
  --accent-glow-hover: rgba(212, 168, 83, 0.2);

  --status-owned:     #6aaa64;
  --status-owned-bg:  rgba(106, 170, 100, 0.15);
  --status-wanted:    #c9a84c;
  --status-wanted-bg: rgba(201, 168, 76, 0.15);
  --status-untracked: #4a443e;
  --status-untracked-bg: rgba(74, 68, 62, 0.3);

  --danger:           #c0565a;
  --danger-bg:        rgba(192, 86, 90, 0.15);

  --badge-pending:    #c0565a;
  --badge-refresh:    #7aa4c0;
  --badge-complete:   #6aaa64;

  --radius-sm:        4px;
  --radius-md:        8px;
  --radius-lg:        14px;

  --font-ui:          'Bricolage Grotesque', sans-serif;
  --font-serif:       'Playfair Display', Georgia, serif;

  --transition:       150ms ease;
  --transition-slow:  300ms ease;
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-ui);
  background-color: var(--bg-base);
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(212, 168, 83, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 85% 90%, rgba(140, 90, 40, 0.05) 0%, transparent 45%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
  background-attachment: fixed;
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100dvh;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input, select, textarea {
  font-family: inherit;
  font-size: 1rem;
}

/* --- Utility ---------------------------------------------- */
.hidden { display: none !important; }

/* --- Screens ---------------------------------------------- */
.screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.screen--loading {
  flex-direction: column;
  gap: 16px;
}

.loading-mark {
  color: var(--accent);
  width: 40px;
  animation: pulse 1.8s ease-in-out infinite;
}

.loading-mark svg { display: block; }

@keyframes pulse {
  0%, 100% { opacity: 0.4; transform: scale(1); }
  50%       { opacity: 1;   transform: scale(1.05); }
}

/* --- Auth screen ------------------------------------------ */
.screen--auth {
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 48px 40px 40px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.auth-emblem {
  color: var(--accent);
  width: 56px;
  margin-bottom: 8px;
}

.auth-emblem svg { display: block; }

.auth-title {
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.auth-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: -8px;
}

.auth-error {
  font-size: 0.8rem;
  color: var(--danger);
  text-align: center;
  padding: 8px 12px;
  background: var(--danger-bg);
  border-radius: var(--radius-sm);
  width: 100%;
}

/* --- Buttons ---------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-family: var(--font-ui);
  font-size: 0.875rem;
  font-weight: 600;
  transition: background var(--transition), color var(--transition),
              border-color var(--transition), opacity var(--transition);
  white-space: nowrap;
}

.btn-icon { width: 18px; height: 18px; flex-shrink: 0; }

.btn--primary {
  background: var(--accent);
  color: var(--bg-base);
  border: 1px solid transparent;
}
.btn--primary:hover { background: #e0b860; }
.btn--primary:active { background: var(--accent-dim); }

.btn--ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn--ghost:hover {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.btn--danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(192, 86, 90, 0.3);
}
.btn--danger:hover { background: rgba(192, 86, 90, 0.25); }

.btn--wide { width: 100%; justify-content: center; }

.btn--add-shelf {
  background: var(--accent-glow);
  color: var(--accent);
  border: 1px solid var(--border);
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: var(--radius-md);
}
.btn--add-shelf:hover {
  background: var(--accent-glow-hover);
  border-color: var(--border-strong);
}

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

/* --- App Layout ------------------------------------------- */
.app { min-height: 100dvh; display: flex; flex-direction: column; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 56px;
  background: rgba(28, 25, 23, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-primary);
}

.header-logo-mark {
  width: 22px;
  color: var(--accent);
}

.header-logo-mark svg { display: block; }

.header-logo-text {
  font-family: var(--font-serif);
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: color var(--transition), background var(--transition);
  position: relative;
}

.nav-link:hover { color: var(--text-primary); background: var(--bg-elevated); }

.nav-icon { width: 16px; height: 16px; }
.nav-link-label { }

.nav-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--badge-pending);
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.router-outlet {
  flex: 1;
  padding: 28px 20px 48px;
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
}

/* --- Home screen ------------------------------------------ */
.home-section {
  margin-bottom: 40px;
}

.home-section-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.home-section-title {
  font-family: var(--font-ui);
  font-size: 0.6875rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.home-section-count {
  font-size: 0.75rem;
  color: var(--text-faint);
}

/* Empty state within a section */
.section-empty {
  padding: 20px 0;
  font-size: 0.875rem;
  color: var(--text-faint);
  font-style: italic;
}

/* --- Shelf Tile ------------------------------------------- */
.shelf-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.shelf-tile {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  text-align: left;
  width: 100%;
}

.shelf-tile:hover {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
}

.shelf-tile:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Cover placeholder */
.shelf-cover {
  width: 52px;
  height: 68px;
  border-radius: 3px;
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  color: var(--text-faint);
}

.shelf-cover svg { width: 24px; height: 24px; }

.shelf-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Seeded: false — placeholder with distinct style */
.shelf-cover--unseeded {
  background: repeating-linear-gradient(
    135deg,
    var(--bg-elevated) 0px,
    var(--bg-elevated) 4px,
    rgba(255,255,255,0.025) 4px,
    rgba(255,255,255,0.025) 8px
  );
  border: 1px dashed var(--border);
}

/* Middle content */
.shelf-info { min-width: 0; }

.shelf-name {
  font-family: var(--font-serif);
  font-size: 1rem;
  font-weight: 400;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.shelf-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.shelf-type-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.shelf-unseeded-label {
  font-size: 0.75rem;
  color: var(--text-faint);
  font-style: italic;
}

/* Badge row */
.shelf-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.shelf-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 20px;
  font-size: 0.6875rem;
  font-weight: 600;
}

.shelf-badge--pending {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(192,86,90,0.2);
}

.shelf-badge--refresh {
  background: rgba(122, 164, 192, 0.1);
  color: var(--badge-refresh);
  border: 1px solid rgba(122,164,192,0.2);
}

/* Right side: progress */
.shelf-progress-col {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}

.shelf-progress {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.shelf-progress-label {
  font-size: 0.6875rem;
  color: var(--text-faint);
}

.shelf-complete-mark {
  color: var(--badge-complete);
  font-size: 0.75rem;
  font-weight: 700;
}

/* --- Book List View --------------------------------------- */
.shelf-view-header {
  margin-bottom: 24px;
}

.shelf-view-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 12px;
  padding: 4px 0;
  transition: color var(--transition);
}

.shelf-view-back:hover { color: var(--text-secondary); }

.shelf-view-back svg { width: 14px; height: 14px; }

.shelf-view-title {
  font-family: var(--font-serif);
  font-size: 1.875rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.shelf-view-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.shelf-view-progress {
  font-size: 0.875rem;
  color: var(--accent);
  font-weight: 600;
}

.shelf-view-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

/* Subshelf group heading */
.subshelf-heading {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 20px 0 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2px;
}

.subshelf-heading:first-child { padding-top: 0; }

/* Book row */
.book-list { display: flex; flex-direction: column; gap: 1px; }

.book-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-surface);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  transition: background var(--transition), border-color var(--transition);
}

.book-row:hover { background: var(--bg-elevated); border-color: var(--border); }

.book-row--omnibus {
  background: rgba(212, 168, 83, 0.04);
  border-left: 2px solid var(--accent-dim);
}

.book-num {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.book-info { min-width: 0; }

.book-title {
  font-family: var(--font-serif);
  font-size: 0.9375rem;
  color: var(--text-primary);
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.book-title--italic { font-style: italic; }

.book-detail {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-type-label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-faint);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* Status toggle button */
.status-btn {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  border: 1px solid transparent;
  text-transform: uppercase;
  transition: background var(--transition), color var(--transition),
              border-color var(--transition), opacity var(--transition);
  cursor: pointer;
  flex-shrink: 0;
}

.status-btn--owned {
  background: var(--status-owned-bg);
  color: var(--status-owned);
  border-color: rgba(106,170,100,0.25);
}
.status-btn--owned:hover { background: rgba(106,170,100,0.25); }

.status-btn--wanted {
  background: var(--status-wanted-bg);
  color: var(--status-wanted);
  border-color: rgba(201,168,76,0.25);
}
.status-btn--wanted:hover { background: rgba(201,168,76,0.25); }

.status-btn--untracked {
  background: var(--status-untracked-bg);
  color: var(--text-faint);
  border-color: var(--border);
}
.status-btn--untracked:hover {
  background: var(--bg-elevated);
  color: var(--text-muted);
}

/* --- Pending Decisions ------------------------------------ */
.decisions-view-header { margin-bottom: 24px; }

.decisions-group { margin-bottom: 32px; }

.decisions-group-title {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}

.decision-card {
  padding: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
}

.decision-card--resolved {
  opacity: 0.5;
}

.decision-type {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-dim);
  margin-bottom: 6px;
}

.decision-subsection {
  font-family: var(--font-serif);
  font-size: 0.9375rem;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.decision-samples {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 12px;
  font-style: italic;
}

.decision-options { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }

.decision-option {
  padding: 6px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), color var(--transition);
}

.decision-option:hover, .decision-option.selected {
  border-color: var(--accent);
  background: var(--accent-glow);
  color: var(--accent);
}

.decision-actions { display: flex; gap: 8px; align-items: center; }

.decision-resolved-label {
  font-size: 0.8rem;
  color: var(--status-owned);
  font-weight: 600;
}

.decisions-empty {
  padding: 32px 0;
  text-align: center;
  color: var(--text-faint);
  font-size: 0.875rem;
}

/* --- Modal ------------------------------------------------ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 20px 24px;
  overflow-y: auto;
  animation: fade-in 150ms ease;
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 28px 28px 24px;
  width: 100%;
  max-width: 480px;
  position: relative;
  animation: slide-up 200ms ease;
}

@keyframes slide-up {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-title {
  font-family: var(--font-serif);
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 20px;
  letter-spacing: -0.02em;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: color var(--transition), background var(--transition);
}
.modal-close:hover { color: var(--text-primary); background: var(--bg-elevated); }
.modal-close svg { width: 16px; height: 16px; }

/* --- Form ------------------------------------------------- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.form-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-label-hint {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-faint);
  margin-left: 6px;
}

.form-input,
.form-select {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.9375rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
  -webkit-appearance: none;
}

.form-input::placeholder { color: var(--text-faint); }

.form-input:focus,
.form-select:focus {
  outline: none;
  border-color: var(--accent-dim);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%237d7268' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  cursor: pointer;
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-faint);
  line-height: 1.4;
}

.form-error {
  font-size: 0.8rem;
  color: var(--danger);
  padding: 8px 12px;
  background: var(--danger-bg);
  border-radius: var(--radius-sm);
  display: none;
}

.form-error.visible { display: block; }

.form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
}

/* --- Extraction progress overlay -------------------------- */
.extraction-status {
  margin-top: 16px;
  padding: 12px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
  color: var(--text-secondary);
  display: none;
}

.extraction-status.visible { display: block; }

.extraction-status-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.extraction-status-line + .extraction-status-line { margin-top: 4px; }

.extraction-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 600ms linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.extraction-step--done { color: var(--text-muted); }
.extraction-step--done .extraction-spinner {
  border-color: var(--status-owned);
  border-top-color: var(--status-owned);
  animation: none;
}
.extraction-step--error { color: var(--danger); }

/* --- Toast / inline notices ------------------------------- */
.notice {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
  line-height: 1.4;
  margin-bottom: 12px;
}

.notice--warning {
  background: rgba(212, 168, 83, 0.1);
  border: 1px solid rgba(212, 168, 83, 0.25);
  color: var(--accent);
}

.notice--error {
  background: var(--danger-bg);
  border: 1px solid rgba(192, 86, 90, 0.3);
  color: var(--danger);
}

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

/* --- Page-level loading spinner --------------------------- */
.page-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 64px 0;
  color: var(--text-faint);
  gap: 12px;
  font-size: 0.875rem;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 600ms linear infinite;
}

/* --- Responsive ------------------------------------------- */
@media (max-width: 600px) {
  .router-outlet { padding: 20px 14px 40px; }

  .shelf-tile {
    grid-template-columns: 44px 1fr auto;
    gap: 10px;
    padding: 10px 12px;
  }

  .shelf-cover { width: 44px; height: 58px; }

  .shelf-name { font-size: 0.9375rem; }

  .book-row {
    grid-template-columns: 22px 1fr auto;
    gap: 8px;
    padding: 9px 10px;
  }

  .modal { padding: 24px 20px 20px; }

  .nav-link-label { display: none; }
}
