@import url('https://fonts.googleapis.com/css2?family=Noto+Nastaliq+Urdu:wght@400;700&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --ink: #1a1a1a;
  --paper: #f7f4ec;
  --rule: #c9c2ab;
  --masthead-green: #0c5c3d;
  --accent-red: #c4262e;
  --muted: #6b6354;
  --card: #ffffff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', sans-serif;
  background: var(--paper);
  color: var(--ink);
}

a { color: inherit; }

/* ---------- Top bar ---------- */
.topbar {
  background: var(--masthead-green);
  color: #fff;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}
.topbar h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.topbar .meta {
  font-size: 13px;
  opacity: 0.85;
}
.topbar nav a {
  color: #fff;
  text-decoration: none;
  margin-left: 16px;
  font-size: 14px;
  opacity: 0.9;
}
.topbar nav a:hover { opacity: 1; text-decoration: underline; }

/* ---------- Auth overlay (login / setup / account settings) ---------- */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 26, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.auth-card {
  background: #fff;
  border-radius: 8px;
  padding: 24px;
  width: 100%;
  max-width: 380px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}
.auth-card h2 {
  font-size: 18px;
  margin: 0 0 14px;
  border-bottom: 2px solid var(--masthead-green);
  padding-bottom: 8px;
}
.auth-card h3 {
  font-size: 13px;
  margin: 0 0 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.auth-error {
  background: #fdeceb;
  color: var(--accent-red);
  border: 1px solid #f3c9c6;
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 12.5px;
  margin-bottom: 10px;
}
#accountBar {
  font-size: 13px;
  margin-right: 6px;
}
#accountBar a {
  color: #fff;
  text-decoration: none;
  opacity: 0.9;
}
#accountBar a:hover { opacity: 1; text-decoration: underline; }

/* ---------- Reader controls ---------- */
.reader-toolbar {
  max-width: 1100px;
  margin: 18px auto 0;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.reader-btn,
.drawer-close {
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--masthead-green);
  background: var(--masthead-green);
  color: #fff;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.reader-btn:hover,
.drawer-close:hover { background: #0a4a30; }
.reader-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.issue-controls {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.issue-controls label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}
.issue-controls input,
.issue-controls select {
  height: 38px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: #fff;
  padding: 0 10px;
  font: inherit;
  font-size: 13px;
}
.page-drawer {
  max-width: 1100px;
  margin: 12px auto 0;
  padding: 14px 16px 18px;
  background: #fff;
  border-top: 3px solid var(--masthead-green);
  border-bottom: 1px solid var(--rule);
}
.page-drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}
.thumb {
  padding: 0;
  border: 2px solid var(--rule);
  background: #fff;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  color: var(--ink);
  text-align: left;
}
.thumb:hover,
.thumb.active { border-color: var(--masthead-green); }
.thumb img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  background: #eee;
}
.thumb span {
  display: block;
  padding: 7px 8px;
  font-size: 12px;
  font-weight: 700;
}

/* ---------- Page viewer / editor canvas ---------- */
.stage-wrap {
  max-width: 1100px;
  margin: 24px auto 60px;
  padding: 0 16px;
}
.stage {
  position: relative;
  display: inline-block;
  background: #fff;
  box-shadow: 0 2px 18px rgba(0,0,0,0.18);
  border: 1px solid var(--rule);
  line-height: 0;
}
.stage img {
  display: block;
  max-width: 100%;
  height: auto;
  user-select: none;
}

.region-box {
  position: absolute;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.12s ease, background-color 0.12s ease;
}
.stage.draw-mode .region-box {
  pointer-events: none;
}
.stage.draw-mode {
  cursor: crosshair;
}
.region-box:hover {
  border-color: var(--accent-red);
  background-color: rgba(196, 38, 46, 0.06);
}
.region-box.editing {
  border-color: var(--accent-red);
  background-color: rgba(196, 38, 46, 0.10);
}
.region-box .handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: var(--accent-red);
  right: -5px;
  bottom: -5px;
  cursor: nwse-resize;
  border-radius: 2px;
}
.region-box .tag {
  position: absolute;
  top: -22px;
  left: -2px;
  background: var(--accent-red);
  color: #fff;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 2px;
  white-space: nowrap;
  font-family: 'Inter', sans-serif;
}

