/* ═══════════════════════════════════════════════════════════════
   CRAFT PLAN REDESIGN — Этап 3 UX
   Подключается ПОСЛЕ tokens.css в craft_plan.html.
   Дизайн: «Доработки дизайна/craft-plan-redesign» (3 мая 2026, v1.0)
   ═══════════════════════════════════════════════════════════════ */

/* ── Индикатор свежести данных ── */
.freshness-indicator {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 12px;
}
.freshness-bar {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  transition: background var(--transition);
  text-align: left;
}
.freshness-bar:hover { background: var(--bg-3); }
.freshness-status { display: flex; align-items: center; gap: 8px; flex: 1; }
.freshness-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.freshness-dot.freshness-fresh   { background: var(--success); box-shadow: 0 0 8px rgba(63,185,80,0.5); }
.freshness-dot.freshness-medium  { background: var(--warn);    box-shadow: 0 0 8px rgba(210,153,34,0.5); }
.freshness-dot.freshness-stale   { background: var(--danger);  box-shadow: 0 0 8px rgba(248,81,73,0.5); }
.freshness-dot.freshness-unknown { background: var(--text-subtle); box-shadow: none; }
.freshness-text strong { color: var(--text); font-weight: 600; }
.freshness-separator { margin: 0 6px; color: var(--border); }
.freshness-sources-preview { font-size: 12px; color: var(--text-subtle); }
.freshness-warn {
  font-size: 12px; font-weight: 600; color: var(--danger);
  margin-left: 6px; cursor: help;
}
.freshness-chevron {
  flex-shrink: 0; color: var(--text-subtle);
  transition: transform 0.3s ease;
}
.freshness-bar[aria-expanded="true"] .freshness-chevron { transform: rotate(180deg); }
.freshness-details {
  max-height: 0; overflow: hidden;
  transition: max-height 0.3s ease;
}
.freshness-details.open { max-height: 75vh; overflow-y: auto; }
.freshness-details-inner {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border-muted);
}
.freshness-details-title {
  font-size: 13px; font-weight: 700; color: var(--text);
  margin: 0 0 10px 0; text-transform: uppercase; letter-spacing: 0.03em;
}
.freshness-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.freshness-table thead th {
  text-align: left; padding: 6px 8px;
  background: var(--border-muted); color: var(--text-subtle);
  font-weight: 600; text-transform: uppercase;
  font-size: 11px; letter-spacing: 0.03em;
}
.freshness-table tbody td {
  padding: 6px 8px; border-bottom: 1px solid var(--border-muted);
  color: var(--text-muted);
}
.freshness-table tbody tr:nth-child(even) { background: var(--bg-3); }
.freshness-table tbody tr:last-child td { border-bottom: none; }
.freshness-note {
  margin-top: 10px; color: var(--text-subtle);
  font-size: 11px; line-height: 1.5;
}
.stale-prices-block {
  margin-top: 12px;
  border: 1px solid var(--border-muted);
  border-radius: 6px;
  overflow: hidden;
}
.stale-prices-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg-3);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.stale-prices-count {
  min-width: 22px;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(248,81,73,.14);
  color: var(--danger);
  text-align: center;
  font-size: 11px;
}
.stale-prices-list { padding: 4px 0; }
.stale-price-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-top: 1px solid var(--border-muted);
}
.stale-price-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 7px; }
.stale-price-name {
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stale-price-kind {
  flex-shrink: 0;
  color: var(--text-subtle);
  font-size: 10px;
  text-transform: uppercase;
}
.stale-price-meta { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.stale-price-value {
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.stale-prices-more {
  padding: 7px 10px;
  border-top: 1px solid var(--border-muted);
  color: var(--text-subtle);
  font-size: 11px;
}

/* ── Таблица ингредиентов v2 ── */
.ing-table-v2 { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; table-layout: fixed; }
.ing-table-v2 thead th {
  padding: 8px 10px; background: var(--border-muted);
  color: var(--text-muted); font-weight: 600; font-size: 11px;
  text-align: left; border-bottom: 2px solid var(--border);
  text-transform: uppercase; letter-spacing: 0.03em;
}
.ing-table-v2 .ing-col-name      { width: 28%; }
.ing-table-v2 .ing-col-qty       { width: 9%;  text-align: right; }
.ing-table-v2 .ing-col-warehouse { width: 11%; text-align: right; }
.ing-table-v2 .ing-col-buy       { width: 9%;  text-align: right; }
.ing-table-v2 .ing-col-price     { width: 13%; text-align: right; }
.ing-table-v2 .ing-col-city      { width: 14%; }
.ing-table-v2 .ing-col-source    { width: 16%; }
.ing-table-v2 td, .ing-table-v2 th { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ing-table-v2 .ing-col-name { white-space: normal; }
.ing-table-v2 tbody td {
  padding: 8px 10px; border-bottom: 1px solid var(--border-muted);
  vertical-align: middle;
}
.ing-table-v2 tbody td.ing-col-source {
  min-width: 88px;
  text-align: left;
  vertical-align: middle;
}
.ing-table-v2 tbody tr:last-child td { border-bottom: none; }
.ing-table-v2 tbody tr:hover td { background: var(--bg-3); }
.ing-row-no-data { background: rgba(248, 81, 73, 0.03); }
.ing-name-cell {
  display: flex; align-items: center; gap: 8px;
  flex-wrap: wrap;
  row-gap: 4px;
}
.ing-name-link {
  color: var(--text); text-decoration: none; font-weight: 500;
  transition: color var(--transition);
}
.ing-name-link:hover { color: var(--accent); text-decoration: underline; }
.ing-table-v2 .ing-col-qty,
.ing-table-v2 .ing-col-warehouse,
.ing-table-v2 .ing-col-buy,
.ing-table-v2 .ing-col-price {
  font-variant-numeric: tabular-nums;
}
.ing-city { color: #e67e22; font-weight: 500; font-size: 12px; }

/* Бейджи источников цен */
.source-badge-wrap {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
}
.source-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px; border-radius: 4px;
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.04em;
  cursor: help; white-space: nowrap;
  position: relative;
}
.source-badge[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute; bottom: 100%; left: 50%;
  transform: translateX(-50%);
  margin-bottom: 6px; padding: 8px 12px;
  background: var(--bg-overlay); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text);
  font-size: 11px; font-weight: 400;
  text-transform: none; letter-spacing: normal;
  white-space: normal; max-width: 250px; width: max-content;
  box-shadow: var(--shadow-md);
  z-index: 1000; line-height: 1.4;
  pointer-events: none;
}
.source-1d   { background: #238636; color: #fff; }
.source-3d   { background: #9a6700; color: #fff; }
.source-10d  { background: #e67e22; color: #fff; }
.source-30d  { background: #6e7681; color: #fff; }
.source-live { background: #1f6feb; color: #fff; }
.source-bm   { background: #6f42c1; color: #fff; }
.source-royal{ background: #1f6feb; color: #fff; }
.source-manual{ background: #f0b040; color: #1f1300; }

.price-no-data {
  display: inline-block; padding: 4px 10px;
  background: var(--danger-bg); color: var(--danger);
  border-radius: 4px;
  font-size: 11px; font-weight: 700;
}

.warning-box {
  background: var(--warn-bg);
  border-left: 3px solid var(--warn);
  padding: 10px 14px; border-radius: 6px;
  font-size: 13px; color: var(--warn);
  margin-top: 12px; line-height: 1.5;
}
.warning-box strong { font-weight: 700; }

/* ── Waterfall Summary ── */
.waterfall-summary {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  font-size: 14px;
}
.waterfall-section { margin-bottom: 20px; }
.waterfall-section:last-of-type { margin-bottom: 16px; }
.waterfall-section-title {
  font-size: 13px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0 0 10px 0; padding-bottom: 6px;
  border-bottom: 1px solid var(--border-muted);
}
.waterfall-rows { display: flex; flex-direction: column; gap: 6px; }
.waterfall-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 0; border-bottom: 1px solid var(--border-muted);
  transition: background var(--transition);
}
.waterfall-row:hover { background: var(--bg-3); }
.waterfall-row:last-child { border-bottom: none; }
.waterfall-row.is-sub {
  padding-left: 18px; font-size: 12px; color: var(--text-muted);
}
.waterfall-label {
  display: flex; align-items: center; gap: 6px;
  color: var(--text); font-size: 14px;
}
.waterfall-row.is-sub .waterfall-label { color: var(--text-muted); font-size: 12px; }
.waterfall-value {
  font-variant-numeric: tabular-nums;
  font-weight: 600; font-size: 15px;
  white-space: nowrap;
}
.waterfall-row.is-sub .waterfall-value { font-size: 12px; }
.waterfall-positive { color: var(--success); }
.waterfall-negative { color: var(--danger); }
.waterfall-neutral  { color: var(--text-muted); }
.info-icon {
  width: 16px; height: 16px; border-radius: 50%;
  background: none; border: 1px solid var(--text-subtle);
  color: var(--text-subtle);
  font-size: 11px; font-weight: 700;
  cursor: help; padding: 0; line-height: 1;
  transition: all var(--transition);
  flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
}
.info-icon:hover {
  border-color: var(--accent); color: var(--accent);
  background: var(--accent-bg);
}
.waterfall-subtotal {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0 0; margin-top: 6px;
  border-top: 2px solid var(--border);
  font-weight: 700; font-size: 15px;
}
.waterfall-subtotal .waterfall-label { font-weight: 700; color: var(--text); }
.waterfall-subtotal .waterfall-value { font-size: 16px; }

.waterfall-profit {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 0 14px; margin-bottom: 16px;
  border-bottom: 3px double var(--border);
}
.waterfall-profit-label {
  font-size: 16px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--success);
}
.waterfall-profit-value {
  font-size: 20px; font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.waterfall-profit-value.positive { color: var(--success); }
.waterfall-profit-value.negative { color: var(--danger); }
.waterfall-profit-percent {
  font-size: 14px; color: var(--text-muted);
  margin-left: 8px;
}

/* Глобальный плавающий тултип waterfall */
.waterfall-tooltip {
  position: fixed;
  background: var(--bg-overlay); border: 1px solid var(--border);
  border-radius: 6px; padding: 10px 14px;
  font-size: 12px; line-height: 1.5;
  max-width: 280px;
  box-shadow: var(--shadow-md);
  z-index: 1000;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  color: var(--text);
}
.waterfall-tooltip.show { opacity: 1; }
.waterfall-tooltip strong { display: block; margin-bottom: 4px; color: var(--text); }

/* ── Объединённый чек-лист закупок ── */
.shopping-tabs {
  display: flex; gap: 8px; margin-bottom: 12px;
  border-bottom: 1px solid var(--border-muted);
  padding-bottom: 8px;
}
.shopping-tab {
  padding: 6px 14px;
  background: none; border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-muted);
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}
.shopping-tab:hover { border-color: var(--accent); color: var(--text); }
.shopping-tab.active {
  background: var(--accent-bg); border-color: var(--accent);
  color: var(--accent);
}
.shopping-summary {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--bg-3); padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px; margin-bottom: 12px;
  flex-wrap: wrap; gap: 8px;
  color: var(--text-muted);
}
.shopping-summary-text strong,
.shopping-summary-total strong {
  color: var(--text); font-weight: 700;
}
.shopping-summary-total strong {
  color: var(--danger); font-size: 15px;
}
.shopping-table-wrap { overflow-x: auto; }
.shopping-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.shopping-table thead th {
  padding: 8px 10px; background: var(--border-muted);
  color: var(--text-muted);
  font-weight: 600; font-size: 11px;
  text-align: left; border-bottom: 2px solid var(--border);
  text-transform: uppercase; letter-spacing: 0.03em;
  white-space: nowrap;
}
.shopping-table thead .col-check { width: 40px; text-align: center; }
.shopping-table thead .col-qty,
.shopping-table thead .col-price,
.shopping-table thead .col-total { text-align: right; }
.shopping-table tbody td {
  padding: 8px 10px; border-bottom: 1px solid var(--border-muted);
  vertical-align: middle;
}
.shopping-table tbody td.col-source {
  min-width: 88px;
  text-align: left;
  white-space: nowrap;
  vertical-align: middle;
}
.shopping-table tbody tr:last-child td { border-bottom: none; }
.shopping-table tbody tr:hover td { background: var(--bg-3); }
.shopping-table tbody tr.checked { opacity: 0.5; }
.shopping-table tbody tr.checked .item-name-cell { text-decoration: line-through; }
.shopping-table tbody tr.hidden { display: none; }
.col-check { text-align: center; }
.shopping-checkbox {
  width: 18px; height: 18px;
  cursor: pointer;
  accent-color: var(--accent);
}
.item-name-cell {
  display: flex; align-items: center; gap: 8px;
  flex-wrap: wrap;
  row-gap: 4px;
}
.shopping-item-icon {
  width: 32px; height: 32px;
  border-radius: 4px;
  background: var(--border-muted);
  flex-shrink: 0;
}
.shopping-item-name {
  color: var(--text); text-decoration: none;
  font-weight: 500;
  transition: color var(--transition);
}
.shopping-item-name:hover { color: var(--accent); text-decoration: underline; }
.shopping-item-type {
  display: inline-block; margin-left: 6px;
  padding: 2px 6px; border-radius: 3px;
  font-size: 10px; font-weight: 700;
  text-transform: uppercase;
}
.type-resource { background: rgba(63, 185, 80, 0.15); color: var(--success); }
.type-journal  { background: rgba(88, 166, 255, 0.15); color: var(--accent); }
.shopping-city { color: #e67e22; font-weight: 500; }
.shopping-table .col-qty,
.shopping-table .col-price,
.shopping-table .col-total {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.shopping-table .col-total { font-weight: 600; }

/* ── Пресеты крафтера ── */
.sb-presets-section {
  padding: 12px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}
.preset-grid {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 8px; margin-bottom: 8px;
}
.preset-card {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  min-height: 78px;
  height: auto;
  box-sizing: border-box;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 8px;
  gap: 6px;
  cursor: pointer; transition: all 0.2s ease;
  text-align: center;
  color: var(--text);
}
.preset-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 100%;
  min-width: 0;
}
.preset-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}
.preset-card.active {
  background: var(--accent-bg);
  border-color: var(--accent);
}
.preset-card.active .preset-name { color: var(--accent); }
.preset-icon { font-size: 20px; line-height: 1; flex-shrink: 0; }
.preset-name {
  font-size: 11px; font-weight: 700;
  color: var(--text);
  line-height: 1.25;
  width: 100%;
  max-width: 100%;
}
.preset-desc {
  font-size: 10px; color: var(--text-muted);
  line-height: 1.35;
  width: 100%;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-wrap: break-word;
  hyphens: auto;
}

/* ── Мобильная адаптация ── */
@media (max-width: 768px) {
  .freshness-bar { flex-direction: column; align-items: flex-start; gap: 6px; }
  .freshness-sources-preview { font-size: 11px; }
  .freshness-table { font-size: 11px; }
  .freshness-table thead th,
  .freshness-table tbody td { padding: 4px 6px; }

  /* Ингредиенты → карточки */
  .ing-table-v2 thead { display: none; }
  .ing-table-v2,
  .ing-table-v2 tbody,
  .ing-table-v2 tr,
  .ing-table-v2 td { display: block; }
  .ing-table-v2 tbody tr {
    background: var(--bg-2); border: 1px solid var(--border);
    border-radius: 8px; padding: 12px; margin-bottom: 10px;
  }
  .ing-table-v2 tbody td { padding: 4px 0; border: none; text-align: left !important; }
  .ing-table-v2 tbody td::before {
    content: attr(data-label);
    display: inline-block; min-width: 90px;
    font-weight: 600; color: var(--text-muted);
    margin-right: 8px;
  }
  .ing-col-name::before { display: none; }
  .ing-name-cell { margin-bottom: 6px; }

  /* Waterfall */
  .waterfall-summary { padding: 12px 14px; }
  .waterfall-label { font-size: 13px; }
  .waterfall-value { font-size: 14px; }
  .waterfall-subtotal { font-size: 14px; }
  .waterfall-subtotal .waterfall-value { font-size: 15px; }
  .waterfall-profit-label { font-size: 14px; }
  .waterfall-profit-value { font-size: 18px; }
  .waterfall-profit-percent { font-size: 12px; }

  /* Чек-лист → карточки */
  .shopping-table thead { display: none; }
  .shopping-table,
  .shopping-table tbody,
  .shopping-table tr,
  .shopping-table td { display: block; }
  .shopping-table tbody tr {
    background: var(--bg-2); border: 1px solid var(--border);
    border-radius: 8px; padding: 12px; margin-bottom: 10px;
    position: relative;
  }
  .shopping-table tbody td { padding: 4px 0; border: none; text-align: left !important; }
  .shopping-table tbody td::before {
    content: attr(data-label);
    display: inline-block; min-width: 80px;
    font-weight: 600; color: var(--text-muted);
    margin-right: 8px;
  }
  .col-item::before { display: none; }
  .col-item { margin-bottom: 6px; }
  .col-check { position: absolute; top: 12px; right: 12px; }
  .col-check::before { display: none; }
  .shopping-summary { flex-direction: column; align-items: flex-start; }

  /* Пресеты */
  .preset-grid { grid-template-columns: 1fr; }
  .preset-card {
    min-height: 64px;
    height: auto;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    text-align: left;
    gap: 12px;
    padding: 10px 12px;
  }
  .preset-body {
    align-items: flex-start;
    flex: 1;
    min-width: 0;
    gap: 2px;
  }
  .preset-icon { font-size: 24px; }
}
