:root {
  color-scheme: light dark;
  --bg: var(--tg-theme-bg-color, #f4f6f9);
  --surface: var(--tg-theme-section-bg-color, #ffffff);
  --surface-soft: var(--tg-theme-secondary-bg-color, #f0f3f7);
  --text: var(--tg-theme-text-color, #18212f);
  --muted: var(--tg-theme-hint-color, #748094);
  --line: var(--tg-theme-section-separator-color, #e3e8ef);
  --accent: var(--tg-theme-button-color, #3478f6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #286de0);
  --danger: #c64444;
  --success: #18835d;
  --warning: #a46712;
  --shadow: 0 8px 28px rgb(18 37 66 / 7%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #111820);
    --surface: var(--tg-theme-section-bg-color, #19232e);
    --surface-soft: var(--tg-theme-secondary-bg-color, #202b37);
    --text: var(--tg-theme-text-color, #edf2f8);
    --muted: var(--tg-theme-hint-color, #9aa8b8);
    --line: var(--tg-theme-section-separator-color, #303b47);
    --link: var(--tg-theme-link-color, #7db0ff);
    --danger: #ff8585;
    --success: #65d2a8;
    --warning: #f0bd68;
    --shadow: 0 8px 28px rgb(0 0 0 / 20%);
  }
}

* { box-sizing: border-box; }

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

body { background: var(--bg); }

button, input, select, textarea { font: inherit; }

button { color: inherit; }

.app {
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

.shell { max-width: 680px; margin: 0 auto; }

.boot, .center-state {
  min-height: 60vh;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 12px;
  text-align: center;
  color: var(--muted);
}

.brandbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  margin-bottom: 16px;
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 800;
  letter-spacing: -1px;
}

.brand-name { margin: 0; font-size: 19px; line-height: 1.15; font-weight: 760; }
.brand-caption { margin: 4px 0 0; color: var(--muted); font-size: 12px; }

.icon-button, .button, .tab, .chip, .category-option {
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.icon-button {
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font-weight: 650;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  padding: 4px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface-soft);
}

.tab {
  min-height: 42px;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-weight: 680;
}

.tab[aria-selected="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgb(0 0 0 / 8%);
}

.page { padding-bottom: 20px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin: 4px 0 16px; }
.page-title { margin: 0; font-size: 24px; line-height: 1.18; letter-spacing: -0.45px; }
.page-subtitle { margin: 6px 0 0; color: var(--muted); line-height: 1.45; font-size: 14px; }
.section-title { margin: 20px 0 10px; font-size: 16px; font-weight: 720; }

.notice {
  margin: 12px 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  line-height: 1.45;
  font-size: 14px;
}
.notice.error { border-color: var(--danger); color: var(--danger); }
.notice.warning { border-color: var(--warning); color: var(--warning); }
.notice.success { border-color: var(--success); color: var(--success); }

.card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }
.card-title { margin: 0; font-size: 17px; line-height: 1.35; font-weight: 720; overflow-wrap: anywhere; }
.card-copy { margin: 8px 0 0; color: var(--muted); font-size: 14px; line-height: 1.45; overflow-wrap: anywhere; }
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.stack { display: grid; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.spread { justify-content: space-between; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 15px;
  border-radius: 13px;
  background: var(--accent);
  color: var(--accent-text);
  text-decoration: none;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
}
.button.secondary { background: var(--surface-soft); color: var(--text); }
.button.outline { border: 1px solid var(--line); background: transparent; color: var(--text); }
.button.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.button.small { min-height: 38px; padding: 0 12px; font-size: 14px; }
.button:disabled, .icon-button:disabled, .tab:disabled { opacity: .55; cursor: wait; }
.button.full { width: 100%; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 6px 9px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
  line-height: 1.15;
  white-space: nowrap;
}
.status.active, .status.ready { color: var(--success); }
.status.delayed, .status.waiting, .status.rotating { color: var(--warning); }
.status.error, .status.stopped, .status.paused, .status.archived { color: var(--muted); }
.status-dot { width: 7px; height: 7px; flex: 0 0 7px; border-radius: 100%; background: currentColor; }

.metric-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin-top: 14px; }
.metric { padding: 11px; border-radius: 13px; background: var(--surface-soft); min-width: 0; }
.metric-value { display: block; font-size: 16px; font-weight: 750; overflow-wrap: anywhere; }
.metric-label { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }

.form { display: grid; gap: 16px; }
.field { min-width: 0; display: grid; gap: 7px; }
.label { font-size: 14px; font-weight: 700; }
.help { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.input, .select, .textarea {
  width: 100%;
  min-height: 48px;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}
.textarea { min-height: 100px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(52 120 246 / 15%); }
.input::placeholder, .textarea::placeholder { color: var(--muted); opacity: .85; }
.input[type="number"] { appearance: textfield; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; padding: 4px; border-radius: 14px; background: var(--surface-soft); }
.segmented .button { min-height: 40px; padding: 0 9px; font-size: 14px; }
.segmented .button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgb(0 0 0 / 8%); }
.price-row { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.category-box { position: relative; }
.category-options { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 8px; }
.category-option { min-height: 36px; padding: 0 11px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface-soft); color: var(--text); font-size: 13px; }
.category-option.selected { border-color: var(--accent); color: var(--link); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 38px; padding: 0 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--text); font-size: 14px; }
.chip[aria-pressed="true"] { border-color: var(--accent); background: var(--surface-soft); color: var(--link); font-weight: 700; }
.panel { padding: 14px; border-radius: 15px; background: var(--surface-soft); }
.panel-title { margin: 0 0 6px; font-size: 14px; font-weight: 740; }
.search-options { padding: 13px 14px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); }
.search-options summary { color: var(--link); font-size: 14px; font-weight: 720; cursor: pointer; }
.search-options[open] summary { margin-bottom: 14px; }
.search-options[open] > .field + .panel { margin-top: 12px; }
.details-toggle { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; padding: 0; border: 0; background: transparent; color: var(--link); text-align: left; font-weight: 700; cursor: pointer; }
.summary-list { display: grid; gap: 0; margin: 0; }
.summary-row { display: grid; grid-template-columns: minmax(92px, .7fr) minmax(0, 1.3fr); gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.summary-row:last-child { border-bottom: 0; }
.summary-key { color: var(--muted); font-size: 13px; }
.summary-value { min-width: 0; font-size: 14px; font-weight: 620; overflow-wrap: anywhere; }
.warning-list { display: grid; gap: 8px; margin: 12px 0 0; padding: 0; list-style: none; }
.warning-list li { padding: 11px 12px; border-radius: 12px; background: var(--surface-soft); color: var(--warning); font-size: 13px; line-height: 1.4; }

.feed-card { overflow: hidden; }
.feed-photo { display: block; width: 100%; max-height: 260px; object-fit: cover; border-radius: 13px; background: var(--surface-soft); }
  .feed-photo-placeholder { display: grid; min-height: 140px; place-items: center; border-radius: 13px; background: var(--surface-soft); color: var(--muted); font-size: 13px; }
.feed-body { display: grid; gap: 8px; margin-top: 12px; }
.feed-price { font-size: 18px; font-weight: 780; }
  .feed-previous-price { margin-top: -5px; color: var(--muted); font-size: 12px; }
.feed-meta { color: var(--muted); font-size: 13px; line-height: 1.4; }
.feed-searches { display: flex; flex-wrap: wrap; gap: 6px; }
.feed-search-tag { padding: 5px 8px; border-radius: 999px; background: var(--surface-soft); color: var(--muted); font-size: 11px; }
.more-row { display: flex; justify-content: center; margin: 16px 0 8px; }

.empty {
  padding: 30px 19px;
  border: 1px dashed var(--line);
  border-radius: 18px;
  background: var(--surface);
  text-align: center;
}
.empty-icon { display: grid; place-items: center; width: 54px; height: 54px; margin: 0 auto 13px; border-radius: 18px; background: var(--surface-soft); font-size: 25px; }
.empty-title { margin: 0; font-size: 17px; font-weight: 740; }
.empty-copy { margin: 7px auto 0; max-width: 360px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.empty .button { margin-top: 17px; }

.back-button { margin: 0 0 14px; padding: 0; border: 0; background: transparent; color: var(--link); font-weight: 700; cursor: pointer; }
.modal-shade { position: fixed; z-index: 10; inset: 0; display: grid; align-items: end; padding: 16px; background: rgb(0 0 0 / 45%); }
.modal { width: min(100%, 460px); margin: 0 auto max(0px, env(safe-area-inset-bottom)); padding: 19px; border: 1px solid var(--line); border-radius: 22px; background: var(--surface); box-shadow: var(--shadow); }
.modal-title { margin: 0; font-size: 19px; }
.modal-copy { margin: 8px 0 17px; color: var(--muted); line-height: 1.45; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.loading { display: inline-flex; align-items: center; gap: 9px; color: var(--muted); font-size: 14px; }
.spinner { width: 17px; height: 17px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 100%; animation: spin .8s linear infinite; }
.divider { height: 1px; margin: 16px 0; background: var(--line); }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 560px) {
  .app { padding-left: 24px; padding-right: 24px; }
  .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .modal-shade { align-items: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
