/* tgcast Mini App — mobile-first, Telegram-native.
 *
 * Every colour comes from Telegram's theme variables with a fallback, so the
 * app matches whatever theme the user runs — including the ones Telegram adds
 * after this ships. Hard-coding a palette is the fastest way to make a Mini App
 * look like a website that wandered into a chat.
 *
 * Sizing rules that matter on a phone:
 *   - 44px minimum tap target, everywhere, no exceptions;
 *   - 16px minimum font size on inputs, or iOS zooms the page on focus;
 *   - safe-area insets at the bottom, or the CTA hides under the home bar.
 */

:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #007aff);
  --accent: var(--tg-theme-button-color, #007aff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --section-bg: var(--tg-theme-section-bg-color, var(--bg));
  --separator: color-mix(in srgb, var(--hint) 24%, transparent);
  --danger: #e5484d;
  --success: #2ea043;
  --warning: #d29922;
  --radius: 14px;
  --gap: 12px;
  --pad: 16px;
  --tap: 44px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--secondary-bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  overscroll-behavior-y: none;
}

#root {
  min-height: 100vh;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

/* ------------------------------------------------------------- structure */

.screen { padding: var(--pad); max-width: 640px; margin: 0 auto; }

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0 12px;
}
.topbar h1 { font-size: 22px; font-weight: 700; margin: 0; flex: 1; }

.section {
  background: var(--section-bg);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: var(--gap);
}
.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--hint);
  padding: 4px 4px 8px;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--tap);
  padding: 11px var(--pad);
  border-bottom: 1px solid var(--separator);
  background: none;
  border-left: 0; border-right: 0; border-top: 0;
  width: 100%;
  text-align: left;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.row:last-child { border-bottom: 0; }
.row:active { background: var(--secondary-bg); }
.row[aria-disabled="true"] { opacity: .45; pointer-events: none; }
.row .icon { font-size: 20px; width: 26px; text-align: center; flex: none; }
.row .body { flex: 1; min-width: 0; }
.row .title { font-weight: 500; }
.row .sub { font-size: 13px; color: var(--hint); margin-top: 2px; }
.row .chev { color: var(--hint); flex: none; }

/* ---------------------------------------------------------------- typography */

.muted { color: var(--hint); }
.small { font-size: 13px; }
.center { text-align: center; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------------------------------------------ buttons */

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  width: 100%;
  padding: 12px 18px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  font: 600 16px/1.2 inherit;
  cursor: pointer;
}
.btn:active { opacity: .85; }
.btn[disabled] { opacity: .4; cursor: default; }
.btn.secondary { background: var(--section-bg); color: var(--link); font-weight: 500; }
.btn.danger { background: transparent; color: var(--danger); }
.btn.inline { width: auto; min-height: 36px; padding: 8px 14px; font-size: 15px; }

.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }

/* -------------------------------------------------------------------- chips */

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 38px;
  padding: 8px 14px;
  border-radius: 19px;
  border: 1px solid var(--separator);
  background: var(--section-bg);
  color: var(--text);
  font: 500 15px/1.2 inherit;
  cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.chip[aria-disabled="true"] { opacity: .4; }
.chip.day { min-width: 44px; padding: 8px 6px; text-align: center; }

/* ------------------------------------------------------------------- inputs */

.field { padding: 10px var(--pad); border-bottom: 1px solid var(--separator); }
.field:last-child { border-bottom: 0; }
.field label { display: block; font-size: 13px; color: var(--hint); margin-bottom: 4px; }

input[type="text"], input[type="url"], input[type="time"], input[type="number"], textarea, select {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  font: 16px/1.4 inherit; /* 16px or iOS zooms on focus */
  padding: 6px 0;
  outline: none;
  resize: vertical;
}
textarea { min-height: 120px; }
.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--section-bg);
  border-radius: 10px;
  padding: 8px 12px;
  margin-bottom: var(--gap);
}
.search input { padding: 4px 0; }

/* ------------------------------------------------------------------ status */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 13px; font-weight: 500;
  padding: 3px 9px; border-radius: 9px;
  background: var(--secondary-bg); color: var(--hint);
}
.badge.active { color: var(--success); }
.badge.paused { color: var(--warning); }
.badge.error  { color: var(--danger); }

.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }

.stat-row { display: flex; gap: 8px; }
.stat {
  flex: 1;
  background: var(--secondary-bg);
  border-radius: 10px;
  padding: 10px;
  text-align: center;
}
.stat .value { font-size: 20px; font-weight: 700; }
.stat .label { font-size: 12px; color: var(--hint); margin-top: 2px; }

/* ------------------------------------------------------------------ wizard */

.steps { display: flex; gap: 5px; margin-bottom: 14px; }
.steps i {
  flex: 1; height: 4px; border-radius: 2px;
  background: var(--separator);
}
.steps i.done { background: var(--success); }
.steps i.current { background: var(--accent); }

.step-head { margin-bottom: 14px; }
.step-head .count { font-size: 13px; color: var(--hint); }
.step-head h2 { margin: 2px 0 0; font-size: 20px; }

.sticky-cta {
  position: sticky;
  bottom: 0;
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--secondary-bg) 70%, transparent);
}

.problem {
  display: flex; gap: 8px; align-items: flex-start;
  color: var(--danger);
  font-size: 14px;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  border-radius: 10px;
  margin-bottom: var(--gap);
}

/* ----------------------------------------------------------------- preview */

.preview {
  background: var(--section-bg);
  border-radius: var(--radius);
  padding: 12px 14px;
  border-left: 3px solid var(--accent);
}
.preview .text { white-space: pre-wrap; word-break: break-word; }
.preview .media {
  height: 120px; border-radius: 10px; margin-bottom: 8px;
  background: var(--secondary-bg);
  display: flex; align-items: center; justify-content: center;
  color: var(--hint); font-size: 28px;
}
.preview-buttons { margin-top: 10px; display: grid; gap: 6px; }
.preview-buttons .pb {
  padding: 9px; border-radius: 8px; text-align: center;
  background: var(--secondary-bg); color: var(--link);
  font-size: 15px;
}
.preview-buttons .pb.branding { border: 1px dashed var(--separator); }

/* ------------------------------------------------------------- empty state */

.empty { text-align: center; padding: 40px 20px; }
.empty .art { font-size: 44px; margin-bottom: 12px; }
.empty p { color: var(--hint); margin: 0 0 20px; }

/* ------------------------------------------------------------------ misc */

.list { display: grid; gap: var(--gap); }
.card {
  background: var(--section-bg);
  border-radius: var(--radius);
  padding: 14px;
}
.card h3 { margin: 0; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.card .meta { color: var(--hint); font-size: 14px; margin: 4px 0 10px; }

.toast {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(24px + env(safe-area-inset-bottom));
  background: rgba(0,0,0,.85); color: #fff;
  padding: 10px 18px; border-radius: 20px;
  font-size: 15px; z-index: 90;
  animation: rise .18s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }

.spinner {
  width: 22px; height: 22px; margin: 40px auto;
  border: 2px solid var(--separator);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
