/* Тёмная тема админки altgram-aibot. Без внешних зависимостей. */

:root {
  --bg: #0f141b;
  --panel: #121821;
  --panel-2: #0b1017;
  --border: #1f2833;
  --text: #e6edf3;
  --muted: #8b98a9;
  --accent: #38bdf8;
  --accent-dim: rgba(56, 189, 248, 0.14);
  --green: #34d399;
  --green-bg: rgba(52, 211, 153, 0.14);
  --red: #f87171;
  --red-bg: rgba(248, 113, 113, 0.14);
  --yellow: #fbbf24;
  --yellow-bg: rgba(251, 191, 36, 0.14);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre {
  font-family: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas,
               "Liberation Mono", monospace;
  font-size: 12.5px;
}

pre {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 8px 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.prewrap { white-space: pre-wrap; word-break: break-word; }

/* ----- каркас ----- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  flex: 0 0 220px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: block;
  padding: 18px 20px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.brand span { color: var(--accent); }
.brand:hover { text-decoration: none; }

.nav { display: flex; flex-direction: column; padding: 10px 8px; gap: 2px; }
.nav a {
  display: block;
  padding: 9px 12px;
  border-radius: 6px;
  color: var(--text);
}
.nav a:hover { background: var(--accent-dim); text-decoration: none; }
.nav a.active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
}

.sidebar-bottom {
  margin-top: auto;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}
.logout { color: var(--muted); }
.logout:hover { color: var(--red); text-decoration: none; }

.content {
  flex: 1 1 auto;
  min-width: 0;
  padding: 24px 28px 48px;
}

.page-title {
  margin: 0 0 18px;
  font-size: 22px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }

.muted { color: var(--muted); }
.dim { color: var(--muted); }
.mt { margin-top: 14px; }

/* ----- панели и карточки ----- */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 18px;
}
.panel-error { border-color: rgba(248, 113, 113, 0.5); }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.card-label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.card-value { font-size: 22px; font-weight: 700; }
.card-sub { color: var(--muted); font-size: 12.5px; margin-top: 4px; }

/* ----- флеши ----- */
.flash {
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
}
.flash.ok { background: var(--green-bg); border-color: rgba(52, 211, 153, 0.4); color: var(--green); }
.flash.err { background: var(--red-bg); border-color: rgba(248, 113, 113, 0.4); color: var(--red); }

/* ----- бейджи ----- */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
  vertical-align: middle;
  white-space: nowrap;
}
.st-done { background: var(--green-bg); color: var(--green); }
.st-failed { background: var(--red-bg); color: var(--red); }
.st-running, .st-planning { background: var(--yellow-bg); color: var(--yellow); }
.badge-tool { background: var(--accent-dim); color: var(--accent); margin-left: 6px; }
.badge-kind { background: var(--accent-dim); color: var(--accent); }

/* ----- таблицы ----- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 600;
}
tbody tr:hover { background: rgba(56, 189, 248, 0.05); }
tbody tr:last-child td { border-bottom: none; }
.nowrap { white-space: nowrap; }
.cell-wide { max-width: 420px; overflow-wrap: anywhere; }

/* ----- формы ----- */
input[type="text"], input[type="password"], input[type="number"],
select, textarea {
  width: 100%;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}
textarea { resize: vertical; }

label { display: block; margin-bottom: 10px; color: var(--text); }
label > input, label > select, label > textarea { margin-top: 5px; }

.check {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 8px;
  cursor: pointer;
}
.check input { width: auto; margin: 0; accent-color: var(--accent); }

.stack { display: flex; flex-direction: column; gap: 10px; }

.inline-form { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
.input-mini { width: 92px; padding: 5px 8px; }

.filter-form {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
}
.filter-form label { margin-bottom: 0; }
.filter-form select, .filter-form input { width: 180px; }

.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px 16px;
}
.grid-3 label { margin-bottom: 0; }

.settings-form .panel h2 { margin-bottom: 14px; }

.row-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

/* ----- кнопки ----- */
.btn {
  display: inline-block;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 14px;
  font: inherit;
  cursor: pointer;
  line-height: 1.4;
}
.btn:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #06202e;
  font-weight: 600;
}
.btn-primary:hover { background: #5ecbfa; color: #06202e; }
.btn-danger { border-color: rgba(248, 113, 113, 0.55); color: var(--red); }
.btn-danger:hover { border-color: var(--red); color: var(--red); background: var(--red-bg); }
.btn-ghost { background: transparent; }
.btn-mini { padding: 3px 9px; font-size: 12.5px; }

/* ----- пары ключ-значение ----- */
.kv {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 6px 22px;
}
.kv .k {
  color: var(--muted);
  display: inline-block;
  min-width: 120px;
  font-size: 12.5px;
}
.kv .v { font-weight: 500; overflow-wrap: anywhere; }

/* ----- факты ----- */
.fact-list { list-style: none; margin: 0; padding: 0; }
.fact-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 2px;
  border-bottom: 1px solid var(--border);
}
.fact-list li:last-child { border-bottom: none; }
.fact-text { flex: 1 1 auto; overflow-wrap: anywhere; }
.fact-meta { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* ----- сообщения диалога ----- */
.msg-list { display: flex; flex-direction: column; gap: 10px; }
.msg {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.msg-user { border-left: 3px solid var(--accent); }
.msg-assistant { border-left: 3px solid var(--green); }
.msg-tool { border-left: 3px solid var(--yellow); }
.msg-system { border-left: 3px solid var(--muted); }
.msg-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 5px;
}
.msg-role { font-weight: 700; font-size: 12px; text-transform: uppercase; color: var(--muted); }
.msg-ts { color: var(--muted); font-size: 12px; white-space: nowrap; }
.msg-body { white-space: pre-wrap; word-break: break-word; }

details.meta { margin-top: 7px; }
details.meta summary { cursor: pointer; color: var(--muted); font-size: 12.5px; }
details.meta[open] summary { color: var(--accent); }

/* ----- план и шаги задачи ----- */
.plan-goal { font-weight: 600; margin: 0 0 10px; }
.plan-list { margin: 0; padding-left: 22px; }
.plan-list li { margin-bottom: 8px; }

details.step {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
}
details.step summary {
  cursor: pointer;
  padding: 9px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  list-style: none;
}
details.step summary::-webkit-details-marker { display: none; }
details.step summary::before {
  content: "▸";
  color: var(--muted);
  transition: transform 0.15s ease;
}
details.step[open] summary::before { transform: rotate(90deg); color: var(--accent); }
.step-n {
  background: var(--accent-dim);
  color: var(--accent);
  border-radius: 999px;
  min-width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex: 0 0 auto;
}
.step-name { font-weight: 600; overflow-wrap: anywhere; }
.step-ms { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.step-body { padding: 0 12px 12px; border-top: 1px solid var(--border); }
.step-sub {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin: 10px 0 4px;
}

/* ----- страница входа ----- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 26px;
}
.login-brand { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.login-brand span { color: var(--accent); }
.login-card h1 { font-size: 15px; font-weight: 500; color: var(--muted); margin: 0 0 18px; }

/* ----- адаптив ----- */
@media (max-width: 820px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex: none;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
  }
  .brand { border-bottom: none; }
  .nav { flex-direction: row; flex-wrap: wrap; padding: 6px 10px; }
  .sidebar-bottom { margin-left: auto; border-top: none; }
  .content { padding: 18px 14px 40px; }
}
