:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #f9fafb;
  --ink: #18202b;
  --muted: #687385;
  --line: #dce2ea;
  --line-strong: #c4ceda;
  --red: #d7192f;
  --red-dark: #a90f22;
  --blue: #1664d8;
  --green: #087f5b;
  --amber: #b56b00;
  --shadow: 0 14px 35px rgba(24, 32, 43, .08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app {
  max-width: 1680px;
  margin: 0 auto;
  padding: 22px;
}

.hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 22px;
  padding: 22px 24px;
  background: #111827;
  color: #fff;
  border-bottom: 5px solid var(--red);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 7px;
  color: #ffb3bc;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 34px;
  line-height: 1.05;
  letter-spacing: 0;
}

.subtitle {
  max-width: 720px;
  margin: 10px 0 0;
  color: #d6dde7;
  font-size: 15px;
  line-height: 1.45;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.drive-bar {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) 160px;
  gap: 10px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 0;
  box-shadow: var(--shadow);
}

button,
.upload-btn {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  color: #fff;
  background: var(--red);
  cursor: pointer;
  font: inherit;
  font-weight: 850;
  line-height: 1;
}

button:hover,
.upload-btn:hover {
  background: var(--red-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: .48;
}

#loadSample,
.preview-btn {
  background: #263241;
}

#loadSample:hover,
.preview-btn:hover {
  background: #111827;
}

#pushFeedback {
  background: var(--green);
}

#pushFeedback:hover {
  background: #065a40;
}

#pushFeedback:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.template-meta,
.stats article,
.controls,
.drive-bar,
.mapping-wrap,
.calendar-month,
.unscheduled,
.week,
.status-section {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.template-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 16px 0;
  padding: 14px 16px;
}

.template-meta b {
  display: block;
  font-size: 17px;
}

.template-meta span,
.template-meta small {
  display: block;
  color: var(--muted);
}

#templateMeta {
  display: grid;
  gap: 2px;
}

#clearTemplate {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 8px 12px;
  color: var(--red);
  background: #fff0f2;
  border: 1px solid #ffd2d7;
}

#clearTemplate:hover {
  color: #fff;
  background: var(--red);
}

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

.stats article {
  padding: 16px;
}

.stats span {
  display: block;
  color: var(--red);
  font-size: 30px;
  font-weight: 950;
}

.stats p {
  margin: 3px 0 0;
  color: var(--muted);
  font-weight: 750;
}

.controls {
  position: sticky;
  top: 0;
  z-index: 3;
  display: grid;
  grid-template-columns: minmax(250px, 1fr) 170px 160px 150px 165px;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 9px 11px;
  color: var(--ink);
  background: #fff;
  font: inherit;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(22, 100, 216, .12);
}

.mapping-wrap {
  margin-bottom: 14px;
  padding: 12px 14px;
}

.mapping-wrap summary {
  color: var(--red);
  cursor: pointer;
  font-weight: 900;
}

.mapping {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  padding-top: 12px;
}

.mapping label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.board {
  display: grid;
  gap: 16px;
}

.calendar-month,
.unscheduled {
  overflow: hidden;
}

.calendar-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}

.calendar-title h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0;
}

.calendar-title span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.calendar-weekdays,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(140px, 1fr));
}

.calendar-weekdays span {
  padding: 10px 12px;
  color: #4a5567;
  background: #eef2f7;
  border-right: 1px solid var(--line);
  font-size: 12px;
  font-weight: 950;
  text-transform: uppercase;
}

.calendar-weekdays span:last-child {
  border-right: 0;
}

.calendar-cell {
  min-height: 190px;
  padding: 9px;
  background: #fff;
  border-top: 1px solid var(--line);
  border-right: 1px solid var(--line);
}

.calendar-cell:nth-child(7n) {
  border-right: 0;
}

.calendar-cell.has-posts {
  background: #fffdfd;
}

