:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1c1c1e);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --card: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --accent: var(--tg-theme-button-color, #2ea6ff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --border: rgba(128,128,128,0.25);
}

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}

.app { padding: 16px 16px 40px; max-width: 520px; margin: 0 auto; }

h1 { font-size: 20px; margin: 4px 0 18px; text-align: center; }

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 13px; color: var(--hint); margin-bottom: 6px; }

select, input, textarea {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--text);
  outline: none;
  appearance: none;
}
select:focus, input:focus, textarea:focus { border-color: var(--accent); }
select:disabled { opacity: 0.5; }
textarea { resize: none; }

.results {
  margin-top: 6px;
  border-radius: 12px;
  overflow: hidden;
}
.results .item {
  padding: 11px 14px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  cursor: pointer;
}
.results .item:last-child { border-bottom: none; }
.results .item:active { background: var(--accent); color: var(--accent-text); }
.results .item .art { color: var(--hint); font-size: 12px; }

.chosen {
  margin-top: 8px;
  padding: 11px 14px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  border: 1px solid var(--accent);
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.chosen .clear { color: var(--accent); font-weight: 600; cursor: pointer; }

.segmented { display: flex; gap: 8px; }
.segmented .seg {
  flex: 1;
  text-align: center;
  padding: 12px;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 15px;
}
.segmented .seg.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.submit {
  width: 100%;
  padding: 15px;
  font-size: 17px;
  font-weight: 600;
  border: none;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  margin-top: 6px;
}
.submit:disabled { opacity: 0.5; }

.status { text-align: center; margin-top: 12px; font-size: 14px; min-height: 20px; }
.status.err { color: #ff3b30; }
.status.ok { color: #34c759; }

.hidden { display: none !important; }

.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tabs .tab {
  flex: 1; text-align: center; padding: 10px; border-radius: 12px;
  background: var(--card); border: 1px solid var(--border); cursor: pointer; font-size: 14px;
}
.tabs .tab.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.stat-grid { display: flex; gap: 10px; margin-bottom: 16px; }
.stat-card {
  flex: 1; background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; padding: 14px; text-align: center;
}
.stat-card .num { font-size: 26px; font-weight: 700; }
.stat-card .lbl { font-size: 12px; color: var(--hint); margin-top: 4px; }

.row-item {
  display: flex; justify-content: space-between; padding: 10px 12px;
  background: var(--card); border-bottom: 1px solid var(--border); font-size: 14px;
}
.row-item:first-child { border-radius: 12px 12px 0 0; }
.row-item:last-child { border-bottom: none; border-radius: 0 0 12px 12px; }
.row-item .badge { color: var(--accent); font-weight: 600; }

/* --- Admin panel (professional) --- */
.hero {
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #7b5cff));
  color: #fff; border-radius: 18px; padding: 18px 18px 16px; margin-bottom: 16px;
}
.hero h1 { color: #fff; text-align: left; margin: 0 0 4px; font-size: 20px; }
.hero .sub { font-size: 13px; opacity: .9; }
.hero .refresh {
  float: right; background: rgba(255,255,255,.2); border: none; color: #fff;
  width: 34px; height: 34px; border-radius: 10px; font-size: 16px; cursor: pointer;
}

.stat-card { position: relative; overflow: hidden; }
.stat-card .num { font-size: 28px; font-weight: 800; line-height: 1; }
.stat-card .ico { font-size: 18px; margin-bottom: 6px; }

.section-title { font-size: 13px; color: var(--hint); margin: 18px 0 8px; font-weight: 600; }

.bar-row { margin-bottom: 10px; }
.bar-row .top { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 4px; }
.bar-row .top .cnt { color: var(--accent); font-weight: 700; }
.bar-track { height: 8px; background: var(--card); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 6px; transition: width .4s; }

.spinner {
  width: 30px; height: 30px; margin: 24px auto; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.retry-btn {
  display: inline-block; margin-top: 10px; padding: 8px 16px; border-radius: 10px;
  background: var(--accent); color: var(--accent-text); border: none; cursor: pointer; font-size: 14px;
}

.sheet-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; margin-bottom: 8px; cursor: pointer; font-size: 14px;
}
.sheet-item.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
.sheet-item .check { color: var(--accent); font-weight: 700; }
