/* =========================================================
   ZA RAMKI — LAYER MAP

   LAYER 0  Page background     → var(--bg)
   LAYER 1  Header / top bar    → var(--panel)
   LAYER 2  Panels / viewer     → var(--card)
   LAYER 3  Items / rows        → var(--item)
   SOFT     Soft fills / code   → var(--surface-soft)
   OVERLAY  Modal / dim         → var(--overlay)
   ACCENT   Hover / active      → var(--accent)
   HERO     Gradient surfaces   → var(--hero-gradient)

   Все оттенки меняем в colors.css.
   В styles.css цвета не хардкодим.
   ========================================================= */
*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color:var(--text);
}

.header{
  position:sticky; top:0; z-index:10;
  backdrop-filter: blur(10px);
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.header-inner{
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 16px;
  display:flex;
  gap:14px;
  align-items:center;
  justify-content:space-between;
}
.brand{
  display:flex; align-items:center; gap:10px;
}
.logo{
  width:34px;height:34px;border-radius:10px;
  background: var(--hero-gradient);
  box-shadow: 0 12px 30px var(--accent-12);
}
.brand h1{
  font-size:14px; margin:0; letter-spacing:.4px;
}
.brand small{display:block; color:var(--muted); margin-top:2px}

.search{
  flex: 1;
  max-width: 520px;
  display:flex; gap:10px; align-items:center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
}
.search input{
  width:100%;
  border:0; outline:0;
  background: transparent;
  color: var(--text);
  font-size: 14px;
}
.pill{
  font-size:12px;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 999px;
  user-select:none;
}

.main{
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
  display:grid;
  grid-template-columns: 360px 1fr;
  gap: 16px;
}

.panel, .viewer{
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow:hidden;
}

.panel-head{
  padding: 14px 14px 10px 14px;
  border-bottom: 1px solid var(--border);
  display:flex;
  align-items:center;
  justify-content:space-between;
}
.panel-head h2{
  margin:0;
  font-size: 13px;
  letter-spacing:.3px;
  color: var(--muted);
  text-transform: uppercase;
}

.list{
  padding: 10px;
  display:flex;
  flex-direction:column;
  gap:10px;
  max-height: calc(100vh - 140px);
  overflow:auto;
}
.item{
  display:block;
  text-decoration:none;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  transition: transform .08s ease, border-color .08s ease;
}
.item:hover{ transform: translateY(-1px); border-color: var(--accent-35); }
.item-title{ font-weight:600; font-size:14px; margin:0 0 6px 0; }
.item-meta{ display:flex; gap:8px; flex-wrap:wrap; color:var(--muted); font-size:12px; }
.tag{
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 8px;
  color: var(--muted);
}
.tag.accent{ border-color: var(--accent-35); color: var(--accent-95); }
.tag.warn{ border-color: rgba(255,140,0,.35); color: rgba(255,200,120,.95); }

.viewer{
  padding: 18px 18px 22px 18px;
  max-height: calc(100vh - 140px);
  overflow: auto;
}
.viewer .empty{
  color: var(--muted);
  line-height:1.6;
  padding: 20px;
  background: var(--item);
  border: 1px dashed var(--border);
  border-radius: 14px;
}
.article-title{ margin:0 0 6px 0; font-size: 22px; }
.article-sub{ color: var(--muted); margin:0 0 14px 0; font-size: 13px; }
.hr{ height:1px; background: var(--border); margin: 14px 0; }

.markdown{
  line-height: 1.65;
}
.markdown h2{ margin-top: 18px; }
.markdown h3{ margin-top: 14px; color: var(--headings); }
.markdown a{ color: var(--accent); }
.markdown code{ background: var(--item); padding: 2px 6px; border-radius: 8px; border:1px solid var(--border);}
.markdown blockquote{
  margin: 14px 0;
  padding: 12px 14px;
  border-left: 3px solid var(--accent-60);
  background: var(--item);
  border-radius: 12px;
  color: var(--headings);
}
.markdown ul{ padding-left: 18px; }

	/* KB: Article layout + TOC (H2 only) */
.article-layout{
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 16px;
  align-items: start;
}
.article-toc{
  position: sticky;
  top: 12px;
  align-self: start;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--item);
}
.article-toc-title{
  margin: 0 0 10px 0;
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
.article-toc a{
  display: block;
  padding: 6px 8px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--muted);
  border: 1px solid transparent;
}
.article-toc a:hover{
  color: var(--text);
  border-color: var(--border);
}
.article-toc a.is-active{
  color: var(--accent-95);
  background: var(--accent-08);
  border-color: var(--accent-35);
}

