/* TFT Scanner Mini App. Colours come from Telegram's theme variables so the
   page follows the user's light/dark theme; every var has a fallback for
   plain browsers. Mobile-first: one column, bottom tab bar. */

:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #6b7280);
  --link: var(--tg-theme-link-color, #1c7ed6);
  --btn: var(--tg-theme-button-color, #1c7ed6);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --ok: #2f9e44;
  --bad: #e03131;
  --warn: #e8590c;
  --radius: 12px;
  --nav-h: 58px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, "Segoe UI", Roboto, system-ui, sans-serif; }
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--link); text-decoration: none; }
[hidden] { display: none !important; }

.top { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between;
  align-items: center; padding: 10px 14px; background: var(--bg);
  border-bottom: 1px solid var(--bg2); }
.brand { font-weight: 700; }

main { padding: 12px 12px calc(var(--nav-h) + 16px); }
.tab > * + * { margin-top: 10px; }

/* cards & rows */
.card { background: var(--bg2); border-radius: var(--radius); padding: 12px; }
.card > * + * { margin-top: 6px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.row.small { font-size: 13px; color: var(--hint); }
.k { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--hint); }
.big { font-size: 20px; font-weight: 700; word-break: break-all; }
.hint { color: var(--hint); font-size: 13px; }
.muted { color: var(--hint); padding: 8px 4px; }
.warn { color: var(--warn); font-size: 13px; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.bar { height: 6px; border-radius: 3px; background: rgba(127,127,127,.25); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--btn); transition: width .3s; }

/* pills */
.pill { display: inline-block; border-radius: 999px; padding: 2px 9px; font-size: 12px;
  border: 1px solid var(--hint); color: var(--hint); white-space: nowrap; }
.pill.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.pill.off { background: var(--bad); border-color: var(--bad); color: #fff; }
.pill.ok { background: rgba(47,158,68,.15); border-color: transparent; color: var(--ok); }
.pill.bad { background: rgba(224,49,49,.15); border-color: transparent; color: var(--bad); }

/* buttons */
.btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn { border: 1px solid var(--hint); background: transparent; border-radius: 10px;
  padding: 11px 8px; font-weight: 600; cursor: pointer; text-align: center; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--btn); color: var(--btn-text); border-color: var(--btn); }
.btn.danger { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.ghost { font-weight: 500; }
.btn.full { grid-column: 1 / -1; }
.reasons { color: var(--hint); font-size: 12.5px; }
.reasons div + div { margin-top: 2px; }

/* lists */
.list { background: var(--bg2); border-radius: var(--radius); padding: 2px 10px; }
.item { display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 9px 2px; border-bottom: 1px dashed rgba(127,127,127,.35); cursor: pointer; }
.item:last-child { border-bottom: 0; }
.item .main { min-width: 0; }
.item .main b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item.dim { opacity: .55; }

/* toolbar */
.toolbar > * + * { margin-top: 8px; }
.search { width: 100%; border: 1px solid var(--hint); border-radius: 10px; padding: 9px 12px;
  background: transparent; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--hint); border-radius: 999px; padding: 3px 10px; font-size: 12.5px;
  background: transparent; color: var(--hint); cursor: pointer; }
.chip.sel { background: var(--btn); color: var(--btn-text); border-color: var(--btn); }

/* forms */
.field { display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 9px 2px; border-bottom: 1px dashed rgba(127,127,127,.35); }
.field:last-child { border-bottom: 0; }
.field label { flex: 1; }
.field input[type="number"], .field input[type="text"] { width: 120px; border: 1px solid var(--hint);
  border-radius: 8px; padding: 6px 8px; background: transparent; text-align: right; }
.field input[type="text"].wide { width: 160px; text-align: left; }
.field input[type="checkbox"] { width: 20px; height: 20px; }
.form label:not(.row) { display: block; margin-top: 10px; font-size: 13px; color: var(--hint); }
.form label.row { margin-top: 12px; }
.form input:not([type="checkbox"]), .form textarea { display: block; width: 100%; margin-top: 4px;
  border: 1px solid var(--hint); border-radius: 8px; padding: 9px 10px; background: transparent; }
.form input[type="checkbox"] { width: 20px; height: 20px; }
.form textarea { min-height: 140px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.errors { color: var(--bad); font-size: 13px; white-space: pre-line; }

/* bottom nav */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; height: var(--nav-h); display: flex;
  background: var(--bg); border-top: 1px solid var(--bg2);
  padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: 11px; color: var(--hint); }
.tabs a i { font-style: normal; font-size: 18px; line-height: 1; }
.tabs a.active { color: var(--btn); font-weight: 600; }

/* bottom sheet */
.sheet { position: fixed; inset: 0; z-index: 20; display: none; }
.sheet.open { display: block; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.sheet-panel { position: absolute; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow: auto;
  background: var(--bg); border-radius: 16px 16px 0 0; padding: 18px 14px calc(16px + env(safe-area-inset-bottom)); }
.sheet-close { position: absolute; top: 8px; right: 10px; border: 0; background: transparent;
  font-size: 18px; color: var(--hint); cursor: pointer; }
.sheet-panel h3 { margin: 0 24px 8px 0; word-break: break-all; }
.sheet-panel h4 { margin: 16px 0 6px; color: var(--hint); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.sheet-panel .btns { margin-top: 12px; }
.shot { width: 100%; border-radius: 8px; margin-top: 8px; background: #000; }
.logs { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; white-space: pre-wrap;
  background: var(--bg2); border-radius: 8px; padding: 8px; max-height: 40vh; overflow: auto; }

/* toasts */
#toasts { position: fixed; left: 12px; right: 12px; bottom: calc(var(--nav-h) + 12px); z-index: 30;
  display: flex; flex-direction: column; gap: 6px; pointer-events: none; }
.toast { background: rgba(20,20,20,.92); color: #fff; border-radius: 10px; padding: 10px 12px;
  font-size: 13.5px; animation: fade .25s ease; }
.toast.err { background: var(--bad); }
.toast.ok { background: var(--ok); }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
