:root {
  --bg: #f4f5f7; --card: #fff; --ink: #1d2230; --muted: #6b7280; --line: #e3e6eb;
  --accent: #3559e0; --ok: #1f9d55; --ok-bg: #e3f6eb; --warn: #b7791f; --warn-bg: #fdf3dc;
  --bad: #c53030; --bad-bg: #fde8e8; --photo: #9cc3f5; --text: #eef0f3;
  --ad-free: #f2c9a0; --ad-res: #f6dd6e; --ad-conf: #79d19c; --ad-tpl: #f0b27a;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1, h2, h3 { margin: 0 0 6px; line-height: 1.2; }
h2 { font-size: 20px; } h3 { font-size: 16px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.pad { padding: 20px; }
.err { color: var(--bad); }
input, select, textarea { font: inherit; color: inherit; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: #fff; max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #c7d3ff; border-color: var(--accent); }
textarea { width: 100%; }
label { display: flex; flex-direction: column; gap: 4px; margin: 0 0 10px; font-size: 13px; color: var(--muted); }
label input, label textarea { color: var(--ink); }
.num { width: 70px; } .num.w { width: 90px; }
.btn { font: inherit; border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 7px 14px; cursor: pointer; }
.btn:hover { border-color: #b9c0cc; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.ic { border: 0; background: none; cursor: pointer; padding: 2px 6px; border-radius: 4px; font-size: 14px; color: var(--muted); }
.ic:hover { background: var(--bg); color: var(--ink); } .ic.del:hover { color: var(--bad); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; align-items: flex-start; }
.row.end { justify-content: flex-end; margin-top: 12px; }
.grow { flex: 1; }
.nowrap { white-space: nowrap; }
.r { text-align: right; }

/* galvene */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 8px 16px; background: #1d2230; color: #fff; }
.brand { font-weight: 700; }
#tabs { display: flex; gap: 2px; }
#tabs button { background: none; border: 0; color: #c4c9d4; padding: 8px 12px; border-radius: 6px; cursor: pointer; font: inherit; }
#tabs button.on, #tabs button:hover { background: #2f3647; color: #fff; }
.top .right { margin-left: auto; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.top .muted { color: #9aa1af; }
.top select { background: #2f3647; color: #fff; border-color: #444c60; }

main#app { max-width: 1280px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 14px; }
.card.narrow { max-width: 560px; }
.issuebar label { margin: 0; }
.issuebar #iName { width: 220px; }

/* rādītāji */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; margin-bottom: 14px; }
.stats .card { margin: 0; }
.stat .k { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.stat .v { font-size: 26px; font-weight: 700; margin: 2px 0 6px; }
.stat .v small { font-size: 14px; font-weight: 500; color: var(--muted); }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.warn-t { color: var(--warn); }
.st { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12.5px; font-weight: 600; }
.st.ok { background: var(--ok-bg); color: var(--ok); }
.st.warn { background: var(--warn-bg); color: var(--warn); }
.st.bad { background: var(--bad-bg); color: var(--bad); }
.meter { position: relative; height: 10px; background: var(--bg); border-radius: 99px; margin-top: 10px; overflow: hidden; }
.meter .fill { height: 100%; background: var(--accent); border-radius: 99px; }
.meter .band { position: absolute; top: 0; height: 100%; background: rgba(31, 157, 85, .25); }
.meter .mark { position: absolute; top: 0; width: 2px; height: 100%; background: var(--ok); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin: 0 4px 0 8px; vertical-align: -1px; }
.dot.free { background: var(--ad-free); } .dot.reserved { background: var(--ad-res); } .dot.confirmed { background: var(--ad-conf); } .dot.ph { background: var(--photo); }
.hint .dot:first-child { margin-left: 0; }
.legend { font-size: 12px; color: var(--muted); }

/* lapas zīmējums (A5 proporcija) */
.pg { position: relative; width: 74px; aspect-ratio: 148 / 210; background: #fff; border: 1px solid #c9ced8; overflow: hidden; flex: none; }
.pg i { position: absolute; display: block; }
.pg .tx { background: repeating-linear-gradient(to bottom, var(--text) 0 2px, transparent 2px 5px); background-clip: content-box; padding: 6%; }
.pg .ph { background: var(--photo); border: 1px solid #fff; }
.pg .ad { background: var(--ad-tpl); border: 1px solid #fff; display: flex; align-items: center; justify-content: center; }
.pg .ad.free { background: repeating-linear-gradient(45deg, var(--ad-free) 0 5px, #f7dcc0 5px 10px); }
.pg .ad.reserved { background: var(--ad-res); } .pg .ad.confirmed { background: var(--ad-conf); }
.pg .ad span { font-size: 10px; font-weight: 700; color: rgba(0, 0, 0, .55); }
.pg .lbl { position: absolute; left: 2px; top: 2px; color: #fff; font-size: 9px; padding: 0 3px; border-radius: 3px; line-height: 14px; }
.pg.sm { width: 40px; } .pg.sm .ad span { font-size: 8px; }
.pg.empty { border: 1px dashed transparent; background: none; }
.spreads { display: flex; flex-wrap: wrap; gap: 14px 18px; margin-top: 8px; }
.spread { display: flex; box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }
.spread .pg[data-goto] { cursor: pointer; }
.spread .pg + .pg { border-left-color: #8a92a3; }
.prev .pg { width: 180px; }

/* bloki */
.block { border-left: 5px solid var(--bc); }
.block .desc { margin: 2px 0 0; white-space: pre-line; }
.pill { display: inline-block; background: var(--bg); padding: 2px 8px; border-radius: 99px; font-size: 12.5px; margin-left: 4px; }
.tblwrap { overflow-x: auto; margin-top: 10px; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); }
td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tfoot td { border-bottom: 0; font-weight: 600; }
td.sub { color: var(--muted); font-size: 12.5px; padding-top: 14px; }
table.pages td.thumb { width: 52px; }
table.pages input.note { margin-top: 3px; width: 150px; padding: 3px 6px; font-size: 12.5px; }
table.pages select { max-width: 230px; }
table.pages input[type=range] { width: 110px; vertical-align: middle; }
tr.flash td { background: #fff7cf; transition: background .3s; }
.chip { display: inline-block; padding: 1px 8px; border-radius: 99px; background: var(--bg); font-size: 12.5px; margin: 1px 0; }
.chip.free { background: #fbe9d8; } .chip.reserved { background: #fcf1bf; } .chip.confirmed { background: var(--ok-bg); }
.chip .x { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0 0 0 4px; }
.addpage { margin-top: 10px; font-size: 13px; color: var(--muted); }
.stsel.free { background: #fbe9d8; } .stsel.reserved { background: #fcf1bf; } .stsel.confirmed { background: var(--ok-bg); }
.adtbl input:not(.num) { width: 200px; }

/* templeiti */
.tplgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; margin-top: 10px; }
.tpl { display: flex; gap: 14px; margin: 0; }
.tpl .pg { width: 90px; }
.tplinfo { flex: 1; min-width: 0; }
.tplinfo .row { margin-top: 10px; }
.adbtns { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.lbl2 { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.twocol { display: grid; grid-template-columns: 1fr auto; gap: 20px; }

/* modālais logs, paziņojumi */
.modal { position: fixed; inset: 0; background: rgba(15, 20, 30, .45); display: flex; align-items: flex-start; justify-content: center; padding: 60px 16px; z-index: 50; overflow: auto; }
.modal-box { background: #fff; border-radius: 12px; padding: 20px; width: 100%; max-width: 640px; }
.hidden { display: none !important; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1d2230; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 60; }
.toast.bad { background: var(--bad); }

.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login .card { width: 100%; max-width: 360px; }
.login input { width: 100%; }
.login .btn { width: 100%; margin-top: 6px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

@media (max-width: 700px) {
  .top { padding: 8px; gap: 8px; position: static; }
  main#app { padding: 10px; }
  .twocol { grid-template-columns: 1fr; }
  .issuebar #iName { width: 100%; }
}
@media print {
  .top, .addpage, .ic, #bNew, .issuebar .btn { display: none !important; }
  body { background: #fff; }
}
