/* ==========================================================================
   Editor ("Vstupy") — shell (section navigation, live summary strip, pager) and the
   sections Základ, Pozemky, Nákup a investície, Kategórie.
   All classes are prefixed .ed- ; colours only through app.css tokens.
   ========================================================================== */

/* ---------- Shell layout ---------- */

.ed-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 28px;
  align-items: start;
  min-width: 0;
}
.ed-aside {
  position: sticky;
  top: calc(var(--header-h) + 12px);
  min-width: 0;
}
.ed-main {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}
.ed-section { min-width: 0; }

/* Section navigation (vertical on desktop) */
.ed-nav { gap: 2px; }
.ed-nav-link {
  gap: 10px;
  min-width: 0;
  padding: 6px 8px;
  line-height: 1.3;
}
.ed-nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--text-2);
  transition: background-color 0.12s, color 0.12s;
}
.ed-nav-link:hover .ed-nav-icon { background: var(--surface); color: var(--text); }
.ed-nav-link.is-active .ed-nav-icon { background: var(--surface); color: var(--link); box-shadow: var(--shadow-sm); }
.ed-nav-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ed-nav-count {
  flex: none;
  padding: 1px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.ed-nav-count.is-zero { color: var(--muted); }
.ed-nav-link.is-active .ed-nav-count { border-color: transparent; color: var(--link); }

/* ---------- Live summary strip ---------- */

.ed-strip {
  position: sticky;
  top: calc(var(--header-h) + 12px);
  z-index: 20;
  display: flex;
  align-items: stretch;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.ed-strip-tiles {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  flex: 1 1 auto;
  min-width: 0;
}
.ed-strip .ed-kpi {
  position: relative;
  gap: 1px;
  padding: 9px 12px 8px;
  background: transparent;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
.ed-strip .ed-kpi + .ed-kpi { border-left: 1px solid var(--border); }
.ed-strip .kpi-label { gap: 4px; font-size: 11.5px; }
.ed-strip .kpi-value {
  gap: 4px;
  font-size: 15.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow-wrap: normal;
}
.ed-strip .kpi-value > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.ed-strip .kpi-sub {
  overflow: hidden;
  font-size: 11.5px;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ed-strip .kpi--bad .kpi-sub { color: var(--critical-text); }
.ed-strip .ed-kpi.has-delta .kpi-sub { visibility: hidden; }
.ed-kpi-delta {
  position: absolute;
  left: 8px;
  bottom: 6px;
  max-width: calc(100% - 12px);
  overflow: hidden;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 11px;
  font-weight: 650;
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0;
  transform: translateY(3px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}
.ed-kpi-delta.is-visible { opacity: 1; transform: none; }
.ed-kpi-delta.is-good { background: var(--good-soft); color: var(--good-text); }
.ed-kpi-delta.is-bad { background: var(--critical-soft); color: var(--critical-text); }
@media (prefers-reduced-motion: reduce) {
  .ed-kpi-delta { transition: none; transform: none; }
}

/* Hint tooltips open downwards (the strip sits right under the sticky app header). */
.ed-strip [data-tooltip]:hover::after,
.ed-strip [data-tooltip]:focus-visible::after { top: calc(100% + 6px); bottom: auto; }
.ed-strip .ed-kpi:nth-last-child(-n+3) [data-tooltip]:hover::after,
.ed-strip .ed-kpi:nth-last-child(-n+3) [data-tooltip]:focus-visible::after { left: auto; right: -8px; }

.ed-strip-error { flex: 1 1 auto; min-width: 0; padding: 6px; }
.ed-strip-link {
  display: flex;
  flex: none;
  align-items: center;
  gap: 2px;
  padding: 0 10px 0 12px;
  border-left: 1px solid var(--border);
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
  color: var(--link);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
}
.ed-strip-link:hover { background: var(--surface-2); text-decoration: none; }

/* Keep focused fields visible below the sticky header + strip. */
.ed-section :is(input, select, textarea, button, a, summary) { scroll-margin-top: calc(var(--header-h) + 112px); }

/* Read-only banner */
.ed-readonly { margin: 0; }

/* ---------- Pager (previous / next section) ---------- */

.ed-pager {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.ed-pager-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  max-width: 48%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}
.ed-pager-link:hover { border-color: var(--border-strong); background: var(--surface-2); text-decoration: none; }
.ed-pager-link .icon { color: var(--text-2); }
.ed-pager-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.ed-pager-link--next .ed-pager-text { text-align: right; }
.ed-pager-dir { font-size: 12px; color: var(--text-2); }
.ed-pager-label { overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Shared bits inside sections ---------- */

.ed-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0;
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.45;
}
.ed-note > .icon { margin-top: 2px; color: var(--muted); }
.ed-note strong { color: var(--text); font-weight: 650; }
.ed-note strong.is-negative { color: var(--critical-text); }

.ed-explainer {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  font-size: 13.5px;
}
.ed-explainer > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: var(--radius);
  color: var(--text-2);
  font-weight: 550;
  list-style: none;
  cursor: pointer;
}
.ed-explainer > summary::-webkit-details-marker { display: none; }
.ed-explainer > summary::after {
  content: "";
  flex: none;
  width: 7px;
  height: 7px;
  margin-left: auto;
  border-right: 1.8px solid currentColor;
  border-bottom: 1.8px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  transition: transform 0.15s;
}
.ed-explainer[open] > summary::after { transform: translateY(1px) rotate(-135deg); }
.ed-explainer > summary:hover { color: var(--text); }
.ed-explainer > summary > .icon { color: var(--accent); }
.ed-explainer-body { padding: 0 14px 12px 37px; color: var(--text-2); line-height: 1.55; }
.ed-explainer-body p { margin: 0 0 8px; }
.ed-explainer-body p:last-child { margin-bottom: 0; }
.ed-explainer-body strong { color: var(--text); font-weight: 650; }

.ed-tiles .kpi-value { font-size: 20px; font-variant-numeric: tabular-nums; }
@media (max-width: 480px) { .ed-tiles .kpi-value { font-size: 17px; } }

.ed-chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
  gap: 16px;
  min-width: 0;
}
.ed-chart-grid--2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); }

/* Record tables inside the editor */
.ed-table-block { min-width: 0; }
.ed-is-empty .rt-empty { display: none !important; }
.ed-cell-tag { margin-left: 3px; color: var(--text-2); font-size: 11.5px; font-weight: 500; }
.ed-cell-tag--pre { margin: 0 4px 0 0; }
.ed-row-info { padding: 8px 10px; border-radius: var(--radius-sm); background: var(--surface); }
.ed-footer { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px 18px; }

/* Delete-plot confirmation (rendered in the modal, outside the section) */
.ed-ref-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  padding-left: 18px;
  font-size: 13.5px;
}
.ed-ref-warn { color: var(--warning-text); }