/* ---------- Editor panel ---------- */
.editor-shell {
  display: flex;
  gap: 20px;
  max-width: 1650px;
  margin: 24px auto 60px;
  padding: 0 16px;
  align-items: flex-start;
}
.editor-side {
  width: 480px;
  flex-shrink: 0;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 16px;
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}
.editor-side h2 {
  font-size: 15px;
  margin: 0 0 12px;
  border-bottom: 2px solid var(--masthead-green);
  padding-bottom: 8px;
}
.field { margin-bottom: 6px; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 2px;
  font-weight: 600;
}
.field input[type=text],
.field input[type=number],
.field input[type=date],
.field textarea {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
}
.field textarea[dir=rtl] {
  font-family: 'Noto Nastaliq Urdu', serif;
  font-size: 16px;
  direction: rtl;
}
.field textarea { resize: vertical; min-height: 36px; }
.btn {
  display: inline-block;
  padding: 9px 14px;
  border: none;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: var(--masthead-green);
  color: #fff;
}
.btn:hover { background: #0a4a30; }
.btn.secondary { background: #fff; color: var(--ink); border: 1px solid var(--rule); }
.btn.secondary:hover { background: #f0ede4; }
.btn.danger { background: var(--accent-red); color: #fff; }
.btn.btn-sm { padding: 5px 9px; font-size: 11px; font-weight: 600; flex-shrink: 0; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.helptext { font-size: 12px; color: var(--muted); margin: 6px 0 14px; line-height: 1.5; }

/* Compact "page loaded" summary row */
.page-summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #f3efe1;
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 10px;
}
.page-summary-text {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.4;
  overflow: visible;
  white-space: normal;
  min-width: 0;
}
.page-summary-text .summary-sub {
  display: block;
  font-weight: 400;
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 1px;
}

.region-editor-block {
  border-top: 1px solid #e3dcc5;
  padding-top: 10px;
  margin-top: 4px;
}

.region-list { list-style: none; margin: 10px 0 0; padding: 10px 0 0; max-height: 160px; overflow-y: auto; border-top: 1px solid #e3dcc5; }
.region-list li {
  padding: 7px 8px;
  border-bottom: 1px solid #eee5d2;
  font-size: 12.5px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.region-list li:hover { background: #f3efe1; }
.region-list li.active { background: #e6efe9; font-weight: 600; }
.region-list .del { color: var(--accent-red); font-size: 12px; }

/* ---------- Detail page ---------- */
.detail-wrap {
  max-width: 760px;
  margin: 30px auto 80px;
  background: var(--card);
  border: 1px solid var(--rule);
  padding: 30px 36px 40px;
  box-shadow: 0 2px 18px rgba(0,0,0,0.10);
}
.detail-eyebrow {
  font-size: 12px;
  color: var(--accent-red);
  letter-spacing: 1px;
  text-transform: uppercase;
  font-weight: 700;
  text-align: right;
  direction: rtl;
}
.detail-title {
  font-family: 'Noto Nastaliq Urdu', serif;
  font-size: 32px;
  line-height: 1.7;
  direction: rtl;
  text-align: right;
  margin: 10px 0 18px;
  color: var(--ink);
}
.detail-image {
  width: 100%;
  border-radius: 4px;
  margin-bottom: 18px;
  border: 1px solid var(--rule);
}
.detail-body {
  font-family: 'Noto Nastaliq Urdu', serif;
  font-size: 21px;
  line-height: 2.1;
  direction: rtl;
  text-align: right;
  white-space: pre-wrap;
}
.detail-back {
  display: inline-block;
  margin-top: 28px;
  font-size: 13px;
  color: var(--masthead-green);
  text-decoration: none;
  font-weight: 600;
}
.detail-back:hover { text-decoration: underline; }
hr.rule { border: none; border-top: 1px solid var(--rule); margin: 18px 0; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}

@media (max-width: 700px) {
  .reader-toolbar { align-items: stretch; }
  .reader-btn { flex: 1 1 30%; }
  .issue-controls {
    width: 100%;
    margin-left: 0;
  }
  .issue-controls input,
  .issue-controls select { flex: 1 1 130px; }
}
