/* Светлая тема — база. Тёмная ниже, по настройке системы. */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6ea;
  --text: #15181d;
  --muted: #6b7280;
  --accent: #2f6bff;
  --accent-soft: #e8efff;
  --ready: #f0a202;
  --approved: #2f6bff;
  --published: #16a34a;
  --rejected: #b4b8bf;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #161a21;
    --surface-2: #1d222b;
    --border: #272d37;
    --text: #e8eaee;
    --muted: #949cab;
    --accent: #5b8cff;
    --accent-soft: #1b2744;
    --rejected: #4a515c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

/* Атрибут hidden должен побеждать любое display из классов. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
.muted { color: var(--muted); }

.logo {
  font-weight: 700; letter-spacing: -.02em; font-size: 22px; color: var(--accent);
}
.logo.sm { font-size: 17px; }

label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }

input, select, textarea {
  font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent;
}
textarea { resize: vertical; }

/* --- Кнопки --- */
.btn {
  font: inherit; font-weight: 550; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 10px; padding: 9px 14px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn.wide { width: 100%; padding: 11px; }

.error {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger); border-radius: 10px; padding: 9px 12px; font-size: 13px;
}

/* --- Шапка --- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { flex: 1; }

.pause { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); }
.pause input { display: none; }
.pause .track {
  width: 38px; height: 22px; border-radius: 999px; background: var(--surface-2);
  border: 1px solid var(--border); display: block; position: relative; transition: background .15s;
}
.pause .knob {
  position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: var(--muted); transition: transform .15s, background .15s;
}
.pause input:checked + .track { background: color-mix(in srgb, var(--danger) 22%, transparent); }
.pause input:checked + .track .knob { transform: translateX(16px); background: var(--danger); }

.banner {
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  color: var(--danger); padding: 10px 16px; font-size: 13px; text-align: center;
}

/* --- Вкладки --- */
.tabs {
  display: flex; gap: 2px; padding: 10px 12px 0;
  overflow-x: auto; background: var(--surface); border-bottom: 1px solid var(--border);
}
.tab {
  font: inherit; font-size: 14px; font-weight: 550; white-space: nowrap;
  background: none; border: 0; border-bottom: 2px solid transparent;
  color: var(--muted); padding: 8px 12px 12px; cursor: pointer;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab .count {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px;
  margin-left: 4px; border-radius: 999px; background: var(--accent); color: #fff;
  font-size: 12px; font-weight: 650;
}
.tab .count:empty, .tab .count[data-zero] { display: none; }

main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 48px; }

/* --- День --- */
.day { margin-bottom: 28px; }
.day-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--border);
}
.day-head h2 { font-size: 16px; }
.day-head .muted { font-size: 13px; flex: 1 1 auto; min-width: 0; }

/* --- Карточки --- */
.cards { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}

/* flex-start, иначе растягивание по высоте отменяет квадратную пропорцию превью. */
.card-top { display: flex; align-items: flex-start; gap: 14px; padding: 14px; }

/* Макет телефона для превью */
.phone {
  flex: 0 0 108px; width: 108px; aspect-ratio: 9 / 16;
  border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); overflow: hidden; position: relative;
}
.phone.square { aspect-ratio: 1; }
.phone img, .phone video { width: 100%; height: 100%; object-fit: cover; display: block; }
.phone .empty {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--muted); font-size: 12px; text-align: center; padding: 8px;
}
.phone .more {
  position: absolute; right: 5px; bottom: 5px;
  background: rgba(0, 0, 0, .65); color: #fff; font-size: 11px;
  padding: 2px 6px; border-radius: 6px;
}

.card-meta { flex: 1; min-width: 0; display: grid; gap: 8px; align-content: start; }
.card-meta .line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.time { font-weight: 650; font-size: 15px; }

.badge {
  font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}
.badge.grey { background: var(--surface-2); color: var(--muted); }

.status { font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot.ready { background: var(--ready); }
.dot.approved { background: var(--approved); }
.dot.published { background: var(--published); }
.dot.rejected { background: var(--rejected); }
.dot.planned { background: var(--muted); }
/* Материал ещё готовится — точка мигает, чтобы было видно, что идёт работа. */
.dot.working { background: var(--ready); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1 } 50% { opacity: .25 } }

.plan-bar {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  margin-bottom: 22px; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius);
}
.plan-bar .hint { flex: 1; min-width: 180px; font-size: 13px; color: var(--muted); }
.dot.changes { background: var(--ready); }

.caption {
  font-size: 14px; white-space: pre-wrap; word-break: break-word;
  max-height: 7.5em; overflow: hidden; position: relative;
}
.caption.open { max-height: none; }
.more-link {
  background: none; border: 0; padding: 0; font: inherit; font-size: 13px;
  color: var(--accent); cursor: pointer; justify-self: start;
}

