:root {
  --bg: #0f1220;
  --bg-soft: #161a2e;
  --bg-elev: #1c2140;
  --panel-border: #2a3059;
  --text: #eef0fb;
  --text-dim: #a5abcf;
  --text-faint: #767ca3;
  --accent: #7c8cff;
  --accent-soft: rgba(124, 140, 255, 0.15);
  --good: #35d399;
  --good-bg: rgba(53, 211, 153, 0.16);
  --warn: #ff8a5b;
  --warn-bg: rgba(255, 138, 91, 0.16);
  --bad: #ff5c7a;
  --bad-bg: rgba(255, 92, 122, 0.16);
  --info: #5bc8ff;
  --info-bg: rgba(91, 200, 255, 0.16);
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --shadow-card: 0 10px 30px rgba(4, 6, 20, 0.45);
  --shadow-pop: 0 20px 60px rgba(4, 6, 20, 0.6);
  font-size: 16px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: radial-gradient(circle at top left, #1a1f3d, #0a0c18 70%);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

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

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

/* ---------- Sidebar / Nav ---------- */

.sidebar {
  width: 230px;
  flex: 0 0 230px;
  background: linear-gradient(180deg, var(--bg-soft), var(--bg));
  border-right: 1px solid var(--panel-border);
  padding: 24px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--info));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  box-shadow: 0 6px 18px rgba(124, 140, 255, 0.45);
}

nav.main-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

nav.main-nav .nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  border: 1px solid transparent;
}

nav.main-nav .nav-item:hover {
  background: var(--bg-elev);
  color: var(--text);
}

nav.main-nav .nav-item.active {
  background: var(--accent-soft);
  color: var(--text);
  border-color: rgba(124, 140, 255, 0.4);
}

.sidebar-footer {
  margin-top: auto;
  font-size: 0.75rem;
  color: var(--text-faint);
  line-height: 1.5;
}

/* ---------- Main content ---------- */

main.content {
  flex: 1;
  padding: 28px 36px 60px;
  max-width: 100%;
  overflow-x: hidden;
}

.screen {
  display: none;
  animation: fadeIn 0.25s ease;
}

.screen.active {
  display: block;
}

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

.screen-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
}

.screen-header h1 {
  font-size: 1.7rem;
  margin: 0 0 4px;
}

.screen-header p {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.92rem;
}

.header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ---------- Buttons ---------- */

button, .btn {
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid var(--panel-border);
  background: var(--bg-elev);
  color: var(--text);
  padding: 9px 16px;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
}

button:hover, .btn:hover {
  background: #232a52;
  border-color: rgba(124, 140, 255, 0.4);
}

button:active, .btn:active {
  transform: translateY(1px);
}

button.primary, .btn.primary {
  background: linear-gradient(135deg, var(--accent), #5f6ef2);
  border-color: transparent;
  color: #0a0c18;
}

button.primary:hover, .btn.primary:hover {
  filter: brightness(1.08);
}

button.ghost {
  background: transparent;
  border-color: var(--panel-border);
}

button.danger {
  background: var(--bad-bg);
  border-color: rgba(255, 92, 122, 0.4);
  color: var(--bad);
}

button.small {
  padding: 5px 10px;
  font-size: 0.78rem;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ---------- KPI cards ---------- */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 30px;
}

.kpi-card {
  background: linear-gradient(160deg, var(--bg-elev), var(--bg-soft));
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
}

.kpi-card::after {
  content: "";
  position: absolute;
  right: -30px;
  top: -30px;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: var(--accent-soft);
  filter: blur(4px);
}

.kpi-label {
  color: var(--text-dim);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.kpi-value {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.kpi-sub {
  margin-top: 6px;
  font-size: 0.78rem;
  color: var(--text-faint);
}

/* ---------- Cards / panels ---------- */

.panel {
  background: var(--bg-soft);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-card);
  margin-bottom: 24px;
}

.panel-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* ---------- Book grid / cover art tiles ---------- */

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 20px;
}

.book-card {
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-elev);
  border: 1px solid var(--panel-border);
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
  display: flex;
  flex-direction: column;
}

.book-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-pop);
  border-color: rgba(124, 140, 255, 0.5);
}

.book-cover {
  position: relative;
  height: 190px;
  width: 100%;
  background-size: cover;
  background-position: center;
  background-color: var(--bg-elev);
  display: flex;
  align-items: flex-end;
  padding: 10px;
}

.book-cover::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,0) 30%, var(--tile-accent, rgba(20,22,45,0.9)) 100%);
  mix-blend-mode: normal;
}

