:root {
  color-scheme: light;
  --bg: #fffaf5;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #171717;
  --muted: #64748b;
  --line: #e5e7eb;
  --accent: #f97316;
  --accent-2: #2563eb;
  --success: #16a34a;
  --danger: #dc2626;
  --shadow: 0 12px 36px rgba(15, 23, 42, 0.08);
}

body[data-theme="dark"] {
  color-scheme: dark;
  --bg: #050914;
  --surface: #0d1424;
  --surface-2: #111c31;
  --text: #eef6ff;
  --muted: #9eb2cc;
  --line: #22304a;
  --accent: #fb923c;
  --accent-2: #60a5fa;
  --success: #4ade80;
  --danger: #f87171;
  --shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

strong {
  font-weight: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  padding: 18px 16px 96px;
  max-width: 1120px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 27px;
  font-weight: 800;
  line-height: 1.1;
}

.telegram-status {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

h2 {
  font-size: 20px;
  font-weight: 400;
  line-height: 1.2;
}

h3 {
  font-size: 17px;
  font-weight: 400;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: none;
}

.balance {
  min-width: 94px;
  height: 48px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  text-align: right;
}

.balance span {
  display: block;
  color: var(--accent);
  font-weight: 900;
  line-height: 1;
}

.balance small {
  color: var(--muted);
  font-size: 11px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 0 12px;
}

.section-title span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
}

.section-title.compact {
  margin-top: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  margin-bottom: 10px;
  padding: 1px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--line);
}

.segmented button {
  display: grid;
  gap: 7px;
  min-width: 0;
  padding: 7px 7px 9px;
  border: 0;
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  text-align: center;
  transition: background 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.mode-title {
  display: block;
  min-width: 0;
  overflow: hidden;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
  text-overflow: ellipsis;
}

.mode-title span {
  color: var(--muted);
  font-weight: 400;
  white-space: nowrap;
}

.segmented button.active {
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  box-shadow: inset 0 0 0 2px var(--accent);
}

.mode-preview {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 7px;
  object-fit: cover;
  background: var(--surface-2);
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.panel {
  border: 0;
  border-radius: 0;
  background: var(--surface);
  box-shadow: none;
}

.form-panel {
  border-left: 1px solid var(--line);
}

.upload-panel {
  display: grid;
  gap: 10px;
  align-content: start;
  padding: 12px;
}

.photo-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.photo-actions small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.photo-add-button {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 42px;
  gap: 9px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  text-transform: none;
}

.photo-add-button input {
  display: none;
}

.camera-add-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 28px;
  height: 24px;
}

.camera-body {
  position: relative;
  width: 26px;
  height: 19px;
  border-radius: 8px;
  background: var(--accent);
}

.camera-body::before {
  content: "";
  position: absolute;
  top: -4px;
  left: 7px;
  width: 10px;
  height: 5px;
  border-radius: 3px 3px 0 0;
  background: var(--accent);
}

.camera-body::after {
  content: "";
  position: absolute;
  top: 5px;
  left: 8px;
  width: 9px;
  height: 9px;
  border: 2px solid #ffffff;
  border-radius: 999px;
}

.camera-plus {
  position: absolute;
  right: -5px;
  bottom: -5px;
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border: 2px solid var(--surface-2);
  border-radius: 999px;
  background: var(--accent-2);
  color: #ffffff;
  font-size: 13px;
  line-height: 1;
}

.photo-strip {
  display: flex;
  min-height: 74px;
  gap: 8px;
  overflow-x: auto;
  padding: 0 0 2px;
}

.photo-thumb {
  position: relative;
  flex: 0 0 70px;
  width: 70px;
  height: 70px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-2);
}

.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.72);
  color: #ffffff;
  font-size: 15px;
  line-height: 1;
}

.form-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  text-transform: none;
}

.field-control {
  gap: 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;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  outline: none;
}

input {
  min-height: 44px;
  padding: 0 12px;
}

textarea {
  min-height: 108px;
  padding: 12px;
  resize: vertical;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.form-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--accent-2);
  font-size: 13px;
  font-weight: 400;
}

.prompt-rail {
  display: flex;
  gap: 8px;
  min-height: 64px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.prompt-chip {
  flex: 0 0 154px;
  min-height: 64px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
}

.prompt-chip.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
}

.prompt-chip strong {
  display: block;
  font-size: 13px;
}

.prompt-chip small {
  color: var(--muted);
  font-size: 11px;
}

.primary-action,
.secondary-action {
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: 8px;
  font-weight: 400;
}

