:root {
  --bg: #f6f3ed;
  --panel: #ffffff;
  --border: #e6ddd0;
  --text: #2b241c;
  --muted: #7a7266;
  --accent: #985522;
  --accent-dark: #70401e;
  --green: #4a7c3f;
  --red: #b3402c;
}

* { box-sizing: border-box; }

a { color: var(--accent-dark); text-decoration: none; text-underline-offset: 3px; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid #b67b42; outline-offset: 3px; }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--accent); }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

header.topbar {
  background: #352b23;
  color: #fff;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 20px;
  box-shadow: 0 2px 8px #352b2314;
}

header.topbar a {
  color: #fff;
  text-decoration: none;
  opacity: 0.85;
}

header.topbar a.brand {
  font-weight: 700;
  font-size: 18px;
  opacity: 1;
  white-space: nowrap;
  letter-spacing: -.4px;
}

.main-nav { flex: 1; min-width: 0; }
.nav-toggle-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
.nav-toggle-label { display: none; margin: 0; color: #fff; cursor: pointer; -webkit-user-select: none; user-select: none; }
.main-nav .nav-caret { display: inline-block; transition: transform .15s; }
.main-nav .nav-current { opacity: .75; font-weight: 400; }
.nav-toggle-input:checked + .nav-toggle-label .nav-caret { transform: rotate(180deg); }
.nav-links { display: flex; flex-wrap: wrap; gap: 4px; }
.nav-group { display: flex; flex-wrap: wrap; gap: 4px; padding-right: 10px; margin-right: 6px; border-right: 1px solid #ffffff26; }
.nav-group:last-child { border-right: 0; margin-right: 0; padding-right: 0; }
.main-nav a { padding: 7px 10px; border-radius: 7px; font-size: 13px; white-space: nowrap; }
header.topbar .main-nav a:hover { background: #ffffff12; text-decoration: none; }
header.topbar a[aria-current=page] { background: #f1dfc6; color: #352b23; opacity: 1; font-weight: 600; }
header.topbar a[aria-current=page]:hover { background: #f1dfc6; }
header.topbar form button { background: #ffffff0d; border: 1px solid #ffffff30; color: #f1dfc6; }

header.topbar a:hover { opacity: 1; text-decoration: underline; }

main {
  max-width: 1280px;
  margin: 32px auto;
  padding: 0 20px 60px;
}

h1 { font-size: 28px; margin: 0 0 20px; letter-spacing: -.7px; line-height: 1.2; }
h2 { font-size: 18px; margin: 24px 0 12px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 18px;
  box-shadow: 0 3px 16px #352b2305;
  min-width: 0;
}

.panel:has(> table) { overflow-x: auto; }
.panel > :first-child { margin-top: 0; }
.panel > :last-child { margin-bottom: 0; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th, td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; background: #faf8f4; }
td { font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }
td > a:not(.button) { font-weight: 600; color: var(--text); }
td > a:not(.button):hover { color: var(--accent); }

tr:hover td { background: #fbf3e8; }

a.button, button, input[type=submit] {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  text-decoration: none;
  font-family: inherit;
  font-weight: 500;
  line-height: 1.4;
  transition: background-color .15s, border-color .15s;
}

a.button:hover, button:hover { background: var(--accent-dark); }
a.button:hover { text-decoration: none; }

a.button.secondary, button.secondary {
  background: transparent;
  color: var(--accent-dark);
  border: 1px solid var(--border);
}
a.button.secondary:hover, button.secondary:hover { background: #f1e9dd; border-color: #ceb99e; }

button.danger { background: var(--red); }

form.inline { display: inline; }

label { display: block; margin: 10px 0 4px; font-size: 13px; color: var(--muted); }

input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: #fff;
  font-family: inherit;
  color: var(--text);
  min-height: 38px;
}
input[type=checkbox], input[type=radio] { min-height: auto; }
textarea { resize: vertical; line-height: 1.5; }

.grid-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 16px;
  max-width: 480px;
}

.filter-form {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 4px 16px;
}

.filter-form label { margin: 10px 0 4px; }
.filter-form input, .filter-form select { width: auto; }

.filter-form label.checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}
.filter-form label.checkbox input { width: auto; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.stats-3 { grid-template-columns: repeat(3, 1fr); }
.stats-4 { grid-template-columns: repeat(4, 1fr); }
.stats-5 { grid-template-columns: repeat(5, 1fr); }

/* Строка поиска */
.search-form { display: flex; gap: 8px; margin-bottom: 16px; }
.search-form input { flex: 1; min-width: 0; margin: 0; }
.search-form .button { white-space: nowrap; }

/* Форма фильтра по периоду: поля перестраиваются по ширине экрана */
.range-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px 14px;
  align-items: end;
}
.range-form label { display: block; margin: 0 0 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
.range-form input, .range-form select { width: 100%; min-width: 0; box-sizing: border-box; margin: 0; }
.range-form button { width: 100%; padding: 11px 14px; }

.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
}

.stat .value { font-size: 26px; font-weight: 700; color: var(--accent-dark); }
.stat .label { font-size: 13px; color: var(--muted); }
.delta { font-size: 12px; font-weight: 600; }
.stat .delta { display: block; margin-top: 4px; }
.delta.up { color: var(--green); }
.delta.down { color: var(--red); }
.delta.flat { color: var(--muted); }

/* Быстрые пресеты периода в «Аналитике» */
.preset-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.preset-row .button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Графики: контейнер задаёт позицию для подсказки при наведении */
.chart-container { position: relative; margin: 4px 0 8px; }
.chart-svg { display: block; overflow: visible; }
.chart-grid { stroke: var(--border); stroke-width: 1; }
.chart-axis-label { fill: var(--muted); font-size: 11px; }
.chart-bar { cursor: pointer; transition: opacity .1s; }
.chart-bar:hover, .chart-bar:focus-visible { opacity: 0.8; outline: none; }
.chart-line { stroke-width: 2; fill: none; stroke-linejoin: round; stroke-linecap: round; }
.chart-area { opacity: 0.1; }
.chart-crosshair { stroke: var(--muted); stroke-width: 1; }
.chart-dot { fill: var(--accent); stroke: var(--panel); stroke-width: 2; }
.chart-tooltip {
  position: absolute;
  transform: translate(-50%, -100%) translateY(-10px);
  background: var(--text);
  color: #fff;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.35;
  white-space: nowrap;
  pointer-events: none;
  z-index: 5;
}
.chart-tooltip-value { font-weight: 700; }
.chart-tooltip-label { opacity: 0.85; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  background: #eee;
}

.badge.status-новый { background: #eee6d9; color: #705438; }
.badge.status-подтверждён { background: #fbeedb; color: #8a5a1a; }
.badge[class~="status-в"][class~="производстве"] { background: #f6dfc0; color: #8a5a1a; }
.badge.status-готов { background: #dff0d8; color: var(--green); }
.badge[class~="status-в"][class~="доставке"] { background: #e7ebdf; color: #52613e; }
.badge.status-выполнен { background: #dff0d8; color: var(--green); }
.badge.status-отменён { background: #f7d9d3; color: var(--red); }
.badge.status-ожидает { background: #eee; color: #666; }
.badge.status-готово { background: #dff0d8; color: var(--green); }

.phone-suggestions {
  position: absolute;
  z-index: 10;
  left: 0;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  max-height: 220px;
  overflow-y: auto;
}

.phone-suggestion {
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.phone-suggestion:last-child { border-bottom: none; }
.phone-suggestion:hover { background: #fbf3e8; }
.phone-suggestion.muted { cursor: default; }
.phone-suggestion.muted:hover { background: transparent; }

.alert-error {
  background: #fbe9e5;
  color: var(--red);
  border: 1px solid #f0c3b8;
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 14px;
}

.alert-success {
  background: #eaf3e6;
  color: var(--green);
  border: 1px solid #cfe3c7;
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 14px;
  transition: opacity 0.4s ease;
}

.muted { color: var(--muted); }
.right { text-align: right; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.nowrap { white-space: nowrap; }

.products-layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.panel-row { display: flex; gap: 20px; align-items: stretch; margin-bottom: 24px; }
.panel-row > .panel { margin-bottom: 0; }

.category-filters {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 180px;
  padding: 8px;
  background: #eee8df;
  border-radius: 12px;
}

.category-filters .button {
  text-align: left;
  border-color: transparent;
  padding: 11px 12px;
}

.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 26px; }
.page-heading h1 { margin-bottom: 0; }
.eyebrow { margin: 0 0 7px; color: var(--muted); font-size: 12px; }
.heading-count { display: inline-block; vertical-align: middle; background: #eae3d8; color: #706253; font-size: 14px; padding: 4px 9px; border-radius: 8px; letter-spacing: 0; }
.products-panel { padding: 8px; }
#products-table td:first-child { min-width: 185px; }
#products-table td.right { white-space: nowrap; }
#products-table td:last-child .button { font-size: 12px; padding: 7px 11px; }

.category-filters .button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.category-filters .button.active .muted {
  color: #fff;
  opacity: 0.85;
}

table.production-table {
  table-layout: fixed;
}

table.production-table td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Кнопка действия не обрезается, если не помещается в фиксированную ширину
   колонки (например, "Взять в производство" на ноутбучной ширине) — переносится
   на вторую строку вместо клиппинга. */
table.production-table td:last-child {
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
}
table.production-table td:last-child button {
  white-space: normal;
}

tr.category-row td {
  background: var(--bg);
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(43, 36, 28, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: modal-fade-in 0.15s ease;
}

.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 22px;
  max-width: 360px;
  width: calc(100% - 40px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
  animation: modal-pop-in 0.15s ease;
}

.modal p {
  margin: 0 0 18px;
  font-size: 15px;
  color: var(--text);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@keyframes modal-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modal-pop-in {
  from { opacity: 0; transform: scale(0.96) translateY(4px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* Delivery board */
.delivery-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.delivery-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.delivery-heading h2 { margin: 0; }
.delivery-fields { display: grid; grid-template-columns: 2fr 1fr 1.3fr auto; align-items: end; gap: 12px; }
.delivery-action { margin-top: 18px; }
.delivery-card li { margin-bottom: 6px; }
.delivery-card { overflow-wrap: anywhere; }
header.topbar { flex-wrap: wrap; }
@media (max-width: 700px) {
  .delivery-fields { grid-template-columns: 1fr; }
  .delivery-tabs .button { flex: 1 1 auto; text-align: center; }
}

button:disabled, button:disabled:hover { background: #ddd; color: #777; cursor: not-allowed; }
.production-blocker { display: block; white-space: normal; color: var(--red); margin-top: 6px; }

@media (max-width: 1100px) {
  header.topbar { gap: 12px; padding: 14px 20px; }
  .main-nav { order: 3; flex-basis: 100%; }
  header.topbar > form { margin-left: auto !important; }
  .products-layout { flex-direction: column; gap: 16px; }
  .panel-row { flex-direction: column; gap: 16px; }
  .category-filters { flex-direction: row; flex-wrap: wrap; width: 100%; gap: 4px; }
  .products-panel { width: 100%; }
}
@media (max-width: 600px) {
  .nav-toggle-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 9px 12px;
    background: #ffffff14;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
  }
  .nav-links { display: none; flex-direction: column; gap: 10px; margin-top: 8px; }
  .nav-toggle-input:checked ~ .nav-links { display: flex; }
  .nav-group { flex-direction: column; gap: 2px; padding-right: 0; margin-right: 0; border-right: 0; padding-bottom: 8px; margin-bottom: 2px; border-bottom: 1px solid #ffffff20; }
  .nav-group:last-child { border-bottom: 0; padding-bottom: 0; margin-bottom: 0; }
  main { margin: 22px auto; padding: 0 12px 36px; }
  h1 { font-size: 24px; }
  .panel { padding: 12px; }
  .page-heading { align-items: flex-start; }
  .page-heading > .button { white-space: nowrap; font-size: 12px; }
  .stats, .stats-3, .stats-4, .stats-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats-3 .stat:last-child, .stats-5 .stat:last-child { grid-column: 1 / -1; }
  .range-form { grid-template-columns: 1fr 1fr; }
  .range-form > :nth-child(n+3) { grid-column: 1 / -1; }
  .stat .value { font-size: 22px; }
  .grid-form { grid-template-columns: 1fr; }
  .grid-form > * { grid-column: auto !important; }
  .filter-form { align-items: stretch; }
  .filter-form > div { flex: 1 1 140px; min-width: 0; }
  .filter-form input, .filter-form select { width: 100%; }
  .category-filters { flex-wrap: nowrap; overflow-x: auto; }
  .category-filters .button { white-space: nowrap; }
  th, td { padding: 10px; }

  /* Таблицы превращаются в карточки: подписи берёт mobile_tables.js из thead */
  .panel:has(> table) { overflow-x: visible; background: none; border: 0; box-shadow: none; padding: 0; }
  table, tbody { display: block; }
  thead { display: none; }
  tbody tr {
    display: block;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 6px 12px;
    margin-bottom: 10px;
  }
  tbody td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    min-width: 0 !important;
    padding: 6px 0;
    border-bottom: 1px solid #f0ebe3;
    text-align: right;
    overflow-wrap: anywhere;
  }
  tbody td:last-child, tbody tr:last-child td:last-child { border-bottom: 0; }
  tbody td[data-label]::before {
    content: attr(data-label);
    flex: 0 0 auto;
    max-width: 45%;
    color: var(--muted);
    font-size: 12px;
    text-align: left;
  }
  tbody td:not([data-label]) { display: block; text-align: left; }
  tbody td.right { text-align: right; }
  tbody td > input, tbody td > select { max-width: 55%; }
  tr:hover td { background: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Раздел «Контент» */
.content-build-form { display: grid; gap: 4px; max-width: 520px; }
.content-build-form button { justify-self: start; margin-top: 12px; }
.content-summary p { margin: 0 0 8px; }
.content-texts-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 12px; }
.content-texts-form .content-busy { flex-basis: 100%; margin: 0; }
.content-card { overflow-wrap: anywhere; }
.content-card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.content-card-head h2 { margin: 0; }
.content-card-head .badge { background: #eae3d8; color: #706253; }
.content-card-head .badge.content-published { background: #eaf3e6; color: var(--green); }
.content-fields { margin: 12px 0 0; }
.content-fields dt { font-size: 13px; color: var(--muted); margin-top: 10px; }
.content-fields dd { margin: 2px 0 0; }
.content-text { white-space: pre-wrap; }
.content-caption { margin-top: 14px; padding: 12px; background: #faf7f2; border: 1px solid var(--border); border-radius: 8px; }
.content-label { margin: 0 0 6px; font-size: 13px; color: var(--muted); }
.content-caption .content-copy { margin-top: 10px; }
.content-card-actions { margin-top: 14px; }
.content-edit { margin-top: 14px; }
.content-edit summary { cursor: pointer; color: var(--accent-dark); }
.content-edit button { margin-top: 12px; }
.content-strategy-text { font-family: monospace; }
.content-form-actions { margin-top: 16px; }
@media (max-width: 600px) {
  .content-build-form button, .content-card-actions button, .content-caption .content-copy { width: 100%; }
}

/* Контент v2: режим недели, ссылки с меткой, поводы, съёмка пачкой, итоги */
.content-mode { margin: 10px 0 0; padding: 0; border: 0; min-width: 0; }
.content-mode legend { padding: 0; font-size: 13px; color: var(--muted); }
.content-mode label { display: flex; align-items: flex-start; gap: 8px; margin: 6px 0 0; font-size: 15px; color: inherit; cursor: pointer; }
.content-mode input { margin-top: 3px; flex: none; }
.content-link { font-family: monospace; font-size: 14px; overflow-wrap: anywhere; word-break: break-all; }
.content-bio .content-copy { margin-top: 10px; }
.content-season ul, .content-batches ul { margin: 6px 0 0; padding-left: 20px; }
.content-season li, .content-batches li { margin-top: 6px; overflow-wrap: anywhere; }
.content-batches h3 { margin: 14px 0 0; font-size: 16px; }
@media (max-width: 600px) {
  .content-bio .content-copy { width: 100%; }
}