.muted-cell {
  background: #f1f4f8;
}

.cell-top,
.post-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.cell-top {
  margin-bottom: 8px;
}

.cell-top span {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: #263241;
  font-size: 13px;
  font-weight: 950;
}

.cell-top small {
  min-height: 16px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
}

.cell-posts,
.unscheduled-list {
  display: grid;
  gap: 7px;
}

.calendar-post {
  display: grid;
  gap: 6px;
  width: 100%;
  min-height: auto;
  padding: 9px;
  overflow: hidden;
  color: var(--ink);
  text-align: left;
  background: #fff;
  border: 1px solid #f0c6cc;
  border-left: 4px solid var(--red);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(24, 32, 43, .06);
}

.calendar-post:hover {
  color: var(--ink);
  background: #fff6f7;
  border-color: #e99aa5;
}

.calendar-post b {
  color: var(--red);
  font-size: 12px;
  white-space: nowrap;
}

.calendar-post em,
.calendar-post i {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calendar-post strong {
  display: -webkit-box;
  overflow: hidden;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.22;
  overflow-wrap: break-word;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
}

.calendar-post .subtle {
  color: var(--muted);
  font-size: 10px;
}

.post-row > * {
  min-width: 0;
}

.post-row.subtle span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.platform-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.platform-pills span {
  border-radius: 5px;
  padding: 3px 5px;
  color: var(--blue);
  background: #edf4ff;
  font-size: 9px;
  font-weight: 900;
}

.unscheduled-list {
  grid-template-columns: repeat(4, 1fr);
  padding: 12px;
}

.week {
  padding: 16px;
}

.week h2 {
  margin: 0 0 12px;
}

.post-grid,
.gallery {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

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

.card {
  overflow: hidden;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  transition: transform .18s, box-shadow .18s;
}

.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
}

.thumb {
  position: relative;
  height: 150px;
  margin-bottom: 12px;
  overflow: hidden;
  background: #eef2f7;
  border-radius: 8px;
}

.thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb.generated {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 4px;
  padding: 16px;
  background: linear-gradient(135deg, #d7192f, #243b74);
}

.thumb.generated::before {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, .38));
  content: "";
}

.thumb.generated strong,
.thumb.generated span {
  position: relative;
  color: #fff;
  text-shadow: 0 2px 12px rgba(0, 0, 0, .26);
}

.thumb.generated strong {
  font-size: 20px;
  letter-spacing: 0;
}

.thumb.generated span {
  display: block;
  font-weight: 800;
  line-height: 1.25;
}

.brand {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 1;
  border-radius: 6px;
  padding: 5px 8px;
  background: rgba(17, 24, 39, .32);
  color: #fff;
  font-size: 11px;
  font-weight: 950;
  line-height: 1;
  text-shadow: 0 2px 12px rgba(0, 0, 0, .26);
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  border: 1px solid #ffd2d7;
  border-radius: 6px;
  padding: 5px 8px;
  color: var(--red);
  background: #fff0f2;
  font-size: 11px;
  font-weight: 950;
}

.badge.red {
  color: #fff;
  background: var(--red);
}

.date {
  color: var(--amber);
  background: #fff6e8;
  border-color: #f4d6a4;
}

.card h3 {
  margin: 10px 0 6px;
  font-size: 17px;
  line-height: 1.2;
  letter-spacing: 0;
}

.series {
  margin: 0;
  color: var(--red);
  font-size: 13px;
  font-weight: 900;
}

.caption-line {
  min-height: 54px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.preview-btn {
  width: 100%;
  margin-top: 10px;
}

.status-workflow {
  display: grid;
  gap: 14px;
}

.status-section {
  overflow: hidden;
}

.status-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  background: var(--panel-soft);
  border-bottom: 1px solid var(--line);
}

.status-title h2 {
  margin: 0;
  font-size: 20px;
}

