:root {
  --bg: #1F1F1F;
  --orange: #CC785C;
  --text: #B0ACA4;
  --bright: #F0EEE6;
  --dim: #777777;
  --green: #34c759;
  --red: #ff453a;
  --panel: #2a2a2a;
  --border: #3a3a3a;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Шапка ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: env(safe-area-inset-top) 16px 0;
  height: calc(52px + env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--orange);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .title { color: var(--orange); font-weight: 600; font-size: 1.15rem; flex: 1; text-align: left; }
.topbar .back {
  background: none; border: none; color: var(--orange);
  font-size: 1rem; padding: 8px 4px; cursor: pointer;
  min-width: 64px; text-align: left;
}
.topbar .back[hidden] { display: none; }
.link-dot {
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--dim); transition: background .2s;
  flex: 0 0 auto;
}
.link-dot[data-state="online"]  { background: var(--green); }
.link-dot[data-state="offline"] { background: var(--red); }
.link-dot[data-state="connecting"] { background: var(--dim); }

/* ── Экран ── */
.screen {
  flex: 1;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  overflow-y: auto;
}
.screen-title { color: var(--orange); font-size: .95rem; margin: 2px 0 16px; letter-spacing: .02em; }
.muted { color: var(--dim); }
.center { text-align: center; }
.spaced { margin-top: 40px; }

/* ── Плитки меню ── */
.tile {
  display: block; width: 100%; text-align: left;
  background: var(--panel); color: var(--bright);
  border: 1px solid var(--border); border-radius: 14px;
  padding: 18px; margin: 0 0 12px; font-size: 1.1rem;
  min-height: 58px; cursor: pointer;
  -webkit-appearance: none;
}
.tile:active { background: var(--orange); color: #000; border-color: var(--orange); }
.tile.danger { border-color: var(--orange); }
.tile .chev { float: right; color: var(--dim); }

/* ── Индикатор жеста «потянуть вниз — обновить» ── */
.ptr {
  position: fixed; top: -40px; left: 50%;
  transform: translateX(-50%);
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel); color: var(--dim);
  border: 1px solid var(--border);
  font-size: 1.2rem; line-height: 1; opacity: 0; z-index: 60;
  transition: opacity .15s ease;
  pointer-events: none;
}
.ptr.ready { color: var(--orange); border-color: var(--orange); }
.ptr.spin { animation: ptr-spin .6s linear infinite; }
@keyframes ptr-spin { from { rotate: 0deg; } to { rotate: 360deg; } }

/* ── Кнопки ── */
.btn {
  display: inline-block; border: none; border-radius: 12px;
  padding: 16px 22px; font-size: 1.05rem; cursor: pointer;
  min-height: 52px; min-width: 110px;
}
.btn-primary { background: var(--orange); color: #000; font-weight: 600; }
.btn-ghost { background: var(--panel); color: var(--bright); border: 1px solid var(--border); }
.btn-row { display: flex; gap: 12px; margin-top: 20px; }
.btn-row .btn { flex: 1; }

/* ── Поле ввода кода ── */
.pin-wrap { max-width: 320px; margin: 48px auto 0; text-align: center; }
.pin-input {
  width: 100%; font-size: 1rem; text-align: center;
  font-family: ui-monospace, Menlo, monospace; letter-spacing: .02em;
  background: var(--panel); color: var(--bright);
  border: 1px solid var(--border); border-radius: 14px;
  padding: 16px; margin: 18px 0; -webkit-appearance: none;
}
.pin-input:focus { outline: none; border-color: var(--orange); }
.pin-msg { color: var(--red); min-height: 1.4em; margin-bottom: 10px; }

/* ── Модальное подтверждение ── */
.modal-back {
  position: fixed; inset: 0; background: rgba(0,0,0,.7);
  display: flex; align-items: center; justify-content: center; z-index: 50;
  padding: 24px;
}
.modal {
  background: var(--bg); border: 1px solid var(--orange); border-radius: 18px;
  padding: 24px; max-width: 360px; width: 100%; text-align: center;
}
.modal h2 { color: var(--orange); font-size: 1.15rem; margin: 0 0 8px; }
.modal p { color: var(--text); margin: 0 0 8px; }

/* ── Экран результата ── */
.result { text-align: center; margin-top: 56px; }
.result .big { font-size: 3rem; font-weight: 700; margin-bottom: 12px; }
.result .big.ok { color: var(--green); }
.result .big.fail { color: var(--red); }
.result .sub { color: var(--dim); margin-bottom: 28px; word-break: break-word; }
.result .spinner { color: var(--orange); }

/* ── Снимок окна Клода ── */
.snapshot {
  background: #151515; border: 1px solid var(--border); border-radius: 12px;
  padding: 12px; font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .8rem; line-height: 1.35; color: var(--bright);
  white-space: pre-wrap; word-break: break-word;
  max-height: 52vh; overflow-y: auto; margin: 0 0 12px;
}
.refresh {
  background: none; border: 1px solid var(--border); color: var(--orange);
  border-radius: 10px; padding: 8px 14px; margin-bottom: 12px; cursor: pointer;
}
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.row-actions .btn { flex: 1 1 30%; min-width: 96px; padding: 13px 10px; font-size: .95rem; }

/* ── Бейдж разрешений ── */
.badge {
  background: var(--red); color: #fff; font-size: .75rem; font-weight: 700;
  min-width: 22px; height: 22px; border-radius: 11px; padding: 0 7px;
  display: inline-flex; align-items: center; justify-content: center;
  margin-right: 10px; cursor: pointer;
}
.badge[hidden] { display: none; }

/* ── Разрешения ── */
.perm-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px; margin-bottom: 12px;
}
.perm-summary {
  color: var(--bright); font-family: ui-monospace, Menlo, monospace; font-size: .9rem;
  margin-bottom: 12px; word-break: break-word; white-space: pre-wrap;
}

