:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #1d2330;
  --muted: #6b7280;
  --line: #dfe3ea;
  --accent: #2f6fed;
  --accent-ink: #ffffff;
  --danger: #b42318;
  --ok: #067647;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 16px/1.5 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 700; color: var(--ink); text-decoration: none; }
.nav { display: flex; align-items: center; gap: 16px; }
.nav a { color: var(--muted); text-decoration: none; }
.nav a:hover { color: var(--ink); }

.page { max-width: 680px; margin: 32px auto; padding: 0 16px; }

h1 { font-size: 26px; margin: 0 0 18px; }
h2 { font-size: 18px; margin: 0 0 12px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
  margin-bottom: 16px;
}

.form { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }

input[type="file"], textarea {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  color: var(--ink);
  background: #fff;
}

textarea { resize: vertical; }
input:focus, textarea:focus { outline: 2px solid rgba(47, 111, 237, 0.25); border-color: var(--accent); }

.file-field { gap: 6px; }
.file-picker {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 6px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.file-picker:hover { border-color: #b9c6e6; background: #f8faff; }
.file-picker:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.18);
}
.file-button {
  flex: none;
  padding: 7px 12px;
  border: 1px solid #d6e3ff;
  border-radius: 8px;
  background: #eef2fb;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}
.file-picker:hover .file-button { background: #e2e9fb; }
.file-selected {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
}
.file-input:focus { outline: none; }

.file-list-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.file-list-wrap[hidden] { display: none; }
.file-count { margin: 0; color: var(--muted); font-size: 13px; }
.file-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}
.file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  padding: 6px 8px 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faff;
}
.file-item-name {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-remove {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  min-height: 28px;
  padding: 0;
  border: 1px solid #d6e3ff;
  border-radius: 8px;
  background: #eef2fb;
  color: var(--accent);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.file-remove:hover { background: #e2e9fb; }
.file-remove:focus-visible {
  outline: 2px solid rgba(47, 111, 237, 0.35);
  outline-offset: 2px;
}

.form-message {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid #d6e3ff;
  border-radius: 8px;
  background: #eef2fb;
  color: var(--ink);
  font-size: 14px;
  overflow-wrap: anywhere;
}
.form-message[hidden] { display: none; }

button, .button {
  display: inline-block;
  padding: 10px 16px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 15px;
  cursor: pointer;
  text-decoration: none;
}

button.secondary, .button.secondary { background: #e8ebf1; color: var(--ink); }

.inline { display: inline; }
.link-button {
  background: none;
  color: var(--muted);
  padding: 0;
  font-size: 14px;
  text-decoration: underline;
}

.notice { border-radius: 8px; padding: 10px 12px; margin-bottom: 16px; font-size: 14px; }
.notice.error { background: #fdecea; color: var(--danger); }
.notice.ok { background: #e7f6ee; color: var(--ok); }

.muted { color: var(--muted); font-size: 14px; }

.jobs, .identities { list-style: none; margin: 0; padding: 0; }
.jobs li, .identities li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.jobs li:last-child, .identities li:last-child { border-bottom: 0; }

.task-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.meta-list, .ops-list { margin: 0; padding-left: 20px; }
.ops-list li { margin-bottom: 6px; }

.files { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.file-link { color: var(--accent); text-decoration: none; }
.file-link:hover { text-decoration: underline; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.plan-form {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 14px;
}

.plan-form:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td {
  text-align: left; vertical-align: top;
  padding: 8px; border-bottom: 1px solid var(--line);
}
.table th { color: var(--muted); font-weight: 600; }

select {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font: inherit;
}

code {
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
}

.examples details { margin-top: 10px; }
.examples summary { cursor: pointer; font-weight: 600; }
.example-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
button.example {
  padding: 6px 10px;
  font-size: 13px;
  background: #eef2fb;
  color: var(--ink);
}
button.example:hover { background: #e2e9fb; }

.badge {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: #eef2fb;
  color: var(--accent);
  border-radius: 999px;
  padding: 2px 8px;
}

.chat-meta { display: flex; flex-direction: column; gap: 8px; }
.chat-controls { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.chat-card { padding: 14px; }

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 4px 2px 12px;
}

.msg {
  max-width: 88%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: #f8f9fb;
}

.msg-user {
  align-self: flex-end;
  background: #eaf1ff;
  border-color: #d6e3ff;
}

.msg-bot { align-self: flex-start; background: #fff; }

.msg-role {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 4px;
}

.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-files { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.file-name { color: var(--muted); font-size: 14px; }

.msg-status {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
}

.msg-status[data-status="failed"] { color: var(--danger); }
.msg-status[data-status="done"] { color: var(--ok); }

.rating {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

button.rating-button {
  padding: 4px 10px;
  font-size: 13px;
  background: #eef2fb;
  color: var(--ink);
}

button.rating-button:hover { background: #e2e9fb; }
button.rating-button:disabled { opacity: 0.5; cursor: default; }

.msg-rating { margin-top: 8px; font-size: 13px; color: var(--muted); }
.chat-form { margin-top: 10px; }
button.secondary.danger { color: var(--danger); }

.guest-message { white-space: pre-line; }

/* Гостевые сообщения: те же пузыри, что в чате, но внутри карточки. */
.guest-msg { max-width: 100%; }
.msg .button, .msg .draft-cancel-button { margin-top: 10px; }
.msg .draft-cancel-button { margin-left: 8px; }

[hidden] { display: none !important; }

