/* ─────────────────────────────────────────────────────────────────────────────
   Libar — The Archivist's Cabinet
   Ink-dark surfaces · antique gold · Cormorant Garamond
   ───────────────────────────────────────────────────────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,300;0,400;0,500;0,600;1,300;1,400;1,500;1,600&family=Source+Sans+3:wght@300;400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Tokens ─────────────────────────────────────────────────────────────────── */
:root {
  --bg-void:     #0B0D11;
  --bg-surface:  #111318;
  --bg-raised:   #181B23;
  --bg-hover:    #1E2230;

  --gold:        #C9A84C;
  --gold-light:  #DFC278;
  --gold-muted:  rgba(201, 168, 76, 0.22);
  --gold-dim:    rgba(201, 168, 76, 0.07);
  --gold-glow:   0 0 18px rgba(201, 168, 76, 0.18);

  --cream:       #F0E6D0;
  --cream-soft:  rgba(240, 230, 208, 0.72);
  --cream-dim:   rgba(240, 230, 208, 0.38);
  --cream-faint: rgba(240, 230, 208, 0.1);

  --sage:        #4E7E5E;
  --sage-bright: #5E9970;
  --terra:       #B85244;
  --terra-soft:  rgba(184, 82, 68, 0.14);
  --blue-info:   rgba(80, 130, 200, 0.12);

  --border:      rgba(201, 168, 76, 0.16);
  --border-sub:  rgba(240, 230, 208, 0.06);
  --border-hover:rgba(201, 168, 76, 0.38);

  --font-display:'Cormorant Garamond', Georgia, serif;
  --font-body:   'Source Sans 3', system-ui, sans-serif;
  --font-mono:   'JetBrains Mono', monospace;

  --radius-sm: 2px;
  --radius:    4px;
  --radius-lg: 8px;

  --shadow:    0 6px 28px rgba(0,0,0,0.45);
  --shadow-xl: 0 16px 56px rgba(0,0,0,0.6);

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

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

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-void);
  color: var(--cream);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Grain overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  opacity: 0.025;
  pointer-events: none;
  z-index: 9999;
  background-image: 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.78' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* Ambient radial glow top-right */
body::after {
  content: '';
  position: fixed;
  width: 700px; height: 700px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(201,168,76,0.045) 0%, transparent 68%);
  top: -250px; right: -250px;
  pointer-events: none;
  z-index: 0;
}

/* ── Typography ─────────────────────────────────────────────────────────────── */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 400;
  line-height: 1.2;
  color: var(--cream);
}

p {
  line-height: 1.65;
  color: var(--cream-soft);
  font-weight: 300;
}

a { color: var(--gold-light); text-decoration: none; transition: color 0.2s; }
a:hover { color: var(--gold); }

/* ── Layout ─────────────────────────────────────────────────────────────────── */
.container {
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
.header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(11, 13, 17, 0.9);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.header-content {
  display: flex; align-items: center;
  justify-content: space-between;
  height: 58px;
}

/* Wordmark */
.logo {
  font-family: var(--font-display);
  font-size: 1.65rem;
  font-weight: 500;
  font-style: italic;
  letter-spacing: 0.03em;
}
.logo a { color: var(--cream); }
.logo a:hover { color: var(--gold-light); }

/* Nav */
.nav { display: flex; align-items: center; gap: 0.2rem; }

.nav-link {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--cream-dim);
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: all 0.2s;
}
.nav-link:hover {
  color: var(--cream-soft);
  background: var(--cream-faint);
  border-color: var(--border-sub);
}
.nav-link.active {
  color: var(--gold-light);
  background: var(--gold-dim);
  border-color: var(--border);
}

