:root {
  color-scheme: light;
  --bg: #ece8e4;
  --bg-deep: #ddd7d1;
  --surface: #ffffff;
  --surface-2: #f7f4f1;
  --surface-3: #eeeae7;
  --line: rgba(49, 39, 131, 0.14);
  --text: #000000;
  --muted: #6f6965;
  --accent: #312783;
  --accent-strong: #251d6f;
  --accent-soft: rgba(49, 39, 131, 0.11);
  --blue: #312783;
  --danger: #d94e5d;
  --warning: #312783;
  --shadow: 0 24px 70px rgba(49, 39, 131, 0.14);
  --radius: 20px;
  font-family: Arial, "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg-deep); }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 82% -12%, rgba(49, 39, 131, 0.15), transparent 32rem),
    linear-gradient(180deg, #f6f3f0 0%, var(--bg) 56%, var(--bg-deep) 100%);
}

button, input, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible, label:has(input:focus-visible) {
  outline: 3px solid rgba(49, 39, 131, 0.42);
  outline-offset: 2px;
}

.app-shell {
  width: 100%;
  min-height: 100vh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px calc(92px + env(safe-area-inset-bottom));
}

.topbar, .section-heading, .status-row, .sheet-heading, .changes-card, .setting-card, .history-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.topbar { justify-content: flex-end; margin-bottom: 22px; }
h2, p { margin: 0; }
h2 { font-family: Comfortaa, Arial, sans-serif; font-size: 1.2rem; font-weight: 500; letter-spacing: -0.02em; }
.eyebrow { color: var(--muted); font-size: 0.7rem; font-weight: 800; letter-spacing: 0.16em; }
.prototype-badge, .slot-badge, .count-pill, .success-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 7px 10px;
  white-space: nowrap;
}
.prototype-badge span { width: 7px; height: 7px; border-radius: 50%; background: var(--warning); box-shadow: 0 0 10px rgba(49, 39, 131, .45); }

.screen { display: none; animation: screen-in 180ms ease-out; }
.screen.is-active { display: block; }
@keyframes screen-in { from { opacity: 0; transform: translateY(5px); } }

.status-row { margin-bottom: 13px; }
.save-status { color: var(--muted); font-size: 0.78rem; }
.text-button { border: 0; background: transparent; padding: 7px 0; font-size: 0.84rem; font-weight: 700; cursor: pointer; }
.text-button.danger { color: var(--danger); }

.audience-card, .media-card, .setting-card, .changes-card, .history-card, .filter-button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(145deg, #ffffff, #faf8f6);
  box-shadow: 0 12px 34px rgba(49, 39, 131, 0.07);
}

.audience-card {
  width: 100%;
  min-height: 98px;
  display: grid;
  grid-template-columns: 48px 1fr auto;
  align-items: center;
  gap: 13px;
  padding: 16px;
  text-align: left;
  cursor: pointer;
}
.audience-card:hover { border-color: rgba(49, 39, 131, 0.42); }
.audience-icon, .changes-icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 15px;
  color: var(--accent);
  background: var(--accent-soft);
  font-size: 1.45rem;
}
.audience-copy { display: grid; gap: 4px; }
.audience-copy small { color: var(--muted); font-size: 0.72rem; }
.audience-copy strong { font-size: 1.03rem; }
.audience-copy span { color: var(--muted); font-size: 0.78rem; }
.audience-copy b { color: var(--text); }
.chevron { color: var(--muted); font-size: 1.7rem; font-weight: 300; }

