:root {
  --obsidian: #0B0F10;
  --charcoal: #111819;
  --surface-base: #101415;
  --surface-container: #1c2021;
  --surface-container-high: #272b2c;
  --surface: rgba(239, 245, 238, 0.075);
  --surface-strong: rgba(239, 245, 238, 0.12);
  --line: rgba(206, 221, 210, 0.14);
  --text: #EDF4EE;
  --muted: #A8B6AB;
  --faint: #738077;
  --accent: #52B788;
  --accent-dim: #75daa8;
  --blue: #00D4FF;
  --danger: #D98B82;
  --warn: #D6BD7D;
  --info: #A2E7FF;
  --sidebar-w: 260px;
  --topbar-h: 64px;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --shadow: 0 18px 52px rgba(0, 0, 0, 0.4);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% 12%, rgba(82, 183, 136, 0.16), transparent 28%),
    radial-gradient(circle at 88% 18%, rgba(0, 212, 255, 0.10), transparent 26%),
    linear-gradient(135deg, var(--obsidian), var(--charcoal) 58%, #0d1213);
  color: var(--text);
  font-family: "Be Vietnam Pro", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(206, 221, 210, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(206, 221, 210, 0.035) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,0.6), transparent 80%);
}

/* App Shell */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0,0,0,0.6);
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: rgba(17, 24, 25, 0.74);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(24px);
  transition: transform 0.25s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--line);
}

.sidebar-add-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  margin: 12px 14px 8px;
  border: 1px solid rgba(82, 183, 136, 0.42);
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #082116;
  font-family: "Be Vietnam Pro", sans-serif;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 0 24px rgba(82, 183, 136, 0.20);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.sidebar-add-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 30px rgba(82, 183, 136, 0.28);
}

.brand-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #0B0F10;
  box-shadow: 0 0 24px rgba(82, 183, 136, 0.28);
}

.brand-text { display: flex; flex-direction: column; }
.brand-name { font-family: "Montserrat", sans-serif; font-weight: 900; font-size: 18px; letter-spacing: -0.05em; line-height: 1.05; }
.brand-version { font-size: 11px; color: var(--muted); }

.sidebar-nav {
  padding: 12px 10px;
}

.nav-section-label {
  padding: 6px 10px 4px;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--faint);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 10px;
  margin: 1px 0;
  border-radius: var(--radius-sm);
  color: var(--muted);
  text-decoration: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.01em;
  transition: all 0.15s ease;
  position: relative;
}

.nav-item:hover { color: var(--text); background: var(--surface); }
.nav-item.active {
  color: var(--text);
  background: rgba(82, 183, 136, 0.12);
  box-shadow: inset 4px 0 0 var(--accent);
}

.nav-item svg { flex-shrink: 0; }

.nav-badge {
  margin-left: auto;
  min-width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: rgba(217, 139, 130, 0.2);
  color: var(--danger);
  font-size: 11px;
  font-weight: 800;
  padding: 0 6px;
}

.sidebar-footer {
  margin-top: auto;
  padding: 14px 16px;
  border-top: 1px solid var(--line);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--accent);
  font-weight: 900;
  font-size: 13px;
}

.user-details {
  display: flex;
  flex-direction: column;
}

.user-role { font-size: 13px; font-weight: 700; color: var(--text); }
.user-quota { font-size: 11px; color: var(--faint); }

/* User ID row — identify & restore library after switching browsers */
.user-id-row {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 5px;
}
.user-id {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--faint);
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 7px;
  cursor: default;
}
.user-id-btn {
  min-height: 22px;
  min-width: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.24);
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
}
.user-id-btn:hover { color: var(--accent); border-color: var(--accent); }
.user-id-help-btn {
  font-weight: 900;
  color: var(--faint);
}
.user-id-help {
  position: fixed;
  left: max(16px, calc(var(--sidebar-w) + 16px));
  bottom: 24px;
  z-index: 130;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(360px, calc(100vw - var(--sidebar-w) - 48px));
  padding: 12px 14px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--muted);
  background: rgba(17, 24, 25, 0.96);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.42);
}
.user-id-help b { color: var(--accent); font-weight: 800; }
.uid-error {
  color: var(--danger);
  font-size: 11px;
  margin: 6px 0 0;
  font-weight: 600;
  line-height: 1.4;
}
.user-id-edit {
  display: flex;
  gap: 5px;
  margin-top: 6px;
}
.user-id-edit input {
  flex: 1;
  min-width: 0;
  min-height: 26px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--text);
  padding: 0 6px;
}
.user-id-save {
  min-height: 26px;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 800;
  border-radius: 5px;
  border: 1px solid var(--accent);
  background: rgba(82, 183, 136, 0.12);
  color: var(--accent);
  cursor: pointer;
}

