@import url('https://fonts.googleapis.com/css2?family=Lato:wght@300;400;700&display=swap');

:root,
[data-theme="light"] {
  --soho-black: #0F0F0F;
  --soho-white: #FAFAF7;
  --soho-warm: #F5F2EC;
  --soho-mid: #C8C4BB;
  --soho-gray: #7A7670;
  --soho-deep: #2A2825;
  --soho-gold: #C49A3C;
  --soho-gold-light: #E8C96A;
  --soho-gold-pale: #F5EDD5;

  --bg: var(--soho-warm);
  --surface: var(--soho-white);
  --surface-elevated: var(--soho-white);
  --text: var(--soho-black);
  --text-secondary: var(--soho-deep);
  --muted: var(--soho-gray);
  --accent: var(--soho-gold);
  --accent-hover: var(--soho-gold-light);
  --border: var(--soho-mid);
  --danger: #8b3a3a;
  --sidebar-bg: var(--soho-white);
  --sidebar-text: var(--soho-deep);
  --sidebar-muted: rgba(42, 40, 37, 0.65);
  --sidebar-active: rgba(196, 154, 60, 0.18);
  --sidebar-active-text: var(--soho-deep);
  --sidebar-hover-bg: rgba(42, 40, 37, 0.06);
  --sidebar-hover-text: var(--soho-deep);
  --sidebar-border: rgba(42, 40, 37, 0.15);
  --input-bg: var(--soho-white);
}

[data-theme="dark"] {
  --bg: var(--soho-black);
  --surface: var(--soho-deep);
  --surface-elevated: #353230;
  --text: var(--soho-white);
  --text-secondary: rgba(250, 250, 247, 0.85);
  --muted: var(--soho-gray);
  --accent: var(--soho-gold);
  --accent-hover: var(--soho-gold-light);
  --border: rgba(200, 196, 187, 0.25);
  --danger: #e07070;
  --sidebar-bg: #171513;
  --sidebar-text: var(--soho-white);
  --sidebar-muted: rgba(250, 250, 247, 0.45);
  --sidebar-active: rgba(196, 154, 60, 0.22);
  --sidebar-active-text: var(--soho-gold-light);
  --sidebar-hover-bg: rgba(255, 255, 255, 0.05);
  --sidebar-hover-text: var(--soho-white);
  --sidebar-border: rgba(196, 154, 60, 0.2);
  --input-bg: #353230;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Lato', sans-serif;
  font-weight: 300;
  font-size: 14px;
  letter-spacing: 0.02em;
  line-height: 1.75;
  background: var(--bg);
  color: var(--text-secondary);
}

a {
  color: var(--soho-deep);
  text-decoration: none;
}

[data-theme="dark"] a { color: var(--soho-gold-light); }
a:hover { color: var(--accent); }

h1, h2, h3 {
  font-family: 'Lato', sans-serif;
  font-weight: 300;
  color: var(--text);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  line-height: 1.2;
}

h1 {
  font-size: 1.65rem;
  letter-spacing: 0.15em;
  margin: 0 0 0.5rem;
}

h2 {
  font-size: 1.15rem;
  letter-spacing: 0.12em;
  margin: 0 0 0.75rem;
}

h3 {
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--accent);
}

.section-label,
.sidebar-section-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--muted);
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 1.5rem 0 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 0.5px solid var(--sidebar-border);
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  padding: 0 1.25rem 1.25rem;
  border-bottom: 0.5px solid var(--sidebar-border);
  margin-bottom: 1.25rem;
}

.brand-logo-mark {
  color: var(--soho-gold);
  line-height: 0;
  flex-shrink: 0;
}

.brand-logo-mark .logo-book { stroke: var(--soho-white); }
.brand-logo-mark .logo-spine { stroke: var(--soho-gold); }
.brand-logo-mark .logo-ring { stroke: var(--soho-gold); }
[data-theme="light"] .brand-logo-mark .logo-book { stroke: var(--soho-deep); }

.brand-logo-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.brand-name {
  font-size: 13px;
  font-weight: 300;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--sidebar-text);
  white-space: nowrap;
}

.brand-divider {
  width: 24px;
  height: 0.5px;
  background: var(--soho-gold);
  opacity: 0.7;
}

.brand-sub {
  font-size: 7px;
  font-weight: 700;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  color: var(--soho-gold);
}

.brand-logo-compact .brand-name {
  font-size: 11px;
  letter-spacing: 0.22em;
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0 0.85rem;
  overflow-y: auto;
}

.sidebar-section {
  margin-top: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.sidebar-section-label {
  padding: 0.5rem 0.65rem 0.35rem;
}

.sidebar-link {
  display: block;
  color: var(--sidebar-text);
  text-decoration: none;
  padding: 0.6rem 0.75rem;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  opacity: 0.85;
}

.sidebar-link:hover {
  background: var(--sidebar-hover-bg);
  opacity: 1;
  color: var(--sidebar-hover-text);
}

.sidebar-link.active {
  background: var(--sidebar-active);
  color: var(--sidebar-active-text);
  opacity: 1;
  box-shadow: inset 2px 0 0 var(--soho-gold);
}

.sidebar-footer {
  padding: 0.85rem 0.85rem 0;
  border-top: 0.5px solid var(--sidebar-border);
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 0.75rem;
  margin-top: 0.35rem;
}

.sidebar-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 0.5px solid rgba(196, 154, 60, 0.4);
}