.section-heading { margin: 24px 0 12px; }
.slot-badge { color: var(--accent); background: var(--accent-soft); border-color: rgba(49, 39, 131, 0.2); }
.story-strip { display: flex; gap: 12px; overflow-x: auto; padding: 2px 2px 12px; scrollbar-width: none; }
.story-strip::-webkit-scrollbar { display: none; }
.story-thumb { min-width: 76px; border: 0; background: transparent; color: var(--muted); display: grid; gap: 7px; justify-items: center; font-size: 0.73rem; cursor: pointer; }
.story-thumb-preview { width: 62px; aspect-ratio: 9 / 16; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); box-shadow: 0 6px 18px rgba(49, 39, 131, .06); font-weight: 800; }
.story-thumb.is-selected .story-thumb-preview { color: var(--accent); border: 2px solid var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.story-thumb.add .story-thumb-preview { border-style: dashed; font-size: 1.4rem; }

.media-card { padding: 12px; }
.media-preview { position: relative; overflow: hidden; width: min(100%, 420px); margin: 0 auto; aspect-ratio: 9 / 16; border-radius: 15px; background: linear-gradient(145deg, #eeeae6, #e2dcd6); }
.media-preview img { width: 100%; height: 100%; object-fit: cover; }
.empty-media { position: absolute; inset: 0; display: grid; place-content: center; gap: 8px; padding: 24px; text-align: center; color: var(--muted); }
.empty-media span { color: var(--accent); font-size: 2.3rem; }
.empty-media strong { color: var(--text); font-size: 1rem; }
.empty-media p { font-size: 0.8rem; line-height: 1.45; }
.ratio-label { position: absolute; right: 10px; top: 10px; border-radius: 9px; padding: 5px 7px; background: rgba(5, 11, 20, 0.78); color: #fff; font-size: 0.7rem; font-weight: 800; }
.media-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 10px; }
.button { border: 1px solid var(--line); border-radius: 13px; background: var(--surface-3); color: var(--text); min-height: 46px; padding: 11px 14px; font-weight: 750; cursor: pointer; }
.button:hover:not(:disabled) { filter: brightness(1.08); }
.button:disabled { cursor: not-allowed; opacity: 0.52; }
.button.primary { color: #ffffff; background: var(--accent); border-color: var(--accent); }
.button.secondary { background: rgba(255, 255, 255, 0.82); }
.button.compact { min-height: 38px; padding: 8px 12px; font-size: 0.8rem; }
.button.wide { width: 100%; margin-top: 14px; }
.file-button { display: grid; place-items: center; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.file-meta { color: var(--muted); font-size: 0.75rem; padding: 10px 3px 1px; }
.media-recovery-actions { min-height: 28px; display: flex; justify-content: space-between; gap: 12px; }
.crop-preview { overflow: hidden; width: min(48vw, 220px); margin: 0 auto 16px; aspect-ratio: 9 / 16; border-radius: 16px; background: var(--surface-3); box-shadow: 0 12px 28px rgba(49, 39, 131, .14); }
.crop-preview img { width: 100%; height: 100%; object-fit: cover; }
.crop-mode { grid-template-columns: 0.8fr 1.6fr; margin-bottom: 14px; }
.range-field { display: grid; gap: 7px; margin-top: 12px; color: var(--muted); font-size: .82rem; font-weight: 700; }
.range-field span { display: flex; justify-content: space-between; gap: 12px; }
.range-field input { width: 100%; accent-color: var(--accent); }
.crop-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 20px; }

.field { display: grid; gap: 8px; margin-top: 18px; color: var(--text); font-weight: 700; }
.field textarea, .search-field input { width: 100%; border: 1px solid var(--line); background: var(--surface); color: var(--text); }
.field textarea { resize: vertical; min-height: 94px; border-radius: 15px; padding: 13px 14px; line-height: 1.45; font-weight: 500; }
.field textarea::placeholder, .search-field input::placeholder { color: #8b8580; }
.field small { justify-self: end; color: var(--muted); font-weight: 500; font-size: 0.72rem; }

.setting-card, .changes-card { margin-top: 14px; padding: 15px; }
.setting-card strong, .changes-card strong { font-size: 0.92rem; }
.setting-card p, .changes-card p { margin-top: 4px; color: var(--muted); font-size: 0.76rem; line-height: 1.35; }
.switch { position: relative; flex: 0 0 auto; width: 50px; height: 30px; }
.switch input { position: absolute; opacity: 0; }
.switch span { display: block; width: 100%; height: 100%; border-radius: 999px; background: #c5d0dc; transition: 160ms ease; cursor: pointer; }
.switch span::after { content: ""; position: absolute; left: 4px; top: 4px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: 160ms ease; box-shadow: 0 2px 7px rgba(0,0,0,.32); }
.switch input:checked + span { background: var(--accent-strong); }
.switch input:checked + span::after { transform: translateX(20px); }
.changes-card > div { display: flex; align-items: center; gap: 12px; }
.changes-icon { width: 42px; height: 42px; font-size: 1rem; }

.review-button { width: 100%; margin-top: 18px; color: #ffffff; background: linear-gradient(135deg, #4b41a0, #312783); border: 0; box-shadow: 0 13px 30px rgba(49, 39, 131, 0.2); }
.prototype-note { margin: 9px 0 0; text-align: center; color: var(--muted); font-size: 0.72rem; }

.sticky-heading { margin-top: 3px; }
.count-pill { color: var(--text); min-width: 38px; justify-content: center; }
.search-field { min-height: 48px; display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); padding: 0 13px; }
.search-field span { color: var(--muted); font-size: 1.3rem; }
.search-field input { border: 0; outline: 0; background: transparent; min-height: 46px; font-size: 0.92rem; }
.segmented { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 3px; margin-top: 12px; padding: 4px; border-radius: 14px; background: var(--surface); }
.segmented button, .mode-switch button { border: 0; border-radius: 10px; background: transparent; color: var(--muted); min-height: 38px; font-size: 0.76rem; font-weight: 750; cursor: pointer; }
.segmented button.is-active, .mode-switch button.is-active { background: var(--surface-3); color: var(--text); box-shadow: 0 3px 10px rgba(0,0,0,.2); }
.segmented b { color: inherit; }
.contact-list { display: grid; gap: 9px; margin-top: 14px; }
.contact-row { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 11px; min-height: 68px; padding: 10px 11px; border: 1px solid var(--line); border-radius: 16px; background: rgba(255, 255, 255, 0.9); box-shadow: 0 6px 18px rgba(49, 39, 131, .05); }
button.contact-row { width: 100%; color: inherit; text-align: left; cursor: pointer; }
.avatar { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 14px; background: linear-gradient(145deg, #e8e5f5, #ddd9ef); color: #312783; font-weight: 800; }
.contact-copy { min-width: 0; display: grid; gap: 4px; }
.contact-copy strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.9rem; }
.contact-copy span { color: var(--muted); font-size: 0.75rem; }
.contact-state { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 5px; }
.tag { border-radius: 8px; padding: 4px 6px; background: rgba(49, 39, 131, .1); color: #312783; font-size: .65rem; font-weight: 750; }
.tag.added { color: var(--accent); background: var(--accent-soft); }
.tag.removed { color: var(--danger); background: rgba(255,125,136,.12); }
.row-action { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 10px; background: rgba(238, 234, 231, .9); cursor: pointer; }
.row-action { display: grid; place-items: center; }
.filter-button { width: 100%; min-height: 54px; display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 10px; margin-top: 11px; padding: 0 15px; text-align: left; cursor: pointer; }
.filter-button b { color: var(--accent); font-size: .82rem; }
.list-note { color: var(--muted); font-size: .74rem; line-height: 1.45; margin: 14px 4px; }

.history-card { padding: 12px; align-items: stretch; }
.history-thumb { width: 58px; aspect-ratio: 9/16; display: grid; place-items: center; border-radius: 12px; background: linear-gradient(160deg, #e8e5f5, #ded9ef); color: #312783; font-size: .72rem; font-weight: 800; }
.history-card > div:nth-child(2) { flex: 1; display: grid; align-content: center; gap: 4px; }
.history-card p, .history-card small { color: var(--muted); font-size: .73rem; }
.success-label { width: fit-content; padding: 3px 7px; color: var(--accent); background: var(--accent-soft); border: 0; font-size: .64rem; }
.empty-section { display: grid; justify-items: center; gap: 8px; margin: 36px 12px 0; text-align: center; color: var(--muted); }
.empty-section > span { font-size: 2rem; color: #746ca5; }
.empty-section strong { color: var(--text); }
.empty-section p { max-width: 340px; font-size: .8rem; line-height: 1.5; }

.bottom-nav { position: fixed; z-index: 20; left: 10px; right: 10px; bottom: max(10px, env(safe-area-inset-bottom)); display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; max-width: 620px; margin: auto; padding: 6px; border: 1px solid var(--line); border-radius: 20px; background: rgba(255, 255, 255, .9); box-shadow: var(--shadow); backdrop-filter: blur(18px); }
.bottom-nav button { border: 0; border-radius: 14px; background: transparent; color: var(--muted); min-height: 54px; display: grid; place-items: center; align-content: center; gap: 3px; font-size: .66rem; font-weight: 700; cursor: pointer; }
.bottom-nav span { font-size: 1.15rem; line-height: 1; }
.bottom-nav button.is-active { color: var(--accent); background: var(--accent-soft); }

.sheet { width: 100%; max-width: 620px; max-height: 86vh; margin: auto auto 0; padding: 0; border: 0; background: transparent; color: var(--text); }
.sheet::backdrop { background: rgba(2, 7, 13, .72); backdrop-filter: blur(5px); }
.sheet[open] { animation: sheet-in 180ms ease-out; }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } }
.sheet-panel { max-height: 86vh; overflow-y: auto; border: 1px solid var(--line); border-bottom: 0; border-radius: 25px 25px 0 0; background: #faf8f6; padding: 10px 16px calc(20px + env(safe-area-inset-bottom)); box-shadow: var(--shadow); }
.sheet-handle { width: 42px; height: 4px; border-radius: 999px; background: #9b9490; margin: 0 auto 16px; }
.sheet-heading { margin-bottom: 14px; }
.icon-button { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--muted); font-size: 1.35rem; cursor: pointer; }
.audience-options { display: grid; gap: 8px; }
.audience-option { width: 100%; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; min-height: 62px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); color: var(--text); text-align: left; cursor: pointer; }
.audience-option strong { display: block; font-size: .9rem; }
.audience-option span { display: block; margin-top: 3px; color: var(--muted); font-size: .72rem; }
.audience-option b { color: var(--muted); font-size: .78rem; }
.audience-option.is-selected { border-color: rgba(49,39,131,.62); background: var(--accent-soft); }
.audience-option.is-selected b { color: var(--accent); }

.check-status { display: flex; gap: 12px; align-items: center; border: 1px solid rgba(49,39,131,.18); border-radius: 16px; background: var(--accent-soft); padding: 13px; }
.check-status > span { width: 36px; height: 36px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 50%; background: var(--accent); color: #ffffff; font-weight: 900; }
.check-status strong { font-size: .88rem; }
.check-status p { margin-top: 3px; color: #6f67a3; font-size: .74rem; }
.check-status.is-loading > span { animation: status-pulse 1s ease-in-out infinite; }
.check-status.is-warning { border-color: rgba(177, 104, 29, .24); background: #fff4df; }
.check-status.is-warning > span { background: #ad641c; }
.check-status.is-warning p { color: #85511e; }
@keyframes status-pulse { 50% { opacity: .55; transform: scale(.92); } }
.review-list { display: grid; margin: 15px 0 0; }
.review-list > div { display: flex; justify-content: space-between; gap: 18px; padding: 12px 1px; border-bottom: 1px solid var(--line); }
.review-list dt { color: var(--muted); font-size: .8rem; }
.review-list dd { margin: 0; text-align: right; font-size: .8rem; font-weight: 750; }
.publish-confirm { margin-top: 18px; }
.publish-confirm input { text-transform: uppercase; letter-spacing: .08em; font-weight: 800; }
.history-card + .history-card { margin-top: 10px; }
.history-label { display: inline-flex; margin-bottom: 3px; color: var(--muted); font-size: .68rem; font-weight: 850; letter-spacing: .05em; text-transform: uppercase; }
.history-label.published { color: #28744a; }
.history-label.failed, .history-label.blocked { color: #a35b18; }
.contact-phone { color: var(--muted); margin: -6px 0 14px; font-size: .84rem; }
.mode-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface); }
.permanent-warning { margin-top: 11px; border-radius: 13px; background: rgba(49,39,131,.08); color: #4b4285; padding: 11px 12px; font-size: .76rem; line-height: 1.4; }
.membership-list { display: grid; gap: 8px; margin-top: 14px; }
.membership-row { min-height: 48px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 11px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); font-size: .82rem; font-weight: 650; }

.toast { position: fixed; z-index: 50; left: 50%; bottom: 95px; width: max-content; max-width: calc(100% - 32px); transform: translate(-50%, 20px); opacity: 0; pointer-events: none; border: 1px solid var(--line); border-radius: 13px; background: #ffffff; color: var(--text); padding: 11px 14px; box-shadow: var(--shadow); font-size: .8rem; transition: 180ms ease; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (min-width: 700px) {
  body { padding: 24px 0; }
  .app-shell { max-width: 620px; min-height: calc(100vh - 48px); border: 1px solid var(--line); border-radius: 30px; background: rgba(250,248,246,.92); box-shadow: var(--shadow); }
  .bottom-nav { bottom: 34px; }
  .sheet { margin-bottom: 24px; }
  .sheet-panel { border-bottom: 1px solid var(--line); border-radius: 25px; }
}

@media (max-width: 410px) {
  .topbar { align-items: flex-start; }
  .prototype-badge { padding: 6px 8px; font-size: .68rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