/* Main Area */
.main-area {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Top Bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-h);
  padding: 0 20px;
  background: rgba(11, 15, 16, 0.72);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(24px);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.mobile-menu-btn:hover { background: var(--surface); }

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
}

.breadcrumb-current {
  font-family: "Montserrat", sans-serif;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
  text-transform: capitalize;
}

.breadcrumb-manga {
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.pages-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(157, 190, 209, 0.1);
  border: 1px solid rgba(157, 190, 209, 0.18);
  color: var(--info);
  font-size: 12px;
  font-weight: 700;
}

.pages-badge.warning { background: rgba(214, 189, 125, 0.12); color: var(--warn); border-color: rgba(214, 189, 125, 0.22); }
.pages-badge.empty { background: rgba(217, 139, 130, 0.12); color: var(--danger); border-color: rgba(217, 139, 130, 0.22); }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  flex-shrink: 0;
}

.status-dot.connected { background: var(--accent); box-shadow: 0 0 6px rgba(82, 183, 136, 0.5); }
.status-dot.disconnected { background: var(--danger); }

.topbar-avatar {
  display: none;
  width: 30px;
  height: 30px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--accent);
  font-weight: 900;
  font-size: 12px;
}

/* Page Content */
.page-content {
  flex: 1;
  padding: 24px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}

/* Page: User Management (admin, changelog #71) — wider than default because
   the user table has 7 columns and a 36-char UUID. Centred with more breathing
   room on large viewports, more gutter on narrow viewports. */
.page.user-management-page {
  max-width: 1600px;
}
.page.user-management-page .section-card {
  margin-bottom: 20px;
}
.user-management-page .section-card-header {
  gap: 12px;
  flex-wrap: wrap;
}
.user-management-page .section-card-header .btn-group {
  flex: 1;
  min-width: 0;
  justify-content: flex-end;
}

/* Search input — reuses input style but caps width and prevents stretching. */
.search-input {
  width: 100%;
  min-width: 220px;
  max-width: 320px;
}

/* Status pill row (sits between header and table for transient feedback) */
.status-pill-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  min-height: 24px;
}
.status-pill-row:empty { display: none; }

/* Data table — used by Credit Log, User Management, etc. */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-base);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-container);
  color: var(--muted);
  font-weight: 600;
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  z-index: 1;
}
.data-table tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--surface); }
.data-table code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.28);
  padding: 2px 6px;
  border-radius: 4px;
  display: inline-block;
  white-space: nowrap;
  vertical-align: middle;
}
.block-meta {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-top: 4px;
  line-height: 1.4;
}

/* Section Cards */
.section-card {
  margin-bottom: 16px;
  background: linear-gradient(145deg, var(--surface), rgba(239, 245, 238, 0.035));
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.section-card-accent {
  border-color: rgba(82, 183, 136, 0.2);
  background: linear-gradient(145deg, rgba(82, 183, 136, 0.06), rgba(255,255,255,0.02));
}

.section-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: "Montserrat", sans-serif;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
}

.section-title svg { color: var(--accent); }

.section-count {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-left: 8px;
}

.section-desc {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 16px;
}

.section-card-body {
  padding: 18px 20px;
}

/* Library */
.library-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  margin-bottom: 16px;
  padding: 22px 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background:
    linear-gradient(135deg, rgba(82, 183, 136, 0.12), transparent 36%),
    linear-gradient(145deg, var(--surface), rgba(239, 245, 238, 0.035));
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.library-hero-copy {
  max-width: 680px;
}