.note {
  margin: 0 14px 14px; padding: 9px 11px; border-radius: 10px;
  background: color-mix(in srgb, var(--ready) 14%, transparent);
  font-size: 13px;
}

.card-actions {
  display: flex; gap: 8px; flex-wrap: wrap;
  padding: 12px 14px; border-top: 1px solid var(--border); background: var(--surface-2);
}
.card-actions .spacer { flex: 1; }

/* --- Календарь --- */
.cal-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.cal-head h2 { font-size: 17px; flex: 1; text-align: center; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-dow { font-size: 12px; color: var(--muted); text-align: center; padding-bottom: 4px; }
.cal-cell {
  min-height: 74px; padding: 7px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border);
}
.cal-cell.out { opacity: .4; }
.cal-cell.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal-num { font-size: 12px; color: var(--muted); }
.cal-items { display: grid; gap: 3px; margin-top: 5px; }
.cal-item { display: flex; align-items: center; gap: 5px; font-size: 11px; }
.cal-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- Форма --- */
.form { padding: 20px; display: grid; gap: 14px; max-width: 620px; }
.form .row { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
.form .actions { display: flex; align-items: center; gap: 12px; }
.file input { padding: 9px; background: var(--surface-2); }

/* --- Журнал --- */
.log { display: grid; gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.log-row { display: flex; gap: 12px; padding: 11px 14px; background: var(--surface); font-size: 14px; }
.log-row time { color: var(--muted); font-size: 13px; flex: 0 0 120px; }

.empty-state { text-align: center; color: var(--muted); padding: 56px 20px; }

.foot { text-align: center; font-size: 12px; padding: 0 16px 28px; }

@media (max-width: 560px) {
  .day-head .muted { flex: 1 1 100%; }
  .form .row { grid-template-columns: 1fr; }
  .log-row { flex-direction: column; gap: 3px; }
  .log-row time { flex: none; }
  .cal-cell { min-height: 58px; padding: 5px; }
  .cal-item span { display: none; }
}

/* --- Просмотр материала целиком --- */
.viewer { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; }
.viewer-backdrop { position: absolute; inset: 0; background: rgba(4, 7, 12, .78); backdrop-filter: blur(3px); }

.viewer-box {
  position: relative; display: flex; gap: 20px; align-items: stretch;
  width: 100%; max-width: 900px; max-height: calc(100dvh - 32px);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow); padding: 20px; overflow: auto;
}

.viewer-close {
  position: absolute; top: 10px; right: 12px; z-index: 2;
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  font-size: 20px; line-height: 1; display: grid; place-items: center;
}
.viewer-close:hover { background: var(--surface-2); color: var(--text); }

/* Размер задаём коробке, а не картинке: иначе во флексе она схлопывается в ноль. */
.viewer-media {
  flex: 0 0 auto; position: relative;
  width: min(330px, 100%); aspect-ratio: 9 / 16; max-height: 68dvh;
  background: #06080d; border-radius: 12px; overflow: hidden;
  display: grid; place-items: center;
}
.viewer-media.square { aspect-ratio: 1; }
.viewer-media img, .viewer-media video { width: 100%; height: 100%; object-fit: contain; display: block; }

.viewer-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer;
  border: 0; background: rgba(0, 0, 0, .55); color: #fff; font-size: 18px;
}
.viewer-nav.prev { left: 8px; }
.viewer-nav.next { right: 8px; }
.viewer-counter {
  position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
  background: rgba(0, 0, 0, .6); color: #fff; font-size: 12px;
  padding: 3px 9px; border-radius: 999px;
}

.viewer-side { flex: 1 1 300px; min-width: 0; display: flex; flex-direction: column; gap: 14px; padding-right: 28px; }
.viewer-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.viewer-caption { font-size: 15px; white-space: pre-wrap; word-break: break-word; }
.viewer-actions {
  margin-top: auto; display: flex; gap: 8px; flex-wrap: wrap;
  padding-top: 14px; border-top: 1px solid var(--border);
}
.viewer-actions .spacer { flex: 1; }

.card-top { cursor: pointer; }
.phone { pointer-events: none; }
.phone video { pointer-events: auto; }

@media (max-width: 760px) {
  /* На узком экране распорка выталкивает последнюю кнопку за край. */
  .viewer-actions .spacer, .card-actions .spacer { display: none; }
  .viewer-box { flex-direction: column; padding: 16px; gap: 14px; }
  .viewer-side { padding-right: 0; }
  .viewer-media { width: 100%; max-width: 280px; margin: 0 auto; max-height: 44dvh; }
}

/* Контекст компании */
.brand-form { max-width: 700px; }
.brand-form p { margin: -4px 0 6px; font-size: 13px; }
.field-hint { font-size: 12px; color: var(--muted); }

/* Расходы */
.spend-total { display: flex; align-items: baseline; gap: 10px; }
.spend-sum { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; }
.spend-bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.spend-bar span { display: block; height: 100%; background: var(--accent); }

/* Стоимость материала */
.cost {
  font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