.book-cover .cover-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  font-weight: 800;
  color: rgba(255,255,255,0.85);
  background: var(--tile-accent, #333a63);
}

.book-cover .accent-chip {
  position: relative;
  z-index: 1;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.7);
  background: var(--tile-accent, var(--accent));
  box-shadow: 0 0 0 3px rgba(0,0,0,0.25);
}

.book-info {
  padding: 14px 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.book-title {
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.3;
  color: var(--text);
}

.book-author {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.book-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
  font-size: 0.75rem;
  color: var(--text-faint);
}

/* ---------- Status badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge.good, .badge.status-available {
  background: var(--good-bg);
  color: var(--good);
}

.badge.info, .badge.status-issued, .badge.status-reserved {
  background: var(--info-bg);
  color: var(--info);
}

.badge.warn, .badge.status-overdue {
  background: var(--warn-bg);
  color: var(--warn);
}

.badge.bad, .badge.status-returned {
  background: var(--bad-bg);
  color: var(--bad);
}

.badge.neutral {
  background: rgba(255,255,255,0.08);
  color: var(--text-dim);
}

/* ---------- Tables ---------- */

.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--panel-border);
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  min-width: 640px;
}

table.data-table thead th {
  text-align: left;
  padding: 12px 14px;
  background: var(--bg-elev);
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--panel-border);
  position: sticky;
  top: 0;
}

table.data-table tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  color: var(--text);
  vertical-align: middle;
}

table.data-table tbody tr {
  transition: background 0.12s ease;
}

table.data-table tbody tr:hover {
  background: rgba(124, 140, 255, 0.06);
}

table.data-table tbody tr:last-child td {
  border-bottom: none;
}

.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------- Book detail ---------- */

.detail-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 28px;
}

.detail-cover {
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: var(--radius-lg);
  background-size: cover;
  background-position: center;
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: flex-end;
}

.detail-cover::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,0) 40%, var(--tile-accent, rgba(20,22,45,0.92)) 100%);
}

.detail-cover .cover-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3.4rem;
  font-weight: 800;
  color: rgba(255,255,255,0.85);
  background: var(--tile-accent, #333a63);
}

.detail-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 18px;
}

.field-block {
  background: var(--bg-elev);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}

.field-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  margin-bottom: 4px;
}

.field-value {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

/* ---------- Forms / modals ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 20, 0.65);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  background: var(--bg-soft);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 26px;
  width: min(480px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow-pop);
}

.modal h2 {
  margin: 0 0 18px;
  font-size: 1.2rem;
}

.form-grid {
  display: grid;
  gap: 14px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-field label {
  font-size: 0.78rem;
  color: var(--text-dim);
  font-weight: 600;
}

.form-field input, .form-field select, .form-field textarea {
  background: var(--bg-elev);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 9px 12px;
  font-size: 0.9rem;
  font-family: inherit;
}

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

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* ---------- Agent panel ---------- */

.agent-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.agent-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  background: var(--bg-elev);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  text-align: left;
}

.agent-btn strong {
  font-size: 0.88rem;
}

.agent-btn span {
  font-size: 0.74rem;
  color: var(--text-faint);
}

.agent-btn:hover {
  border-color: rgba(124, 140, 255, 0.5);
  background: #202650;
}

/* ---------- Toast / feedback ---------- */

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-elev);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 0.85rem;
  box-shadow: var(--shadow-pop);
  z-index: 60;
  animation: fadeIn 0.2s ease;
}

.toast.error {
  border-color: rgba(255, 92, 122, 0.5);
  color: var(--bad);
}

.toast.success {
  border-color: rgba(53, 211, 153, 0.5);
  color: var(--good);
}

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-faint);
  font-size: 0.9rem;
}

.search-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.search-bar input, .search-bar select {
  background: var(--bg-elev);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 9px 12px;
  font-size: 0.88rem;
  font-family: inherit;
  min-width: 160px;
}

/* ---------- Responsive ---------- */

@media (max-width: 1080px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .detail-layout {
    grid-template-columns: 1fr;
  }

  .detail-cover {
    max-width: 260px;
  }
}

@media (max-width: 780px) {
  #app-shell {
    flex-direction: column;
  }

  .sidebar {
    position: relative;
    width: 100%;
    flex: none;
    height: auto;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: 14px 16px;
  }

  nav.main-nav {
    flex-direction: row;
  }

  .sidebar-footer {
    display: none;
  }

  main.content {
    padding: 20px 16px 40px;
  }

  .kpi-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 520px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .book-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }

  .modal {
    padding: 18px;
  }
}