.eyebrow {
  display: inline-flex;
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.library-hero h1 {
  font-family: "Montserrat", sans-serif;
  font-size: clamp(28px, 5vw, 46px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.06em;
}

.library-hero p {
  max-width: 560px;
  margin-top: 10px;
  color: var(--muted);
}

.library-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(86px, 1fr));
  gap: 8px;
  align-self: center;
}

.metric-card {
  min-width: 98px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.22);
}

.metric-value {
  display: block;
  color: var(--text);
  font-family: "Montserrat", sans-serif;
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
}

.metric-label {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.import-console {
  margin-bottom: 16px;
}

.library-catalog .section-card-header {
  align-items: flex-start;
  flex-direction: column;
}

.catalog-titlebar {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.catalog-search {
  width: min(100%, 380px);
}

.view-chip,
.view-toggle {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.24);
  color: var(--muted);
}

.view-chip {
  padding: 0 12px;
  font: inherit;
  font-size: 12px;
  font-weight: 800;
}

.view-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 9px;
}

.view-dot {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  border: 1px solid var(--line);
}

.view-dot.active {
  background: var(--accent);
  border-color: var(--accent);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  border-color: rgba(82, 183, 136, 0.4);
  background: var(--surface);
  transform: translateY(-1px);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
}

.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-sm { min-height: 32px; padding: 6px 12px; font-size: 12px; }
.btn-lg { min-height: 42px; padding: 10px 20px; font-size: 14px; }
.btn-primary { background: rgba(0, 212, 255, 0.13); color: var(--blue); border-color: rgba(0, 212, 255, 0.32); }
.btn-primary:hover:not(:disabled) { background: rgba(0, 212, 255, 0.22); border-color: rgba(0, 212, 255, 0.48); }
.btn-success { background: var(--accent); color: #0B0F10; border-color: var(--accent); }
.btn-success:hover:not(:disabled) { background: var(--accent-dim); box-shadow: 0 0 28px rgba(82, 183, 136, 0.26); }
.btn-secondary { background: var(--surface); color: var(--muted); }
.btn-danger { background: rgba(217, 139, 130, 0.15); color: var(--danger); border-color: rgba(217, 139, 130, 0.3); }
.btn-danger:hover:not(:disabled) { background: rgba(217, 139, 130, 0.25); }

.btn-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-icon:hover { background: var(--surface); color: var(--text); }

/* Form Elements */
input[type="text"],
input[type="number"],
input[type="file"],
select,
textarea {
  width: 100%;
  min-height: 40px;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(0, 212, 255, 0.62);
  box-shadow: 0 0 0 4px rgba(0, 212, 255, 0.10);
}

textarea { min-height: 80px; resize: vertical; }

select { cursor: pointer; }

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

.form-field label {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.form-status {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 700;
}

.form-status.success { background: rgba(82, 183, 136, 0.12); color: var(--accent); }
.form-status.error { background: rgba(217, 139, 130, 0.12); color: var(--danger); }
.form-status.info { background: rgba(157, 190, 209, 0.1); color: var(--info); }
.form-status.warning { background: rgba(214, 189, 125, 0.12); color: var(--warn); }

/* Search Box */
.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}

.search-box .search-icon {
  position: absolute;
  left: 12px;
  color: var(--faint);
  pointer-events: none;
}

.search-box input {
  padding-left: 36px;
  padding-right: 32px;
}

.search-clear {
  position: absolute;
  right: 8px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  font-size: 12px;
}

.search-clear:hover { color: var(--text); background: var(--surface); }

/* Tags */
.existing-tags, .tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.tag {
  display: inline-flex;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

/* URL Input */
.url-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.url-input-row input { flex: 1; }

/* MangaDex Preview */
.mangadex-preview {
  margin-top: 12px;
  padding: 12px;
  background: rgba(0,0,0,0.2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.preview-header strong { color: var(--blue); font-size: 14px; }
.preview-meta { font-size: 12px; color: var(--muted); }

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 6px;
  max-height: 200px;
  overflow-y: auto;
}

.preview-grid img {
  width: 100%;
  border-radius: 4px;
  border: 1px solid var(--line);
}

/* Limited preview: [first] [+N hidden] [middle] [+M hidden] [last]
   Gap chips are placeholders so users understand pages exist in between;
   full set arrives after "Download & Import". */
.preview-cell { min-width: 0; }

/* Preview thumbs open the shared full-size modal, same as the library grid */
.preview-thumb-clickable {
  cursor: zoom-in;
}

.preview-grid-limited {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  max-height: none;
  overflow-x: auto;
}

.preview-grid-limited .preview-cell img {
  width: auto;
  max-width: 30vw;
  max-height: 200px;
  border-radius: 6px;
}

.preview-gap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 72px;
  padding: 10px 12px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-align: center;
}

.preview-note {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

/* Manga Grid */
.manga-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(164px, 1fr));
  gap: 14px;
}

.manga-card {
  position: relative;
  min-height: 270px;
  padding: 8px;
  background: rgba(239, 245, 238, 0.045);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all 0.15s ease;
}

.manga-card:hover {
  border-color: rgba(82, 183, 136, 0.3);
  background: rgba(239, 245, 238, 0.075);
  transform: translateY(-2px);
}

.manga-card.active {
  border-color: rgba(82, 183, 136, 0.5);
  background: linear-gradient(135deg, rgba(82, 183, 136, 0.1), rgba(0,0,0,0.15));
  box-shadow: 0 0 0 2px rgba(82, 183, 136, 0.16);
}

.manga-cover {
  position: relative;
  min-height: 190px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background:
    radial-gradient(circle at 32% 20%, rgba(0, 212, 255, 0.42), transparent 28%),
    radial-gradient(circle at 78% 74%, rgba(82, 183, 136, 0.36), transparent 30%),
    linear-gradient(145deg, #172526, #0b0f10);
}

.manga-cover::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, transparent 34%, rgba(0, 0, 0, 0.78)),
    linear-gradient(45deg, rgba(255,255,255,0.08) 0 1px, transparent 1px 10px);
}

