:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #e2e5ea;
  --text: #1e2530;
  --muted: #7a8494;
  --accent: #0b6bcb;
  --accent-soft: #e8f1fb;
  --danger: #c0392b;
  --dev: #2e7d4f;
  --prod: #b03a2e;
  --radius: 8px;
}
* { box-sizing: border-box; margin: 0; }
body {
  font: 14px/1.45 'Inter', -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--text); height: 100vh; overflow: hidden;
}
.hidden { display: none !important; }
.logo { color: var(--accent); }
.muted { color: var(--muted); }

/* ================================================= login */
.login-wrap { height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 30px 34px; width: 360px; display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 8px 34px rgba(20,30,50,.12);
}
.login-card h1 { font-size: 17px; text-align: center; margin-bottom: 6px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 12px;
                    color: var(--muted); font-weight: 600; }
.login-card input {
  height: 34px; border: 1px solid var(--border); border-radius: 7px; padding: 0 10px;
  font: inherit; color: var(--text);
}

/* ================================================= shell / top menu */
.app { height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 10px 16px;
  background: var(--panel); border-bottom: 1px solid var(--border); flex: none;
}
.brand { font-weight: 700; font-size: 15px; white-space: nowrap; flex: none; }
.topnav { display: flex; gap: 8px; flex: none; }
.btn.nav { border-color: transparent; color: var(--muted); }
.btn.nav.active, .btn.nav:hover { color: var(--text); background: #f2f5f8; }
.filters { display: flex; gap: 8px; flex: 1; min-width: 0; max-width: 640px; }
.filters select, .filters input {
  height: 32px; padding: 0 10px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; font: inherit; color: inherit; min-width: 60px; flex: 1;
}
.filters input { flex: 1.5; }
.env-ctrl { display: flex; align-items: center; gap: 8px; flex: none; margin-left: auto; }
.env-ctrl select { height: 30px; border: 1px solid var(--border); border-radius: 6px;
                   background: #fff; font: inherit; }
.badge { font-size: 11.5px; font-weight: 700; letter-spacing: .5px; padding: 3px 12px;
         border-radius: 20px; border: 1px solid var(--border); white-space: nowrap; }
.badge.dev  { color: var(--dev);  background: #eef8f1; border-color: #bfe0cc; }
.badge.prod { color: #fff; background: var(--prod); border-color: var(--prod); }
.user-ctrl { display: flex; align-items: center; gap: 10px; flex: none; }

/* ================================================= layout / views */
.layout { flex: 1; min-height: 0; display: flex; }
.view { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; }

/* ================================================= BROWSE : cards */
.browse-head {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 16px 26px 6px;
}
.browse-head h2 { font-size: 16px; }
.sort { font-size: 12.5px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.sort select { height: 30px; border: 1px solid var(--border); border-radius: 6px; background: #fff; font: inherit; }

.card-grid {
  flex: 1; overflow-y: auto; padding: 12px 26px 30px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 18px;
  grid-auto-rows: max-content; align-content: start;
}
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden; cursor: pointer; display: flex; flex-direction: column;
  transition: box-shadow .12s, transform .12s; position: relative;
}
.card:hover { box-shadow: 0 6px 18px rgba(20,30,50,.13); transform: translateY(-2px); }
.card .thumb {
  background: #eceef2; display: flex; align-items: center; justify-content: center;
  padding: 12px 0; height: 180px;
}
.card .mini-page {
  position: relative; background: #fff; box-shadow: 0 1px 5px rgba(20,30,50,.18);
  border-radius: 1px; overflow: hidden;
}
.card .mini-block { position: absolute; border: 1px dashed #aab4c3; border-radius: 2px;
                    background: rgba(240,244,249,.6); overflow: hidden; }
.card .mini-block svg { width: 100%; height: 100%; }
.card .report-thumb {
  max-height: 156px; max-width: 88%; border-radius: 1px;
  box-shadow: 0 1px 5px rgba(20,30,50,.18); background: #fff;
}
.card .pages-badge {
  position: absolute; top: 8px; right: 8px; font-size: 10.5px; background: rgba(30,37,48,.72);
  color: #fff; border-radius: 9px; padding: 1px 7px;
}
.card .edit-btn { position: absolute; top: 8px; left: 8px; opacity: 0; transition: opacity .12s; }
.card:hover .edit-btn { opacity: 1; }
.card .meta { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 3px; }
.card .c-name { font-weight: 650; font-size: 13px; line-height: 1.3; }
.card .c-sub { font-size: 11.5px; color: var(--muted); }
.card .c-tags { display: flex; gap: 6px; align-items: center; margin-top: 3px; flex-wrap: wrap; }
.tag-type { font-size: 10px; font-weight: 700; letter-spacing: .4px; border-radius: 8px; padding: 1px 8px; }
.tag-type.VARIANT  { background: #e3f2e8; color: #2e7d4f; }
.tag-type.PROJECT  { background: #e8f1fb; color: #0b6bcb; }
.tag-type.ARCHIVED { background: #eeeeee; color: #888; }
.tag-type.none     { background: #f2f2f2; color: #aaa; }
.proj-pin { font-size: 11px; color: var(--accent); display: inline-flex; align-items: center; gap: 3px;
            max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-grid { color: var(--muted); padding: 40px; text-align: center; grid-column: 1/-1; }

/* ================================================= EDIT view */
.edit-toolbar {
  display: flex; align-items: center; gap: 14px;
  padding: 8px 18px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.tb-left { flex: none; display: flex; align-items: center; }
.tb-center { flex: 1; min-width: 0; text-align: center;
             overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tb-right { flex: none; display: flex; gap: 8px; }
.rpt-title { font-weight: 700; }
.rpt-meta { color: var(--muted); font-size: 12px; margin-left: 8px; }
.grp { font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; white-space: nowrap; }
.grp select { height: 30px; border: 1px solid var(--border); border-radius: 6px; background: #fff;
              font: inherit; width: 150px; }

.page-tabs { display: flex; gap: 6px; padding: 8px 18px 0; background: var(--bg); }
.page-tabs button {
  border: 1px solid var(--border); background: var(--panel); border-radius: 6px 6px 0 0;
  padding: 4px 14px; cursor: pointer; font: inherit; color: var(--muted);
}
.page-tabs button.active { color: var(--text); font-weight: 600; }

.edit-body { flex: 1; min-height: 0; display: flex; }
.canvas-wrap { flex: 1; min-width: 0; overflow: auto; display: flex;
               justify-content: center; align-items: center; padding: 26px; }
.page {
  position: relative; background: white; box-shadow: 0 2px 14px rgba(20,30,50,.12);
  border-radius: 2px; flex: none;
}

/* blocks on canvas */
.block {
  position: absolute; border: 1.5px dashed #93a0b4; border-radius: 4px;
  background: rgba(240,244,249,.55); cursor: move; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 4px; user-select: none;
}
.block:hover { border-color: var(--accent); }
.block.selected { border-style: solid; border-color: var(--accent); background: rgba(11,107,203,.06); }
.block .b-type { font-size: 10px; color: var(--muted); pointer-events: none; }
.block .b-ds   { font-size: 10px; color: var(--accent); pointer-events: none; }
.block .b-text { font-size: 10px; color: #3c4657; pointer-events: none; max-height: 100%; overflow: hidden; }
.block .b-glyph { flex: 1; width: 100%; min-height: 0; pointer-events: none;
                  display: flex; align-items: center; justify-content: center; }
.block .b-glyph svg { width: 92%; height: 92%; }
.block .b-foot {
  flex: none; width: 100%; pointer-events: none; text-align: center;
  font-size: 10px; color: #3c4657; padding: 1px 4px 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.block .b-foot b { font-size: 10.5px; }
.block .b-foot .b-type, .block .b-foot .b-ds { margin-left: 5px; }
.block .handle {
  position: absolute; right: -5px; bottom: -5px; width: 11px; height: 11px;
  background: var(--accent); border-radius: 3px; cursor: nwse-resize; display: none;
}
.block.selected .handle { display: block; }

/* ================================================= Block Format pane */
.block-pane {
  width: 300px; flex: none; background: var(--panel); border-left: 1px solid var(--border);
  overflow-y: auto;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px;
}
.panel-head h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }

.form { padding: 4px 16px 20px; display: flex; flex-direction: column; gap: 10px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.form input, .form select, .form textarea {
  height: 30px; border: 1px solid var(--border); border-radius: 6px; padding: 0 8px;
  font: inherit; color: var(--text); width: 100%;
}
.form textarea { height: auto; padding: 6px 8px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
fieldset.geom { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px 10px; }
fieldset.geom legend { font-size: 11px; font-weight: 700; color: var(--muted);
                       text-transform: uppercase; letter-spacing: .5px; padding: 0 4px; }

.type-picker { position: relative; }
.type-current {
  width: 100%; display: flex; align-items: center; gap: 10px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 6px; background: #fff; padding: 5px 8px; font: inherit;
}
.type-current .tp-glyph, .type-option .tp-glyph {
  width: 44px; height: 30px; flex: none; background: #f4f6f9; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
}
.type-current .tp-glyph svg, .type-option .tp-glyph svg { width: 90%; height: 90%; }
.type-current::after { content: '▾'; margin-left: auto; color: var(--muted); }
.type-menu {
  position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; right: 0;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 26px rgba(20,30,50,.18); max-height: 320px; overflow-y: auto; padding: 4px;
}
.type-option {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 5px 8px;
  border: 0; background: none; font: inherit; cursor: pointer; border-radius: 6px; text-align: left;
}
.type-option:hover { background: var(--accent-soft); }
.type-option.selected { background: var(--accent-soft); font-weight: 600; }

/* ================================================= buttons / modals */
.btn {
  height: 32px; padding: 0 14px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--panel); font: inherit; font-weight: 600; cursor: pointer; color: var(--text);
  white-space: nowrap;
}
.btn:hover { background: #f2f5f8; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #095cb0; }
.btn.primary:disabled { opacity: .55; cursor: not-allowed; }
.btn.danger { color: var(--danger); border-color: #ecc8c3; }
.btn.sm { height: 26px; padding: 0 10px; font-size: 12.5px; }

.modal {
  position: fixed; inset: 0; background: rgba(18,26,38,.45);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-box {
  background: var(--panel); border-radius: 12px; padding: 20px 22px; width: 420px;
  box-shadow: 0 10px 40px rgba(0,0,0,.25); max-height: 92vh; display: flex; flex-direction: column;
}
.modal-box h3 { margin-bottom: 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

.status { font-size: 12.5px; min-height: 18px; color: var(--muted); }
.status.err { color: var(--danger); }

/* ================================================= live preview / thumbnails */
.live-ctrl { display: inline-flex; gap: 6px; align-items: center; margin-left: 12px; flex: none; }
.live-sel {
  height: 28px; width: 150px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; font: inherit; font-size: 12.5px;
}
#btn-live.on { background: var(--accent); border-color: var(--accent); color: #fff; }
#btn-live-refresh.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.page img.ghost { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.block.ghosted { background: transparent; border-color: rgba(147,160,180,.5); }
.block.ghosted .b-glyph, .block.ghosted .b-foot,
.block.ghosted .b-text, .block.ghosted .b-thumb { opacity: .1; }
.block.ghosted:hover { border-color: var(--accent); }
.block.ghosted.selected { border-color: var(--accent); background: rgba(11,107,203,.05); }
.block .b-thumb {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: fill; pointer-events: none;
}
.block .b-foot.overlay {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: rgba(255,255,255,.82); border-top: 1px solid rgba(147,160,180,.25);
}

/* ================================================= preview modal */
.modal-box.wide { width: min(1060px, 94vw); height: 88vh; }
.preview-body { flex: 1; display: flex; gap: 16px; min-height: 0; }
.scenario-col { width: 290px; display: flex; flex-direction: column; gap: 10px; }
.scenario-col h4 { font-size: 12px; text-transform: uppercase; color: var(--muted); letter-spacing: .5px; }
.scenario-list { flex: 1; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 8px; }
.scenario-list label { display: flex; gap: 8px; align-items: baseline; padding: 4px 2px; font-size: 12.5px; cursor: pointer; }
.scenario-list .s-id { color: var(--muted); font-size: 11px; }
.scenario-list label.no-run { opacity: .5; cursor: not-allowed; }
.scenario-list .tag {
  font-size: 10px; color: var(--muted); border: 1px solid var(--border);
  border-radius: 8px; padding: 0 6px; margin-left: 4px; vertical-align: 1px;
}
.proj-select {
  height: 32px; border: 1px solid var(--border); border-radius: 6px; padding: 0 8px;
  font: inherit; color: var(--text); background: #fff; width: 100%;
}
.pdf-frame { flex: 1; border: 1px solid var(--border); border-radius: 8px; background: #fafbfc; }