/* Mobile: TOC on top */
@media (max-width: 960px){
  .article-layout{ grid-template-columns: 1fr; }
  .article-toc{ position: relative; top: 0; }
}
.footer{
  max-width:1200px;
  margin: 0 auto;
  padding: 0 16px 18px 16px;
  color: var(--muted);
  font-size: 12px;
}
@media (max-width: 960px){
  .main{ grid-template-columns: 1fr; }
  .list{ max-height: 42vh; }
}

/* Tabs */
.tabs{
  display:flex;
  gap:8px;
  padding: 10px;
  border-bottom: 1px solid var(--border);
  background: var(--item);
}
.tab{
  appearance:none;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 12px;
  cursor:pointer;
  font-size: 13px;
}
.tab:hover{ border-color: var(--accent-35); }
.tab.is-active{
  border-color: var(--accent-55);
  box-shadow: 0 10px 22px var(--accent-08);
}

/* Action buttons inside viewer */
.actions{ display:flex; gap:10px; flex-wrap:wrap; margin: 10px 0 6px 0; }
.btn{
  display:inline-flex;
  align-items:center;
  gap:8px;
  text-decoration:none;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  padding: 9px 12px;
  border-radius: 12px;
  cursor:pointer;
}
.btn:hover{ border-color: var(--accent-35); transform: translateY(-1px); }
.btn .dot{
  width:8px;height:8px;border-radius:999px;
  background: var(--accent-95);
}

/* Simple cards in contacts/templates lists */
.kv{ color:var(--muted); font-size:12px; margin-top:6px; line-height:1.5; }
.kv b{ color: var(--text); font-weight:600; }

/* Callouts (blockquote variants) */
.markdown blockquote.kb-callout{
  margin: 14px 0;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--item);
}

.markdown blockquote.kb-callout p{ margin: 0; }

.markdown blockquote.kb-callout .kb-callout-title{
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-right: 8px;

  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--headings);
}

/* ВАЖНО — терракотовый прозрачный фон + яркая обводка */
.markdown blockquote.kb-callout.kb-important{
  background: var(--accent-08);
  border-color: var(--accent-55);
}

/* ОСТОРОЖНО — светлая вертикальная полоса слева */
.markdown blockquote.kb-callout.kb-caution{
  background: var(--item);
  border-color: var(--border);
  border-left: 4px solid rgba(255,243,234,.22);
  padding-left: 12px;
}

/* НЕ ЗАБУДЬ — фон чуть темнее (как карточки) */
.markdown blockquote.kb-callout.kb-remember{
  background: var(--card);
  border-color: var(--border);
}

/* KB: Updated badge on article cards (appears if updatedAt is within NEW window) */
.kb-updated-badge{
  display:inline-flex;
  align-items:center;
  margin-left:10px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 11px;
  line-height: 1.2;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent-95);
  background: var(--accent-08);
  border: 1px solid var(--accent-35);
}/* KB: inline NEW highlight
   Markers supported:
   - >text<
   - [[new]]text[[/new]]
*/
.markdown mark.kb-newmark{
  background: linear-gradient(180deg, transparent 58%, var(--accent-35) 58%);
  color: inherit;
  padding: 0 .08em;
  border-radius: 2px;
}






/* Planner: disable item hover motion (tasks are static) */
#list .item:hover,
#viewer .item:hover{
  transform: none !important;
}

/* ================================
   PLANNER — anti-jitter stabilizer
   ================================ */

