/* hypmap — веб. Стиль §5 SPEC: белый, акцент #0088FF, полоска типа слева, скругления 12–16, без теней. */
:root {
  --bg: #FFFFFF;
  --surface: #F2F2F7;
  --surface2: #F9F9FB;
  --text: #000000;
  --muted: #636366;
  --accent: #0088FF;
  --accent-bg: #E0F4FF;
  --accent-dark: #155980;
  --error: #D62516;
  --error-bg: #FDECEA;
  --success: #34C759;
  --warn: #FF9500;
  --warn-bg: #FFF4E5;
  --r: 12px;
  --r2: 16px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
#app { height: 100%; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; margin: 18px 0 8px; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1; }
.loading { padding: 40px; color: var(--muted); text-align: center; }
.error-text { color: var(--error); min-height: 18px; font-size: 13px; }
.hint { color: var(--muted); font-size: 12px; }
kbd { background: var(--surface); border-radius: 6px; padding: 1px 6px; font: 12px ui-monospace, monospace; }

button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--surface);
  border: 0;
  border-radius: var(--r);
  padding: 7px 12px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { background: #E8E8EE; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: #fff; }
button.primary:hover { background: #0077E0; }
button.danger { background: var(--error-bg); color: var(--error); }
button.link { background: none; color: var(--accent); padding: 4px 6px; }
button.link:hover { text-decoration: underline; }
button.icon { background: none; padding: 2px 8px; font-size: 18px; line-height: 1; color: var(--muted); }
button.on { background: var(--accent-bg); color: var(--accent-dark); }
input, select, textarea {
  background: var(--surface2);
  border: 1px solid var(--surface);
  border-radius: var(--r);
  padding: 8px 10px;
  width: 100%;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); background: #fff; }
textarea { resize: vertical; }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.row-form { display: flex; gap: 8px; }
.row-btns { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.check { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--surface); border-radius: 10px; padding: 3px 10px; font-size: 12px; }
.chip.warn { background: var(--warn-bg); color: #8a5300; }
.spin { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--accent); border-right-color: transparent; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- логин и список карт --- */
.login { display: grid; place-items: center; height: 100%; padding: 16px; }
.login-box { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }
.maps { max-width: 760px; margin: 0 auto; padding: 32px 16px; display: flex; flex-direction: column; gap: 16px; }
.maps-list { display: flex; flex-direction: column; gap: 8px; }
.map-item { background: var(--surface2); border-radius: var(--r2); padding: 12px 16px; border-left: 4px solid var(--accent); }
.map-item.archived { border-left-color: var(--muted); opacity: .75; }
.map-title { font-size: 16px; font-weight: 600; color: var(--text); text-decoration: none; }
.map-title:hover { color: var(--accent); }
.map-actions { margin-top: 4px; display: flex; gap: 4px; margin-left: -6px; }

/* --- экран карты --- */
.mapscreen { display: flex; flex-direction: column; height: 100%; }
.top { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--surface); flex-wrap: wrap; }
.back { color: var(--accent); text-decoration: none; white-space: nowrap; }
.top-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.top-more { display: none; position: relative; }
.top-more > summary { list-style: none; cursor: pointer; padding: 6px 12px; border-radius: var(--r); background: var(--surface); font-size: 18px; line-height: 1; user-select: none; }
.top-more > summary::-webkit-details-marker { display: none; }
.top-more[open] > summary { background: #E8E8EE; }
.top-menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 50; display: flex; flex-direction: column; gap: 4px; min-width: 210px; padding: 6px; background: var(--bg); border-radius: var(--r); box-shadow: 0 6px 24px rgba(0, 0, 0, .18); }
.top-menu button { text-align: left; background: none; }
.top-menu button:hover { background: var(--surface); }
.map-name { font-size: 17px; max-width: 32ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seg { display: inline-flex; background: var(--surface); border-radius: var(--r); padding: 2px; gap: 2px; }
.seg button { background: none; padding: 5px 12px; border-radius: 10px; }
.seg button.on { background: #fff; color: var(--text); font-weight: 600; }
.seg.wrap { flex-wrap: wrap; }
.seg.wrap button.on { color: var(--c, var(--accent)); }
.jobs { display: flex; gap: 6px; flex-wrap: wrap; }
.split { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(340px, 34%); min-height: 0; }
.left { display: flex; flex-direction: column; min-width: 0; min-height: 0; border-right: 1px solid var(--surface); }
.left-body { flex: 1; overflow: auto; min-height: 0; position: relative; }
.right { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.right-body { flex: 1; overflow: auto; padding: 12px 16px 24px; }
.keys { padding: 6px 16px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--surface); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.empty { padding: 32px 24px; }

.leftbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--surface); }
.crumbs { display: flex; align-items: center; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; }
.crumb { background: none; padding: 3px 8px; color: var(--muted); font-size: 13px; }
.crumb.on { color: var(--text); font-weight: 600; background: none; }
.crumb-sep { color: var(--muted); }
.filter { padding: 8px 12px; border-bottom: 1px solid var(--surface); display: flex; flex-direction: column; gap: 6px; background: var(--surface2); }
.filter-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.filter-row > .muted { width: 50px; }
.fchip { padding: 3px 10px; font-size: 12px; background: #fff; border-left: 3px solid var(--c, var(--muted)); }
.fchip.on { background: var(--accent-bg); color: var(--accent-dark); }

/* --- дерево --- */
.tree { padding: 8px 8px 40px; }
.section-title { margin: 16px 8px 6px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.mapq { margin: 4px 8px 8px; background: var(--warn-bg); color: #8a5300; font-size: 13px; }
.trow { display: flex; align-items: flex-start; gap: 2px; padding-left: calc(var(--depth) * 22px); margin: 2px 0; border-radius: var(--r); }
.trow .caret { background: none; width: 22px; padding: 8px 0; color: var(--muted); font-size: 12px; flex: none; }
.tcard { position: relative; flex: 1; min-width: 0; background: var(--bg); border-radius: var(--r); border: 1px solid transparent; padding: 6px 10px 6px 16px; cursor: pointer; }
.tcard::before { content: ""; position: absolute; left: 4px; top: 7px; bottom: 7px; width: 4px; border-radius: 2px; background: var(--c); }
.trow:hover .tcard { background: var(--surface2); }
.trow.sel .tcard { background: var(--accent-bg); border-color: var(--accent-bg); }
.tline { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.label { font-weight: 700; font-size: 12px; flex: none; }
.wording { flex: 0 1 auto; min-width: 0; overflow-wrap: anywhere; }
.motivation { color: var(--muted); font-size: 12px; margin-top: 2px; }
.status { font-size: 11px; color: var(--c); background: color-mix(in srgb, var(--c) 12%, #fff); border-radius: 8px; padding: 0 7px; white-space: nowrap; }
.badge { font-size: 11px; border-radius: 8px; padding: 0 7px; white-space: nowrap; background: var(--surface); color: var(--muted); }
.badge.rank { background: var(--accent-bg); color: var(--accent-dark); font-weight: 600; }
.badge.q { background: var(--warn-bg); color: #8a5300; font-weight: 600; }
.badge.ai { background: #F3E8FB; color: #7B2FA6; }
.badge.warn { background: var(--warn-bg); color: #8a5300; }
.chips, .atts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.mchip, .att { font-size: 12px; padding: 3px 8px; border-radius: 10px; background: var(--surface2); box-shadow: none; border: 0; white-space: normal; text-align: left; display: inline-flex; gap: 4px; align-items: baseline; flex-wrap: wrap; }
.mchip.sel, .att.sel { background: #fff; outline: 2px solid var(--accent); }
.mchip b, .att b { color: var(--c); }

/* перетаскивание */
body.dragging .trow.drop-invalid .tcard { border-color: color-mix(in srgb, var(--error) 35%, #fff); }
.trow.drop-bad .tcard { border-color: var(--error) !important; background: var(--error-bg) !important; }
.trow.drop-ok .tcard { border-color: var(--accent) !important; background: var(--accent-bg) !important; }
.trow.drop-before .tcard { box-shadow: inset 0 3px 0 var(--accent); }
.trow.drop-after .tcard { box-shadow: inset 0 -3px 0 var(--accent); }

/* --- доска «как в Holst» --- */
.board {
  position: absolute; inset: 0; overflow: hidden; cursor: grab; touch-action: none; user-select: none;
  background-color: #EFEFEF; background-image: radial-gradient(#D9D9D9 1px, transparent 1px); background-size: 18px 18px;
}
.board.panning { cursor: grabbing; }
.board-stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; font-size: 12px; line-height: 1.35; color: #1C1C1E; }
.board-measure { visibility: hidden; pointer-events: none; left: -100000px; }
.board-measure .bcard { position: static; }
.board-frame { position: absolute; background: #fff; border: 1px solid #D5D5D5; border-radius: 3px; }
.board-tab { position: absolute; background: #F4F4F4; border: 1px solid #D0D0D0; border-radius: 3px; padding: 1px 7px; font-size: 13px; color: #3A3A3C; white-space: nowrap; }
.board-name { position: absolute; font-size: 15px; color: #3A3A3C; }
.board-name small, .board-colh small { display: block; font-size: 9px; color: #8E8E93; font-weight: 400; margin-top: 1px; }
.board-colh { position: absolute; font-size: 13px; font-weight: 600; color: #3A3A3C; }
.board-edges { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.bcard {
  position: absolute; box-sizing: border-box; padding: 6px 8px 7px; border-radius: 2px; cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .14); overflow-wrap: anywhere;
}
.bcard:hover { box-shadow: 0 0 0 1px rgba(0, 0, 0, .28), 0 1px 2px rgba(0, 0, 0, .14); }
.bcard.sel { box-shadow: 0 0 0 2px var(--accent), 0 2px 8px rgba(0, 0, 0, .18); z-index: 1; }
.bcard.t-goal { font-size: 11px; }
.bline { white-space: pre-wrap; }
.bline.done { text-decoration: line-through; color: rgba(0, 0, 0, .55); }
.btitle { font-weight: 700; white-space: pre-wrap; }
.bhead { font-weight: 700; margin-top: 5px; }
.blist { margin: 0; padding-left: 18px; }
.blist li { padding-left: 1px; }
.bmetric.sel { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 2px; }
.bhyphead { display: flex; align-items: center; gap: 6px; margin-bottom: 2px; min-height: 16px; }
.bprio { min-width: 16px; height: 16px; padding: 0 3px; box-sizing: border-box; border-radius: 2px; color: #fff; font-weight: 700; font-size: 11px; display: inline-flex; align-items: center; justify-content: center; }
.bnum { color: rgba(0, 0, 0, .7); }
.bblock { color: #B71C1C; }
.bscore, .bmot { color: rgba(0, 0, 0, .6); font-size: 11px; margin-top: 3px; }
.bmot { font-style: italic; white-space: pre-wrap; }
.bmarks { float: right; display: inline-flex; gap: 3px; margin: 0 0 2px 6px; }
.bmark { font-size: 10px; font-weight: 600; padding: 0 5px; border-radius: 8px; background: rgba(255, 255, 255, .75); color: var(--muted); white-space: nowrap; }
.bmark.q, .bmark.warn { color: #8a5300; }
.bmark.ai { color: #7B2FA6; }
.bside {
  position: absolute; right: calc(100% + 6px); top: 22px; width: 54px; box-sizing: border-box;
  background: #E3E3E3; color: #636366; font-size: 8.5px; line-height: 1.2; padding: 3px 4px; border-radius: 2px;
}
.board-tools { position: absolute; right: 12px; bottom: 12px; display: flex; gap: 4px; }
.board-tools button { background: #fff; border: 1px solid #DADADA; min-width: 34px; }

/* доска на узком экране (< 700px): колонки со свайпом */
.bcols-wrap { position: absolute; inset: 0; display: flex; flex-direction: column; background: #EFEFEF; }
.bcols-tabs { display: flex; gap: 2px; padding: 6px 8px; background: #fff; border-bottom: 1px solid var(--surface); overflow-x: auto; }
.bcols-tabs button { background: none; padding: 4px 10px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.bcols-tabs button.on { background: var(--accent-bg); color: var(--accent-dark); font-weight: 600; }
.bcols {
  flex: 1; min-height: 0; display: flex; gap: 8px; padding: 0 8px; position: relative;
  overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory; overscroll-behavior-x: contain;
  scroll-padding: 0 8px; scrollbar-width: none;
}
.bcols::-webkit-scrollbar { display: none; }
.bcol {
  flex: 0 0 calc(93% - 8px); scroll-snap-align: start; overflow-y: auto; position: relative;
  padding: 8px 0 24px; font-size: 13px; line-height: 1.38; color: #1C1C1E; box-sizing: border-box;
}
.bcol-title { font-size: 15px; font-weight: 600; color: #3A3A3C; margin: 2px 2px 8px; }
.bcol-title small { display: block; font-size: 11px; font-weight: 400; color: #8E8E93; }
.bcol-empty { color: var(--muted); margin: 8px 2px; }
.bgroup { margin-bottom: 14px; }
.bgroup-head {
  display: block; width: 100%; text-align: left; background: #fff; border-left: 4px solid var(--c, #ccc);
  border-radius: 4px; padding: 3px 8px; margin-bottom: 6px; font-size: 12px; color: #48484A;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bgroup-head.none { border-left-color: #bbb; color: var(--muted); }
.bcol .bcard { position: relative; width: auto !important; margin-bottom: 8px; padding: 9px 11px 10px; }
.bcol .bcard.t-goal { font-size: 13px; }
.bcol .bside { position: static; display: inline-block; width: auto; margin-top: 6px; font-size: 11px; padding: 2px 6px; }
.bnext {
  display: inline-block; margin-top: 8px; padding: 3px 10px; font-size: 12px; border-radius: 12px;
  background: rgba(255, 255, 255, .8); color: var(--accent-dark);
}

/* --- правая панель --- */
.tabs { display: flex; gap: 4px; padding: 8px 12px; border-bottom: 1px solid var(--surface); }
.tabs button { background: none; }
.tabs button.on { background: var(--accent-bg); color: var(--accent-dark); font-weight: 600; }
.count { display: inline-block; margin-left: 6px; background: var(--accent); color: #fff; border-radius: 9px; font-size: 11px; padding: 0 6px; min-width: 18px; text-align: center; }

.card { border-left: 4px solid var(--c); padding-left: 12px; }
.card-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-head .label { font-size: 14px; }
.field { margin-top: 14px; }
.field-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.editable { padding: 6px 8px; margin: 0 -8px; border-radius: 10px; cursor: text; white-space: pre-wrap; overflow-wrap: anywhere; }
.editable:hover { background: var(--surface2); }
.editable.big { font-size: 16px; font-weight: 500; }
textarea.edit { font-size: 15px; }
.warnbox { margin-top: 10px; background: var(--warn-bg); color: #6b4000; border-radius: var(--r); padding: 8px 10px; font-size: 13px; }
.scores { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.score { display: flex; flex-direction: column; gap: 2px; }
.score b { padding: 8px 0; }
.quote { display: block; width: 100%; text-align: left; white-space: normal; background: var(--surface2); border-left: 3px solid var(--surface); border-radius: 10px; margin: 4px 0; font-style: italic; color: #333; }
.quote:hover { border-left-color: var(--accent); }
.link-row { display: flex; align-items: center; gap: 6px; margin: 3px 0; }
.ref { background: none; padding: 2px 6px; text-align: left; white-space: normal; border-left: 3px solid var(--c); border-radius: 2px 8px 8px 2px; font-size: 13px; }
.ref b { color: var(--c); }
.ref:hover { background: var(--surface2); }
.field select { margin-top: 6px; }
.hist { padding: 6px 0; border-bottom: 1px solid var(--surface); font-size: 13px; }
.hist.reverted { opacity: .6; }
.diff { color: var(--muted); margin: 2px 0 2px 10px; }
.card-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 22px; padding-top: 12px; border-top: 1px solid var(--surface); }

/* входящие */
.inbox-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.qcard, .pcard { background: var(--surface2); border-radius: var(--r2); padding: 10px 12px; margin: 8px 0; }
.qcard textarea { margin-top: 8px; }
.qhead { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.rule { font-size: 11px; color: var(--accent-dark); background: var(--accent-bg); border-radius: 8px; padding: 0 7px; }
.qtext { margin: 6px 0; }
.pitem { display: flex; gap: 10px; align-items: flex-start; padding: 8px; margin: 6px 0; background: #fff; border-radius: 2px var(--r) var(--r) 2px; border-left: 4px solid var(--c); cursor: pointer; }
.pitem input { margin-top: 4px; }
.basis { color: var(--muted); font-style: italic; margin-top: 2px; }
.pcard.prio { border: 1px solid var(--accent-bg); background: #FAFDFF; }
.pcard.prio h3 { margin-top: 2px; }
.formula code { background: #fff; border-radius: 6px; padding: 1px 6px; }
table.rank { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 13px; }
table.rank th { text-align: left; font-size: 11px; color: var(--muted); font-weight: 500; padding: 4px; }
table.rank td { padding: 6px 4px; border-top: 1px solid var(--surface); vertical-align: top; }
table.rank td.num { font-variant-numeric: tabular-nums; font-weight: 600; }
.flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: var(--accent-bg); } }

/* --- модалки и тосты --- */
#modal[hidden] { display: none; }
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .25); display: grid; place-items: start center; padding: 8vh 16px 16px; z-index: 10; overflow: auto; }
.modal-box { background: #fff; border-radius: var(--r2); width: 100%; max-width: 520px; padding: 16px 18px 18px; }
.modal-box.wide { max-width: 860px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.form { display: flex; flex-direction: column; gap: 10px; }
.form .field { margin-top: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; }
textarea.notes { min-height: 280px; }
.source-text { white-space: pre-wrap; background: var(--surface2); border-radius: var(--r); padding: 12px; max-height: 60vh; overflow: auto; margin-top: 8px; }
.source audio { width: 100%; margin-top: 8px; }
mark { background: #FFE9A8; border-radius: 3px; }
pre.export { background: var(--surface2); border-radius: var(--r); padding: 12px; max-height: 55vh; overflow: auto; font: 12px/1.5 ui-monospace, monospace; white-space: pre-wrap; margin: 0; }
.search-list { display: flex; flex-direction: column; gap: 2px; max-height: 50vh; overflow: auto; }
.search-item { text-align: left; white-space: normal; background: none; border-left: 3px solid var(--c); border-radius: 2px 10px 10px 2px; }
.search-item b { color: var(--c); }
.search-item.on { background: var(--accent-bg); }
.keys-table td { padding: 4px 10px 4px 0; vertical-align: top; }

#toasts { position: fixed; left: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 20; max-width: min(520px, calc(100vw - 32px)); }
.toast { display: flex; align-items: center; gap: 10px; background: #1C1C1E; color: #fff; border-radius: var(--r); padding: 8px 8px 8px 14px; }
.toast .link { color: #64B5FF; font-weight: 600; }
.toast .icon { color: #aaa; }
.toast-error { background: var(--error); }
.toast-error .icon { color: #fff; }

@media (max-width: 900px) {
  .split { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); }
  .left { border-right: 0; border-bottom: 1px solid var(--surface); }
  .keys { display: none; }
}
@media (max-width: 699px) {
  .top { flex-wrap: nowrap; gap: 8px; padding: 8px 12px; }
  .top .back-text, .top-actions { display: none; }
  .top .map-name { flex: 1 1 auto; min-width: 0; max-width: none; font-size: 16px; }
  .top .spacer { display: none; }
  .top .seg button { padding: 5px 9px; }
  .top .jobs { flex: 0 1 auto; min-width: 0; flex-wrap: nowrap; overflow: hidden; }
  .top .jobs .chip { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .top-more { display: block; flex: none; }
  .split { grid-template-rows: minmax(0, 3fr) minmax(0, 2fr); }
  /* ничего не выбрано — от правой панели остаются вкладки, остальное — доске */
  .split.nosel { grid-template-rows: minmax(0, 1fr) auto; }
  .split.nosel .right-body { display: none; }
}
.warn-text { color: #8a5300; font-style: normal; }
