/* ============================================================
   Username Collector — Telegram Mini App
   Clean, modern, Telegram-native design
   ============================================================ */

/* ---------- Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--tg-theme-text-color, #1a1a1a);
  background: var(--tg-theme-bg-color, #ffffff);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* ---------- Theme variables ---------- */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg-secondary: var(--tg-theme-secondary-bg-color, #f0f0f0);
  --bg-tertiary: var(--tg-theme-secondary-bg-color, #e8e8e8);
  --text: var(--tg-theme-text-color, #1a1a1a);
  --text-secondary: var(--tg-theme-hint-color, #8e8e93);
  --accent: var(--tg-theme-button-color, #3390ec);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #3390ec);
  --card-bg: var(--tg-theme-section-bg-color, #ffffff);
  --separator: var(--tg-theme-separator-color, #e0e0e0);
  --ok: #34c759;
  --warn: #ff9f0a;
  --bad: #ff3b30;
  --found: #5856d6;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-lg: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ---------- App container ---------- */
.app {
  max-width: 600px;
  margin: 0 auto;
  padding: 0 16px 100px;
}

/* ---------- Header ---------- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--separator);
}
.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #5856d6);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 15px;
  color: #fff;
  flex-shrink: 0;
  letter-spacing: -0.5px;
}
.header-info h1 {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.2;
}
.header-status {
  font-size: 12px;
}
.muted { color: var(--text-secondary); }
.header-right { display: flex; align-items: center; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 0;
  position: sticky;
  top: 77px;
  z-index: 99;
  background: var(--bg);
}
.tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}
.tab:hover:not(:disabled) {
  background: var(--bg-secondary);
}
.tab.active {
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 2px 8px rgba(51, 144, 236, 0.3);
}
.tab:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.tab svg { flex-shrink: 0; }

/* ---------- Screens ---------- */
.screen { animation: screenIn 0.2s ease; }
@keyframes screenIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.hidden { display: none !important; }

/* ---------- Section header ---------- */
.section-header { margin-bottom: 16px; }
.section-header h2 {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 4px;
}
.section-header .muted {
  font-size: 13px;
}

/* ---------- Lists ---------- */
.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

/* ---------- Item cards ---------- */
.item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--separator);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.item:active { transform: scale(0.985); }
.item .avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 16px;
  color: #fff;
}
.avatar.accent { background: linear-gradient(135deg, var(--accent), #5856d6); }
.avatar.chat { background: linear-gradient(135deg, #34c759, #30d158); }
.item .body { flex: 1; min-width: 0; }
.item .title {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item .sub {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item .actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}
.badge-ok { background: rgba(52,199,89,0.12); color: var(--ok); }
.badge-warn { background: rgba(255,159,10,0.12); color: var(--warn); }
.badge-bad { background: rgba(255,59,48,0.12); color: var(--bad); }
.badge-muted { background: var(--bg-secondary); color: var(--text-secondary); }
.badge-accent { background: rgba(51,144,236,0.12); color: var(--accent); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  width: 100%;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 2px 8px rgba(51,144,236,0.25);
}
.btn-primary:hover:not(:disabled) { box-shadow: 0 4px 16px rgba(51,144,236,0.35); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--separator);
}
.btn-ghost:hover { background: var(--bg-secondary); }

.btn-sm {
  padding: 8px 14px;
  font-size: 13px;
  border-radius: 10px;
  width: auto;
}

.btn-wide { margin-top: 12px; }
.btn-danger { color: var(--bad); }
.btn-danger:hover { background: rgba(255,59,48,0.08); }

.btn-icon {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-icon:hover { background: var(--bg-tertiary); }

/* ---------- Form cards ---------- */
.form-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--separator);
}
.form-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.form-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}
.form-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
}
.form-check input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

/* ---------- Inputs ---------- */
.input {
  flex: 1;
  min-width: 0;
  padding: 11px 14px;
  font-size: 15px;
  color: var(--text);
  background: var(--bg-secondary);
  border: 1.5px solid transparent;
  border-radius: 10px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}
.input::placeholder { color: var(--text-secondary); }
.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(51,144,236,0.15);
}
.input-center { text-align: center; font-size: 24px; font-weight: 700; letter-spacing: 4px; }

select.input {
  -webkit-appearance: none;
  appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%238e8e93' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

/* ---------- Action bar ---------- */
.action-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}
.action-bar .btn { flex: 1; }

/* ---------- Modals ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  animation: modalIn 0.2s ease;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
}
.modal-sheet {
  position: relative;
  background: var(--card-bg);
  border-radius: 20px 20px 0 0;
  padding: 8px 24px 24px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  animation: sheetUp 0.25s ease;
}
.modal-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--separator);
  margin: 0 auto 16px;
}
.modal-sheet h3 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
}
.modal-sheet .input {
  width: 100%;
  margin: 10px 0;
  flex: none;
}
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}
.modal-actions .btn { flex: 1; }

@keyframes modalIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* ---------- Dashboard ---------- */
.dashboard { margin-top: 8px; }
.dash-stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-top: 12px;
}
.stat {
  text-align: center;
  padding: 10px 4px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--separator);
}
.stat span {
  display: block;
  font-size: 20px;
  font-weight: 800;
  line-height: 1.2;
}
.stat small {
  font-size: 10px;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.stat[data-color="accent"] span { color: var(--accent); }
.stat[data-color="warn"] span { color: var(--warn); }
.stat[data-color="ok"] span { color: var(--ok); }
.stat[data-color="bad"] span { color: var(--bad); }
.stat[data-color="found"] span { color: var(--found); }

.overall {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.overall-track {
  flex: 1;
  height: 8px;
  background: var(--bg-secondary);
  border-radius: 4px;
  overflow: hidden;
}
.overall-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #5856d6);
  border-radius: 4px;
  transition: width 0.4s ease;
}
.overall-pct {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  min-width: 36px;
  text-align: right;
}

/* ---------- Job cards ---------- */
.job-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--separator);
}
.job-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.job-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.job-acc {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 10px;
}
.job-bar {
  height: 6px;
  background: var(--bg-secondary);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 8px;
}
.job-bar .fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent), #5856d6);
  transition: width 0.35s ease;
}
.job-bar .fill.done { background: var(--ok); }
.job-bar .fill.fail { background: var(--bad); }
.job-bar .fill.cancel { background: var(--text-secondary); }
.job-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary);
}
.job-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

/* ---------- Error / Toast ---------- */
.error {
  color: var(--bad);
  font-size: 13px;
  margin-top: 8px;
  min-height: 1em;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  z-index: 300;
  box-shadow: var(--shadow-lg);
  max-width: 90vw;
  animation: toastIn 0.2s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(10px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

/* ---------- Empty states ---------- */
.empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-secondary);
  font-size: 14px;
}
.empty svg { opacity: 0.3; margin-bottom: 8px; }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 0; height: 0; }

/* ---------- Focus visible ---------- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Dark mode overrides (auto) ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --card-bg: #1c1c1e;
    --bg-secondary: #2c2c2e;
    --bg-tertiary: #3a3a3c;
    --separator: #38383a;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
  }
}

/* ---------- Telegram dark theme fallback ---------- */
body:has(.tg-theme-dark) {
  --card-bg: #1c1c1e;
  --bg-secondary: #2c2c2e;
  --bg-tertiary: #3a3a3c;
  --separator: #38383a;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
}
