/* E-Palli Auto Format - design system */
:root {
  --brand: #0d5c32; --brand-2: #12814a; --brand-3: #e8f4ed; --brand-ink: #063d20;
  --ink: #17201b; --ink-2: #3c4842; --muted: #6b7871; --line: #e2e8e4; --line-2: #eef2ef;
  --bg: #f4f7f5; --card: #ffffff; --shadow: 0 1px 2px rgba(16, 32, 24, .05), 0 6px 24px rgba(16, 32, 24, .06);
  --warn: #9a6400; --warn-bg: #fdf5e1; --err: #b42318; --err-bg: #fdeceb; --info: #1d5aa6; --info-bg: #e9f1fb;
  --ok: #0f7a43; --ok-bg: #e4f5ec; --radius: 12px; --side: 236px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 14px/1.5 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; line-height: 1.25; margin: 0; letter-spacing: -.2px; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 0 0 8px; }
code { background: var(--line-2); padding: 1px 6px; border-radius: 5px; font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
svg.i { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- shell */
.shell { display: flex; min-height: 100vh; }
.side { width: var(--side); flex: none; background: #0b2f1c; color: #cfe3d7; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 11px; padding: 20px 18px 18px; color: #fff; }
.brand .mark { width: 38px; height: 38px; border-radius: 10px; background: #fff; display: grid; place-items: center; overflow: hidden; }
.brand .mark img { width: 30px; }
.brand b { display: block; font-size: 15px; letter-spacing: .2px; }
.brand span { font-size: 11.5px; color: #8fb8a0; }
.nav { padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 9px; color: #cfe3d7; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; color: #fff; }
.nav a.on { background: #12814a; color: #fff; }
.side-foot { margin-top: auto; padding: 14px 18px; font-size: 12px; color: #7fa892; border-top: 1px solid rgba(255,255,255,.08); }
.side-foot .engine { display: inline-flex; gap: 6px; align-items: center; background: rgba(255,255,255,.08); color: #d7eadf; padding: 3px 9px; border-radius: 20px; margin-top: 6px; }
.main { flex: 1; min-width: 0; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 22px 32px 0; flex-wrap: wrap; }
.top .sub { color: var(--muted); margin-top: 3px; }
.content { padding: 20px 32px 48px; }

/* ---------- elements */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 18px 20px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; }
.btn { font: inherit; font-weight: 600; font-size: 13.5px; display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 9px;
  border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; white-space: nowrap; transition: .12s; }
.btn:hover { background: #f5f8f6; text-decoration: none; border-color: #cfd8d2; }
.btn.primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn.primary:hover { background: var(--brand); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--line-2); }
.btn.danger { color: var(--err); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn[disabled] { opacity: .55; cursor: default; }
input, select, textarea { font: inherit; color: var(--ink); background: #fff; border: 1px solid #d5ddd8; border-radius: 9px; padding: 8px 11px; outline: none; transition: .12s; }
input:focus, select:focus, textarea:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(18,129,74,.14); }
textarea { width: 100%; resize: vertical; line-height: 1.55; }
label.f { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
label.f input, label.f select, label.f textarea { font-weight: 400; font-size: 14px; }
label.f .hint { font-weight: 400; color: var(--muted); }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.span2 { grid-column: span 2; } .span3 { grid-column: span 3; } .span4 { grid-column: 1 / -1; }

.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 20px; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .8; }
.chip.review { background: var(--warn-bg); color: var(--warn); }
.chip.ready { background: var(--info-bg); color: var(--info); }
.chip.queued { background: var(--info-bg); color: var(--info); }
.chip.running { background: #dfe9fb; color: #1546a0; }
.chip.running::before { animation: pulse 1s infinite; }
.chip.done { background: var(--ok-bg); color: var(--ok); }
.chip.error { background: var(--err-bg); color: var(--err); }
@keyframes pulse { 50% { opacity: .2; } }
.tag { display: inline-block; font-size: 11.5px; font-weight: 700; letter-spacing: .3px; padding: 2px 8px; border-radius: 6px; background: var(--brand-3); color: var(--brand); }

.flash { display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-radius: 10px; margin-bottom: 12px; border: 1px solid; font-weight: 500; }
.flash.ok { background: var(--ok-bg); border-color: #b5e2c8; color: #0b5a32; }
.flash.warn { background: var(--warn-bg); border-color: #f1d99a; color: #7a5000; }
.flash.error { background: var(--err-bg); border-color: #f5c2bd; color: #8c1d14; }
.flash ul { margin: 4px 0 0; padding-left: 18px; font-weight: 400; }

/* ---------- dashboard */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat { padding: 16px 18px; display: flex; gap: 14px; align-items: center; }
.stat .ico { width: 42px; height: 42px; border-radius: 11px; display: grid; place-items: center; }
.stat b { font-size: 24px; display: block; line-height: 1.1; }
.stat span { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.ico.g { background: var(--brand-3); color: var(--brand); } .ico.y { background: var(--warn-bg); color: var(--warn); }
.ico.b { background: var(--info-bg); color: var(--info); } .ico.k { background: #eef0ff; color: #4b3fb8; }
.drop { display: flex; align-items: center; gap: 18px; padding: 22px 24px; border: 2px dashed #b8d3c3; border-radius: var(--radius);
  background: linear-gradient(180deg, #fbfdfc, #f2f8f4); cursor: pointer; transition: .15s; margin-bottom: 18px; }
.drop:hover, .drop.over { border-color: var(--brand-2); background: var(--brand-3); }
.drop input { display: none; }
.drop .big { width: 54px; height: 54px; border-radius: 14px; background: var(--brand-2); color: #fff; display: grid; place-items: center; flex: none; }
.drop .big svg { width: 26px; height: 26px; }
.drop strong { font-size: 15.5px; display: block; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.filters { display: flex; gap: 4px; background: var(--line-2); padding: 3px; border-radius: 9px; }
.filters button { border: 0; background: transparent; font: inherit; font-size: 12.5px; font-weight: 600; color: var(--muted); padding: 5px 11px; border-radius: 7px; cursor: pointer; }
.filters button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.search { position: relative; } .search input { padding-left: 32px; width: 230px; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 15px; color: var(--muted); }
.bulkbar { display: none; gap: 8px; align-items: center; flex-wrap: wrap; padding: 10px 16px; background: #f7faf8; border-bottom: 1px solid var(--line); }
.bulkbar.show { display: flex; }
.bulkbar input { padding: 6px 9px; font-size: 13px; }
.list { width: 100%; border-collapse: collapse; }
.list th { text-align: left; font-size: 11.5px; letter-spacing: .4px; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line); background: #fafcfb; }
.list td { padding: 13px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.list tr:hover td { background: #fafcfb; }
.list .t { font-weight: 600; color: var(--ink); line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; max-width: 520px; }
.list .n { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.list .msg { font-size: 12px; color: var(--muted); max-width: 240px; margin-top: 4px; }
.list .acts { text-align: right; white-space: nowrap; }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty svg { width: 44px; height: 44px; color: #b5c9bd; }

/* ---------- editor */
.ed-top { position: sticky; top: 0; z-index: 20; background: rgba(244,247,245,.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
  padding: 12px 24px; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.ed-top .title { min-width: 0; flex: 1; }
.ed-top .title b { font-size: 16px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ed-top .title span { font-size: 12.5px; color: var(--muted); }
.ed { display: grid; grid-template-columns: minmax(520px, 1fr) minmax(420px, 46%); gap: 18px; padding: 18px 24px 40px; align-items: start; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); padding: 0 16px; }
.tabs button { border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted); padding: 12px 12px 10px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; display: flex; gap: 7px; align-items: center; }
.tabs button.on { color: var(--brand); border-color: var(--brand-2); }
.tabs .count { background: var(--line-2); color: var(--ink-2); border-radius: 10px; font-size: 11px; padding: 1px 7px; }
.pane { display: none; padding: 18px 20px; } .pane.on { display: block; }
.sec { margin-bottom: 22px; } .sec > h3 { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.preview { position: sticky; top: 76px; display: flex; flex-direction: column; height: calc(100vh - 96px); overflow: hidden; }
.preview .head { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.preview iframe { flex: 1; width: 100%; border: 0; background: #e8ece9; }
.preview .placeholder { flex: 1; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 30px; background: repeating-linear-gradient(45deg, #f5f7f6, #f5f7f6 12px, #f0f3f1 12px, #f0f3f1 24px); }
.preview .foot { border-top: 1px solid var(--line); padding: 10px 14px; max-height: 32%; overflow: auto; font-size: 12.5px; }
.journal-line { background: var(--brand-3); border: 1px solid #cfe6d8; color: var(--brand-ink); border-radius: 10px; padding: 10px 12px; font-size: 12.5px; line-height: 1.6; }

.blocks { display: flex; flex-direction: column; gap: 6px; }
.blk { border: 1px solid var(--line); border-radius: 10px; background: #fff; position: relative; transition: .1s; }
.blk:hover { border-color: #c9d6ce; }
.blk.focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(18,129,74,.1); }
.blk .bh { display: flex; align-items: center; gap: 6px; padding: 5px 8px 0; }
.blk .bh select { font-size: 11.5px; font-weight: 600; padding: 3px 6px; border-radius: 6px; border-color: transparent; background: var(--line-2); color: var(--ink-2); }
.blk .bh .tools { margin-left: auto; display: flex; gap: 2px; opacity: 0; transition: .1s; }
.blk:hover .tools, .blk.focus .tools { opacity: 1; }
.blk .bh .tools button { border: 0; background: none; padding: 4px; border-radius: 6px; cursor: pointer; color: var(--muted); display: grid; place-items: center; }
.blk .bh .tools button:hover { background: var(--line-2); color: var(--ink); }
.blk .bh .tools svg { width: 15px; height: 15px; }
.blk .bb { padding: 4px 12px 10px; }
.ce { outline: none; min-height: 1.5em; font-family: Garamond, "EB Garamond", Georgia, serif; font-size: 15.5px; line-height: 1.5; color: #222; }
.ce:empty::before { content: "Type here..."; color: #aab5ae; }
.r-h1 .ce { font-weight: 700; text-transform: uppercase; }
.r-h2 .ce { font-weight: 700; } .r-h3 .ce { font-weight: 700; font-style: italic; }
.r-caption_table .ce, .r-caption_figure .ce { color: #7a5000; }
.r-note .ce { font-style: italic; font-size: 14px; }
.r-ref .ce { padding-left: 22px; text-indent: -22px; font-size: 14.5px; }
.r-ref_head .ce { font-weight: 700; }
.r-skip { opacity: .5; } .r-skip .ce { text-decoration: line-through; }
.r-list .ce { padding-left: 14px; }
.blk.r-h1 { border-left: 4px solid var(--brand); } .blk.r-h2, .blk.r-h3 { border-left: 4px solid #4fae7c; }
.blk.r-caption_table, .blk.r-caption_figure { border-left: 4px solid #e0a82e; }
.blk.r-table, .blk.r-figure, .blk.r-equation { border-left: 4px solid #3b82c4; }
.blk.r-ref, .blk.r-ref_head { border-left: 4px solid #9aa8a0; }
.blk.r-skip { border-left: 4px solid #e6b3ae; }
.eqchip, .picchip { display: inline-block; font: 600 11.5px var(--font); background: #e9f1fb; color: #1d5aa6; border-radius: 5px; padding: 0 6px; margin: 0 1px; user-select: none; }
.etable { border-collapse: collapse; width: 100%; font-family: Garamond, Georgia, serif; font-size: 14px; }
.etable td { border: 1px solid #cfd8d2; padding: 4px 7px; vertical-align: top; min-width: 30px; outline: none; }
.etable td:focus { background: #f2f9f5; box-shadow: inset 0 0 0 2px var(--brand-2); }
.etable tr:first-child td { font-weight: 600; background: #fafcfb; }
.tablewrap { overflow-x: auto; }
.fig { display: flex; gap: 14px; align-items: flex-start; }
.fig img { max-width: 220px; max-height: 170px; border: 1px solid var(--line); border-radius: 8px; background: #fafafa; }
.eqsrc { font-family: Consolas, monospace; font-size: 12.5px; }
.ins { display: flex; justify-content: center; height: 6px; position: relative; }
.ins .add { position: absolute; top: -9px; opacity: 0; transition: .1s; display: flex; gap: 4px; }
.ins:hover .add { opacity: 1; }
.ins .add button { font: 600 11px var(--font); border: 1px solid #cfe0d6; background: #fff; color: var(--brand); border-radius: 12px; padding: 1px 9px; cursor: pointer; }
.fmtbar { position: fixed; z-index: 50; display: none; gap: 2px; background: #10251a; padding: 4px; border-radius: 9px; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.fmtbar button { border: 0; background: none; color: #fff; font: 600 13px var(--font); min-width: 28px; height: 28px; border-radius: 6px; cursor: pointer; }
.fmtbar button:hover { background: rgba(255,255,255,.14); }
.savestate { font-size: 12px; color: var(--muted); }
.savestate.dirty { color: var(--warn); font-weight: 600; }
.warnlist { margin: 0; padding-left: 18px; color: #7a5000; }
.versions { display: flex; gap: 6px; flex-wrap: wrap; }
.versions a { font-size: 12px; padding: 3px 9px; border-radius: 14px; background: var(--line-2); color: var(--ink-2); }
.versions a.on { background: var(--brand-2); color: #fff; }
.spinner { width: 15px; height: 15px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); background: #10251a; color: #fff; padding: 11px 18px; border-radius: 10px; font-weight: 500; opacity: 0; transition: .2s; z-index: 100; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: #8c1d14; }

/* ---------- journals */
.jgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.jcard { display: flex; gap: 12px; padding: 12px; cursor: pointer; transition: .12s; }
.jcard:hover { border-color: #b9d3c3; transform: translateY(-1px); }
.jcard img, .jcard .nocov { width: 64px; height: 88px; object-fit: cover; border-radius: 6px; flex: none; border: 1px solid var(--line); }
.jcard .nocov { display: grid; place-items: center; background: var(--line-2); color: var(--muted); font-size: 10.5px; text-align: center; }
.jcard b { display: block; font-size: 13.5px; line-height: 1.35; }
.jcard .meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.modal { position: fixed; inset: 0; background: rgba(10, 25, 17, .45); display: none; align-items: flex-start; justify-content: center; padding: 50px 16px; z-index: 60; overflow: auto; }
.modal.show { display: flex; }
.modal .box { width: 720px; max-width: 100%; }
.modal .box header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal .box .body { padding: 18px 20px; }
.modal .box footer { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- login & help */
.login { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(circle at 20% 10%, #12814a 0, #0b2f1c 55%); padding: 20px; }
.login .card { width: 380px; max-width: 100%; padding: 30px; }
.help h2 { margin-top: 22px; } .help li { margin: 5px 0; }
.steps { counter-reset: s; list-style: none; padding: 0; display: grid; gap: 10px; }
.steps li { counter-increment: s; display: flex; gap: 12px; align-items: flex-start; }
.steps li::before { content: counter(s); flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--brand-2); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; }

@media (max-width: 1150px) { .ed { grid-template-columns: 1fr; } .preview { position: static; height: 80vh; } .stats { grid-template-columns: 1fr 1fr; } }
@media (max-width: 760px) { .side { display: none; } .content, .top { padding-left: 16px; padding-right: 16px; } .grid3, .grid4 { grid-template-columns: 1fr 1fr; } }

/* form grids never overflow their card */
.grid2 > *, .grid3 > *, .grid4 > * { min-width: 0; }
label.f input, label.f select, label.f textarea { width: 100%; min-width: 0; }
#pane-details .grid4 { grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); }
