/* ============================================================
   Мастер летучек — интерфейс

   Оформление общее с остальными конструкторами «Могу писать»
   (карточки для разбора): зелёная шапка с градиентом, белая
   панель настроек слева, мандариновый акцент на действиях.
   ============================================================ */

:root {
  --grass: #51BA40;
  --moss: #2E9127;
  --pine: #2F5626;
  --leaf: #6BA33F;
  --leaf-soft: #E5EFD4;
  --mandarin: #E8833A;
  --amber-soft: #FBE7CF;
  --paper: #FFFFFF;
  --bg: #F5F7EE;
  --ink: #26301F;
  --muted: #6B7A5C;
  --line: #DFE7CE;
  --green-flow: linear-gradient(180deg, #51BA40 0%, #2E9127 100%);
  --radius: 14px;
  --shadow: 0 2px 4px rgba(30, 70, 53, .06), 0 12px 28px rgba(30, 70, 53, .10);
  --font-ui: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 16px/1.5 var(--font-ui);
  color: var(--ink);
  background: var(--bg);
}

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

/* ============================================================
   Шапка
   ============================================================ */

header.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 22px;
  background: var(--green-flow);
  color: #F2F7E9;
  box-shadow: 0 1px 0 rgba(0, 0, 0, .15);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-right: auto;
  min-width: 0;
}
.brand .app-logo {
  display: block;
  width: 34px;
  height: 34px;
  flex: none;
  filter: drop-shadow(0 2px 3px rgba(12, 46, 20, .3));
}
.brand b { font-size: 19px; font-weight: 700; letter-spacing: .2px; white-space: nowrap; }
.brand .brand-sub {
  display: block;
  font-size: 12px;
  opacity: .85;
  white-space: nowrap;
  margin-top: 1px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.preview-info {
  font-size: 12.5px;
  color: #EAF4EC;
  opacity: .9;
  white-space: nowrap;
}

/* ---------- кнопки ---------- */

.btn {
  border: 0;
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  background: #fff;
  color: var(--pine);
  transition: transform .12s, box-shadow .12s, background .12s;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { cursor: default; opacity: .5; transform: none; }

/* в шапке — полупрозрачные, на светлом фоне — с рамкой */
.topbar .btn-ghost { background: rgba(255, 255, 255, .12); color: #EAF4EC; }
.topbar .btn-ghost:hover:not(:disabled) { background: rgba(255, 255, 255, .2); }

@keyframes own-elements-attention {
  0%, 100% {
    background: rgba(255, 255, 255, .12);
    color: #EAF4EC;
    box-shadow: none;
    transform: translateY(0) scale(1);
  }
  50% {
    background: #fff;
    color: #B85B17;
    box-shadow: 0 0 0 4px rgba(255, 255, 255, .28),
                0 5px 18px rgba(79, 45, 13, .35);
    transform: translateY(-1px) scale(1.04);
  }
}

#btn-own.needs-attention {
  animation: own-elements-attention .7s ease-in-out 2;
}

@media (prefers-reduced-motion: reduce) {
  #btn-own.needs-attention {
    animation: none;
    background: #fff;
    color: #B85B17;
    box-shadow: 0 0 0 4px rgba(255, 255, 255, .28);
  }
}

.btn-print { background: var(--mandarin); color: #fff; box-shadow: 0 4px 12px rgba(232, 131, 58, .4); }
.btn-print:hover:not(:disabled) { background: #DE7629; }

.btn-site {
  background: #287F22;
  color: #fff;
  text-decoration: none;
  box-shadow: 0 4px 12px rgba(31, 96, 26, .34);
}
.btn-site:hover { background: #23731E; }

/* светлые кнопки внутри панели и окна */
.btn-sm {
  padding: 7px 12px;
  font-size: 13px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--pine);
}
.btn-sm:hover:not(:disabled) { border-color: var(--leaf); background: var(--leaf-soft); }

.btn-primary { background: linear-gradient(120deg, var(--grass), var(--moss)); color: #fff; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.05); }

.btn-danger { background: #fff; border: 1px solid #E7C3C3; color: #A33B3B; }
.btn-danger:hover:not(:disabled) { background: #FBECEC; border-color: #D89393; }

/* ============================================================
   Рабочий экран: панель настроек, темы, предпросмотр
   ============================================================ */

.app {
  display: grid;
  grid-template-columns: 340px 400px 1fr;
  height: calc(100vh - var(--chrome-h, 64px));
  min-height: 0;
}
.app > * { min-height: 0; }

.panel {
  background: #fff;
  border-right: 1px solid var(--line);
  padding: 20px 20px 40px;
  overflow-y: auto;
}

.rules-pane {
  background: #fff;
  border-right: 1px solid var(--line);
  padding: 20px 20px 30px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* ---------- секция настроек ---------- */

.sec { margin: 0 0 22px; }

.sec-h {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--pine);
  margin: 0 0 10px;
}
.sec-h .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--mandarin);
  flex: none;
}
.sec-h .sec-count {
  margin-left: auto;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- строки настроек ---------- */

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
}
.row label { font-size: 13.5px; }
.row .sub {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
}

.field {
  display: block;
  margin-bottom: 10px;
}
.field > span {
  display: block;
  font-size: 13.5px;
  margin-bottom: 5px;
}

.two-up { display: flex; gap: 10px; }
.two-up > * { flex: 1; min-width: 0; }

select,
input[type=text],
input[type=number],
input[type=file] {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 9px;
  padding: 8px 11px;
  background: #FCFEFC;
  font-size: 13.5px;
  color: var(--ink);
}
select:focus,
input[type=text]:focus,
input[type=number]:focus { border-color: var(--leaf); outline: none; background: #fff; }

.type-select { font-weight: 600; color: var(--pine); padding: 10px 12px; }

textarea {
  width: 100%;
  min-height: 104px;
  resize: vertical;
  padding: 12px 13px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: #FCFEFC;
  font-size: 15px;
  line-height: 1.55;
}
textarea:focus { border-color: var(--leaf); background: #fff; outline: none; }

.hint {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
  margin: 8px 0 0;
}

.count {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 13px;
  color: var(--muted);
}
.count b { color: var(--pine); }

/* ---------- переключатель-тумблер ---------- */

.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input {
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
  position: relative;
  z-index: 2;
}
.switch .track {
  position: absolute;
  inset: 0;
  border-radius: 99px;
  background: #DEE6D0;
  transition: background .16s;
  pointer-events: none;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .16s;
}
.switch input:checked + .track { background: linear-gradient(120deg, var(--grass), var(--moss)); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 3px solid var(--mandarin); outline-offset: 2px; }

/* ============================================================
   Откуда брать элементы
   ============================================================ */

.source-modes {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.source-modes label {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 9px 11px;
  border: 1.5px solid var(--line);
  border-radius: 11px;
  background: #FCFEFC;
  cursor: pointer;
  line-height: 1.3;
}
.source-modes label:hover { border-color: var(--leaf); }
.source-modes label.on {
  background: var(--leaf-soft);
  border-color: var(--leaf);
}

.source-modes input { margin: 2px 0 0; flex: none; accent-color: var(--moss); }
.source-modes label > span { display: block; min-width: 0; }
.source-modes b { display: block; font-size: 13.5px; font-weight: 600; color: var(--pine); }
.source-modes em {
  display: block;
  font-style: normal;
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
}

.source-modes label.disabled {
  opacity: .55;
  cursor: default;
  background: #F7F9F3;
}
.source-modes label.disabled:hover { border-color: var(--line); }

/* ============================================================
   Типы заданий
   ============================================================ */

.task-pick {
  border: 1.5px solid var(--line);
  border-radius: 11px;
  background: #FCFEFC;
  padding: 8px 10px;
  margin-bottom: 6px;
  cursor: pointer;
}
.task-pick:hover { border-color: var(--leaf); }
.task-pick.on { background: var(--leaf-soft); border-color: var(--leaf); }

.pick-head {
  display: flex;
  align-items: center;
  gap: 8px;
}
.pick-check {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 1;
  min-width: 0;
  cursor: pointer;
}
.pick-check input { margin: 0; flex: none; accent-color: var(--moss); }
.pick-src {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
}
.pick-count { flex: none; }
.pick-count input[type=number] {
  width: 58px;
  padding: 4px 7px;
  font-size: 13px;
}
.pick-wording {
  font-size: 13.5px;
  line-height: 1.3;
  margin-top: 3px;
  color: var(--ink);
}

.pick-mix {
  margin-top: 7px;
  padding-top: 6px;
  border-top: 1px solid rgba(105, 145, 75, .2);
}
.pick-mix[hidden] { display: none; }
.pick-mix-values {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.2;
}
.pick-mix-values b {
  color: var(--pine);
  font-weight: 700;
}
.pick-mix input[type=range] {
  display: block;
  width: 100%;
  height: 18px;
  margin: 0;
  padding: 0;
  accent-color: var(--moss);
  cursor: ew-resize;
}
.task-pick:not(.on) .pick-mix { opacity: .78; }

.sentence-filters {
  display: grid;
  gap: 7px;
  margin-top: 7px;
  padding-top: 7px;
  border-top: 1px solid rgba(105, 145, 75, .2);
}
.sentence-filter-values {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.2;
}
.sentence-filter-values b {
  flex: none;
  color: var(--pine);
  font-size: 11px;
}
.sentence-range-row {
  display: grid;
  grid-template-columns: auto minmax(80px, 1fr) auto;
  align-items: center;
  gap: 7px;
  min-width: 0;
}
.sentence-range-edge {
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1;
  white-space: nowrap;
}
.sentence-range-edge b {
  color: var(--pine);
  font-size: 11px;
}
.sentence-dual-range {
  --range-low: 0%;
  --range-high: 100%;
  position: relative;
  height: 22px;
  min-width: 0;
}
.sentence-range-rail {
  position: absolute;
  z-index: 0;
  left: 0;
  right: 0;
  top: 9px;
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(to right,
    var(--line) 0 var(--range-low),
    var(--moss) var(--range-low) var(--range-high),
    var(--line) var(--range-high) 100%);
}
.sentence-dual-range input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  position: absolute;
  z-index: 2;
  inset: 0;
  display: block;
  width: 100%;
  height: 22px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  pointer-events: none;
}
.sentence-dual-range input[type=range]::-webkit-slider-runnable-track {
  height: 4px;
  background: transparent;
}
.sentence-dual-range input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 15px;
  height: 15px;
  margin-top: -5.5px;
  border: 2px solid var(--moss);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(40, 67, 32, .22);
  cursor: ew-resize;
  pointer-events: auto;
}
.sentence-dual-range input[type=range]::-moz-range-track {
  height: 4px;
  background: transparent;
}
.sentence-dual-range input[type=range]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border: 2px solid var(--moss);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(40, 67, 32, .22);
  cursor: ew-resize;
  pointer-events: auto;
}
.sentence-dual-range input[type=range]:focus-visible::-webkit-slider-thumb {
  outline: 2px solid var(--pine);
  outline-offset: 2px;
}
.sentence-dual-range input[type=range]:focus-visible::-moz-range-thumb {
  outline: 2px solid var(--pine);
  outline-offset: 2px;
}
.task-pick:not(.on) .sentence-filters { opacity: .78; }

/* ============================================================
   Браузер цветных фонов — тот же принцип, что в Мастере контента:
   тема выбирается из списка или стрелками, ниже показаны миниатюры.
   ============================================================ */

.color-background-browser {
  margin-top: 9px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #F8FAF3;
}
.color-background-browser[hidden] { display: none; }
.color-background-head {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) 30px;
  align-items: center;
  gap: 6px;
}
.color-background-head select {
  min-width: 0;
  height: 34px;
  padding: 0 8px;
  font-size: 12px;
}
.color-background-nav {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--pine);
  background: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.color-background-nav:hover { border-color: var(--leaf); background: var(--leaf-soft); }
.color-background-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin: 7px 1px 6px;
  color: var(--muted);
  font-size: 10.5px;
  line-height: 1.2;
}
.color-background-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  max-height: 365px;
  overflow-y: auto;
  padding-right: 2px;
}
.color-background-option { position: relative; min-width: 0; }
.color-background-option[hidden] { display: none; }
.color-background-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.color-background-card {
  min-height: 103px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 5px;
  padding: 6px;
  border: 1.5px solid var(--line);
  border-radius: 9px;
  background: #fff;
  cursor: pointer;
  transition: border-color .16s, box-shadow .16s, transform .16s;
}
.color-background-card:hover { transform: translateY(-1px); border-color: var(--leaf); }
.color-background-option input:checked + .color-background-card {
  border-color: var(--mandarin);
  background: var(--amber-soft);
  box-shadow: 0 0 0 2px rgba(232, 131, 58, .16);
}
.color-background-thumb {
  display: block;
  flex: none;
  border: 1px solid rgba(47, 86, 38, .16);
  border-radius: 4px;
  background-position: center;
  background-size: cover;
  box-shadow: 0 1px 3px rgba(36, 62, 29, .13);
}
.color-background-thumbs {
  min-height: 61px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.color-background-thumb.vertical { width: 47px; aspect-ratio: 1050 / 1480; }
.color-background-thumb.horizontal { width: 62px; aspect-ratio: 1480 / 1050; }
.color-background-name {
  color: var(--pine);
  font-size: 10.5px;
  font-weight: 650;
  line-height: 1.15;
  text-align: center;
}

/* ============================================================
   Темы
   ============================================================ */

.rules-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  margin-bottom: 10px;
}

.rules-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1.5px solid var(--line);
  border-radius: 9px;
  background: #FCFEFC;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.3;
}
.rules-list label:hover { border-color: var(--leaf); }
.rules-list label.on { background: var(--leaf-soft); border-color: var(--leaf); }
.rules-list label input { margin: 0; flex: none; accent-color: var(--moss); }

