/* ============================================================
   ГЛАВНАЯ v423: приветствие, лента дня, низкие карточки, новые виджеты,
   настройка с «Шагом назад». Свой слой, подключается последним; всё
   замкнуто на .home4, чтобы не задеть рабочие разделы.
   ============================================================ */

.home4 {
  --h4-radius: 18px;
  --h4-now: #e6555f;
  --h4-ring: color-mix(in srgb, var(--home3-wine) 26%, transparent);
  gap: 16px;
}
.home4 > .home-greet, .home4 > .home-tune, .home4 > .home-gallery { grid-column: 1 / -1; min-width: 0; }
.home-ico { width: 100%; height: 100%; }

/* ---- Приветствие ---- */
.home-greet {
  display: flex; align-items: center; gap: 24px; min-width: 0;
  padding: 20px 24px; border: 1px solid var(--line); border-radius: var(--h4-radius);
  background:
    radial-gradient(120% 140% at 0% 0%, color-mix(in srgb, var(--home3-wine-soft) 95%, transparent), transparent 55%),
    radial-gradient(90% 120% at 100% 100%, color-mix(in srgb, var(--home3-teal-soft) 90%, transparent), transparent 60%),
    var(--surface-card);
  box-shadow: var(--shadow);
}
.hg-main { flex: 1 1 auto; min-width: 0; }
.hg-date { display: block; margin-bottom: 4px; color: var(--home3-wine); font-size: 11px; font-weight: 850; letter-spacing: .1em; text-transform: uppercase; }
.home-greet h1 { margin: 0 0 10px; font-size: 26px; line-height: 1.15; letter-spacing: -.02em; font-weight: 800; }
.hg-status { display: flex; flex-wrap: wrap; gap: 6px 8px; }
.hg-chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 11px;
  border: 1px solid var(--line); border-radius: 999px; background: color-mix(in srgb, var(--surface-card) 82%, transparent);
  color: var(--text); font-size: 12px; font-weight: 650; white-space: nowrap;
}
.hg-chip i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: none; }
.hg-chip.is-on i { background: #1f9d6b; box-shadow: 0 0 0 3px rgba(31, 157, 107, .16); }
.hg-chip.is-idle { color: var(--muted); }
.hg-chip.is-duty { border-color: color-mix(in srgb, var(--home3-gold) 45%, var(--line)); background: var(--home3-gold-soft); color: var(--home3-gold); }
.hg-side { display: flex; align-items: center; gap: 18px; flex: none; }
.hg-weather { display: flex; align-items: center; gap: 10px; }
.hg-weather-ico { font-size: 30px; line-height: 1; }
.hg-weather b { display: block; font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
.hg-weather small, .hg-clock small { display: block; max-width: 150px; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.hg-clock { padding-left: 18px; border-left: 1px solid var(--line); text-align: right; }
.hg-clock b { display: block; font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.hg-tune {
  display: inline-flex; align-items: center; gap: 7px; padding: 9px 14px;
  border: 1px solid var(--line); border-radius: 11px; background: var(--surface-card);
  color: var(--text); font: inherit; font-size: 12.5px; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.hg-tune .home-ico { width: 16px; height: 16px; color: var(--home3-wine); }
.hg-tune:hover { border-color: var(--home3-wine); color: var(--home3-wine); }

/* ---- Сетка: высота в половинках строки ---- */
.home4 .home-grid { grid-auto-rows: 127px; gap: 14px; }
.home4 .home-w[data-h="0.5"] { grid-row: span 1; }
.home4 .home-w[data-h="1"] { grid-row: span 2; }
.home4 .home-w[data-h="1.5"] { grid-row: span 3; }
.home4 .home-w[data-h="2"] { grid-row: span 4; }

/* ---- Карточка ---- */
.home4 .home-w {
  padding: 14px 16px; border-radius: var(--h4-radius);
  border-color: color-mix(in srgb, var(--line) 85%, transparent);
  transition: box-shadow .15s ease, transform .15s ease;
}
.home4 .home-w:hover { box-shadow: 0 10px 28px rgba(16, 24, 40, .08); }
.home4 .home-w-head { margin-bottom: 10px; }
.home4 .home-w-ico {
  width: 32px; height: 32px; padding: 7px; border-radius: 10px;
  background: var(--home3-wine-soft); color: var(--home3-wine); font-size: 0;
}
.home4 .home-w-title h2 { font-size: 14px; letter-spacing: -.005em; }
.home4 .home-w[data-h="0.5"] { padding: 10px 14px; }
.home4 .home-w[data-h="0.5"] .home-w-head { margin-bottom: 6px; }
.home4 .home-w[data-h="0.5"] .home-w-ico { width: 26px; height: 26px; padding: 5px; border-radius: 8px; }
.home4 .home-w[data-h="0.5"] .home-w-title small { display: none; }

/* Тихое пустое состояние вместо одной строки в углу пустой карточки. */
.home-quiet { display: grid; place-items: center; align-content: center; gap: 4px; height: 100%; min-height: 70px; text-align: center; }
.home-quiet .home-ico { width: 30px; height: 30px; margin-bottom: 4px; color: color-mix(in srgb, var(--home3-wine) 55%, var(--muted)); }
.home-quiet b { font-size: 13px; }
.home-quiet span { max-width: 260px; color: var(--muted); font-size: 11.5px; }
.home4 .home-w[data-h="0.5"] .home-quiet { grid-auto-flow: column; justify-content: start; gap: 10px; text-align: left; min-height: 0; }
.home4 .home-w[data-h="0.5"] .home-quiet .home-ico { width: 22px; height: 22px; margin: 0; }
.home4 .home-w[data-h="0.5"] .home-quiet span { display: none; }

/* ---- Лента дня ---- */
.htl-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.htl-tabs button {
  display: inline-flex; align-items: center; gap: 8px; padding: 5px 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface-card);
  color: var(--text); font: inherit; font-size: 12px; font-weight: 750; cursor: pointer;
}
.htl-tabs button em { color: var(--muted); font-size: 11px; font-style: normal; font-weight: 600; }
.htl-tabs button.is-on { border-color: var(--home3-wine); background: var(--home3-wine); color: #fff; }
.htl-tabs button.is-on em { color: rgba(255, 255, 255, .8); }
.htl-sum { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; margin-bottom: 10px; color: var(--muted); font-size: 11.5px; }
.htl-sum b { color: var(--text); font-variant-numeric: tabular-nums; }
.htl-sum .is-live { display: inline-flex; align-items: center; gap: 6px; color: var(--text); font-weight: 650; }
.htl-sum .is-live i { width: 7px; height: 7px; border-radius: 50%; background: var(--h4-now); animation: h4-pulse 1.8s ease-in-out infinite; }
.htl-sum .is-past b { color: var(--muted); }
.htl-open { margin-left: auto; padding: 0; border: 0; background: none; color: var(--home3-wine); font: inherit; font-size: 11.5px; font-weight: 800; cursor: pointer; }
@keyframes h4-pulse { 50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--h4-now) 20%, transparent); } }

.htl { position: relative; min-width: 0; }
.htl-axis { position: relative; height: 16px; margin: 0 8px 4px; color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.htl-axis span { position: absolute; top: 0; transform: translateX(-50%); white-space: nowrap; }
.htl-axis span:first-child { transform: none; }
.htl-axis span:last-child { transform: translateX(-100%); }
.htl-track { position: relative; margin: 0 8px; min-height: 26px; }
.htl-hour { position: absolute; top: -2px; bottom: -2px; width: 1px; background: color-mix(in srgb, var(--line) 70%, transparent); }
.htl-bar {
  position: absolute; height: 22px; min-width: 6px; padding: 0 7px; overflow: hidden;
  border: 0; border-left: 3px solid var(--c); border-radius: 6px;
  background: color-mix(in srgb, var(--c) 16%, var(--surface-card));
  color: var(--text); font: inherit; font-size: 11px; line-height: 22px; text-align: left; cursor: pointer;
}
.htl-bar b { display: block; overflow: hidden; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.htl-bar.is-live { background: color-mix(in srgb, var(--c) 30%, var(--surface-card)); box-shadow: 0 2px 8px color-mix(in srgb, var(--c) 30%, transparent); }
.htl-bar.is-live b { font-weight: 800; }
.htl-bar.is-past { opacity: .45; }
.htl-bar:hover { z-index: 2; outline: 2px solid color-mix(in srgb, var(--c) 55%, transparent); opacity: 1; }
.htl-now { position: absolute; top: -20px; bottom: -4px; z-index: 3; width: 2px; margin-left: -1px; background: var(--h4-now); pointer-events: none; }
.htl-now span {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%); padding: 1px 6px;
  border-radius: 6px; background: var(--h4-now); color: #fff; font-size: 10px; font-weight: 800; font-variant-numeric: tabular-nums;
}
.htl-list { display: grid; gap: 4px; }
.htl-cap { margin: 4px 0 1px; color: var(--muted); font-size: 10px; font-weight: 850; letter-spacing: .08em; text-transform: uppercase; }
.htl-row {
  display: grid; grid-template-columns: 78px minmax(0, 1fr); align-items: center; gap: 8px;
  padding: 6px 9px; border: 0; border-left: 3px solid var(--c); border-radius: 8px;
  background: color-mix(in srgb, var(--c) 10%, var(--surface-card)); color: var(--text);
  font: inherit; font-size: 12px; text-align: left; cursor: pointer;
}
.htl-row span { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.htl-row b { overflow: hidden; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.htl-row.is-live { background: color-mix(in srgb, var(--c) 22%, var(--surface-card)); }
.htl-row.is-live b { font-weight: 800; }
.htl-more { justify-self: start; margin-top: 2px; padding: 0; border: 0; background: none; color: var(--home3-wine); font: inherit; font-size: 12px; font-weight: 800; cursor: pointer; }

/* ---- Дни рождения ---- */
.hbd { display: grid; gap: 6px; }
.hbd-row { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 12px; }
.hbd-row.is-today { background: var(--home3-gold-soft); }
.hbd-date { display: grid; place-items: center; height: 40px; border-radius: 10px; background: var(--home3-wine-soft); color: var(--home3-wine); line-height: 1.05; }
.hbd-date b { font-size: 16px; font-weight: 850; }
.hbd-date small { font-size: 9px; font-weight: 700; }
.hbd-row.is-today .hbd-date { background: var(--home3-gold); color: #fff; }
.hbd-copy { min-width: 0; }
.hbd-copy b { display: block; overflow: hidden; font-size: 12.5px; text-overflow: ellipsis; white-space: nowrap; }
.hbd-copy small { display: block; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.hbd-row em { color: var(--muted); font-size: 11px; font-style: normal; font-weight: 650; white-space: nowrap; }
.hbd-row.is-today em { color: var(--home3-gold); font-weight: 850; }

/* ---- Что нового ---- */
.hnews { display: grid; gap: 8px; }
.hnews header { display: flex; align-items: center; gap: 8px; }
.hnews header b { font-size: 13px; line-height: 1.3; }
.hnews-new { padding: 1px 8px; border-radius: 999px; background: var(--home3-wine); color: #fff; font-size: 10px; font-weight: 800; white-space: nowrap; }
.hnews-body { font-size: 12.5px; line-height: 1.5; color: var(--text); }
.hnews-body ul { margin: 0; padding-left: 18px; }
.hnews-body li { margin: 0 0 5px; }
.hnews-body p { margin: 0 0 6px; }
.hnews .home3-text-button { justify-self: start; }

/* ---- Быстрые действия ---- */
.hact { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.hact button {
  display: flex; align-items: center; gap: 10px; min-width: 0; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface-card);
  color: var(--text); font: inherit; text-align: left; cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.hact button:hover { border-color: var(--home3-wine); background: color-mix(in srgb, var(--home3-wine-soft) 55%, var(--surface-card)); }
.hact-ico { display: grid; place-items: center; width: 30px; height: 30px; padding: 6px; flex: none; border-radius: 9px; background: var(--home3-wine-soft); color: var(--home3-wine); }
.hact-copy { min-width: 0; }
.hact-copy b { display: block; overflow: hidden; font-size: 12.5px; text-overflow: ellipsis; white-space: nowrap; }
.hact-copy small { display: block; overflow: hidden; color: var(--muted); font-size: 10.5px; text-overflow: ellipsis; white-space: nowrap; }
.home4 .home-w[data-h="0.5"] .hact { grid-auto-flow: column; grid-template-columns: none; grid-auto-columns: minmax(0, 1fr); }
.home4 .home-w[data-h="0.5"] .hact button { padding: 7px 10px; }
.home4 .home-w[data-w="1"] .hact { grid-template-columns: 1fr 1fr; }
.home4 .home-w[data-w="1"][data-h="0.5"] .hact { grid-auto-flow: row; grid-template-columns: 1fr 1fr; }
.home4 .home-w[data-w="1"] .hact-copy small { display: none; }

/* ---- Заметки ---- */
.hnote { display: flex; flex-direction: column; gap: 6px; height: 100%; }
.hnote textarea {
  flex: 1 1 auto; min-height: 60px; width: 100%; resize: none; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px;
  background: color-mix(in srgb, var(--home3-gold-soft) 40%, var(--surface-card));
  color: var(--text); font: inherit; font-size: 13px; line-height: 1.5;
}
.hnote textarea:focus { outline: 2px solid var(--h4-ring); border-color: var(--home3-wine); }
.hnote-state { color: var(--muted); font-size: 11px; }

/* ---- Настройка ---- */
.home-tune {
  position: sticky; top: 8px; z-index: 30;
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px 16px; padding: 10px 14px; margin: 0;
  border: 1px solid color-mix(in srgb, var(--home3-wine) 30%, var(--line)); border-radius: 14px;
  background: color-mix(in srgb, var(--home3-wine-soft) 60%, var(--surface-card)); color: var(--text);
  box-shadow: 0 10px 26px rgba(16, 24, 40, .1);
}
.home-tune-copy { display: grid; gap: 1px; min-width: 220px; font-size: 12px; }
.home-tune-copy b { font-size: 13px; }
.home-tune-copy span { color: var(--muted); }
.home-save-state { padding: 3px 10px; border-radius: 999px; background: var(--surface-card); color: var(--muted); font-size: 11px; font-weight: 700; white-space: nowrap; }
.home-save-state.is-saved { color: #13795b; }
.home-save-state.is-error { color: #b4233c; }
.home-tune-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-left: auto; }
.home-tune-actions button { display: inline-flex; align-items: center; gap: 6px; }
.home-tune-actions .home-ico { width: 15px; height: 15px; }
.home-tune-actions button em { padding: 0 6px; border-radius: 999px; background: var(--home3-wine); color: #fff; font-size: 10px; font-style: normal; }
.home-tune-actions button.is-on { border-color: var(--home3-wine); color: var(--home3-wine); }
.home-tune-actions button:disabled { opacity: .45; cursor: default; }
.home-tune-actions .text { border: 0; background: none; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

.home-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.hg-card { display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 12px 14px; border: 1px dashed color-mix(in srgb, var(--home3-wine) 35%, var(--line)); border-radius: 14px; background: var(--surface-card); }
.hg-card .home-w-ico { width: 32px; height: 32px; padding: 7px; border-radius: 10px; background: var(--home3-wine-soft); color: var(--home3-wine); }
.hg-card b { display: block; font-size: 13px; }
.hg-card small { display: block; color: var(--muted); font-size: 11.5px; line-height: 1.35; }
.hg-card button { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.hg-card button .home-ico { width: 14px; height: 14px; }
.hg-new { padding: 1px 6px; border-radius: 999px; background: var(--home3-gold-soft); color: var(--home3-gold); font-size: 10px; font-style: normal; font-weight: 800; }

.home4.is-tuning .home-w { border: 1.5px dashed color-mix(in srgb, var(--home3-wine) 45%, var(--line)); cursor: grab; }
.home4.is-tuning .home-w:active { cursor: grabbing; }
.home4.is-tuning .home-w-body { opacity: .5; pointer-events: none; user-select: none; }
.home4.is-tuning .home-w-head .home3-badge, .home4.is-tuning .home-w-head .home3-header-link { display: none; }
.hwe {
  position: absolute; top: 9px; right: 9px; z-index: 4;
  display: flex; align-items: center; gap: 2px; padding: 3px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface-card);
  box-shadow: 0 6px 18px rgba(16, 24, 40, .12);
}
.hwe button {
  display: grid; place-items: center; min-width: 24px; height: 24px; padding: 0 5px;
  border: 0; border-radius: 7px; background: none; color: var(--muted);
  font: inherit; font-size: 11.5px; font-weight: 800; cursor: pointer;
}
.hwe button .home-ico { width: 14px; height: 14px; }
.hwe button:hover { background: var(--home3-wine-soft); color: var(--home3-wine); }
.hwe button.is-on { background: var(--home3-wine); color: #fff; }
.hwe-group { display: inline-flex; gap: 1px; }
.hwe-sep { width: 1px; height: 16px; margin: 0 2px; background: var(--line); }
.hwe-h i { display: block; width: 10px; border-radius: 2px; background: currentColor; }
.hwe-h05 i { height: 5px; }
.hwe-h1 i { height: 9px; }
.hwe-h2 i { height: 14px; }
.hwe-hide:hover { background: #fde8ec !important; color: #b4233c !important; }
.hwe-grab {
  position: absolute; left: 12px; bottom: 9px; z-index: 4;
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px;
  border-radius: 999px; background: var(--surface-card); color: var(--muted);
  font-size: 11px; font-weight: 700; pointer-events: none; box-shadow: 0 2px 8px rgba(16, 24, 40, .08);
}
.hwe-grab .home-ico { width: 13px; height: 13px; }
.home4 .home-w[data-h="0.5"] .hwe-grab { display: none; }
/* На узкой карточке панель уходит вниз: сверху она закрывала заголовок. */
.home4 .home-w[data-w="1"] .hwe { top: auto; bottom: 9px; left: 9px; right: 34px; justify-content: space-between; }
.home4 .home-w[data-w="1"] .hwe-grab { display: none; }
.home4 .home-grid.is-dragging .home-w:not(.is-drag) { transition: none; }
.home4 .home-w.is-drag { opacity: .35; }
.home4 .home-w.is-flash { animation: h4-flash 1.6s ease; }
@keyframes h4-flash { 0%, 60% { box-shadow: 0 0 0 4px var(--h4-ring); } 100% { box-shadow: var(--shadow); } }

/* ---- Тёмная тема ---- */
[data-theme=dark] .home4 { --h4-now: #ff7a82; }
[data-theme=dark] .home4 .home-w:hover { box-shadow: 0 10px 28px rgba(0, 0, 0, .35); }
[data-theme=dark] .hg-chip.is-on i { background: #5fd3a3; box-shadow: 0 0 0 3px rgba(95, 211, 163, .16); }
[data-theme=dark] .htl-tabs button.is-on { background: #a0214f; border-color: #a0214f; }
[data-theme=dark] .hnews-new { background: #a0214f; }
[data-theme=dark] .hbd-row.is-today .hbd-date { color: #231700; }
[data-theme=dark] .hwe button.is-on { background: #a0214f; }
[data-theme=dark] .hwe-hide:hover { background: rgba(233, 94, 120, .16) !important; color: #f59aab !important; }
[data-theme=dark] .home-save-state.is-saved { color: #6fd6ae; }
[data-theme=dark] .home-save-state.is-error { color: #f59aab; }

/* ---- Узкие экраны ---- */
@media (max-width: 1100px) {
  .home-greet { flex-wrap: wrap; }
  .hg-side { width: 100%; justify-content: flex-start; }
}
@media (max-width: 760px) {
  .home-greet { padding: 16px; gap: 12px; }
  .home-greet h1 { font-size: 21px; }
  .hg-side { gap: 12px; }
  .hg-clock { padding-left: 12px; }
  .home4 .home-grid { grid-auto-rows: auto; }
  .home4 .home-w[data-h] { grid-row: auto; min-height: 0; }
  .home4 .home-w[data-h="0.5"] .home-w-title small { display: block; }
  .hact { grid-template-columns: 1fr 1fr; }
  .home4 .home-w[data-h="0.5"] .hact { grid-auto-flow: row; grid-template-columns: 1fr 1fr; }
  .hnote textarea { min-height: 140px; }
  /* Длинные карточки на телефоне листаются внутри, а не растягивают экран на три прокрутки. */
  .home4 .home-w[data-id="news"] .home-w-body, .home4 .home-w[data-id="changes"] .home-w-body { max-height: 360px; overflow: auto; }
}
@media (prefers-reduced-motion: reduce) {
  .htl-sum .is-live i, .home4 .home-w.is-flash { animation: none; }
}