/* ── Терминал ── */
.btn-stop { background: var(--red); color: #fff; font-weight: 600; }
.term-cwd { color: var(--dim); font-size: .8rem; font-family: ui-monospace, Menlo, monospace; margin-bottom: 10px; word-break: break-all; }
.term-input-row { display: flex; gap: 8px; margin-bottom: 10px; }
.term-input {
  flex: 1; min-width: 0; background: var(--panel); color: var(--bright);
  border: 1px solid var(--border); border-radius: 10px; padding: 13px;
  font-family: ui-monospace, Menlo, monospace; font-size: .95rem; -webkit-appearance: none;
}
.term-input:focus { outline: none; border-color: var(--orange); }
.term-input:disabled { opacity: .6; }
.term-go { min-width: 96px; padding: 13px 10px; }
.chips-label { color: var(--dim); font-size: .75rem; margin: 0 0 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip {
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: 999px; padding: 7px 13px; font-size: .85rem;
  font-family: ui-monospace, Menlo, monospace; cursor: pointer;
}
.chip.fav { border-color: var(--orange); color: var(--orange); }
.term-out {
  background: #101010; border: 1px solid var(--border); border-radius: 12px;
  padding: 12px; font-family: ui-monospace, Menlo, monospace; font-size: .8rem;
  line-height: 1.4; color: var(--bright); white-space: pre-wrap; word-break: break-word;
  height: 44vh; overflow-y: auto;
}

/* ── Лимиты и расход ── */
.tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tab {
  flex: 1; background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 11px 6px; font-size: .9rem; cursor: pointer;
}
.tab.active { background: var(--orange); color: #000; border-color: var(--orange); font-weight: 600; }
.limit { margin-bottom: 18px; }
.limit-head { display: flex; justify-content: space-between; color: var(--bright); margin-bottom: 7px; }
.limit-pct { color: var(--orange); font-weight: 600; }
.limit-reset { color: var(--dim); font-size: .8rem; margin-top: 6px; }
.bar { background: #333; border-radius: 6px; height: 10px; overflow: hidden; }
.bar-fill { background: var(--orange); height: 100%; border-radius: 6px; }
.stat { display: flex; justify-content: space-between; align-items: baseline; padding: 15px 0; border-bottom: 1px solid var(--border); }
.stat-label { color: var(--text); }
.stat-value { color: var(--bright); font-size: 1.2rem; font-weight: 600; }
.stale { color: var(--dim); font-size: .8rem; margin-bottom: 10px; font-style: italic; }
.usage-section { color: var(--orange); font-size: .8rem; font-weight: 600; margin: 22px 0 10px; text-transform: uppercase; letter-spacing: .05em; }

/* ── Сервер: стадии операции ── */
.stages { margin: 8px 0; }
.stage {
  color: var(--text); font-family: ui-monospace, Menlo, monospace; font-size: .9rem;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.stage.done { color: var(--green); font-weight: 600; }
.stage.fail { color: var(--red); font-weight: 600; }

/* ── Партнёр: крупный блок контекста бота ── */
.ctx-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 20px; margin-bottom: 14px; text-align: center;
}
.ctx-label { color: var(--dim); font-size: .85rem; margin-bottom: 6px; }
.ctx-big { color: var(--orange); font-size: 3rem; font-weight: 700; line-height: 1.1; margin-bottom: 14px; }
.ctx-card .bar { height: 14px; }
.ctx-sub { color: var(--text); font-size: .85rem; margin-top: 10px; min-height: 1em; }

/* ── Всплывающее короткое подтверждение ── */
.toast {
  position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 60;
  background: var(--green); color: #000; font-weight: 600;
  padding: 12px 20px; border-radius: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.4);
}
.toast.bad { background: var(--red); color: #fff; }

/* ── Спиннер ожидания ── */
.waiting { text-align: center; margin-top: 64px; color: var(--orange); }
.dots::after { content: ""; animation: dots 1.2s steps(4,end) infinite; }
@keyframes dots { 0%{content:""} 25%{content:"."} 50%{content:".."} 75%{content:"..."} 100%{content:""} }