.rules-list label > span {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.rules-list label.off {
  opacity: .5;
  cursor: default;
  background: #F7F9F3;
}
.rules-list label.off:hover { border-color: var(--line); }

.rule-count {
  flex: none;
  margin-left: auto;
  font-size: 11.5px;
  padding: 1px 7px;
  border-radius: 9px;
  background: var(--leaf-soft);
  color: var(--pine);
}
.rules-list label.on .rule-count { background: #fff; }
.rule-count.none { background: #EFEFE8; color: var(--muted); }

.rule-mine {
  flex: none;
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: 8px;
  background: var(--amber-soft);
  color: #A2551A;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-weight: 600;
}

.rule-section + .rule-section { margin-top: 12px; }
.rule-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 6px;
}
.rule-section-title span {
  margin-left: auto;
  font-weight: 600;
  letter-spacing: 0;
  font-size: 11.5px;
}

.orthography-rules-notice {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 9px;
  margin: 0 0 10px;
  padding: 10px 11px;
  border: 1px solid #EDC997;
  border-left: 4px solid var(--mandarin);
  border-radius: 10px;
  background: linear-gradient(135deg, #FFF8E8, #FFFDF7);
  color: #59452E;
  box-shadow: 0 2px 8px rgba(112, 73, 25, .06);
}
.orthography-rules-notice-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--mandarin);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  line-height: 1;
}
.orthography-rules-notice p {
  margin: 0;
  font-size: 12.25px;
  line-height: 1.48;
}

.rules-empty {
  padding: 18px 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.rules-actions { display: flex; gap: 8px; flex: none; }

/* ============================================================
   Предпросмотр
   ============================================================ */

.preview-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow-y: auto;
  padding: 18px 20px 40px;
}

#preview { display: flex; flex-direction: column; align-items: center; gap: 16px; }

.preview-empty {
  margin: 60px auto;
  max-width: 420px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.sheet-wrap {
  transform-origin: top left;
  filter: drop-shadow(0 2px 4px rgba(30, 70, 53, .06))
          drop-shadow(0 12px 28px rgba(30, 70, 53, .10));
}

/* ---------- сообщения ---------- */

.msg {
  border-radius: 10px;
  padding: 9px 13px;
  margin-bottom: 8px;
  font-size: 13px;
  line-height: 1.5;
}
.msg.ok    { background: var(--leaf-soft); color: #2A5A22; }
.msg.warn  { background: var(--amber-soft); color: #8A4E14; }
.msg.error { background: #FBE4E4; color: #9B2C2C; }

#build-messages { width: 100%; max-width: 900px; margin: 0 auto 10px; }

/* ============================================================
   Окно «Мои элементы»
   ============================================================ */

body.modal-open { overflow: hidden; }

.modal-back {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(20, 46, 16, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

/* display:flex перебивает атрибут hidden — закрытое окно иначе
   продолжает перехватывать клики по странице под ним */
.modal-back[hidden] { display: none; }

.modal {
  background: var(--bg);
  border-radius: var(--radius);
  width: min(1180px, 100%);
  height: min(760px, 100%);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(20, 46, 16, .4);
}

.modal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 20px;
  background: var(--green-flow);
  color: #F2F7E9;
}
.modal-head h2 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: .2px; }

.modal-close {
  margin-left: auto;
  border: 0;
  background: rgba(255, 255, 255, .12);
  color: #F2F7E9;
  font-size: 22px;
  line-height: 1;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  cursor: pointer;
}
.modal-close:hover { background: rgba(255, 255, 255, .22); }

.subtabs {
  display: flex;
  gap: 4px;
  padding: 10px 20px 0;
  background: #fff;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.subtabs button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 9px 15px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 9px 9px 0 0;
  border-bottom: 3px solid transparent;
}
.subtabs button:hover { color: var(--pine); background: var(--leaf-soft); }
.subtabs button.active {
  color: var(--pine);
  border-bottom-color: var(--mandarin);
}

.tab-count {
  display: inline-block;
  min-width: 18px;
  padding: 0 6px;
  margin-left: 6px;
  border-radius: 9px;
  background: var(--mandarin);
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
}

.modal-body {
  flex: 1;
  min-height: 0;
  padding: 18px 20px;
  overflow: hidden;
  display: flex;
}

.own-page { display: none; }
.own-page.active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  min-width: 0;
}

.modal-lead { margin: 0 0 14px; }

.add-form {
  display: grid;
  grid-template-columns: 190px 1fr 300px;
  gap: 18px;
  flex: 1;
  min-height: 0;
}
.add-form > div { min-width: 0; }

.add-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 15px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
}

/* столбец тем: список тянется, поле «своя тема» прижато книзу */
.add-card .multi.rules {
  flex: 1;
  min-height: 90px;
  max-height: none;
}

.store-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

/* ---------- фишки классов и тем ---------- */

.multi {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 4px;
}
.multi.rules {
  max-height: 260px;
  overflow-y: auto;
  align-content: flex-start;
}

.chip {
  border: 1.5px solid var(--line);
  background: #FCFEFC;
  color: var(--ink);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 12.5px;
  cursor: pointer;
  line-height: 1.3;
}
.chip:hover { border-color: var(--leaf); background: var(--leaf-soft); }
.chip.on {
  background: linear-gradient(120deg, var(--grass), var(--moss));
  border-color: var(--moss);
  color: #fff;
}
.multi.grades .chip { min-width: 32px; text-align: center; }

.chip.mine { border-color: #EAA96F; background: var(--amber-soft); }
.chip.mine.on { background: var(--mandarin); border-color: var(--mandarin); color: #fff; }

.chip-x { margin-left: 5px; padding: 0 2px; opacity: .65; font-weight: 700; }
.chip-x:hover { opacity: 1; }

.chip.add-rule { border-style: dashed; color: var(--muted); }

.own-rule-add {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  flex: none;
}
.own-rule-add input { flex: 1; min-width: 0; }

/* ---------- таблица своих элементов ---------- */

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
  flex: none;
}
.toolbar select, .toolbar input[type=text] { width: auto; min-width: 150px; }
.toolbar-info { font-size: 12.5px; color: var(--muted); margin-left: auto; }

.scroll {
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.scroll.grow { flex: 1; min-height: 0; }

table.db {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.db th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #F3F7EB;
  color: var(--pine);
  text-align: left;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.db td {
  padding: 7px 10px;
  border-bottom: 1px solid #EEF3E4;
  vertical-align: top;
}
table.db tr:last-child td { border-bottom: 0; }
table.db td.narrow { width: 1%; white-space: nowrap; }

table.db input.cell {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 4px 7px;
  background: transparent;
  font-size: 13px;
}
table.db input.cell:hover { border-color: var(--line); background: #FCFEFC; }
table.db input.cell:focus { border-color: var(--leaf); background: #fff; outline: none; }

/* В личном списке длинный текст должен читаться и правиться целиком.
   Предложения и определения получают растущие многострочные поля; два
   текстовых столбца сделаны шире за счёт компактных служебных столбцов. */
#tbl-my {
  table-layout: fixed;
  min-width: 1080px;
}
#tbl-my th:nth-child(1) { width: 100px; }
#tbl-my th:nth-child(2) { width: 24%; }
#tbl-my th:nth-child(3) { width: 29%; }
#tbl-my th:nth-child(4) { width: 70px; }
#tbl-my th:nth-child(6) { width: 94px; }
#tbl-my td.own-text-cell { vertical-align: top; }
#tbl-my .own-delete-col {
  position: sticky;
  right: 0;
  width: 94px;
  min-width: 94px;
  background: #fff;
  text-align: center;
  box-shadow: -6px 0 8px rgba(31, 77, 25, .06);
}
#tbl-my th.own-delete-col {
  z-index: 2;
  background: #F3F7EB;
}
#tbl-my .own-delete {
  width: 100%;
  padding-inline: 8px;
  white-space: nowrap;
}
#tbl-my textarea.cell {
  display: block;
  width: 100%;
  min-height: 68px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  font-size: 13px;
  line-height: 1.45;
  resize: vertical;
  overflow-y: hidden;
}
#tbl-my textarea.cell:hover { border-color: var(--leaf); }
#tbl-my textarea.cell:focus {
  border-color: var(--moss);
  box-shadow: 0 0 0 2px rgba(75, 155, 54, .12);
  outline: none;
}

table.db .multi { margin: 0; gap: 3px; }
table.db .multi .chip { font-size: 11px; padding: 1px 6px; }
table.db .multi.grades .chip { min-width: 22px; padding: 1px 4px; }

/* Свёрнутые темы: display:contents перебивает атрибут hidden,
   поэтому скрытое состояние задаём явно */
table.db .rules-rest { display: contents; }
table.db .rules-rest[hidden] { display: none; }

.kind-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 8px;
  background: var(--leaf-soft);
  color: var(--pine);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.empty-cell {
  padding: 30px 18px;
  text-align: center;
  color: var(--muted);
  line-height: 1.6;
}

.no-rule { opacity: .7; }

/* ============================================================
   Печать: на бумагу идут только карточки
   ============================================================ */

@media print {
  .no-print, header.topbar, .panel, .rules-pane, .modal-back { display: none !important; }
  body { background: #fff; }
  .app { display: block; height: auto; }
  .preview-pane { padding: 0; overflow: visible; }
  #preview { display: block; gap: 0; }
  .sheet-wrap { filter: none; transform: none !important; width: auto !important; height: auto !important; }
}

/* ============================================================
   Узкие экраны
   ============================================================ */

@media (max-width: 1280px) {
  .app { grid-template-columns: 310px 340px 1fr; }
}

@media (max-width: 1080px) {
  .app { grid-template-columns: 1fr; height: auto; }
  body.constructor-view { overflow: auto; }
  .panel, .rules-pane {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow: visible;
  }
  .rules-list { max-height: 320px; }
}

@media (max-width: 900px) {
  .modal-back { padding: 0; }
  .modal { height: 100%; border-radius: 0; }
  .add-form { grid-template-columns: 1fr; }
  header.topbar { flex-wrap: wrap; gap: 10px; }
  .brand { margin-right: 0; width: 100%; }
}

/* Любой скрытый список фишек: display:flex у .multi перебивает
   атрибут hidden, поэтому скрытое состояние задаём явно */
.multi[hidden] { display: none !important; }

/* ============================================================
   Плашки тем — тёмно-зелёные

   На светлом градиенте белые буквы читались плохо, особенно
   у длинных названий в две строки. Классы (цифры) и остальные
   элементы не трогаем: там текст короткий и контраста хватает.
   ============================================================ */
.multi.rules .chip.on,
table.db .rules-rest .chip.on {
  background: #1F6B18;
  border-color: #1A5A14;
  color: #fff;
}
.multi.rules .chip.on:hover,
table.db .rules-rest .chip.on:hover {
  background: #185412;
  border-color: #133F0E;
}

/* своя тема остаётся оранжевой — её нужно отличать от библиотечной */
.multi.rules .chip.mine.on,
table.db .rules-rest .chip.mine.on {
  background: #C96A22;
  border-color: #B25C1B;
}