/* Правая панель уже имеет overflow:auto,
   но явно фиксируем поведение */
.viewer{
  overflow: auto;
}

/* Стабилизируем высоту async-блоков */
#plChecklist,
#plDocs,
#plComments{
  min-height: 96px;
  transition: opacity .08s ease;
}

/* Мягкий fade вместо резкого появления */
#plChecklist:empty,
#plDocs:empty,
#plComments:empty{
  opacity: .65;
}

/* ================================
   PLANNER — A1 UI-3b (document mode)
   Lines + light fill only for controls
   ================================ */

.pl-eyebrow{
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.pl-eyebrow-link{
  cursor: pointer;
  user-select: none;
}
.pl-help{
  font-size: 12px;
  color: var(--muted);
}

.pl-board-head{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap: 14px;
  padding: 10px 12px 12px 12px;
}
.pl-board-head-left{
  min-width:240px;
  display:flex;
  flex-direction:column;
  gap:6px;
}

.pl-board-head-right{
  display:flex;
  align-items:center;
  gap:8px;
  margin-top:18px;
}

.pl-head .pl-progress{
  margin-top: 14px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255,255,255,.10);
  overflow: hidden;
}
.pl-head .pl-progress-bar{
  height: 100%;
  background: var(--accent);
}

.pl-quickadd{
  display:flex;
  flex-direction:column;
  align-items:stretch;
  gap: 6px;
  min-width: 260px;
}
.pl-quickadd-row{
  display:flex;
  gap: 8px;
  align-items:center;
}
.pl-quickadd-input{ height: 34px; }

.pl-doc{
  padding: 8px 12px 14px 12px;
}
.pl-title{
  font-size: 20px;
  font-weight: 650;
  margin-top: 10px;
}
.pl-meta{
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
  display:flex;
  flex-wrap:wrap;
  gap: 8px;
}
.pl-divider{
  border:0;
  border-top: 1px solid var(--border);
  margin: 14px 0;
}
.pl-section-title{
  font-size: 12px;
  line-height: 1.2;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--accent-95);
}
.pl-body{
  margin-top: 8px;
  font-size: 14px;
  line-height: 1.45;
}

.pl-actions{
  margin-top: 10px;
  display:flex;
  gap: 8px;
  flex-wrap:wrap;
}
.pl-status-msg{ margin-top: 8px; }

.pl-control{
  width:100%;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--text);
  border-radius: 14px;
  padding: 10px 12px;
  outline: none;
}
.pl-control:focus{
  border-color: var(--accent-35);
  box-shadow: 0 0 0 2px var(--accent-12);
}
.pl-textarea{
  resize: vertical;
  min-height: 72px;
}

.pl-comment-actions{
  margin-top: 8px;
  display:flex;
  gap: 10px;
  align-items:center;
}
.pl-comment{
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  background: var(--item);
}
.pl-comment + .pl-comment{ margin-top: 10px; }

.pl-attach-list{
  display:flex;
  flex-direction:column;
  gap: 6px;
  margin-top: 8px;
}
.pl-attach{
  display:flex;
  gap: 10px;
  align-items:center;
  width: 100%;
  text-align:left;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 12px;
  padding: 8px 10px;
  cursor: pointer;
}
.pl-attach:hover{
  border-color: var(--accent-35);
  background: var(--accent-08);
}
.pl-attach-ico{ opacity: .85; }
.pl-attach-label{ flex: 1; }

.pl-chip{
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 8px;
  color: var(--muted);
  background: transparent;
  user-select:none;
  cursor: default;
}
.pl-chip--warn{
  /* same size as .tag */
  padding:0;
  font-size:inherit;
  border-radius:inherit;

  background:transparent;
  border-color:rgba(255,140,0,.35);
  color:rgba(255,200,120,.95);
}

/* Soft highlight for freshly created task */
.pl-flash{
  box-shadow: 0 0 0 1px var(--accent-35), 0 0 0 6px var(--accent-12);
}