.manga-cover-art {
  position: absolute;
  inset: 18px 18px 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.20);
  transform: skewY(-5deg);
}

.cover-initials {
  color: rgba(237, 244, 238, 0.9);
  font-family: "Montserrat", sans-serif;
  font-size: 34px;
  font-weight: 900;
  letter-spacing: -0.08em;
  transform: skewY(5deg);
}

.cover-badge,
.source-chip {
  position: absolute;
  z-index: 1;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.cover-badge {
  top: 8px;
  right: 8px;
  padding: 4px 8px;
}

.cover-badge.complete { background: rgba(82, 183, 136, 0.88); color: #082116; }
.cover-badge.incomplete { background: rgba(214, 189, 125, 0.90); color: #261f0a; }

.source-chip {
  left: 8px;
  bottom: 8px;
  padding: 4px 7px;
  background: rgba(11, 15, 16, 0.76);
  border: 1px solid var(--line);
  color: var(--muted);
  backdrop-filter: blur(10px);
}

.manga-card-body { display: flex; flex-direction: column; gap: 8px; padding: 10px 2px 2px; }
.manga-card-title { min-height: 36px; font-size: 13px; font-weight: 900; color: var(--text); line-height: 1.35; }
.manga-card-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.manga-card-footer { font-size: 11px; color: var(--faint); }

.meta-text { font-size: 11px; color: var(--faint); }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.status-pill.complete { background: rgba(82, 183, 136, 0.12); color: var(--accent); }
.status-pill.incomplete { background: rgba(214, 189, 125, 0.12); color: var(--warn); }
.status-pill.warning { background: rgba(214, 189, 125, 0.12); color: var(--warn); }
.status-pill.info { background: rgba(157, 190, 209, 0.1); color: var(--info); }
.status-pill.error { background: rgba(217, 139, 130, 0.12); color: var(--danger); }

.empty-state {
  padding: 32px;
  text-align: center;
  color: var(--faint);
  font-size: 13px;
}

.load-more {
  text-align: center;
  padding: 16px 0 8px;
}

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.selection-badge {
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(82, 183, 136, 0.12);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
}

/* Per-chapter collapse footer (shown below each expanded chapter's images) */
.chapter-collapse {
  display: flex;
  justify-content: center;
  padding: 14px 12px;
  border-top: 1px solid var(--line);
  background: rgba(255,255,255,0.015);
}

/* Floating Collapse All — pinned to the viewport so it stays reachable
   even after a long scroll through expanded chapters. Placed outside the
   section-card in the DOM because that card's overflow/backdrop-filter
   would break position:fixed. */
.collapse-all-fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 60;
  box-shadow: var(--shadow);
}

/* Chapter Group */
.chapter-group {
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.chapter-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 14px;
  background: rgba(255,255,255,0.02);
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

.chapter-header:hover { background: rgba(255,255,255,0.04); }
.chapter-header.expanded {
  background: linear-gradient(135deg, rgba(82, 183, 136, 0.08), rgba(255,255,255,0.02));
  box-shadow: inset 4px 0 0 var(--accent);
}

.chapter-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.chapter-chevron { transition: transform 0.18s; color: var(--accent); flex-shrink: 0; }
.chapter-chevron.rotated { transform: rotate(90deg); }

.chapter-label { font-size: 13px; font-weight: 800; color: var(--text); }
.chapter-count { font-size: 11px; color: var(--muted); font-weight: 600; }

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

.report-btn { color: var(--danger); }
.report-btn:hover { background: rgba(217, 139, 130, 0.15); }

.reported-badge {
  font-size: 10px;
  color: var(--accent);
  font-weight: 700;
}

.chapter-images { padding: 10px; }
.chapter-images.hidden { display: none; }

/* Image Grid */
.image-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.image-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}

.image-card:hover { border-color: rgba(82, 183, 136, 0.3); }
.image-card.translated { border-color: rgba(82, 183, 136, 0.3); }
.image-card.selected {
  border-color: rgba(82, 183, 136, 0.7);
  box-shadow: 0 0 0 2px rgba(82, 183, 136, 0.15);
}

.image-card img {
  display: block;
  width: 100%;
  aspect-ratio: 2/3;
  object-fit: cover;
  cursor: zoom-in;
  background: rgba(0,0,0,0.3);
}

.img-wrap { position: relative; }

.img-checkbox {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 2;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  background: rgba(11, 15, 16, 0.8);
  border: 2px solid var(--accent);
  color: transparent;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
  backdrop-filter: blur(8px);
}

.img-checkbox.checked { background: var(--accent); color: #0B0F10; }

.image-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
  color: var(--muted);
  font-size: 10px;
  word-break: break-word;
}

.image-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-height: 20px;
}

.image-edit-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent, #38bdf8);
  border: 1px solid rgba(56, 189, 248, 0.4);
  border-radius: var(--radius);
  padding: 0;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  flex-shrink: 0;
}