.sidebar-avatar-initials {
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0.75px solid var(--soho-gold);
  color: var(--soho-gold);
  font-size: 11px;
  font-weight: 300;
  letter-spacing: 0.1em;
}

.sidebar-user-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar-user-name {
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.08em;
  color: var(--sidebar-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-logout {
  color: var(--sidebar-muted);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  text-decoration: none;
}

.sidebar-logout:hover { color: var(--soho-gold); }

/* ── Main content ── */
.main-panel {
  flex: 1;
  min-width: 0;
  background: var(--bg);
}

.main-content {
  max-width: 980px;
  padding: 2.25rem 2.5rem 3rem;
}

.hero,
.panel {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 4px;
  padding: 1.75rem;
  margin-bottom: 1.5rem;
}

.hero {
  border-top: 2px solid var(--soho-gold);
}

.hero .eyebrow {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.75rem;
}

.hero h1 {
  font-size: 1.75rem;
  margin-bottom: 0.75rem;
}

.hero p {
  max-width: 520px;
  margin-bottom: 1.25rem;
}

/* ── Buttons ── */
.button, button {
  background: var(--soho-black);
  color: var(--soho-white);
  border: none;
  padding: 0.65rem 1.25rem;
  cursor: pointer;
  font-family: 'Lato', sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  text-decoration: none;
  display: inline-block;
  border-radius: 3px;
  line-height: 1.4;
}

.button:hover, button:hover {
  background: var(--soho-deep);
  color: var(--soho-white);
}

.button-secondary {
  background: transparent;
  color: var(--text);
  border: 0.5px solid var(--border);
}

.button-secondary:hover {
  background: var(--soho-gold-pale);
  color: var(--soho-black);
  border-color: var(--soho-gold);
}

[data-theme="dark"] .button-secondary:hover {
  background: rgba(196, 154, 60, 0.15);
  color: var(--soho-gold-light);
}

.button-accent {
  background: var(--soho-gold);
  color: var(--soho-black);
}

.button-accent:hover {
  background: var(--soho-gold-light);
  color: var(--soho-black);
}

/* ── Cards & grid ── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}

.card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 4px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.card:hover {
  border-color: var(--soho-gold);
  box-shadow: 0 2px 12px rgba(196, 154, 60, 0.08);
}

.card a {
  color: inherit;
  text-decoration: none;
  display: block;
  padding: 0.85rem;
}

.card h3 {
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: none;
  color: var(--text);
  margin: 0.5rem 0 0.25rem;
}

.card p {
  font-size: 12px;
  color: var(--muted);
  margin: 0;
}

.card img, .detail-cover img, .cover-preview-wrap img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--soho-warm);
  border-radius: 2px;
}

.cover-placeholder {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--soho-warm);
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  text-align: center;
  padding: 0.5rem;
  border-radius: 2px;
}

.cover-placeholder.large { min-height: 280px; }

.badge {
  display: inline-block;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  background: var(--soho-gold-pale);
  color: var(--soho-deep);
  padding: 0.2rem 0.5rem;
  border-radius: 2px;
}

[data-theme="dark"] .badge {
  background: rgba(196, 154, 60, 0.2);
  color: var(--soho-gold-light);
}

/* ── Forms ── */
.filters, .type-links, .scan-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
  margin-bottom: 1rem;
}

.filters input, .filters select,
.form input, .form select, .form textarea, .form label,
.scan-row input, .scan-row select {
  font-family: 'Lato', sans-serif;
  color: var(--text-secondary);
}

.form input, .form select, .form textarea,
.scan-row input, .scan-row select,
.filters input, .filters select {
  background: var(--input-bg);
  border: 0.5px solid var(--border);
  border-radius: 3px;
  font-weight: 300;
}

.form input:focus, .form select:focus, .form textarea:focus,
.scan-row input:focus, .scan-row select:focus {
  border-color: var(--soho-gold);
  outline: none;
  box-shadow: 0 0 0 2px rgba(196, 154, 60, 0.12);
}

.form label, .scan-row label {
  display: block;
  margin-bottom: 0.75rem;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--muted);
}

.form input, .form select, .form textarea {
  display: block;
  width: 100%;
  max-width: 100%;
  padding: 0.5rem 0.6rem;
  margin-top: 0.3rem;
  font-size: 14px;
  text-transform: none;
  letter-spacing: 0.02em;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 1rem;
}

.form-grid .full-width { grid-column: 1 / -1; }

fieldset {
  border: 0.5px solid var(--border);
  border-radius: 4px;
  padding: 1rem 1.25rem;
  margin: 1rem 0;
}

legend {
  padding: 0 0.35rem;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
}

/* ── Detail pages ── */
.detail-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 2rem;
}

.detail-meta .creator {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 1rem;
}

