/* ===== StoryForge — Editorial Design ===== */

:root {
  /* Main palette */
  --bg:             #f6f4ef;
  --surface:        #ffffff;
  --surface-2:      #f0ede6;
  --border:         #ddd8ce;
  --border-light:   #e8e3d8;

  /* Sidebar */
  --sb-bg:          #1b1b19;
  --sb-hover:       #252522;
  --sb-active:      #2f2f2b;
  --sb-text:        #a09880;
  --sb-text-active: #ede8dc;
  --sb-border:      #272724;
  --sb-label:       #4a4740;

  /* Typography */
  --text:           #1a1917;
  --text-muted:     #605a52;
  --text-faint:     #9a9288;

  /* Accent — warm amber-brown */
  --accent:         #7c5c3c;
  --accent-hover:   #9a7250;
  --accent-light:   #f4ece2;

  /* Status */
  --success:        #3a7054;
  --warning:        #a87020;
  --danger:         #942828;
  --info:           #265680;

  /* Layout */
  --sidebar-w:      224px;
  --content-hdr:    52px;
  --radius:         3px;
  --radius-lg:      5px;
  --radius-xl:      8px;

  /* Fonts */
  --font-serif: Georgia, "Times New Roman", "Palatino Linotype", Palatino, serif;
  --font-ui:    -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;

  /* Shadows */
  --shadow-xs:  0 1px 2px rgba(0,0,0,0.06);
  --shadow-sm:  0 1px 4px rgba(0,0,0,0.08);
  --shadow:     0 2px 8px rgba(0,0,0,0.09);
  --shadow-lg:  0 4px 20px rgba(0,0,0,0.11);
  --book-sh:    -2px 2px 6px rgba(0,0,0,0.20), 2px 3px 12px rgba(0,0,0,0.13);
  --book-sh-hv: -3px 8px 18px rgba(0,0,0,0.24), 3px 6px 22px rgba(0,0,0,0.16);

  --transition: 0.18s ease;
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }

body {
  font-family: var(--font-serif);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  min-height: 100vh;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ===== Typography ===== */
h1 { font-family: var(--font-serif); font-size: 1.85rem; font-weight: normal; line-height: 1.2; letter-spacing: -0.01em; }
h2 { font-family: var(--font-serif); font-size: 1.35rem; font-weight: normal; line-height: 1.3; }
h3 { font-family: var(--font-serif); font-size: 1.05rem; font-weight: normal; }
h4 { font-family: var(--font-ui); font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-faint); }
a  { color: inherit; text-decoration: none; transition: color var(--transition); }
p  { color: var(--text-muted); line-height: 1.7; }
strong { font-weight: 600; }
em { font-style: italic; }

/* ===== App Shell ===== */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
  background: var(--sb-bg);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 200;
}
.sidebar::-webkit-scrollbar { width: 3px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--sb-border); }

.sidebar-brand {
  padding: 1.75rem 1.25rem 1.4rem;
  border-bottom: 1px solid var(--sb-border);
  flex-shrink: 0;
}
.sidebar-brand a {
  display: block;
  font-family: var(--font-serif);
  font-size: 1.15rem;
  color: #ede8dc;
  letter-spacing: 0.02em;
  line-height: 1.2;
}
.sidebar-brand a small {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--sb-label);
  margin-top: 0.2rem;
  font-style: normal;
}

.sidebar-nav {
  flex: 1;
  padding: 0.5rem 0;
}

.sidebar-section {
  padding: 0.75rem 0 0.25rem;
}
.sidebar-section-label {
  font-family: var(--font-ui);
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  color: var(--sb-label);
  padding: 0 1.25rem 0.4rem;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.42rem 1.25rem;
  font-family: var(--font-ui);
  font-size: 0.78rem;
  color: var(--sb-text);
  border-left: 2px solid transparent;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  white-space: nowrap;
  overflow: hidden;
}
.sidebar-item svg { flex-shrink: 0; opacity: 0.55; transition: opacity var(--transition); }
.sidebar-item:hover { background: var(--sb-hover); color: var(--sb-text-active); }
.sidebar-item:hover svg { opacity: 0.9; }
.sidebar-item.active {
  background: var(--sb-active);
  color: var(--sb-text-active);
  border-left-color: var(--accent);
}
.sidebar-item.active svg { opacity: 1; }

.sidebar-divider {
  height: 1px;
  background: var(--sb-border);
  margin: 0.6rem 1.25rem;
}