/* ── Main ───────────────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  padding: 3rem 0 5rem;
  position: relative;
  z-index: 1;
}

/* ── Footer ─────────────────────────────────────────────────────────────────── */
.footer {
  border-top: 1px solid var(--border-sub);
  padding: 1.4rem 0;
  position: relative; z-index: 1;
}
.footer .container {
  display: flex; align-items: center;
  justify-content: space-between;
  flex-wrap: wrap; gap: 0.75rem;
}
.footer p, .footer-links {
  font-size: 0.75rem;
  color: var(--cream-dim);
}
.footer-links {
  display: flex; gap: 1.5rem;
}
.footer-links a {
  color: var(--cream-dim);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.footer-links a:hover { color: var(--gold); }

/* ── Card ───────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 2.25rem;
  position: relative;
  overflow: hidden;
  animation: fadeUp 0.5s var(--ease-out) both;
}

/* Gold left spine */
.card::before {
  content: '';
  position: absolute;
  left: 0; top: 20%; width: 2px; height: 60%;
  background: linear-gradient(180deg, transparent, var(--gold), transparent);
  opacity: 0.55;
}

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 0.68rem 1.5rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--gold);
  background: var(--gold-dim);
  color: var(--gold-light);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: all 0.2s var(--ease-out);
}
.btn:hover:not(:disabled) {
  background: var(--gold-muted);
  border-color: var(--gold-light);
  color: var(--cream);
  box-shadow: var(--gold-glow);
  transform: translateY(-1px);
}
.btn:disabled {
  opacity: 0.32;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary, .btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--cream-dim);
}
.btn-secondary:hover:not(:disabled), .btn-ghost:hover:not(:disabled) {
  background: var(--cream-faint);
  border-color: var(--cream-dim);
  color: var(--cream-soft);
  box-shadow: none;
}

/* ── Form elements ──────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1.4rem; }

label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--cream-dim);
  margin-bottom: 0.45rem;
}

input[type="text"],
input[type="number"],
input[type="search"],
textarea, select {
  width: 100%;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 300;
  color: var(--cream);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.95rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-dim);
}
input::placeholder, textarea::placeholder {
  color: var(--cream-faint);
}
textarea { resize: vertical; min-height: 80px; line-height: 1.6; }

/* ── Spinner ────────────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--gold-muted);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

/* ── Status messages ────────────────────────────────────────────────────────── */
.status-message {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  border: 1px solid;
  animation: fadeIn 0.3s ease both;
}
.status-message.processing {
  background: var(--blue-info);
  border-color: rgba(80, 130, 200, 0.22);
  color: #9BBAE0;
}
.status-message.success {
  background: rgba(78, 126, 94, 0.1);
  border-color: rgba(78, 126, 94, 0.28);
  color: var(--sage-bright);
}
.status-message.error {
  background: var(--terra-soft);
  border-color: rgba(184, 82, 68, 0.28);
  color: #D97869;
}

/* ── Progress bar ───────────────────────────────────────────────────────────── */
.progress-bar {
  width: 100%;
  height: 2px;
  background: var(--border-sub);
  border-radius: 1px;
  overflow: hidden;
  margin-top: 0.75rem;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, transparent, var(--gold), var(--gold-light), var(--gold), transparent);
  background-size: 300% 100%;
  width: 0%;
  transition: width 0.4s var(--ease-out);
  animation: shimmer 1.6s infinite linear;
}

/* ── Progress container visibility ─────────────────────────────────────────── */
.progress-container { display: none; margin-top: 1.5rem; }
.progress-container.active { display: block; }

.result-container { display: none; margin-top: 1.5rem; }
.result-container.active { display: block; animation: fadeUp 0.4s var(--ease-out) both; }

/* ── Animations ─────────────────────────────────────────────────────────────── */
@keyframes spin    { to { transform: rotate(360deg); } }
@keyframes fadeUp  { from { opacity:0; transform:translateY(14px); } to { opacity:1; transform:none; } }
@keyframes fadeIn  { from { opacity:0; } to { opacity:1; } }
@keyframes shimmer { from { background-position:200% 0; } to { background-position:-200% 0; } }

/* ── Phase 1 D-04: rapid-capture-loop flash banner (upload page) ─────────────── */
.flash-banner {
  display: block;
  width: 100%;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  background: var(--cream);
  color: #2a1f14;
  border-left: 3px solid var(--gold);
  border-radius: 4px;
  font-family: var(--font-display);
  font-size: 0.95rem;
  opacity: 0;
  transition: opacity 0.3s var(--ease-out);
}
.flash-banner[hidden] { display: none; }
.flash-banner--visible { opacity: 1; }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .main { padding: 2rem 0 4rem; }
  .card { padding: 1.4rem 1.25rem; }
}

/* ── Phase 02-01: /library browse page ─────────────────────────────────────── */
.library-layout {
  max-width: 960px;
  margin: 0 auto;
  animation: fadeUp 0.45s var(--ease-out) both;
}

.library-heading {
  font-family: var(--font-display);
  font-style: italic;
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  color: var(--cream);
  margin-bottom: 1.5rem;
}

