/* RBS Ассистент — светлая тема, системный шрифт, акцент только на кнопках (docs/05-frontend.md) */

:root {
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --blue-soft: #eff4ff;
  --text: #1f2937;
  --muted: #6b7280;
  --faint: #9ca3af;
  --line: #e5e7eb;
  --bg: #ffffff;
  --bg-soft: #f7f8fa;
  --error: #b91c1c;
  --error-soft: #fef2f2;
  --radius: 10px;
  --topbar: 52px;
  --sidebar: 280px;
  --measure: 760px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .55; }
[hidden] { display: none !important; }

.button-primary {
  border: 0; border-radius: var(--radius); padding: 10px 18px;
  background: var(--blue); color: #fff; font-weight: 600;
}
.button-primary:hover:not(:disabled) { background: var(--blue-dark); }
.button-secondary {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 14px;
  background: var(--bg);
}
.button-secondary:hover { border-color: var(--blue); color: var(--blue); }
.button-link { border: 0; background: none; padding: 6px 4px; color: var(--muted); }
.button-link:hover { color: var(--blue); }
a.button-link { text-decoration: none; }
.icon-button { border: 0; background: none; font-size: 20px; line-height: 1; padding: 8px; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* --- вход ------------------------------------------------------------------ */

.page-login { background: var(--bg-soft); }
.login { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 14px; padding: 28px 24px; display: flex; flex-direction: column;
}
.login-logo {
  width: 48px; height: 48px; border-radius: 12px; background: var(--blue); color: #fff;
  font-size: 26px; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.login-card h1 { margin: 16px 0 2px; font-size: 22px; }
.login-hint { margin: 0 0 18px; color: var(--muted); }
.login-card label { margin: 12px 0 6px; font-size: 14px; color: var(--muted); }
.login-card input {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; font-size: 16px;
}
.login-card input:focus { border-color: var(--blue); outline: none; }
.login-card button { margin-top: 22px; }
.login-error {
  margin: 0 0 6px; padding: 10px 12px; border-radius: var(--radius);
  background: var(--error-soft); color: var(--error);
}

/* --- каркас чата ---------------------------------------------------------------- */

.page-chat { overflow: hidden; }

.topbar {
  height: var(--topbar); display: flex; align-items: center; gap: 12px;
  padding: 0 16px; padding-top: env(safe-area-inset-top); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; }
.user-name { margin-left: auto; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-toggle { display: none; margin-left: -8px; }

.connection {
  padding: 8px 16px; background: var(--error-soft); color: var(--error); text-align: center; font-size: 14px;
}

.layout { display: flex; height: calc(100% - var(--topbar)); }

.sidebar {
  width: var(--sidebar); flex: none; border-right: 1px solid var(--line);
  background: var(--bg-soft); display: flex; flex-direction: column; min-height: 0;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 8px 16px;
  font-weight: 600;
}
.conversation-list { overflow-y: auto; padding: 0 8px 12px; }
.conversation {
  display: flex; align-items: center; border-radius: 8px; margin: 2px 0;
}
.conversation.active { background: var(--blue-soft); }
.conversation-open {
  flex: 1; min-width: 0; border: 0; background: none; text-align: left; padding: 8px 10px;
  display: flex; gap: 8px; align-items: baseline;
}
.conversation-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation-time { flex: none; font-size: 13px; color: var(--faint); }
.conversation-delete { border: 0; background: none; color: var(--faint); padding: 6px 10px; visibility: hidden; }
.conversation:hover .conversation-delete, .conversation.active .conversation-delete { visibility: visible; }
.conversation-delete:hover { color: var(--error); }
.conversations-empty { color: var(--muted); padding: 8px 10px; font-size: 14px; }

.chat { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.messages { flex: 1; overflow-y: auto; padding: 24px 16px 8px; }
.messages > * { max-width: var(--measure); margin-left: auto; margin-right: auto; }

/* --- пустой чат ------------------------------------------------------------------ */

.empty { text-align: center; padding-top: 8vh; }
.empty h2 { margin: 0 0 6px; font-size: 22px; }
.empty p { margin: 0 0 20px; color: var(--muted); }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.suggestion {
  border: 1px solid var(--line); border-radius: 999px; background: var(--bg); padding: 8px 14px;
}
.suggestion:hover { border-color: var(--blue); color: var(--blue); }

/* --- сообщения -------------------------------------------------------------------- */

.message { margin-bottom: 20px; }
.message-user { display: flex; justify-content: flex-end; }
.message-user .bubble {
  background: var(--blue-soft); border-radius: 14px 14px 4px 14px; padding: 10px 14px;
  max-width: 85%; white-space: pre-wrap; overflow-wrap: anywhere;
}

.status { color: var(--muted); display: flex; align-items: center; gap: 8px; }
.status::before {
  content: ""; width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--blue); animation: spin .8s linear infinite;
}
.status.done::before { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.steps { margin: 4px 0 8px; font-size: 14px; color: var(--muted); }
.steps summary { cursor: pointer; }
.steps ol { margin: 4px 0 0; padding-left: 22px; }

.answer { overflow-wrap: anywhere; }
.answer.streaming { white-space: pre-wrap; }
.answer p { margin: 0 0 10px; }
.answer ul, .answer ol { margin: 0 0 10px; padding-left: 22px; }
.answer li { margin: 2px 0; }
.answer h3, .answer h4 { margin: 14px 0 6px; font-size: 17px; }
.answer code { background: var(--bg-soft); border-radius: 4px; padding: 1px 4px; font-size: 15px; }
.answer pre { background: var(--bg-soft); border-radius: 8px; padding: 10px 12px; overflow-x: auto; }
.answer pre code { background: none; padding: 0; }
.answer hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 0 12px; }
.answer table { border-collapse: collapse; min-width: 100%; font-size: 15px; }
.answer th, .answer td { border-bottom: 1px solid var(--line); padding: 6px 10px; text-align: left; white-space: nowrap; }
.answer th { font-weight: 600; background: var(--bg-soft); }
.answer td.num { text-align: right; font-variant-numeric: tabular-nums; }

.error {
  margin: 6px 0 0; padding: 10px 12px; border-radius: var(--radius);
  background: var(--error-soft); color: var(--error);
}

.meta { margin-top: 6px; font-size: 13px; color: var(--faint); }
.meta details { display: inline; }
.meta summary { display: inline; cursor: pointer; color: var(--muted); list-style: none; }
.meta summary::-webkit-details-marker { display: none; }
.meta summary:hover { color: var(--blue); }
.meta ul { margin: 6px 0 0; padding-left: 18px; }
.meta .onec-request { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; overflow-wrap: anywhere; }

/* --- поле ввода ------------------------------------------------------------------ */

.composer {
  display: flex; gap: 8px; align-items: flex-end; width: 100%; max-width: calc(var(--measure) + 32px);
  margin: 0 auto; padding: 8px 16px 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
.composer textarea {
  flex: 1; resize: none; min-height: 46px; max-height: 200px; padding: 11px 14px;
  border: 1px solid var(--line); border-radius: 12px; font-size: 16px; line-height: 1.4;
}
.composer textarea { overflow-y: hidden; }
.composer textarea.scroll { overflow-y: auto; }
.composer textarea::placeholder { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer textarea:focus { border-color: var(--blue); outline: none; }
.composer button { height: 46px; flex: none; }

/* --- телефон ------------------------------------------------------------------------ */

@media (max-width: 760px) {
  .menu-toggle { display: block; }
  .sidebar {
    position: fixed; z-index: 20; top: 0; bottom: 0; left: 0; width: min(85vw, var(--sidebar));
    transform: translateX(-100%); transition: transform .2s ease; padding-top: env(safe-area-inset-top);
  }
  .sidebar.open { transform: none; box-shadow: 0 0 24px rgba(0, 0, 0, .15); }
  .backdrop { position: fixed; inset: 0; z-index: 10; background: rgba(0, 0, 0, .25); }
  .conversation-delete { visibility: visible; }
  .messages { padding: 16px 12px 8px; }
  .composer { padding: 8px 12px 12px; padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .composer button { padding-left: 14px; padding-right: 14px; }
  .message-user .bubble { max-width: 92%; }
}

/* --- администрирование --------------------------------------------------------- */

.page-admin { background: var(--bg-soft); }
.back-link { text-decoration: none; }
.admin { max-width: 1100px; margin: 0 auto; padding: 16px 16px 48px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; overflow-y: hidden; }
.tab {
  border: 0; background: none; padding: 10px 14px; color: var(--muted); white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab.active { color: var(--blue); border-bottom-color: var(--blue); font-weight: 600; }

.card {
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin: 16px 0;
}
.card h3 { margin: 0 0 10px; font-size: 17px; }
.card h4 { margin: 16px 0 6px; font-size: 15px; }
.card p { margin: 6px 0; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 16px; }
.form-grid h3, .form-grid .wide, .form-grid .form-actions { grid-column: 1 / -1; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.form-grid input, .form-grid select, .editor input {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 9px 12px; font-size: 16px;
  color: var(--text); background: var(--bg);
}
.form-grid input:disabled { background: var(--bg-soft); color: var(--muted); }
.form-grid input:focus, .form-grid select:focus, .editor input:focus { border-color: var(--blue); outline: none; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.password-row { display: flex; gap: 8px; }
.password-row input { flex: 1; min-width: 0; }

.hint { color: var(--muted); font-size: 14px; }

table.grid { width: 100%; border-collapse: collapse; background: var(--bg); font-size: 15px; }
table.grid th, table.grid td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.grid th { background: var(--bg-soft); font-weight: 600; font-size: 14px; color: var(--muted); }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid td.question { min-width: 240px; }
table.grid td.nowrap { white-space: nowrap; }
table.grid td.actions { white-space: nowrap; text-align: right; }
table.grid td.actions button { margin-left: 6px; }
table.grid select { border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; background: var(--bg); }
table.grid tr.inactive td { color: var(--faint); }
table.grid tr.clickable { cursor: pointer; }
table.grid tr.clickable:hover td { background: var(--blue-soft); }
table.grid tr.row-error td { color: var(--error); }
table.grid.compact { font-size: 13px; }
.editor td { background: var(--bg-soft); }
.editor input { width: min(360px, 100%); margin-right: 8px; }
.editor button { margin-right: 6px; }

.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 12px 0; color: var(--muted); font-size: 14px; }

.result.result-error { border-color: #fecaca; background: var(--error-soft); }
.checklist { list-style: none; padding: 0; margin: 8px 0; }
.checklist li { padding: 2px 0; }
.ok { color: #15803d; }
.fail, .error { color: var(--error); }
.warning { color: #92400e; background: #fffbeb; border-radius: 8px; padding: 8px 10px; }
.details, .code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.quote { background: var(--bg-soft); border-radius: 8px; padding: 8px 10px; white-space: pre-wrap; }
.detail { position: relative; }
.detail .close { position: absolute; top: 12px; right: 12px; }
.detail ol { padding-left: 22px; }
.detail li { margin: 6px 0; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 30; max-width: calc(100% - 32px);
  background: var(--text); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 15px;
}
.toast.toast-error { background: var(--error); }

@media (max-width: 760px) {
  .admin { padding: 12px 12px 48px; }
  .topbar .brand { display: none; }
  table.grid td.actions { white-space: normal; }
  table.grid td.actions button { margin: 2px 0 2px 4px; }
}

/* --- подтверждение действий в чате ---------------------------------------------- */

.action-card {
  margin: 10px 0 4px; border: 1px solid #bfdbfe; background: #f8fbff; border-radius: 12px; padding: 12px 14px;
}
.action-title { font-weight: 600; margin-bottom: 4px; }
.action-card ul { margin: 4px 0 10px; padding-left: 20px; }
.action-card li { margin: 2px 0; }
.action-footer { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.action-result { flex: 1; }
.action-result p { margin: 0 0 6px; }
.action-result.done { color: #15803d; }
.action-result.failed { color: var(--error); }
.action-result.cancelled { color: var(--muted); }
.action-card.done { border-color: #bbf7d0; background: #f0fdf4; }
.action-card.failed { border-color: #fecaca; background: var(--error-soft); }
.action-card.cancelled { border-color: var(--line); background: var(--bg-soft); }
.answer a, .action-result a { color: var(--blue); overflow-wrap: anywhere; }

/* --- страница «Встречи» ------------------------------------------------------------ */

.meetings-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--bg); }
.segmented .period { border: 0; background: none; padding: 8px 14px; color: var(--muted); }
.segmented .period + .period { border-left: 1px solid var(--line); }
.segmented .period.active { background: var(--blue-soft); color: var(--blue); font-weight: 600; }
.meeting-day { margin: 20px 0 8px; font-size: 16px; color: var(--muted); }
.meeting {
  display: flex; gap: 14px; align-items: center; background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; margin: 8px 0;
}
.meeting-time { flex: none; width: 100px; font-weight: 600; font-variant-numeric: tabular-nums; }
.meeting-body { flex: 1; min-width: 0; }
.meeting-subject { font-weight: 600; }
.meeting-people { font-size: 14px; color: var(--muted); margin-top: 2px; }
.meeting-join { flex: none; text-decoration: none; }

/* --- админка: e-mail в Толке --------------------------------------------------------- */

.email-cell input {
  width: 100%; min-width: 180px; border: 1px solid transparent; border-radius: 8px; padding: 5px 8px;
  background: transparent; font-size: 15px;
}
.email-cell input:hover { border-color: var(--line); }
.email-cell input:focus { border-color: var(--blue); outline: none; background: var(--bg); }

@media (max-width: 760px) {
  .meeting { flex-wrap: wrap; }
  .meeting-time { width: auto; }
  .meeting-join { width: 100%; text-align: center; }
}

.calendar-account { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin: 12px 0; }
.calendar-account p { margin: 0 0 8px; }
.calendar-account .button-primary { display: inline-block; text-decoration: none; }