.image-edit-btn:hover {
  background: rgba(56, 189, 248, 0.3);
  border-color: rgba(56, 189, 248, 0.65);
}

.image-edit-icon {
  width: 14px;
  height: 14px;
}

/* Translate Section */
.translate-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 16px;
}

.translate-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.control-group label {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.control-group select {
  min-height: 36px;
  font-size: 12px;
  padding: 6px 10px;
}

.top-language-control {
  min-width: 190px;
}

.top-language-control select {
  min-height: 32px;
}

/* Progress */
.progress-section {
  margin-top: 12px;
}

.progress-bar {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: rgba(0,0,0,0.3);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--blue), var(--accent));
  border-radius: 999px;
  transition: width 0.3s ease;
}

.progress-text {
  display: block;
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
}

/* Pipeline Steps */
.pipeline-settings {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding: 12px;
  background: rgba(0,0,0,0.15);
  border-radius: var(--radius-sm);
}

.pipeline-steps {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.step {
  display: flex;
  gap: 12px;
  padding: 14px;
  border-left: 2px solid var(--line);
  position: relative;
  margin-left: 8px;
  transition: all 0.2s;
}

.step:last-child { border-left-color: transparent; }

.step.active { background: rgba(0, 212, 255, 0.04); border-left-color: var(--blue); }
.step.completed { background: rgba(82, 183, 136, 0.04); border-left-color: var(--accent); }
.step.failed { background: rgba(217, 139, 130, 0.04); border-left-color: var(--danger); }

.step-indicator {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}

.step-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--obsidian);
  z-index: 1;
}