.status-title span {
  border-radius: 6px;
  padding: 4px 10px;
  color: var(--red);
  background: #fff0f2;
  font-size: 13px;
  font-weight: 950;
}

.status-table {
  display: grid;
  min-width: 1050px;
}

.status-section {
  overflow-x: auto;
}

.status-row {
  display: grid;
  grid-template-columns: 120px minmax(230px, 1.25fr) 170px minmax(210px, 1fr) minmax(250px, 1.1fr) 92px;
  gap: 14px;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.status-row:last-child {
  border-bottom: 0;
}

.status-row:nth-child(even):not(.status-head) {
  background: #fbfcfe;
}

.status-head {
  position: sticky;
  top: 0;
  z-index: 1;
  color: #4a5567;
  background: #eef2f7;
  font-size: 12px;
  font-weight: 950;
  text-transform: uppercase;
}

.status-date,
.status-post,
.status-series,
.status-creative {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.status-date b,
.status-post b,
.status-creative b {
  color: var(--red);
  font-size: 13px;
}

.status-post b {
  display: block;
}

.status-date small,
.status-series small,
.status-creative small {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-post strong {
  overflow: hidden;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-platform {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.status-platform em {
  border-radius: 5px;
  padding: 4px 6px;
  color: var(--blue);
  background: #edf4ff;
  font-size: 11px;
  font-style: normal;
  font-weight: 900;
}

.status-series {
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  font-weight: 850;
}

.status-preview {
  width: 100%;
  min-height: 34px;
  padding: 8px 10px;
  background: #263241;
  font-size: 12px;
}

.empty {
  padding: 42px;
  color: var(--muted);
  text-align: center;
  background: #fff;
  border: 1px dashed var(--line-strong);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: rgba(17, 24, 39, .62);
}

.modal[aria-hidden="false"] {
  display: flex;
}

.modal-panel {
  position: relative;
  width: min(1180px, 94vw);
  max-height: 88vh;
  overflow: auto;
  padding: 18px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .25);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  min-height: 34px;
  padding: 0;
  background: #263241;
  font-size: 22px;
}

.preview-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 18px;
  align-items: start;
  padding-right: 42px;
}

.preview-layout .thumb {
  height: 280px;
  margin: 0;
}

.preview-layout h2 {
  margin: 4px 0 12px;
  max-width: 760px;
  font-size: 32px;
  line-height: 1.08;
  letter-spacing: 0;
}

.preview-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.preview-tags span {
  border: 1px solid #cfe0fb;
  border-radius: 6px;
  padding: 6px 9px;
  color: var(--blue);
  background: #edf4ff;
  font-size: 12px;
  font-weight: 900;
}

dl {
  display: grid;
  grid-template-columns: 94px 1fr;
  gap: 7px 12px;
  margin: 0;
  max-width: 760px;
  font-size: 15px;
  line-height: 1.35;
}

dt {
  color: var(--red);
  font-weight: 900;
}

dd {
  margin: 0;
  color: var(--muted);
}

.preview-copy {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.feedback-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 10px;
  margin-top: 16px;
  padding: 13px;
  background: #fff9eb;
  border: 1px solid #f2d59d;
  border-radius: 8px;
}

.feedback-panel label {
  grid-column: 1 / -1;
  color: var(--amber);
  font-weight: 950;
}

.feedback-panel textarea {
  width: 100%;
  min-height: 78px;
  resize: vertical;
  border: 1px solid #e5c47d;
  border-radius: 8px;
  padding: 10px 11px;
  font: inherit;
}

.feedback-panel button {
  align-self: end;
  min-width: 132px;
  background: var(--amber);
}

.feedback-panel button:hover {
  background: #8a5100;
}

.preview-copy h3 {
  margin: 8px 0 0;
  color: var(--red);
  font-size: 20px;
  line-height: 1.15;
}

.preview-copy p {
  margin: 0;
  padding: 12px;
  color: #2b3441;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 15px;
  line-height: 1.5;
  white-space: normal;
}

/* ── Asset blocks (image / video / links inside preview modal) ──────────────── */
.asset-block {
  margin-bottom: 4px;
}

.asset-heading {
  margin: 14px 0 8px;
  color: var(--red);
  font-size: 17px;
  line-height: 1.15;
}

.asset-img-wrap {
  position: relative;
  display: inline-block;
  width: 100%;
  max-width: 560px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel-soft);
  border: 1px solid var(--line);
}

.asset-img {
  display: block;
  width: 100%;
  max-height: 380px;
  object-fit: contain;
  background: #f4f6f8;
}

.asset-open-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 9px 14px;
  background: #263241;
  color: #fff;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 900;
  text-decoration: none;
  transition: background .15s;
}

.asset-open-btn:hover { background: #111827; color: #fff; }

.asset-link {
  display: inline-block;
  margin-top: 7px;
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
  word-break: break-all;
}

.asset-link:hover { text-decoration: underline; }

.asset-text {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.asset-unavail {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 80px;
  color: var(--muted);
  font-size: 13px;
}

.thumb-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  background: #f4f6f8;
}

.thumb-fallback a {
  padding: 8px 14px;
  background: #263241;
  color: #fff;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 900;
  text-decoration: none;
}

.landing-links {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ── Password / login overlay ───────────────────────────────────────────────── */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(17,24,39,.72);
  backdrop-filter: blur(4px);
}
.login-box {
  width: min(420px, 92vw);
  padding: 36px 32px 28px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 30px 80px rgba(0,0,0,.28);
  border-top: 5px solid var(--red);
}
.login-box h2 { margin: 4px 0 20px; font-size: 26px; }
.login-box form { display: grid; gap: 12px; }
.login-box input { width:100%; min-height:46px; border:1px solid var(--line-strong); border-radius:8px; padding:10px 12px; font:inherit; font-size:15px; }
.login-box button[type=submit] { width:100%; min-height:46px; font-size:15px; }

/* ── Toast notification ─────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  z-index: 999;
  padding: 12px 22px;
  background: #1a2b1f;
  color: #6ee7a0;
  border: 1px solid #2e6645;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.01em;
  box-shadow: 0 8px 30px rgba(0,0,0,.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
}

#toast.toast-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#toast.toast-hide {
  opacity: 0;
  transform: translateX(-50%) translateY(20px);
}

@media (max-width: 1250px) {
  .calendar-weekdays,
  .calendar-grid {
    grid-template-columns: repeat(7, minmax(118px, 1fr));
  }

  .calendar-cell {
    min-height: 175px;
  }

  .unscheduled-list,
  .gallery,
  .post-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 980px) {
  .hero,
  .template-meta {
    align-items: flex-start;
    flex-direction: column;
  }

  .actions {
    justify-content: flex-start;
  }

  .drive-bar {
    grid-template-columns: 1fr;
  }

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

  .controls,
  .mapping {
    grid-template-columns: 1fr;
  }

  .preview-layout {
    grid-template-columns: 220px 1fr;
    gap: 16px;
  }

  .calendar-month {
    overflow-x: auto;
  }

  .calendar-weekdays,
  .calendar-grid {
    min-width: 980px;
  }

  .preview-layout .thumb {
    height: 220px;
  }
}

@media (max-width: 640px) {
  .app {
    padding: 12px;
  }

  .hero {
    padding: 18px;
  }

  h1 {
    font-size: 28px;
  }

  .stats,
  .unscheduled-list,
  .gallery,
  .post-grid {
    grid-template-columns: 1fr;
  }

  .modal {
    padding: 10px;
  }

  .modal-panel {
    padding: 18px;
  }

  .preview-layout {
    grid-template-columns: 1fr;
    padding-right: 0;
  }

  .preview-layout .thumb {
    height: 180px;
  }

  .feedback-panel {
    grid-template-columns: 1fr;
  }
}
