:root {
  --tg-bg: #f4efe7;
  --tg-surface: #efe5d8;
  --tg-card: #fff9f2;
  --tg-text: #241f1a;
  --tg-hint: #70685d;
  --tg-link: #8c4a2f;
  --tg-button: #bc6842;
  --tg-button-text: #fffaf4;
  --tg-destructive: #b43f3f;

  --bg: #f4efe7;
  --bg-deep: #eadfce;
  --surface: rgba(255, 251, 245, 0.88);
  --surface-strong: rgba(255, 251, 245, 0.96);
  --surface-muted: rgba(248, 240, 230, 0.9);
  --line: rgba(60, 42, 27, 0.12);
  --line-strong: rgba(91, 61, 36, 0.22);
  --text: var(--tg-text);
  --muted: var(--tg-hint);
  --accent: #bc6842;
  --accent-soft: #efd2b3;
  --accent-strong: #8f4726;
  --accent-ink: #fffaf4;
  --danger: var(--tg-destructive);
  --shadow: 0 28px 70px rgba(94, 63, 33, 0.14);
  --radius-xl: 30px;
  --radius-lg: 24px;
  --radius-md: 18px;
  --radius-sm: 14px;
  --shell-width: 1260px;
  --font-title: "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --font-body: "Segoe UI Variable Text", "Trebuchet MS", sans-serif;
}