/* Filter row (D-03 + D-05 page-size dropdown share the form) */
.lib-filter {
  display: flex;
  gap: 0.6rem;
  align-items: stretch;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.lib-filter-input {
  flex: 1 1 16rem;
  min-width: 12rem;
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--cream);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.85rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.lib-filter-input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-dim);
}
.lib-filter-button {
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold-light);
  background: var(--gold-dim);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 1.25rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.lib-filter-button:hover {
  background: var(--gold-muted);
  border-color: var(--gold);
  color: var(--cream);
}
.lib-page-size {
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: var(--cream-soft);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.75rem;
  cursor: pointer;
}

/* Library table (D-01) */
.library-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1.25rem;
  animation: fadeUp 0.5s 0.06s var(--ease-out) both;
}
.library-table .lib-th {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--cream-dim);
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.library-table .lib-th--num {
  text-align: right;
}
.lib-th--sortable .lib-sort-link {
  color: var(--cream-dim);
  text-decoration: none;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: inherit;
  transition: color 0.15s;
}
.lib-th--sortable .lib-sort-link:hover {
  color: var(--cream-soft);
}
.lib-th--sortable .lib-sort-active {
  color: var(--gold-light);
}
.sort-indicator {
  margin-left: 0.25em;
  color: var(--gold);
  font-size: 0.85em;
}

.library-table .lib-cell {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--cream-soft);
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border-sub);
  vertical-align: top;
}
.library-table .lib-cell-title {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1rem;
  color: var(--cream);
  max-width: 24rem;
}
.library-table .lib-cell-title a {
  color: var(--cream);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.library-table .lib-cell-title a:hover {
  color: var(--gold-light);
  border-bottom-color: var(--gold-muted);
}
.library-table .lib-cell-authors {
  max-width: 18rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.library-table .lib-cell-year {
  text-align: right;
  white-space: nowrap;
}
.library-table .lib-cell-added {
  white-space: nowrap;
  color: var(--cream-dim);
}
.library-table tr:hover .lib-cell {
  background: var(--bg-raised);
}

/* Pagination (D-04) */
.lib-pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-sub);
  font-size: 0.78rem;
  color: var(--cream-dim);
  letter-spacing: 0.04em;
}
.lib-pagination-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
}
.lib-page-link {
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  color: var(--gold-light);
  background: var(--gold-dim);
  text-decoration: none;
  transition: all 0.15s;
}
.lib-page-link:hover {
  background: var(--gold-muted);
  color: var(--cream);
}
.lib-page-link--disabled {
  color: var(--cream-faint);
  background: transparent;
  border-color: var(--border-sub);
  cursor: not-allowed;
}
.lib-page-indicator {
  font-family: var(--font-mono);
  color: var(--cream-soft);
}

/* Empty / no-match states (D-06) */
.lib-empty {
  text-align: center;
  padding: 4rem 1rem;
  border: 1px dashed var(--border-sub);
  border-radius: var(--radius);
  background: var(--bg-surface);
  animation: fadeUp 0.5s var(--ease-out) both;
}
.lib-empty-heading {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.6rem;
  color: var(--cream);
  margin-bottom: 0.4rem;
}
.lib-empty-sub {
  font-size: 0.95rem;
  color: var(--cream-dim);
  margin-bottom: 1.25rem;
}
.lib-empty-cta {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold-light);
  border: 1px solid var(--gold);
  background: var(--gold-dim);
  padding: 0.65rem 1.5rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: all 0.2s var(--ease-out);
}
.lib-empty-cta:hover {
  background: var(--gold-muted);
  color: var(--cream);
  box-shadow: var(--gold-glow);
}

.lib-no-match {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--cream-dim);
  font-style: italic;
  border: 1px solid var(--border-sub);
  border-radius: var(--radius);
  background: var(--bg-surface);
}
.lib-no-match code {
  font-family: var(--font-mono);
  color: var(--gold-light);
  background: var(--gold-dim);
  padding: 0.05em 0.35em;
  border-radius: 2px;
}

@media (max-width: 600px) {
  .lib-filter { flex-direction: column; }
  .lib-filter-input, .lib-filter-button, .lib-page-size { width: 100%; }
  .library-table .lib-cell { padding: 0.4rem 0.5rem; font-size: 0.78rem; }
  .library-table .lib-cell-title { font-size: 0.92rem; }
  .lib-pagination { flex-direction: column; align-items: stretch; }
}