.step-dot.running { border-color: var(--warn); background: rgba(214, 189, 125, 0.2); }
.step-dot.done { border-color: var(--accent); background: var(--accent); }
.step-dot.error { border-color: var(--danger); background: var(--danger); }

.step-line {
  width: 2px;
  flex: 1;
  min-height: 20px;
  background: var(--line);
}

.step-content {
  flex: 1;
}

.step-title { font-size: 13px; font-weight: 800; color: var(--text); }
.step-desc { font-size: 11px; color: var(--muted); margin-top: 2px; }
.step-status-text { font-size: 11px; margin-top: 4px; font-weight: 600; }
.step-status-text.running { color: var(--warn); }
.step-status-text.done { color: var(--accent); }
.step-status-text.error { color: var(--danger); }

.step-action { flex-shrink: 0; }

.step-sub-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}

.sub-step {
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.sub-step:hover:not(:disabled) { border-color: rgba(82, 183, 136, 0.4); color: var(--text); }
.sub-step:disabled { opacity: 0.4; cursor: not-allowed; }
.sub-step.running { border-color: var(--warn); color: var(--warn); background: rgba(214, 189, 125, 0.1); }
.sub-step.done { border-color: var(--accent); color: var(--accent); background: rgba(82, 183, 136, 0.1); }
.sub-step.error { border-color: var(--danger); color: var(--danger); background: rgba(217, 139, 130, 0.1); }

/* Debug Panel */
.debug-panel {
  margin-top: 12px;
  padding: 12px;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  max-height: 300px;
  overflow-y: auto;
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
}

/* Log Panel */
.log-panel {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.log-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(0,0,0,0.2);
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}

.log-entries {
  max-height: 200px;
  overflow-y: auto;
  padding: 8px 12px;
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  line-height: 1.6;
}

.log-entry { margin-bottom: 2px; }
.log-entry.info { color: var(--info); }
.log-entry.success { color: var(--accent); }
.log-entry.error { color: var(--danger); }
.log-entry.warn { color: var(--warn); }

/* Report Stats */
.report-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.stat-card {
  padding: 14px;
  background: rgba(0,0,0,0.15);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: center;
}

.stat-value { display: block; font-size: 24px; font-weight: 900; color: var(--text); }
.stat-value.warn { color: var(--warn); }
.stat-value.success { color: var(--accent); }
.stat-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--faint); font-weight: 700; }

/* Report List */
.report-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.report-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  background: rgba(0,0,0,0.15);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.report-card.resolved { opacity: 0.6; }

.notification-unread {
  border-color: var(--accent, #00d4ff);
  background: rgba(0, 212, 255, 0.05);
}

.notification-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 6px;
}

.report-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.report-card-body { flex: 1; }

.report-title { font-size: 13px; font-weight: 700; color: var(--text); }
.report-msg { font-size: 12px; color: var(--muted); margin-top: 4px; }
.report-meta { font-size: 11px; color: var(--faint); margin-top: 6px; }

/* Credit Log — per-user filter + full User ID token (click = filter) */
.credit-user-filter {
  width: auto;
  min-width: 220px;
  min-height: 32px;
  padding: 4px 10px;
  font-size: 12px;
}

.credit-user-token {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  cursor: pointer;
  word-break: break-all;
  text-align: left;
}

.credit-user-token:hover { text-decoration: underline; }


/* Diagnostics */
.diag-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.diag-item {
  padding: 12px;
  background: rgba(0,0,0,0.15);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.diag-label {
  display: block;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--faint);
  margin-bottom: 4px;
}

.diag-value {
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
}

.diag-value.success { color: var(--accent); }
.diag-value.error { color: var(--danger); }

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(18px);
  cursor: pointer;
}

.modal-overlay.active { display: flex; }

.modal-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  max-width: 94vw;
  max-height: 90vh;
  cursor: default;
}

.modal-preview img {
  max-width: 94vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius);
}

.modal-nav-btn {
  position: fixed;
  bottom: 20px;
  z-index: 1001;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(11, 15, 16, 0.85);
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--text);
  font-size: 28px;
  cursor: pointer;
  backdrop-filter: blur(12px);
  transition: all 0.15s;
}