/* Planner: archived task read-only */
.pl-archived{
  opacity: .82;
  filter: saturate(.92);
}
.pl-archived .item{
  opacity: .92;
}
.pl-archived .btn,
.pl-archived input,
.pl-archived textarea,
.pl-archived select{
  pointer-events: none;
}


/* Planner — overdue due-date */
.pl-due.is-overdue{
  color: var(--accent-95);
  font-weight: 600;
}
/* Planner — normalize tag size in left list meta (ALL / overdue etc.) */
#list .item-meta .tag{
  font-size: 12px;
  padding: 3px 8px;
  line-height: 1.2;
  display: inline-flex;
  align-items: center;
}
/* Planner — compact tags in left list (ALL / overdue) */
#list .item-title .tag,
#list .item-meta .tag{
  font-size:10px;
  padding:2px 6px;
  line-height: 1.2;
}
/* Planner — warn tag uses accent palette (no yellow) */
#list .tag.warn{
  border-color: var(--accent-55);
  color: var(--accent-95);
  background: var(--accent-08);
  opacity: 1;
}

/* ================================
   PLANNER — header progress + actions
   ================================ */

.pl-head{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap: 12px;
  padding:10px 12px;
}

.pl-head-left{ flex:1; min-width:260px; }
.pl-head-actions{
  display:flex;
  align-items:flex-start;
  gap: 8px;
  flex-wrap:wrap;
}

/* progress: strict bracket bar (no rounding) */
.pl-progress-row{
  display:flex;
  align-items:center;
  gap:10px;
  margin-top:10px;
}

.pl-bracket{
  opacity:.75;
  font-weight:700;
  letter-spacing:.06em;
}

.pl-progress{
  flex: 1 1 auto; width: 100%; min-width: 0;
  height: 8px;
  border-radius: 0;
  background: rgba(255,255,255,.10);
  overflow: hidden;
  border: 1px solid var(--border);
}

.pl-progress-bar{
  height: 100%;
  border-radius: 0;
  /* green with safe fallback */
  background: var(--ok, #3ad37a);
}

/* buttons: make primary look like action (not pill) */
.pl-btn-primary{
  border-color: transparent;
  background: var(--accent);
  color: #111;
  font-weight: 650;
}
.pl-btn-primary:hover{
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.pl-btn-ghost{
  background: transparent;
}
/* Planner header progress — final scoped override */
.pl-head{
  display:grid;
  grid-template-columns: minmax(0,1fr) auto;
  gap:12px;
  align-items:start;
}

.pl-head-left{
  min-width:0;
}

.pl-progress-row{
  display:grid;
  grid-template-columns:auto minmax(0,1fr) auto;
  align-items:center;
  gap:8px;
  width:100%;
  margin-top:10px;
}

.pl-head .pl-progress{
  width:100%;
  min-width:0;
  height:8px;
  border-radius:0;
  overflow:hidden;
  border:1px solid var(--border);
  background:rgba(255,255,255,.10);
}

.pl-head .pl-progress-bar{
  height:100%;
  width:var(--pl-progress, 0%);
  border-radius:0;
  background:#3aa76d;
}

.pl-bracket{
  color:var(--muted);
  opacity:.85;
  font-weight:600;
}
/* STEP 8.5 layout stabilize */
.pl-details-col .item{
  width:100%;
}

/* Planner — refresh button feedback */
#plRefresh{
  position: relative;
  min-width: 132px;
  justify-content: center;
}

#plRefresh.is-loading{
  opacity: .88;
}

#plRefresh.is-loading::after{
  content: "";
  width: 12px;
  height: 12px;
  margin-left: 8px;
  display: inline-block;
  vertical-align: -2px;
  border-radius: 999px;
  border: 1.5px solid currentColor;
  border-right-color: transparent;
  animation: pl-refresh-spin .7s linear infinite;
}

#plRefresh:disabled{
  cursor: default;
  opacity: .72;
}

@keyframes pl-refresh-spin{
  to{ transform: rotate(360deg); }
}
/* --- FIX: refresh button should not jump on click --- */
#plRefresh,
#plRefresh:hover,
#plRefresh:active,
#plRefresh:focus,
#plRefresh:focus-visible{
  transform:none !important;
}