:root[data-telegram-scheme="dark"] {
  --bg: #161515;
  --bg-deep: #1f1d1c;
  --surface: rgba(30, 29, 28, 0.9);
  --surface-strong: rgba(34, 32, 31, 0.98);
  --surface-muted: rgba(39, 37, 36, 0.92);
  --line: rgba(255, 245, 232, 0.08);
  --line-strong: rgba(255, 224, 183, 0.16);
  --text: var(--tg-text, #f4ece1);
  --muted: var(--tg-hint, #b7aa98);
  --accent: #f1a470;
  --accent-soft: rgba(110, 67, 40, 0.42);
  --accent-strong: #ffd0a9;
  --accent-ink: #21140f;
  --shadow: 0 32px 90px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  overflow-x: hidden;
  background:
    radial-gradient(circle at top left, rgba(224, 172, 127, 0.24), transparent 28%),
    radial-gradient(circle at 82% 8%, rgba(173, 111, 73, 0.18), transparent 20%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
  color: var(--text);
  font-family: var(--font-body);
}

body.is-loading {
  cursor: progress;
}

.backdrop,
.paper-grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.backdrop {
  filter: blur(72px);
  opacity: 0.5;
}

.backdrop-a {
  inset: -10% auto auto -12%;
  width: 22rem;
  height: 22rem;
  border-radius: 999px;
  background: rgba(225, 167, 117, 0.28);
}

.backdrop-b {
  inset: auto -12% -8% auto;
  width: 24rem;
  height: 24rem;
  border-radius: 999px;
  background: rgba(191, 111, 70, 0.16);
}

.paper-grain {
  opacity: 0.06;
  background-image:
    linear-gradient(rgba(0, 0, 0, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 0, 0, 0.05) 1px, transparent 1px);
  background-size: 18px 18px;
  mask-image: radial-gradient(circle at center, rgba(0, 0, 0, 0.96), transparent 88%);
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(calc(100% - 24px), var(--shell-width));
  margin: 0 auto;
  padding: 18px 0 28px;
}

.masthead,
.sheet,
.global-note {
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.masthead {
  padding: 24px;
}

.masthead-top,
.identity,
.hero-actions,
.section-head,
.inline-actions,
.field-row,
.media-actions,
.ideas-toolbar,
.job-top,
.idea-top {
  display: flex;
  gap: 12px;
}

.masthead-top,
.section-head,
.job-top,
.idea-top {
  align-items: flex-start;
  justify-content: space-between;
}

.identity {
  align-items: flex-start;
}

.identity-copy {
  display: grid;
  gap: 6px;
}

.avatar {
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--accent), #d28a60);
  color: var(--accent-ink);
  font-family: var(--font-title);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.eyebrow,
.idea-kicker,
.job-kicker {
  margin: 0;
  color: var(--accent-strong);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: var(--font-title);
  line-height: 1.04;
}

h1 {
  font-size: clamp(2rem, 4vw, 2.9rem);
}

h2 {
  font-size: 1.5rem;
}

h3 {
  font-size: 1.18rem;
}

.hero-copy,
.section-copy,
.global-note,
.media-caption,
.hint,
.idea-meta,
.job-meta,
.job-summary {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.hero-actions,
.inline-actions,
.hero-badges,
.chip-row {
  flex-wrap: wrap;
}

.toolbar-select,
.ideas-toolbar {
  display: grid;
  gap: 6px;
  min-width: 220px;
}

.toolbar-select select,
.ideas-toolbar select {
  min-height: 44px;
  border-radius: 999px;
  background: var(--surface-muted);
}

.hero-badges {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.metric-card {
  display: grid;
  gap: 6px;
  min-height: 88px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-muted);
}

.metric-label {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.metric-value {
  color: var(--text);
  font-size: 1.02rem;
  line-height: 1.4;
}

.global-note {
  margin: 14px 0 0;
  padding: 14px 18px;
}

.global-note[data-tone="info"] {
  border-color: rgba(126, 92, 63, 0.18);
  background: rgba(255, 249, 241, 0.84);
  color: var(--text);
}

.global-note[data-tone="warn"] {
  border-color: rgba(190, 125, 70, 0.28);
  background: rgba(255, 240, 221, 0.9);
  color: #7a461e;
}

.global-note[data-tone="error"] {
  border-color: rgba(180, 63, 63, 0.26);
  background: rgba(255, 234, 234, 0.92);
  color: #8a2f2f;
}

:root[data-telegram-scheme="dark"] .global-note[data-tone="info"] {
  background: rgba(43, 39, 36, 0.84);
  color: var(--text);
}

:root[data-telegram-scheme="dark"] .global-note[data-tone="warn"] {
  background: rgba(89, 57, 34, 0.46);
  color: #ffd8b1;
}

:root[data-telegram-scheme="dark"] .global-note[data-tone="error"] {
  background: rgba(84, 31, 31, 0.48);
  color: #ffb8b8;
}

.tab-bar {
  position: sticky;
  top: 10px;
  z-index: 4;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 251, 245, 0.76);
  box-shadow: 0 16px 44px rgba(60, 42, 27, 0.12);
  backdrop-filter: blur(14px);
}

:root[data-telegram-scheme="dark"] .tab-bar {
  background: rgba(27, 25, 24, 0.84);
}

.tab-button,
.primary-button,
.ghost-button,
.upload-button,
.tiny-button,
.chip {
  font: inherit;
}

.tab-button,
.primary-button,
.ghost-button,
.upload-button,
.tiny-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background-color 160ms ease,
    color 160ms ease,
    opacity 160ms ease;
}

.tab-button {
  background: transparent;
  color: var(--muted);
}

.tab-button.is-active {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.2);
}

.primary-button {
  background: linear-gradient(135deg, var(--accent), #d6875d);
  color: var(--accent-ink);
  font-weight: 800;
}

.ghost-button,
.upload-button,
.tiny-button {
  border-color: var(--line);
  background: var(--surface-muted);
  color: var(--text);
}

.ghost-button.danger {
  color: var(--danger);
}

.tiny-button {
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 0.88rem;
}

.tab-button:hover,
.primary-button:hover,
.ghost-button:hover,
.upload-button:hover,
.tiny-button:hover,
.chip:hover {
  transform: translateY(-1px);
}

.panel {
  display: none;
  animation: panel-fade 180ms ease;
}

.panel.is-active {
  display: block;
}

@keyframes panel-fade {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.composer-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(340px, 0.9fr);
  gap: 16px;
}

.sheet {
  padding: 22px;
}

.stack-sheet {
  display: grid;
  gap: 18px;
}

.preview-sheet {
  position: sticky;
  top: 88px;
  align-self: start;
}

.toolbar-select-compact {
  min-width: 120px;
}

.field {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.field-row {
  align-items: center;
  justify-content: space-between;
}

.field-label,
.inline-label {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.5);
  color: var(--text);
  font: inherit;
}

:root[data-telegram-scheme="dark"] textarea,
:root[data-telegram-scheme="dark"] input,
:root[data-telegram-scheme="dark"] select {
  background: rgba(255, 255, 255, 0.04);
}

textarea {
  min-height: 280px;
  padding: 16px 18px;
  resize: vertical;
  line-height: 1.68;
}

input,
select {
  min-height: 50px;
  padding: 0 16px;
}

.media-field {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.media-copy {
  display: grid;
  gap: 8px;
}

.media-actions {
  align-items: center;
}

.chip-row {
  display: flex;
  gap: 10px;
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background-color 160ms ease,
    color 160ms ease;
}

.chip.active {
  border-color: transparent;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

:root[data-telegram-scheme="dark"] .chip.active {
  color: #ffd8b6;
}

.preview-platform,
.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--text);
  font-size: 0.9rem;
}

.preview-media-shell {
  margin-top: 18px;
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: rgba(0, 0, 0, 0.06);
}

.preview-media-shell img,
.idea-cover img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: cover;
}

.preview-status {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.preview-body,
.idea-text,
.job-text {
  color: var(--text);
  font-size: 1rem;
  line-height: 1.72;
  white-space: normal;
}

.preview-body {
  margin-top: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.36), rgba(255, 255, 255, 0.16));
  min-height: 320px;
}

.version-stack {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.compact-head {
  align-items: center;
}

.version-list,
.jobs-calendar {
  display: grid;
  gap: 12px;
}

.version-card {
  display: grid;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface-strong);
}

.version-top {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.jobs-calendar {
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.calendar-pill {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.16);
  text-align: center;
}

.calendar-pill.has-count {
  border-color: transparent;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.calendar-pill span,
.calendar-pill small {
  color: inherit;
  opacity: 0.82;
}

.calendar-pill strong {
  font-size: 1.05rem;
}

.job-day-divider {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

:root[data-telegram-scheme="dark"] .preview-body {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.02));
}

.ideas-list,
.jobs-list {
  display: grid;
  gap: 14px;
}

.idea-card,
.job-card {
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface-strong);
  overflow: hidden;
}

.idea-card {
  grid-template-columns: minmax(0, 240px) minmax(0, 1fr);
}

.idea-cover {
  min-height: 100%;
  background: rgba(0, 0, 0, 0.06);
}

.idea-body,
.job-card {
  padding: 18px;
}

.idea-body {
  display: grid;
  gap: 12px;
}

.idea-meta,
.job-meta {
  font-size: 0.92rem;
}

.idea-text,
.job-text {
  padding-top: 2px;
}

.job-error {
  padding: 12px 14px;
  border: 1px solid rgba(180, 63, 63, 0.2);
  border-radius: 16px;
  background: rgba(255, 238, 238, 0.86);
  color: #8a2f2f;
  line-height: 1.55;
}

:root[data-telegram-scheme="dark"] .job-error {
  background: rgba(84, 31, 31, 0.42);
  color: #ffb8b8;
}

.job-title,
.idea-title {
  padding-top: 2px;
}

.empty-state {
  padding: 24px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  color: var(--muted);
  text-align: center;
  background: rgba(255, 255, 255, 0.18);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 10;
  min-width: min(560px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  padding: 14px 18px;
  border-radius: 16px;
  background: rgba(26, 23, 20, 0.92);
  color: #fffaf4;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.26);
  transform: translate(-50%, 24px);
  opacity: 0;
  pointer-events: none;
  transition:
    transform 160ms ease,
    opacity 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 1080px) {
  .hero-badges {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .composer-grid {
    grid-template-columns: 1fr;
  }

  .preview-sheet {
    position: static;
  }

  .idea-card {
    grid-template-columns: 1fr;
  }

  .jobs-calendar {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(calc(100% - 16px), var(--shell-width));
    padding-top: 12px;
  }

  .masthead,
  .sheet {
    padding: 18px;
    border-radius: 22px;
  }

  .masthead-top,
  .media-field,
  .section-head,
  .job-top,
  .idea-top {
    grid-template-columns: 1fr;
    display: grid;
  }

  .hero-actions,
  .media-actions,
  .ideas-toolbar {
    width: 100%;
  }

  .hero-actions > *,
  .media-actions > * {
    flex: 1 1 auto;
  }

  .hero-badges {
    grid-template-columns: 1fr;
  }

  .jobs-calendar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tab-bar {
    top: 8px;
    gap: 8px;
    padding: 6px;
  }

  .tab-button,
  .primary-button,
  .ghost-button,
  .upload-button {
    min-height: 42px;
    padding: 0 14px;
  }

  textarea {
    min-height: 220px;
  }

  .preview-body {
    min-height: 220px;
  }
}
