/* Тёмная тема в духе панели Claude Code */
:root {
  --bg: #1b1b1f;
  --bg-side: #141417;
  --bg-input: #232329;
  --bg-card: #232329;
  --bg-hover: #2a2a31;
  --border: #2e2e36;
  --fg: #e8e6e3;
  --hint: #8b8b93;
  --accent: #d97757;      /* оранжевый Claude */
  --bar: #4a9eff;         /* синие прогресс-бары как в панели */
  --bar-bg: #2b2b33;
  --danger: #e5534b;
  --ok: #3fb950;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.45 -apple-system, "Segoe UI", Roboto, sans-serif;
}

#app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ---------- Сайдбар ---------- */

#sidebar {
  width: 270px;
  flex: none;
  background: var(--bg-side);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 12px 0;
}

.side-section {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
}
.side-section:last-child { border-bottom: none; }
.side-section.grow { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.side-label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--hint);
  margin: 6px 0 8px;
}

.side-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.side-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0 8px;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  font-size: 11px;
  color: var(--hint);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1px 7px;
}

/* Лимиты */
.usage-list { display: flex; flex-direction: column; gap: 10px; padding-bottom: 8px; }
.usage-item .u-top {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 4px;
}
.usage-item .u-pct { color: var(--fg); }
.usage-item .u-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--bar-bg);
  overflow: hidden;
}
.usage-item .u-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--bar);
}
.usage-item .u-reset {
  font-size: 11px;
  color: var(--hint);
  margin-top: 3px;
}
.usage-extra { font-size: 12px; color: var(--hint); }

/* Сессии */
.new-session {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 1px dashed var(--border);
  color: var(--fg);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  cursor: pointer;
  margin-bottom: 8px;
}
.new-session:hover { background: var(--bg-hover); }

.session-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
}

.session-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  color: var(--fg);
}
.session-item:hover { background: var(--bg-hover); }
.session-item.active { background: var(--bg-hover); }

.s-dot {
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--hint);
}
.session-item.running .s-dot {
  background: var(--accent);
  animation: pulse 1.2s infinite;
}
.session-item.attention .s-dot { background: var(--bar); }
@keyframes pulse { 50% { opacity: 0.35; } }

.s-body { flex: 1; min-width: 0; }
.s-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.s-proj {
  font-size: 11px;
  color: var(--hint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.s-close {
  flex: none;
  background: none;
  border: none;
  color: var(--hint);
  font-size: 15px;
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 6px;
  visibility: hidden;
}
.session-item:hover .s-close { visibility: visible; }
.s-close:hover { color: var(--danger); background: var(--bg); }

.empty-hint {
  color: var(--hint);
  font-size: 13px;
  padding: 10px 4px;
}

/* ---------- Основная область ---------- */

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  flex: none;
}

.title-wrap { flex: 1; min-width: 0; }
#tabTitle {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.subtitle {
  font-size: 12px;
  color: var(--hint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.iconbtn {
  background: none;
  border: none;
  color: var(--fg);
  font-size: 18px;
  cursor: pointer;
  padding: 6px 9px;
  border-radius: 8px;
  flex: none;
}
.iconbtn:hover { background: var(--bg-hover); }
.iconbtn.menu { display: none; }

.stopbtn {
  background: none;
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
}
.stopbtn:hover { background: color-mix(in srgb, var(--danger) 15%, transparent); }

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg { max-width: 92%; white-space: pre-wrap; word-break: break-word; }
.msg.user {
  align-self: flex-end;
  background: var(--bg-input);
  border-radius: 14px 14px 4px 14px;
  padding: 9px 13px;
}
.msg.assistant {
  align-self: flex-start;
  padding: 2px 2px;
}
.msg.assistant::before {
  content: "●";
  color: var(--accent);
  font-size: 9px;
  margin-right: 8px;
  vertical-align: 2px;
}
.msg.error {
  align-self: center;
  color: var(--danger);
  font-size: 13px;
  text-align: center;
}
.msg.notice {
  align-self: center;
  color: var(--hint);
  font-size: 13px;
  text-align: center;
}

/* Карточки подтверждений и вопросов */
.card {
  align-self: stretch;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}
.card .c-title { font-weight: 600; margin-bottom: 8px; }
.card .c-desc {
  font-size: 13px;
  color: var(--hint);
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 10px;
}
.card .c-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 9px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  text-align: left;
}
.btn:hover { background: var(--bg-hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.selected { border-color: var(--bar); color: var(--bar); }
.btn .b-desc { display: block; font-size: 12px; color: var(--hint); }
.btn.block { display: block; width: 100%; margin-bottom: 6px; }

#statusBar {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 16px;
  color: var(--hint);
  font-size: 13px;
  flex: none;
}
#statusBar[hidden] { display: none; }
#statusText {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.spinner {
  flex: none;
  width: 12px;
  height: 12px;
  border: 2px solid var(--bar-bg);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 14px;
  flex: none;
}
.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  padding: 3px 8px;
}
.attach-chip button {
  background: none;
  border: none;
  color: var(--hint);
  cursor: pointer;
  font-size: 13px;
  padding: 0;
}

#quickbar {
  display: flex;
  gap: 6px;
  padding: 6px 14px 0;
  flex: none;
  flex-wrap: wrap;
}
.chip {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--hint);
  border-radius: 10px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}
.chip:hover { background: var(--bg-hover); }
.chip.on { color: var(--ok); border-color: var(--ok); }

footer {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  flex: none;
}

#input {
  flex: 1;
  resize: none;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--fg);
  font: inherit;
  padding: 10px 13px;
  max-height: 140px;
  outline: none;
}
#input:focus { border-color: var(--accent); }

.iconbtn.send { color: var(--accent); font-size: 20px; }

/* ---------- Модальные окна ---------- */

#sheet { position: fixed; inset: 0; z-index: 30; }
#sheet[hidden] { display: none; }
#sheetBackdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); }
#sheetBody {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(430px, calc(100vw - 28px));
  max-height: 78vh;
  overflow-y: auto;
  background: var(--bg-side);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
}
#sheetBody h3 { margin: 0 0 12px; font-size: 16px; }
#sheetBody .hint { color: var(--hint); font-size: 13px; margin: 8px 0; }

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.setting-row:last-child { border-bottom: none; }

/* Переключатель */
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  background: var(--bar-bg);
  transition: background 0.15s;
  cursor: pointer;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}
.switch input:checked + .track { background: var(--ok); }
.switch input:checked + .track::after { transform: translateX(18px); }

/* ---------- Прочее ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #000;
  color: #fff;
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 14px;
  z-index: 50;
  max-width: calc(100vw - 40px);
}
#toast[hidden] { display: none; }

#guard {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
  text-align: center;
}
#guard[hidden] { display: none; }

#sidebarBackdrop {
  display: none;
}

/* ---------- Мобильная версия ---------- */

@media (max-width: 860px) {
  #sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 25;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    width: min(300px, 84vw);
    box-shadow: 4px 0 24px rgba(0,0,0,0.4);
  }
  #sidebar.open { transform: translateX(0); }
  #sidebarBackdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 20;
    background: rgba(0,0,0,0.45);
  }
  #sidebarBackdrop[hidden] { display: none; }
  .iconbtn.menu { display: block; }
}