#plRefresh{
  transition:border-color .08s ease, background-color .08s ease, color .08s ease !important;
}




/* ZA RAMKI — sticky header polish */

[data-ins-section="header"],
[data-cl-section="header"],
[data-tpl-section="header"]{
  position: sticky;
  top: 0;
  z-index: 8;
  background: var(--bg);
  padding-top: 4px;
  padding-bottom: 6px;
  box-shadow: 0 1px 0 rgba(0,0,0,0.04);
}


/* ZA RAMKI — mini header mode */

.viewer-mini-header [data-ins-section="header"],
.viewer-mini-header [data-cl-section="header"],
.viewer-mini-header [data-tpl-section="header"]{
  padding-top:2px;
  padding-bottom:2px;
}

.viewer-mini-header .article-sub{
  display:none;
}

.viewer-mini-header .article-title{
  font-size:16px;
}


/* ZA RAMKI — mini header tighter */

.viewer-mini-header{
  padding-top:0 !important;
}

.viewer-mini-header [data-ins-section="header"],
.viewer-mini-header [data-cl-section="header"],
.viewer-mini-header [data-tpl-section="header"]{
  margin-top:0 !important;
  padding-top:2px !important;
  padding-bottom:2px !important;
  border-radius:0 !important;
  box-shadow:none !important;
}

.viewer-mini-header .article-sub{
  display:none !important;
}

.viewer-mini-header .article-title{
  font-size:15px !important;
  line-height:1.25 !important;
}

.viewer-mini-header .btn{
  padding:2px 8px !important;
  font-size:12px !important;
}


/* ZA RAMKI — smooth mini header */

[data-ins-section="header"],
[data-cl-section="header"],
[data-tpl-section="header"]{
  transition:
    padding 0.18s ease,
    margin 0.18s ease,
    box-shadow 0.18s ease,
    background 0.18s ease;
}

.article-title{
  transition: font-size 0.18s ease, line-height 0.18s ease;
}

.article-sub{
  transition: opacity 0.16s ease;
}

.viewer-mini-header .article-sub{
  opacity:0;
}

.viewer-mini-header .article-title{
  font-size:15px !important;
  line-height:1.25 !important;
}


/* ZA RAMKI — mini header smoother */

[data-ins-section="header"],
[data-cl-section="header"],
[data-tpl-section="header"]{
  transition:
    padding-top 0.24s ease,
    padding-bottom 0.24s ease,
    margin-top 0.24s ease,
    box-shadow 0.24s ease,
    background 0.24s ease;
  will-change: padding-top, padding-bottom;
}

.article-title{
  transition:
    font-size 0.24s ease,
    line-height 0.24s ease,
    transform 0.24s ease;
}

.article-sub{
  overflow:hidden;
  max-height:48px;
  opacity:1;
  margin-top:6px;
  margin-bottom:0;
  transition:
    max-height 0.24s ease,
    opacity 0.18s ease,
    margin-top 0.24s ease,
    margin-bottom 0.24s ease;
}

[data-ins-section="header"] .btn,
[data-cl-section="header"] .btn,
[data-tpl-section="header"] .btn{
  transition:
    padding 0.24s ease,
    font-size 0.24s ease,
    transform 0.24s ease;
}

.viewer-mini-header [data-ins-section="header"],
.viewer-mini-header [data-cl-section="header"],
.viewer-mini-header [data-tpl-section="header"]{
  padding-top:1px !important;
  padding-bottom:1px !important;
}

.viewer-mini-header .article-title{
  font-size:14px !important;
  line-height:1.2 !important;
}

.viewer-mini-header .article-sub{
  max-height:0 !important;
  opacity:0 !important;
  margin-top:0 !important;
  margin-bottom:0 !important;
}

.viewer-mini-header [data-ins-section="header"] .btn,
.viewer-mini-header [data-cl-section="header"] .btn,
.viewer-mini-header [data-tpl-section="header"] .btn{
  padding:1px 7px !important;
  font-size:12px !important;
}





