:root {
  --bg: #0d1117;
  --bg-soft: #141b24;
  --card: #161f2a;
  --card-2: #1c2733;
  --line: #263241;
  --text: #e6edf3;
  --muted: #8b9bb0;
  --accent: #2f81f7;
  --accent-2: #1f6feb;
  --green: #2ea043;
  --amber: #d29922;
  --red: #f85149;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(47, 129, 247, .10), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(46, 160, 67, .07), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Noto Naskh Arabic", "Amiri", Tahoma, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
a { color: var(--accent); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(13, 17, 23, .85);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; font-size: 18px; }
.brand .logo {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(140deg, var(--accent), #7c3aed);
  font-size: 18px;
}
.brand small { color: var(--muted); font-size: 12px; font-weight: 400; }

.topbar .status { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.on { background: var(--green); box-shadow: 0 0 10px rgba(46, 160, 67, .8); }
.dot.off { background: var(--red); }

.layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 20px;
  padding: 20px;
  max-width: 1600px;
  margin: 0 auto;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 86px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 106px);
}

.book-list { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; padding-inline-end: 4px; }

.book-item {
  text-align: start;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color .15s, transform .15s, background .15s;
}
.book-item:hover { border-color: #3b4b5f; transform: translateY(-1px); }
.book-item.active { border-color: var(--accent); background: #16243a; }
.book-item .title { font-weight: 600; font-size: 14px; display: block; margin-bottom: 4px; }
.book-item .meta { color: var(--muted); font-size: 12px; display: flex; gap: 8px; flex-wrap: wrap; }

.content { min-width: 0; display: flex; flex-direction: column; gap: 18px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.card h2 { margin: 0 0 4px; font-size: 18px; }
.card .sub { color: var(--muted); font-size: 13px; margin-bottom: 14px; }

.btn {
  border: 1px solid var(--line);
  background: var(--card-2);
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #24313f; border-color: #3b4b5f; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: linear-gradient(160deg, var(--accent), var(--accent-2)); border-color: transparent; font-weight: 600; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.danger { color: #ffb4ae; border-color: #5c2b2b; background: #2a1a1a; }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; justify-content: center; }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.grow { flex: 1; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--muted); }
input[type=text], input[type=password], input[type=number], select, textarea {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  outline: none;
  width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }

.dropzone {
  border: 1.5px dashed #33465c;
  border-radius: 14px;
  padding: 34px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  background: rgba(47, 129, 247, .03);
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: rgba(47, 129, 247, .08); }
.dropzone .big { font-size: 34px; display: block; margin-bottom: 6px; }
.dropzone .hint { color: var(--muted); font-size: 13px; }

.progress {
  height: 10px;
  background: #0b1219;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.progress > i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), #56d364);
  transition: width .4s ease;
}

.badges { display: flex; gap: 8px; flex-wrap: wrap; }
.badge {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--card-2);
  border: 1px solid var(--line);
  color: var(--muted);
}
.badge.ok { color: #7ee787; border-color: #2b4d34; background: #13231a; }
.badge.warn { color: #e3b341; border-color: #4d3f1a; background: #241d10; }
.badge.err { color: #ff9b94; border-color: #5c2b2b; background: #2a1a1a; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.stat {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}
.stat b { display: block; font-size: 19px; }
.stat span { color: var(--muted); font-size: 12px; }

.log {
  background: #0a0f15;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  max-height: 190px;
  overflow: auto;
  font-family: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  line-height: 1.7;
  color: #9fb1c6;
  direction: ltr;
  text-align: left;
  white-space: pre-wrap;
}

.pages-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(54px, 1fr));
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
}
.page-chip {
  border: 1px solid var(--line);
  background: var(--bg-soft);
  border-radius: 8px;
  padding: 6px 0;
  font-size: 12px;
  cursor: pointer;
  text-align: center;
  color: var(--muted);
}
.page-chip.done { color: #7ee787; border-color: #2b4d34; background: #101c15; }
.page-chip.failed { color: #ff9b94; border-color: #5c2b2b; background: #1e1414; }
.page-chip.current { outline: 2px solid var(--accent); outline-offset: 1px; color: var(--text); }

.review {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  gap: 16px;
  align-items: start;
}
@media (max-width: 1050px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: none; }
  .review { grid-template-columns: 1fr; }
}

.viewer-img {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  max-height: 78vh;
  object-fit: contain;
}

.blocks { display: flex; flex-direction: column; gap: 10px; max-height: 78vh; overflow-y: auto; padding-inline-end: 4px; }
.block {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.block .head { display: flex; gap: 8px; align-items: center; }
.block select { width: auto; padding: 4px 8px; font-size: 12px; border-radius: 8px; }
.block .conf { font-size: 11px; color: var(--muted); margin-inline-start: auto; }
.block textarea {
  min-height: 64px;
  resize: vertical;
  line-height: 1.9;
  direction: rtl;
  background: #0f1620;
}

.toast-wrap {
  position: fixed;
  inset-inline-start: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
}
.toast {
  background: var(--card-2);
  border: 1px solid var(--line);
  border-inline-start: 3px solid var(--accent);
  border-radius: 10px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  font-size: 13px;
  max-width: 380px;
  animation: slide .2s ease;
}
.toast.err { border-inline-start-color: var(--red); }
.toast.ok { border-inline-start-color: var(--green); }
@keyframes slide { from { transform: translateY(8px); opacity: 0; } }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1; }
hr.sep { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.center { text-align: center; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  width: min(380px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card p.sub { margin: 0 0 18px; color: var(--muted); font-size: 13px; }
.error { color: #ff9b94; font-size: 13px; margin: 0 0 10px; }