.sidebar-footer {
  flex-shrink: 0;
  padding: 0.9rem 1.25rem;
  border-top: 1px solid var(--sb-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
}
.sidebar-avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-ui);
  font-size: 0.68rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sidebar-username {
  font-family: var(--font-ui);
  font-size: 0.73rem;
  color: var(--sb-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-logout {
  display: flex;
  padding: 0.25rem;
  color: var(--sb-label);
  border-radius: var(--radius);
  transition: color var(--transition);
}
.sidebar-logout:hover { color: var(--sb-text); }

/* ===== App Body ===== */
.app-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ===== Content Header ===== */
.content-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 2rem;
  height: var(--content-hdr);
  background: var(--surface);
  border-bottom: 1px solid var(--border-light);
  position: sticky;
  top: 0;
  z-index: 100;
}
.search-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.3rem 0.75rem;
  flex: 1;
  max-width: 300px;
}
.search-wrap svg { color: var(--text-faint); flex-shrink: 0; }
.search-wrap input {
  background: none; border: none; outline: none;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  color: var(--text);
  width: 100%;
}
.search-wrap input::placeholder { color: var(--text-faint); }
.content-header-book {
  font-family: var(--font-serif);
  font-size: 0.82rem;
  font-style: italic;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
  margin-left: auto;
}

/* ===== Main ===== */
.main {
  flex: 1;
  padding: 2.5rem 2.5rem;
  max-width: 1280px;
  width: 100%;
}

/* ===== Page Header ===== */
.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 2.25rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}
.page-header h1 { font-family: var(--font-serif); }
.page-header .subtitle {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  color: var(--text-faint);
  margin-top: 0.3rem;
  font-weight: normal;
}

