/* Marketing → SMM: content plan calendar and the post editor. */
@layer components {
  .tabs[data-tabs="marketing"] .tab-mark { view-transition-name: tab-mark-marketing; }

  /* Each status has its own color: the stripe of a post in the calendar, the legend dot and the badge. */
  .status-idea { --smm-c: var(--color-text-muted); }
  .status-draft { --smm-c: var(--color-warn-tint); }
  .status-review { --smm-c: var(--color-warn); }
  .status-ready { --smm-c: var(--color-accent); }
  .status-published { --smm-c: var(--color-ok); }

  .smm-dot {
    flex: none;
    inline-size: .625rem;
    block-size: .625rem;
    border-radius: 50%;
    background: var(--smm-c);
  }

  .smm-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin-block-end: var(--space-3);
  }

  .smm-month-nav {
    display: flex;
    align-items: center;
    gap: var(--space-2);

    & h2 { margin: 0; min-inline-size: 9.5rem; text-align: center; font-size: 1.25rem; }
    & :is(.link-button, .button.small) {
      min-block-size: 2.25rem;
      min-inline-size: 2.25rem;
      justify-content: center;
      padding-inline: var(--space-3);
    }
  }

  .smm-filter {
    flex: 1 1 28rem;
    justify-content: flex-end;

    & select { flex: 0 1 12rem; }
  }

  .smm-plan {
    margin-block: 0 var(--space-3);
    padding: var(--space-3) var(--space-4);
  }

  .smm-plan-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
  }

  .smm-plan-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: var(--space-2);
  }

  .smm-plan-decide {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: var(--space-2);

    & input { min-inline-size: 12rem; }
  }

  .smm-legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-4);
    margin: 0 0 var(--space-4);
    padding: 0;
    list-style: none;
    color: var(--color-text-muted);
    font-size: .875rem;

    & li { display: flex; align-items: center; gap: var(--space-2); }
    & strong { color: var(--color-text); font-variant-numeric: tabular-nums; }
  }

  .smm-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 15rem;
    gap: var(--space-4);
    align-items: start;

    @media (width < 68rem) { grid-template-columns: minmax(0, 1fr); }
  }

  .smm-calendar {
    overflow: hidden;
    background: var(--color-surface);
    border: 1px solid var(--color-line);
    border-radius: var(--radius-l);
    box-shadow: var(--shadow-card);
  }

  .smm-weekdays, .smm-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }

  .smm-weekdays {
    border-block-end: 1px solid var(--color-line);
    color: var(--color-text-muted);
    font-size: .8125rem;
    font-weight: 500;

    & span { padding: var(--space-2); }
  }

  .smm-grid { margin: 0; padding: 0; list-style: none; }

  .smm-day {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    min-block-size: 7.5rem;
    min-inline-size: 0;
    padding: var(--space-1);
    border-block-end: 1px solid var(--color-line);
    border-inline-end: 1px solid var(--color-line);
    transition: background-color var(--duration);

    &:nth-child(7n) { border-inline-end: 0; }
    &:nth-last-child(-n+7) { border-block-end: 0; }
    &:nth-child(7n + 6), &:nth-child(7n) { background: color-mix(in oklab, var(--color-surface-subtle) 45%, var(--color-surface)); }
    &.is-outside { background: var(--color-surface-subtle); }
    &.is-outside .smm-day-num { color: var(--color-text-muted); opacity: .7; }
  }

  .smm-day-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-block-size: 1.75rem;
    padding-inline-start: var(--space-1);
  }

  .smm-day-num {
    font-size: .875rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;

    &[aria-current="date"] {
      display: inline-grid;
      place-items: center;
      min-inline-size: 1.75rem;
      block-size: 1.75rem;
      margin-inline-start: calc(var(--space-1) * -1);
      border-radius: var(--badge-radius, var(--radius-s));
      background: var(--color-accent);
      color: var(--color-accent-text);
    }
  }

  .smm-day-wd { display: none; }

  .smm-add {
    display: inline-grid;
    place-items: center;
    inline-size: 1.75rem;
    block-size: 1.75rem;
    border-radius: var(--radius-s);
    color: var(--color-text-muted);
    font-size: 1.125rem;
    line-height: 1;
    text-decoration: none;
    opacity: 0;
    transition: opacity var(--duration), background-color var(--duration);

    &:hover { background: var(--color-accent-soft); color: var(--color-accent); }
  }
  .smm-day:hover .smm-add, .smm-add:focus-visible { opacity: 1; }
  @media (hover: none) { .smm-add { opacity: 1; } }

  .smm-posts {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .smm-post {
    & a {
      display: flex;
      flex-direction: column;
      gap: .125rem;
      padding: .25rem .375rem;
      border-inline-start: 3px solid var(--smm-c);
      border-radius: var(--radius-s);
      background: color-mix(in oklab, var(--smm-c) 12%, var(--color-surface));
      color: var(--color-text);
      font-size: .8125rem;
      line-height: 1.3;
      text-decoration: none;
      transition: background-color var(--duration);
    }
    & a:hover { background: color-mix(in oklab, var(--smm-c) 22%, var(--color-surface)); color: var(--color-text); }
    &[data-movable] a {
      cursor: grab;
      -webkit-user-drag: none;
      -webkit-touch-callout: none;
      user-select: none;
    }
    /* The card's old place stays as an outline while it is in the air. */
    &.is-lifted a {
      background: transparent;
      outline: 1.5px dashed color-mix(in oklab, var(--smm-c) 55%, transparent);
      outline-offset: -1.5px;
    }
    &.is-lifted a > * { visibility: hidden; }
    &.is-settled a { animation: smm-settle .7s var(--ease-out, cubic-bezier(.2, .8, .2, 1)); }
    &.status-published .smm-post-title::before { content: "✓ "; content: "✓ " / ""; color: var(--color-ok); }
  }

  .smm-post-meta {
    display: flex;
    flex-wrap: wrap;
    gap: .25rem;
    color: var(--color-text-muted);
    font-size: .6875rem;
    font-weight: 600;

    &:empty { display: none; }
    & time { font-variant-numeric: tabular-nums; }
  }

  .smm-post-event {
    overflow: hidden;
    color: var(--color-accent);
    font-size: .6875rem;
    font-weight: 500;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .smm-ch {
    padding-inline: .25rem;
    border-radius: .25rem;
    background: color-mix(in oklab, var(--color-text) 8%, transparent);
  }

  .smm-post-title {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
    overflow-wrap: anywhere;
  }

  .is-drop-target {
    background: color-mix(in oklab, var(--drop-c, var(--color-accent)) 9%, var(--color-surface)) !important;
    box-shadow: inset 0 0 0 2px color-mix(in oklab, var(--drop-c, var(--color-accent)) 70%, transparent);
    transition: background-color var(--duration), box-shadow var(--duration);
  }

  .smm-ghost {
    position: fixed;
    inset: 0 auto auto 0;
    z-index: 1000;
    margin: 0;
    list-style: none;
    pointer-events: none;
    transition: rotate .18s cubic-bezier(.2, .8, .2, 1), scale .18s cubic-bezier(.2, .8, .2, 1);

    & a {
      box-shadow: var(--shadow-raised, 0 8px 24px rgb(0 0 0 / .18));
      cursor: grabbing;
    }
    &.is-up { rotate: 2deg; scale: 1.03; }
  }

  .smm-slot {
    display: grid;
    place-items: center;
    border: 1.5px dashed var(--smm-c);
    border-radius: var(--radius-s);
    background: color-mix(in oklab, var(--smm-c) 10%, transparent);
    color: var(--color-text-muted);
    font-size: .6875rem;
    font-weight: 600;
    list-style: none;
    animation: smm-slot-in .16s cubic-bezier(.2, .8, .2, 1);

    & span {
      overflow: hidden;
      max-inline-size: 100%;
      padding-inline: .25rem;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }

  @keyframes smm-slot-in {
    from { opacity: 0; scale: .96; }
  }
  @keyframes smm-settle {
    from { background: color-mix(in oklab, var(--smm-c) 40%, var(--color-surface)); }
  }

  body.smm-dragging, body.smm-dragging * {
    cursor: grabbing !important;
    user-select: none;
  }

  @media (prefers-reduced-motion: reduce) {
    .smm-ghost { transition: none; }
    .smm-ghost.is-up { rotate: 0deg; scale: 1; }
    .smm-slot, .smm-post.is-settled a { animation: none; }
  }

  @media (forced-colors: active) {
    .is-drop-target { outline: 2px solid Highlight; outline-offset: -2px; }
    .smm-slot, .smm-post.is-lifted a { border-color: CanvasText; outline-color: CanvasText; }
  }

  .smm-ideas {
    position: sticky;
    inset-block-start: 4.5rem;
    margin: 0;
    padding: var(--space-4);
    max-block-size: calc(100dvh - 6rem);
    overflow-y: auto;
    scrollbar-width: thin;

    & .hint { margin-block: var(--space-2) var(--space-3); }
    & .smm-posts { min-block-size: 3rem; }
    & .smm-post a { font-size: .875rem; }

    @media (width < 68rem) { position: static; max-block-size: none; }
  }

  .smm-ideas-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);

    & h2 { margin: 0; font-size: 1rem; }
  }

  /* On a phone the month becomes a list of the days that have posts, plus today. */
  @media (width < 40rem) {
    .smm-weekdays { display: none; }
    .smm-grid { grid-template-columns: minmax(0, 1fr); }
    .smm-day {
      min-block-size: 0;
      padding: var(--space-2);
      border-inline-end: 0;

      &.is-outside, &.is-empty:not(.is-today) { display: none; }
      &:nth-last-child(-n+7) { border-block-end: 1px solid var(--color-line); }
    }
    .smm-day-wd { display: inline; }
    .smm-day-num[aria-current="date"] {
      display: inline-flex;
      align-items: center;
      padding-inline: var(--space-2);
      white-space: pre;
    }
    .smm-post a { font-size: .9375rem; }
    .smm-filter select { flex: 1 1 100%; }
  }

  /* Editor */
  .smm-editor {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 20rem;
    gap: var(--space-5);
    align-items: start;

    & > .card { margin: 0; }

    @media (width < 60rem) { grid-template-columns: minmax(0, 1fr); }
  }

  /* Status switch above the post: every status in its own color, the chosen one filled with it. */
  .smm-status-picker {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    padding: 0;
    border: 0;

    & label {
      display: inline-flex;
      align-items: center;
      gap: var(--space-2);
      min-block-size: var(--control-size);
      padding-inline: var(--space-4);
      border: 1px solid color-mix(in oklab, var(--smm-c) 45%, var(--color-line));
      border-radius: var(--badge-radius, var(--radius-s));
      background: color-mix(in oklab, var(--smm-c) 10%, var(--color-surface));
      color: var(--color-text);
      font-size: .9375rem;
      font-weight: 500;
      cursor: pointer;
      transition: background-color var(--duration), border-color var(--duration), color var(--duration);
    }
    & label:hover { background: color-mix(in oklab, var(--smm-c) 20%, var(--color-surface)); }
    & input { position: absolute; opacity: 0; pointer-events: none; }
    & label:has(:focus-visible) { outline: 2px solid var(--color-accent); outline-offset: 2px; }
    & label:has(:checked) {
      border-color: var(--smm-c);
      background: var(--smm-c);
      color: light-dark(var(--slate-0), var(--night-900));
      font-weight: 600;
    }
    & label:has(:checked) .smm-dot { background: currentColor; }
    /* Amber is too light for white text. */
    & label.status-draft:has(:checked) { color: var(--slate-900); }

    @media (width < 40rem) {
      & label { flex: 1 1 auto; justify-content: center; padding-inline: var(--space-3); }
    }
  }

  .smm-body { min-block-size: 16rem; }

  .smm-counter {
    font-variant-numeric: tabular-nums;

    &.is-over { color: var(--color-danger); font-weight: 500; }
  }

  .smm-when {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
    gap: var(--space-3);
  }
  .smm-when + .hint { margin-block-start: calc(var(--space-3) * -1); }

  .smm-channels {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: var(--space-3);

    & .check { min-block-size: 2.25rem; }
  }

  .smm-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
    margin-block-start: var(--space-5);

    & .hint { flex: 1 1 16rem; margin: 0; }
  }
}