.modal-nav-btn:hover { border-color: rgba(82, 183, 136, 0.4); background: rgba(82, 183, 136, 0.15); }
.modal-nav-btn.prev { left: calc(50% - 50px); }
.modal-nav-btn.next { right: calc(50% - 50px); }

.modal-counter {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 10px;
  background: rgba(11, 15, 16, 0.8);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  backdrop-filter: blur(10px);
}

.modal-dialog {
  width: min(100%, 480px);
  padding: 20px;
  background: rgba(28, 32, 33, 0.86);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
  cursor: default;
}

.modal-dialog h3 {
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 4px;
}

.modal-subtitle {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 16px;
}

.modal-dialog .form-field {
  margin-bottom: 12px;
}

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

.modal-error {
  color: var(--danger);
  font-size: 12px;
  margin: 8px 0 0;
  font-weight: 600;
}

/* Responsive */
@media (min-width: 640px) {
  .image-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }

  .image-label {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .report-card {
    flex-direction: row;
    align-items: center;
  }

  .modal-nav-btn {
    top: 50%;
    bottom: auto;
    transform: translateY(-50%);
    width: 48px;
    height: 48px;
  }

  .modal-nav-btn.prev { left: 20px; }
  .modal-nav-btn.next { right: 20px; }

  .topbar-avatar { display: flex; }
}

@media (min-width: 860px) {
  .image-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
  .manga-grid { grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); }
  .page-content { padding: 24px; }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.open {
    display: block;
  }

  .main-area {
    margin-left: 0;
  }

  .mobile-menu-btn {
    display: flex;
  }

  .page-content {
    padding: 16px;
  }

  .section-card-body {
    padding: 14px;
  }

  .section-title {
    font-size: 20px;
  }

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

  .pages-badge {
    font-size: 11px;
    padding: 4px 8px;
  }

  .manga-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .library-hero {
    grid-template-columns: 1fr;
    padding: 18px;
  }

  .library-metrics {
    grid-template-columns: repeat(3, 1fr);
  }

  .catalog-titlebar {
    align-items: flex-start;
    flex-direction: column;
  }

  .catalog-search {
    width: 100%;
  }

  .manga-card {
    min-height: 238px;
  }

  .manga-cover {
    min-height: 156px;
  }

  .report-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .user-id-help {
    left: 16px;
    right: 16px;
    bottom: 16px;
    width: auto;
  }
}

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

  .library-metrics {
    grid-template-columns: 1fr;
  }
}

/* ---------------------------------------------------------------------------
 * Edit translation modal (per-page, after one-click translate)
 * Phase 4 — feature #87. Button sits in the bottom-right of the image
 * preview; the modal itself uses the existing .modal-dialog styling.
 * --------------------------------------------------------------------------- */
.modal-edit-btn {
  position: absolute;
  right: 12px;
  bottom: 12px;
  background: rgba(15, 23, 42, 0.85);
  color: #f8fafc;
  border: 1px solid rgba(148, 163, 184, 0.4);
  border-radius: var(--radius);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: background 0.15s ease;
}

.modal-edit-btn:hover {
  background: rgba(30, 41, 59, 0.95);
}

.edit-blocks-dialog {
  max-width: 640px;
  width: 90vw;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
}

.edit-blocks-body {
  overflow-y: auto;
  flex: 1 1 auto;
  margin: 12px 0 18px;
  padding-right: 4px;
}

.edit-block-row {
  background: rgba(15, 23, 42, 0.4);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 10px;
}

.edit-block-row label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
  color: var(--text-muted, #94a3b8);
}

.edit-block-source {
  font-size: 12px;
  color: var(--text-muted, #94a3b8);
  background: rgba(0, 0, 0, 0.25);
  padding: 6px 8px;
  border-radius: 4px;
  margin-bottom: 8px;
  white-space: pre-wrap;
  max-height: 80px;
  overflow-y: auto;
}

.edit-block-textarea {
  width: 100%;
  resize: vertical;
  min-height: 36px;
  background: rgba(0, 0, 0, 0.3);
  color: var(--text, #f8fafc);
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 4px;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.4;
}

.edit-block-textarea:focus {
  outline: none;
  border-color: var(--accent, #38bdf8);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}