/* ---------- Základ ---------- */

.ed-settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
  min-width: 0;
}
.ed-field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 16px;
  align-items: start;
}
.ed-finance-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px 24px;
  align-items: start;
}
.ed-finance .chart-card { box-shadow: none; background: var(--surface); }
.ed-fin-chart { min-width: 0; }
.ed-fin-empty {
  padding: 16px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}
.ed-fin-overview { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.ed-fin-kv {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}
.ed-fin-kv dd.strong { font-size: 15px; }
.ed-kv-hint { display: inline-flex; align-items: center; gap: 4px; cursor: help; }
.ed-kv-hint > .icon { color: var(--muted); }

/* ---------- Nákup a investície ---------- */

.ed-filter .chip { height: 32px; gap: 7px; }
.ed-chip-dot { flex: none; width: 9px; height: 9px; border-radius: 3px; }
.ed-chip-meta { color: var(--muted); font-size: 11.5px; font-weight: 500; font-variant-numeric: tabular-nums; }
.chip.is-active .ed-chip-meta { color: var(--link); }

/* ---------- Kategórie ---------- */

.ed-cat-intro { margin-bottom: 16px; }
.ed-cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
  gap: 16px;
  align-items: start;
  min-width: 0;
}
.ed-cat-title { display: inline-flex; align-items: center; gap: 8px; }
.ed-cat-count {
  padding: 0 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.6;
}
.ed-cat-list {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  list-style: none;
}
.ed-cat-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 0;
  padding: 8px 0;
  border-bottom: 1px solid var(--grid);
}
.ed-cat-row:last-child { border-bottom: 0; }
.ed-swatch {
  flex: none;
  width: 14px;
  height: 14px;
  margin-top: 10px;
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px var(--border);
}
.ed-swatch.is-folded {
  background-image: repeating-linear-gradient(45deg, transparent 0 3px, var(--surface) 3px 5px);
}
.ed-cat-main { display: flex; flex: 1 1 auto; flex-direction: column; gap: 4px; min-width: 0; }
.ed-cat-main .input { height: 34px; }
.ed-cat-main .input:disabled {
  padding-inline: 0;
  border-color: transparent;
  background: transparent;
  color: var(--text);
  -webkit-text-fill-color: var(--text);
  opacity: 1;
  cursor: default;
}
.ed-cat-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  color: var(--text-2);
  font-size: 12px;
}
.ed-cat-usage { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-cat-usage.is-unused { color: var(--muted); }
.ed-cat-total { flex: none; color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ed-cat-bar {
  display: block;
  height: 4px;
  overflow: hidden;
  border-radius: 2px;
  background: var(--surface-3);
}
.ed-cat-bar-fill { display: block; height: 100%; border-radius: 2px; transition: width 0.25s ease; }
.ed-cat-actions { display: flex; flex: none; gap: 0; margin-top: 3px; }
.ed-cat-list--system {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px dashed var(--border-strong);
}
.ed-cat-row--system .ed-swatch { margin-top: 3px; }
.ed-cat-sysname { display: flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 13.5px; font-weight: 550; }
.ed-cat-sysname > .icon { color: var(--muted); }

/* ---------- Responsive ---------- */

@media (max-width: 1179px) {
  .ed-layout { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .ed-aside { position: static; margin-inline: calc(var(--gutter) * -1); }
  .ed-nav {
    flex-direction: row;
    gap: 6px;
    overflow-x: auto;
    padding: 2px var(--gutter) 4px;
    scroll-padding-inline: var(--gutter);
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .ed-nav::-webkit-scrollbar { display: none; }
  .ed-nav-link {
    flex: none;
    gap: 7px;
    padding: 4px 12px 4px 4px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
  }
  .ed-nav-link.is-active { border-color: var(--accent); }
  .ed-nav-icon { width: 26px; height: 26px; border-radius: 999px; }
  .ed-nav-label { overflow: visible; }
  .ed-strip { top: calc(var(--header-h) + 8px); }
}

@media (max-width: 1024px) {
  .ed-settings-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 899px) {
  .ed-strip { position: static; box-shadow: var(--shadow-sm); }
  .ed-strip-tiles {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
  }
  .ed-strip .ed-kpi { flex: 0 0 auto; min-width: 138px; scroll-snap-align: start; }
  .ed-strip-link { display: none; }
  .ed-strip [data-tooltip]:hover::after,
  .ed-strip [data-tooltip]:focus-visible::after { left: -8px; right: auto; }
  .ed-section :is(input, select, textarea, button, a, summary) { scroll-margin-top: calc(var(--header-h) + 12px); }
  .ed-finance-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 640px) {
  .ed-main { gap: 16px; }
  .ed-filter { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
  .ed-filter::-webkit-scrollbar { display: none; }
  .ed-filter .chip { flex: none; }
  .ed-pager-link { padding: 8px 10px; }
  .ed-explainer-body { padding-left: 14px; }
}

@media (max-width: 480px) {
  .ed-field-row { grid-template-columns: minmax(0, 1fr); }
  .ed-footer { justify-content: flex-start; }
}

/* ---------- Print ---------- */

@media print {
  .ed-layout { display: block; }
  .ed-aside, .ed-pager, .ed-strip-link, .ed-cat-actions, .ed-filter { display: none !important; }
  .ed-strip { position: static; margin-bottom: 12px; box-shadow: none; }
  .ed-kpi-delta { display: none; }
  .ed-explainer:not([open]) { display: none; }
}
