:root{
  --bg:#f6f8fb;
  --panel:#ffffff;
  --panel2:#f2f5fa;
  --line:#d6dde8;
  --text:#0f172a;
  --muted:#4b5563;
  --accent:#2563eb;
  --accentSoft: rgba(37,99,235,.12);
  --shadow: 0 18px 45px rgba(2,6,23,.10);
  --font: 13px/1.25 system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;

  /* A4-ish page in px (browser display) */
  --pageW: 794px;
  --pageH: 1123px;
  --padX: 56px;
  --padY: 64px;
}

*{ box-sizing:border-box }
html,body{ height:100% }

body{
  margin:0;
  font:var(--font);
  background:var(--bg);
  color:var(--text);
  overflow:hidden;
}

.app{ height:100%; display:flex; flex-direction:column }

.topbar{
  display:flex;
  flex-wrap:wrap;
  gap:10px;
  align-items:center;
  padding:10px 12px;
  background:linear-gradient(180deg, var(--panel), var(--panel2));
  border-bottom:1px solid var(--line);
}

.brand{
  display:flex;
  align-items:baseline;
  gap:8px;
  font-weight:900;
  letter-spacing:.2px;
  white-space:nowrap;
}
.brand a{ text-decoration:none; color:inherit }
.brand .sub{ font-weight:700; color:var(--muted) }

.group{
  display:flex;
  gap:8px;
  align-items:center;
  padding:6px 8px;
  border:1px solid var(--line);
  border-radius:12px;
  background:#fff;
}

.sep{
  width:1px;
  height:28px;
  background:var(--line);
  margin:0 2px;
}

button, select{
  background:#fff;
  color:var(--text);
  border:1px solid var(--line);
  border-radius:10px;
  padding:7px 10px;
  cursor:pointer;
  outline:none;
}
button:hover, select:hover{ border-color:#9fb2cf }
button:active{ transform:translateY(1px) }
button.primary{
  border-color:rgba(37,99,235,.55);
  box-shadow:0 0 0 3px var(--accentSoft) inset;
}
button.ghost{ background:transparent }

.status{
  margin-left:auto;
  display:flex;
  gap:10px;
  align-items:center;
  color:var(--muted);
  white-space:nowrap;
}

.badge{
  padding:4px 10px;
  border:1px solid rgba(180,83,9,.35);
  background:rgba(180,83,9,.08);
  color:#b45309;
  border-radius:999px;
  font-weight:800;
}

/* Layout */
.layout{
  flex:1;
  min-height:0;
  display:flex;
}

.sidebar{
  width:260px;
  border-right:1px solid var(--line);
  background:linear-gradient(180deg, #ffffff, #f2f5fa);
  padding:12px;
  display:flex;
  flex-direction:column;
  gap:10px;
}

.sideTitle{
  font-weight:900;
  color:var(--text);
}

.sideTools{
  display:flex;
  gap:8px;
}

.pageList{
  flex:1;
  overflow:auto;
  padding-right:4px;
}

.pageItem{
  border:1px solid var(--line);
  background:#fff;
  border-radius:12px;
  padding:10px;
  display:flex;
  gap:10px;
  align-items:flex-start;
  cursor:pointer;
  user-select:none;
  margin-bottom:8px;
}
.pageItem:hover{ border-color:#9fb2cf }
.pageItem.active{
  border-color:rgba(37,99,235,.55);
  box-shadow:0 0 0 3px var(--accentSoft) inset;
}
.pnum{
  width:34px;
  height:34px;
  border-radius:10px;
  border:1px solid var(--line);
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight:900;
  color:var(--muted);
  flex:0 0 auto;
}
.psnip{
  font-size:12px;
  color:var(--muted);
  line-height:1.3;
  max-height:2.6em;
  overflow:hidden;
}

.sideFooter{
  font-size:12px;
  color:var(--muted);
  padding-top:8px;
  border-top:1px solid var(--line);
}
.sideFooter a{ color:inherit; font-weight:800; text-decoration:none }

/* Workspace / Pages */
.workspace{
  flex:1;
  min-width:0;
  overflow:auto;
  padding:18px 14px;
}

.doc{
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:16px;
  padding-bottom:28px;
}

.page{
  width:var(--pageW);
  height:var(--pageH);
  background:#fff;
  border:1px solid var(--line);
  border-radius:16px;
  box-shadow:var(--shadow);
  position:relative;
}

.pageHeader{
  position:absolute;
  top:10px;
  right:14px;
  font-size:12px;
  color:var(--muted);
  user-select:none;
}

.pageBody{
  position:absolute;
  left:var(--padX);
  right:var(--padX);
  top:var(--padY);
  bottom:var(--padY);
  overflow:hidden;        /* IMPORTANT: enables pagination by moving overflow blocks */
  outline:none;
}

/* Typography inside pages */
.pageBody h1{ font-size:28px; margin:18px 0 10px }
.pageBody h2{ font-size:22px; margin:16px 0 8px }
.pageBody h3{ font-size:18px; margin:14px 0 6px }
.pageBody p{ margin:10px 0 }
.pageBody ul, .pageBody ol{ margin:10px 0 10px 22px }
.pageBody table{ border-collapse:collapse; width:100%; margin:12px 0 }
.pageBody td, .pageBody th{ border:1px solid var(--line); padding:8px; vertical-align:top }
.pageBody img{ max-width:100%; height:auto }

/* Footer */
.footer{
  display:flex;
  justify-content:space-between;
  gap:12px;
  padding:10px 12px;
  border-top:1px solid var(--line);
  background:linear-gradient(180deg, #f6f8fb, #f2f5fa);
  color:var(--muted);
  font-size:12px;
}
.footer a{ color:inherit; font-weight:800; text-decoration:none }
.hint{ white-space:nowrap; overflow:hidden; text-overflow:ellipsis }

/* Modal */
.modal{
  position:fixed;
  inset:0;
  display:none;
  align-items:center;
  justify-content:center;
  background:rgba(2,6,23,.55);
  z-index:50;
}
.modalBox{
  width:min(760px, 92vw);
  background:#fff;
  border:1px solid var(--line);
  border-radius:16px;
  padding:14px;
  box-shadow:0 25px 70px rgba(2,6,23,.30);
}
.modalTitle{ font-weight:900; margin:4px 0 10px }
.modalBody{
  color:#111827;
  background:#f8fafc;
  border:1px solid var(--line);
  border-radius:12px;
  padding:12px;
  line-height:1.45
}
.modalActions{ display:flex; justify-content:flex-end; margin-top:12px }

/* Print */
@media print{
  body{ background:#fff; overflow:visible }
  .topbar, .sidebar, .footer{ display:none !important }
  .workspace{ padding:0 !important; overflow:visible !important }
  .doc{ gap:0 !important; padding:0 !important }
  .page{
    box-shadow:none !important;
    border:none !important;
    border-radius:0 !important;
    page-break-after:always;
  }
  .pageHeader{ display:none !important }
}