.primary-action {
  margin-top: 16px;
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 12px 26px color-mix(in srgb, var(--accent) 26%, transparent);
}

.primary-action:disabled {
  opacity: 0.62;
  cursor: wait;
}

.secondary-action {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

.secondary-action.wide {
  margin-top: 4px;
}

.result-layout {
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
  gap: 12px;
  margin-top: 18px;
}

.result-visual,
.result-copy {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.result-visual {
  overflow: hidden;
}

.result-visual img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
}

.result-copy {
  padding: 14px;
}

.result-copy textarea {
  min-height: 230px;
}

.hashtags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.hashtags span {
  padding: 7px 9px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent-2) 12%, var(--surface));
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 400;
}

.action-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.prompt-list,
.history-list,
.channel-list,
.payment-channel-list,
.ledger-list {
  display: grid;
  gap: 10px;
}

.prompt-card,
.history-item,
.channel-item,
.payment-channel-item,
.ledger-item,
.metric-panel,
.tariff-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
  box-shadow: var(--shadow);
}

.prompt-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.prompt-card p,
.history-item p,
.channel-item p,
.payment-channel-item p,
.tariff-card p,
.metric-panel p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.tag {
  align-self: start;
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
}

.prompt-form {
  display: grid;
  gap: 12px;
  margin-top: 14px;
  padding: 14px;
}

.history-item {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 12px;
}

.history-item img {
  width: 86px;
  height: 108px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--surface-2);
}

.history-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.history-meta span,
.channel-status {
  padding: 5px 7px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
}

.channel-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.billing-summary {
  display: grid;
  grid-template-columns: 0.8fr 1.2fr;
  gap: 12px;
}

.metric-panel {
  min-height: 104px;
  display: grid;
  align-content: center;
  gap: 6px;
}

.metric-panel span {
  color: var(--accent);
  font-size: 36px;
  font-weight: 400;
  line-height: 1;
}

.metric-panel small,
.payment-channel-item small,
.ledger-item small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.tariff-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.tariff-card {
  display: grid;
  gap: 12px;
}

.tariff-meta {
  display: grid;
  gap: 2px;
}

.tariff-meta strong {
  color: var(--accent);
  font-size: 24px;
}

.tariff-meta span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.payment-channel-item,
.ledger-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.payment-channel-item small {
  display: block;
  margin-top: 6px;
}

.ledger-item span {
  font-weight: 400;
}

.ledger-item strong {
  flex: 0 0 auto;
}

.ledger-item strong.positive {
  color: var(--success);
}

.ledger-item strong.negative {
  color: var(--danger);
}

.channel-status.ready {
  background: color-mix(in srgb, var(--success) 14%, var(--surface));
  color: var(--success);
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 14px;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  width: min(560px, calc(100% - 28px));
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: var(--shadow);
  transform: translateX(-50%);
  backdrop-filter: blur(14px);
}

.bottom-nav button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.bottom-nav button.active {
  background: var(--accent);
  color: #ffffff;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 78px;
  z-index: 20;
  width: min(420px, calc(100% - 32px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #111827;
  color: #ffffff;
  font-size: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 14px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 760px) {
  .app-shell {
    padding: 14px 12px 94px;
  }

  h1 {
    font-size: 24px;
  }

  .workspace-grid,
  .result-layout,
  .billing-summary,
  .tariff-grid {
    grid-template-columns: 1fr;
  }

  .segmented button {
    padding: 6px 6px 8px;
  }

  .form-panel {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .photo-actions {
    align-items: flex-start;
  }

  .mode-title {
    font-size: 12px;
  }
}

@media (max-width: 420px) {
  .topbar {
    align-items: flex-start;
  }

  .bottom-nav {
    width: calc(100% - 16px);
    gap: 4px;
    padding: 6px;
  }

  .bottom-nav button {
    padding: 0 2px;
    font-size: 11px;
  }

  .balance {
    min-width: 80px;
  }

  .form-row,
  .action-row {
    grid-template-columns: 1fr;
  }

  .history-item {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  .history-item img {
    width: 72px;
    height: 90px;
  }
}

@media (min-width: 900px) {
  .app-shell {
    padding: 18px 16px 42px 112px;
  }

  .bottom-nav {
    top: 132px;
    bottom: auto;
    left: max(14px, calc((100vw - 1120px) / 2 + 16px));
    grid-template-columns: 1fr;
    width: 86px;
    transform: none;
  }

  .bottom-nav button {
    min-height: 50px;
    padding: 0 6px;
  }
}