/* ===== Alerts / Flash ===== */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: 0.82rem;
  margin-bottom: 1.25rem;
  border: 1px solid;
}
.alert-success { background: #edf7f2; color: var(--success); border-color: #b8ddc9; }
.alert-error   { background: #fdf0f0; color: var(--danger);  border-color: #e8c0c0; }
.alert-info    { background: #edf3fa; color: var(--info);    border-color: #b8ccde; }
.alert-warning { background: #fdf6e8; color: var(--warning); border-color: #ddc898; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.48rem 1rem;
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.015em;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
  line-height: 1;
}
.btn-primary  { background: var(--text); color: var(--surface); border-color: var(--text); }
.btn-primary:hover { background: #2e2b26; border-color: #2e2b26; color: var(--surface); }
.btn-secondary { background: var(--surface); color: var(--text-muted); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--text-muted); color: var(--text); }
.btn-danger   { background: transparent; color: var(--danger); border-color: #dcc; }
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-ghost    { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm  { padding: 0.3rem 0.65rem; font-size: 0.72rem; }
.btn-lg  { padding: 0.65rem 1.25rem; font-size: 0.82rem; }

/* ===== Book Grid (Shelf) ===== */
.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 2rem 1.75rem;
}

.book-item {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  cursor: grab;
}
.book-item:active { cursor: grabbing; }

/* Cover wrapper — portrait 2:3 ratio */
.book-cover-link { display: block; text-decoration: none; }
.book-cover-wrap {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: 2px 5px 5px 2px;
  overflow: hidden;
  box-shadow: var(--book-sh);
  transition: transform 0.22s ease, box-shadow 0.22s ease;
}

/* Spine highlight */
.book-cover-wrap::before {
  content: '';
  position: absolute;
  left: 0; top: 0;
  width: 9px; height: 100%;
  background: linear-gradient(to right, rgba(0,0,0,0.22), rgba(0,0,0,0.04));
  z-index: 2;
  pointer-events: none;
}
/* Page edge on right */
.book-cover-wrap::after {
  content: '';
  position: absolute;
  right: 0; top: 0;
  width: 4px; height: 100%;
  background: rgba(255,255,255,0.12);
  z-index: 2;
  pointer-events: none;
}

.book-cover-link:hover .book-cover-wrap {
  transform: translateY(-6px) rotate(0.6deg);
  box-shadow: var(--book-sh-hv);
}

.book-cover-img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}

/* Text cover (no image) */
.book-cover-text {
  width: 100%; height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.1rem 0.8rem;
  text-align: center;
}
.book-cover-rule {
  width: 36%;
  height: 1px;
  background: rgba(255,255,255,0.3);
  flex-shrink: 0;
}
.book-cover-title {
  font-family: var(--font-serif);
  font-size: clamp(0.65rem, 1.5vw, 0.9rem);
  font-weight: normal;
  color: rgba(255,255,255,0.92);
  line-height: 1.3;
  margin: 0.55rem 0;
}
.book-cover-genre {
  font-family: var(--font-ui);
  font-size: 0.52rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  color: rgba(255,255,255,0.5);
  margin-top: 0.5rem;
}

/* Info below cover */
.book-info-below { padding: 0 0.2rem; }
.book-info-title {
  font-family: var(--font-serif);
  font-size: 0.82rem;
  color: var(--text);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.book-info-status {
  font-family: var(--font-ui);
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin-top: 0.2rem;
}

/* ===== Cards ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-light);
}
.card-body { padding: 1.25rem; }

/* ===== Stats Grid ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 2rem;
}
.stat-card {
  background: var(--surface);
  padding: 1.25rem 1rem;
  text-align: center;
}
.stat-value {
  font-family: var(--font-serif);
  font-size: 1.8rem;
  font-weight: normal;
  color: var(--text);
  line-height: 1;
}
.stat-label {
  font-family: var(--font-ui);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  margin-top: 0.35rem;
}

/* ===== Activity Items ===== */
.activity-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1.25rem;
  border-bottom: 1px solid var(--border-light);
  transition: background var(--transition);
}
.activity-item:last-child { border-bottom: none; }
.activity-item:hover { background: var(--bg); }
.activity-icon {
  width: 34px; height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-2);
}
.activity-icon img { width: 100%; height: 100%; object-fit: cover; }
.activity-meta {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  color: var(--text-faint);
  margin-top: 0.1rem;
}

/* ===== Forms ===== */
.form-group { margin-bottom: 1.1rem; }
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.form-label {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}
.form-control {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: 0.82rem;
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}
.form-control::placeholder { color: var(--text-faint); }
textarea.form-control { resize: vertical; min-height: 100px; line-height: 1.6; font-family: var(--font-serif); }
select.form-control { appearance: none; cursor: pointer; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%239a9288'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 0.75rem center; padding-right: 2rem; }
.form-hint {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  color: var(--text-faint);
  margin-top: 0.3rem;
}

/* ===== Tabs ===== */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  gap: 0;
  margin-bottom: 1.75rem;
}
.tab-btn {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 500;
  padding: 0.6rem 1.1rem;
  color: var(--text-muted);
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color var(--transition), border-color var(--transition);
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ===== Badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.18rem 0.5rem;
  border-radius: 2px;
  font-family: var(--font-ui);
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.badge-idea      { background: #f0edff; color: #5040a0; }
.badge-planning  { background: #fffbe8; color: #8a6000; }
.badge-writing   { background: #eaf5ee; color: #2d6040; }
.badge-revision  { background: #fff2e8; color: #8a3800; }
.badge-finished  { background: #e8f4ea; color: #205030; }
.badge-draft     { background: var(--surface-2); color: var(--text-faint); }
.badge-in_progress { background: #eaf2ff; color: #2040a0; }
.badge-complete  { background: #eaf5ee; color: #2d6040; }

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-faint);
}
.empty-state h3 {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}
.empty-state p {
  font-family: var(--font-ui);
  font-size: 0.82rem;
  margin-bottom: 1.25rem;
}
.empty-icon {
  width: 48px; height: 48px;
  margin: 0 auto 1.25rem;
  color: var(--border);
}

/* ===== Table ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  font-family: var(--font-ui);
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  padding: 0.6rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 0.7rem 1rem;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg); }

/* ===== Chapter Editor ===== */
.editor-wrap { display: grid; grid-template-columns: 1fr 280px; gap: 1.5rem; align-items: start; }
.editor-status-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 1rem;
  font-family: var(--font-ui);
  font-size: 0.72rem;
  color: var(--text-faint);
}
.editor-autosave {
  margin-left: auto;
  font-size: 0.7rem;
  color: var(--text-faint);
  font-style: italic;
}

/* Override EasyMDE to match theme */
.EasyMDEContainer { border-radius: var(--radius-lg); overflow: hidden; }
.EasyMDEContainer .CodeMirror {
  font-family: var(--font-serif);
  font-size: 0.95rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-top: none;
  padding: 1rem;
  min-height: 420px;
}
.EasyMDEContainer .editor-toolbar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: 1px solid var(--border-light);
}
.EasyMDEContainer .editor-toolbar button { color: var(--text-muted) !important; }
.EasyMDEContainer .editor-toolbar button:hover { background: var(--surface-2) !important; }

/* ===== Cytoscape network ===== */
#cy-container {
  width: 100%;
  height: 560px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

/* ===== Image Gallery ===== */
.image-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 0.75rem;
}
.gallery-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
.gallery-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery-item-del {
  position: absolute;
  top: 4px; right: 4px;
  width: 22px; height: 22px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition);
}
.gallery-item:hover .gallery-item-del { opacity: 1; }

/* ===== Timeline ===== */
.timeline-event {
  display: flex;
  gap: 1rem;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border-light);
}
.timeline-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-top: 0.45rem;
  flex-shrink: 0;
}
.timeline-date {
  font-family: var(--font-ui);
  font-size: 0.72rem;
  color: var(--text-faint);
  margin-top: 0.15rem;
}
.timeline-title {
  font-family: var(--font-serif);
  font-size: 0.95rem;
  color: var(--text);
}

/* ===== Character Profile ===== */
.profile-avatar {
  width: 100px; height: 100px;
  border-radius: var(--radius-lg);
  object-fit: cover;
  border: 1px solid var(--border);
}
.profile-avatar-placeholder {
  width: 100px; height: 100px;
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-ui);
  font-size: 2rem;
  color: var(--text-faint);
  font-weight: 300;
}
.profile-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem 1.5rem;
}
.profile-meta-item label {
  display: block;
  font-family: var(--font-ui);
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  margin-bottom: 0.2rem;
}
.profile-meta-item span {
  font-family: var(--font-serif);
  font-size: 0.9rem;
  color: var(--text);
}