/* ── Lists ── */
.copy-list, .staff-list {
  list-style: none;
  padding: 0;
}

.copy-list li, .staff-list li {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 3px;
  padding: 0.85rem 1rem;
  margin-bottom: 0.5rem;
  font-size: 14px;
}

.status-available { color: var(--soho-gold); font-weight: 700; }
.status-borrowed { color: var(--soho-gold-light); font-weight: 700; }
.status-requested { color: var(--muted); }

.overdue { color: var(--danger); }

.inline-form { display: inline; margin-left: 0.5rem; }

.empty-state, .hint, .settings-lead {
  color: var(--muted);
  font-size: 13px;
  font-weight: 300;
}

.settings-lead { margin-top: -0.25rem; margin-bottom: 1.25rem; }

.profile-dl {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 0.5rem 1rem;
}

.profile-dl dt {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--muted);
}

.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.message.success { color: var(--soho-gold); }
.message.error { color: var(--danger); }

/* ── Settings ── */
.settings-layout {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 2rem;
  align-items: start;
}

.settings-tabs {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.settings-tab {
  display: block;
  padding: 0.65rem 0.85rem;
  text-decoration: none;
  color: var(--muted);
  border-radius: 3px;
  border: 0.5px solid transparent;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.settings-tab:hover {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.settings-tab.active {
  background: var(--surface);
  border-color: var(--soho-gold);
  color: var(--accent);
  box-shadow: inset 2px 0 0 var(--soho-gold);
}

.settings-panel {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 4px;
  padding: 1.75rem;
}

.theme-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 0;
  border-bottom: 0.5px solid var(--border);
}

.theme-toggle {
  display: inline-flex;
  border: 0.5px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.theme-option {
  background: var(--surface-elevated);
  color: var(--text);
  border: none;
  border-radius: 0;
  padding: 0.5rem 1rem;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.theme-option.active {
  background: var(--soho-gold);
  color: var(--soho-black);
}

.field-error {
  display: block;
  color: var(--danger);
  font-size: 12px;
  text-transform: none;
  letter-spacing: normal;
}

/* ── Barcode scanner ── */
.barcode-input-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.3rem;
}

.scan-barcode-field label {
  display: block;
  margin-bottom: 0;
}

.barcode-input-row input { flex: 1; min-width: 0; }

#camera-scan-btn {
  min-height: 44px;
  min-width: 44px;
  flex-shrink: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

body.scanner-open { overflow: hidden; }

.scanner-modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 15, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.scanner-modal[hidden] { display: none; }

.scanner-modal-content {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 6px;
  padding: 1.25rem;
  width: min(480px, 100%);
}

.scanner-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.scanner-modal-header h3 {
  margin: 0;
  font-size: 12px;
}

#barcode-scanner-video {
  width: 100%;
  max-height: 60vh;
  min-height: 240px;
  background: var(--soho-black);
  border-radius: 3px;
  object-fit: cover;
}

.lookup-status { font-size: 13px; margin-top: 0.5rem; }
.lookup-status.success { color: var(--soho-gold); }
.lookup-status.warn { color: var(--soho-gold-light); }
.lookup-status.error { color: var(--danger); }

.cover-preview-wrap { max-width: 160px; margin-bottom: 1rem; }

.type-links a {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  padding: 0.35rem 0.65rem;
  border: 0.5px solid var(--border);
  border-radius: 3px;
}

.type-links a:hover {
  border-color: var(--soho-gold);
  background: var(--soho-gold-pale);
}

/* ── Allauth account forms ── */
.main-content form p {
  margin-bottom: 1rem;
}

.main-content form label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--muted);
}

.main-content form input[type="email"],
.main-content form input[type="password"],
.main-content form input[type="text"] {
  display: block;
  width: 100%;
  max-width: 400px;
  margin-top: 0.3rem;
  padding: 0.5rem 0.6rem;
  background: var(--input-bg);
  border: 0.5px solid var(--border);
  border-radius: 3px;
  font-family: 'Lato', sans-serif;
}

.main-content form button,
.main-content form input[type="submit"] {
  margin-top: 0.5rem;
}

.main-content .errorlist {
  color: var(--danger);
  list-style: none;
  padding: 0;
  font-size: 13px;
}

/* ── Responsive ── */
@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    padding: 0.85rem;
  }
  .brand-logo {
    border: none;
    margin: 0;
    padding: 0.35rem 0.5rem;
  }
  .brand-divider, .brand-sub { display: none; }
  .sidebar-nav, .sidebar-footer {
    flex-direction: row;
    flex-wrap: wrap;
    border: none;
    padding: 0.25rem;
  }
  .sidebar-section { margin: 0; flex-direction: row; align-items: center; }
  .sidebar-section-label { display: none; }
  .sidebar-user { display: none; }
  .main-content { padding: 1.25rem; }
  .form-grid { grid-template-columns: 1fr; }
  .detail-layout { grid-template-columns: 1fr; }
  .settings-layout { grid-template-columns: 1fr; }
  .settings-tabs { flex-direction: row; flex-wrap: wrap; }
}