/* ===== Scenes / Drag list ===== */
.drag-list { display: flex; flex-direction: column; gap: 0.5rem; }
.drag-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: grab;
}
.drag-item:active { cursor: grabbing; opacity: 0.8; }
.drag-handle { color: var(--border); flex-shrink: 0; }
.drag-item.sortable-ghost { opacity: 0.4; }

/* ===== Toast ===== */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}
.toast {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  padding: 0.65rem 1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  max-width: 300px;
  line-height: 1.4;
}
.toast.info    { background: var(--sb-bg); color: var(--sb-text-active); }
.toast.success { background: #e8f5ed; color: var(--success); border: 1px solid #b8d8c4; }
.toast.error   { background: #fdf0f0; color: var(--danger); border: 1px solid #e8c0c0; }

/* ===== Misc helpers ===== */
.text-muted { color: var(--text-muted); }
.text-faint  { color: var(--text-faint); }
.text-sm     { font-size: 0.82rem; }
.text-xs     { font-size: 0.72rem; font-family: var(--font-ui); }
.text-serif  { font-family: var(--font-serif); }
.font-ui     { font-family: var(--font-ui); }
.divider     { height: 1px; background: var(--border); margin: 1.5rem 0; }
.sortable-ghost { opacity: 0.35; }

/* ===== Sidebar Mobile Toggle ===== */
.sidebar-mobile-toggle {
  display: none;
  position: fixed;
  bottom: 1.25rem;
  left: 1.25rem;
  z-index: 300;
  width: 42px; height: 42px;
  background: var(--sb-bg);
  color: var(--sb-text-active);
  border: none;
  border-radius: 50%;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
  .editor-wrap { grid-template-columns: 1fr; }
  .books-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}

@media (max-width: 768px) {
  :root { --sidebar-w: 224px; }

  .app-shell { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    left: 0; top: 0;
    transform: translateX(-100%);
    transition: transform 0.28s ease;
    height: 100vh;
    width: var(--sidebar-w);
    z-index: 250;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-mobile-toggle { display: flex; }

  .app-body { min-height: 100vh; }
  .main { padding: 1.5rem 1.25rem; }
  .content-header { padding: 0 1.25rem; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .books-grid { grid-template-columns: repeat(3, 1fr); gap: 1.25rem 1rem; }

  .page-header { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
  .form-row { grid-template-columns: 1fr; }
  div[style*="grid-template-columns:1fr 1fr"] { grid-template-columns: 1fr !important; }
}

@media (max-width: 480px) {
  .books-grid { grid-template-columns: repeat(2, 1fr); }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ===== Sidebar overlay on mobile ===== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 240;
}
.sidebar-overlay.open { display: block; }
