/* ЛоМакс admin — minimal, semantic, professional */
:root {
  --bg: #f7f6f2;
  --panel: #ffffff;
  --text: #1f2328;
  --muted: #6b7280;
  --border: #e1e4e8;
  --accent: #2d5dab;
  --accent-light: #e8efff;
  --success: #15803d;
  --danger: #b91c1c;
  --warning: #b45309;
  --code-bg: #f4f4f4;
  --shadow: 0 1px 2px rgba(0,0,0,0.04), 0 0 0 1px rgba(0,0,0,0.05);
}

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

.topbar {
  background: #1e2433;
  color: white;
  border-bottom: 1px solid #11141d;
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px 24px;
}
.brand {
  color: white;
  text-decoration: none;
  font-weight: 600;
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
}
.brand-logo {
  display: block;
  width: 150px;
  height: 30px;
  object-fit: contain;
}
.brand-mark { color: #ffb74a; }
.brand-text small { font-weight: 400; opacity: 0.7; font-size: 12px; white-space: nowrap; }
.nav { display: flex; gap: 4px; }
.nav a {
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 14px;
  transition: background 0.1s, color 0.1s;
}
.nav a:hover, .nav a.active { color: white; background: rgba(255,255,255,0.08); }
.logout-form { margin: 0; }
.logout-form button {
  color: rgba(255,255,255,0.7);
  background: transparent;
  border: 0;
  padding: 6px 12px;
  border-radius: 6px;
  font: inherit;
  cursor: pointer;
}
.logout-form button:hover { color: white; background: rgba(255,255,255,0.08); }

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 32px 24px;
}

h1 { font-size: 24px; margin: 0 0 24px 0; font-weight: 600; }
h1 small { color: var(--muted); font-weight: 400; font-size: 16px; }
h2 { font-size: 18px; margin: 32px 0 16px 0; font-weight: 600; }
h3 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); margin: 0 0 12px 0; }

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

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

/* Metric grid */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.metric-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  box-shadow: var(--shadow);
}
.metric-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.metric-value { font-size: 32px; font-weight: 600; margin-top: 4px; }
.metric-sub { color: var(--muted); font-size: 11px; margin-top: 2px; }

/* Tables */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.data-table th, .data-table td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.data-table th {
  background: #fafbfc;
  font-weight: 600;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover { background: #fafbfc; }
.data-table.compact th, .data-table.compact td { padding: 6px 12px; font-size: 13px; }

/* Badges (state) */
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
  background: #e8eef9;
  color: #2d5dab;
}
.badge-greeting { background: #eef2f7; color: #555; }
.badge-qualify_object, .badge-qualify_basis, .badge-qualify_load, .badge-qualify_area,
.badge-qualify_region, .badge-qualify_photo, .badge-qualify_format, .badge-qualify_contact {
  background: #fff4d4; color: #92500c;
}
.badge-estimate { background: #d6f5d6; color: #15803d; }
.badge-propose { background: #d6f5d6; color: #15803d; }
.badge-handoff { background: #ffe0e0; color: #b91c1c; }

/* Status */
.status { font-size: 12px; padding: 2px 8px; border-radius: 4px; font-weight: 500; }
.status.active { background: #d6f5d6; color: var(--success); }
.status.closed { background: #eef2f7; color: var(--muted); }

/* Empty state */
.empty { color: var(--muted); padding: 24px; text-align: center; font-style: italic; }

/* Dialog workspace */
.dialogs-workspace {
  display: grid;
  grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.dialogs-sidebar {
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.dialogs-sidebar-head {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}
.dialogs-sidebar-head h1 {
  margin: 0 0 2px;
  font-size: 18px;
}
.dialog-tree {
  overflow-y: auto;
  padding: 8px;
}
.dialog-tree-item {
  display: block;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
}
.dialog-tree-item:hover {
  background: #fafbfc;
  border-color: var(--border);
}
.dialog-tree-item.active {
  background: var(--accent-light);
  border-color: #b8c9f0;
}
.dialog-tree-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.dialog-tree-title {
  min-width: 0;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dialog-tree-id {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: transparent;
}
.dialog-tree-meta {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}
.sidebar-pagination {
  margin: 0;
  padding: 10px 16px 14px;
  border-top: 1px solid var(--border);
}
.dialogs-detail {
  min-width: 0;
}
.dialog-detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.dialog-detail-head h1 {
  margin-bottom: 4px;
}
.dialog-id-full {
  display: block;
  color: var(--muted);
  background: transparent;
  word-break: break-all;
}
.notice-success { background:#e6f5e6; border-color:#86c186; }
.notice-warning { background:#fff8d6; border-color:#e0d486; }
.notice-danger { background:#fde6e6; border-color:#e8a0a0; }

/* Panels */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.panel dl { margin: 0; }
.panel dt { font-size: 12px; color: var(--muted); }
.panel dd { margin: 0 0 8px 0; font-weight: 500; }
.row-between { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }

/* Chat (dialog detail) */
.chat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.msg {
  margin-bottom: 14px;
  padding: 8px 12px;
  border-radius: 6px;
  border-left: 3px solid var(--border);
}
.msg-user { background: #fff4d4; border-left-color: #b45309; }
.msg-assistant { background: var(--accent-light); border-left-color: var(--accent); }
.msg-tool { background: #e8eef9; }
.msg-meta { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.msg-meta strong { color: var(--text); }
.msg-body { white-space: pre-wrap; line-height: 1.5; }
.rag-chunks { margin-top: 6px; font-size: 12px; }
.rag-chunks summary { cursor: pointer; user-select: none; }
.rag-chunks ul { margin: 6px 0 0 16px; padding: 0; }
.rag-chunks li { margin: 2px 0; }

/* Instructions editor */
.learning-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}
.learning-head h1 { margin-bottom: 8px; }
.learning-head p {
  max-width: 760px;
  margin: 0;
}
.learning-summary {
  min-width: 120px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
  text-align: right;
}
.learning-summary strong {
  display: block;
  font-size: 28px;
  line-height: 1;
}
.learning-summary span {
  color: var(--muted);
  font-size: 12px;
}
.learning-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 18px;
}
.learning-tabs a {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
}
.learning-tabs a:hover {
  border-color: #b8c9f0;
  background: #fafbfc;
}
.learning-tabs a.active {
  background: var(--accent-light);
  border-color: #b8c9f0;
  color: var(--accent);
}
.learning-tabs small {
  color: var(--muted);
  background: rgba(0,0,0,0.06);
  border-radius: 999px;
  padding: 1px 7px;
}
.learning-section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}
.learning-section-head h2 { margin: 0; }
.learning-section-head p { margin: 2px 0 0; }
.learning-workspace {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.learning-tree {
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.learning-tree-head {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}
.learning-tree-head h2 {
  margin: 0 0 2px;
  font-size: 18px;
}
.learning-tree-head p { margin: 0; }
.learning-tree-list {
  overflow-y: auto;
  padding: 8px;
}
.learning-tree-item {
  display: block;
  color: var(--text);
  text-decoration: none;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px;
}
.learning-tree-item:hover {
  background: #fafbfc;
  border-color: var(--border);
}
.learning-tree-item.active {
  background: var(--accent-light);
  border-color: #b8c9f0;
}
.learning-tree-item code {
  display: block;
  max-width: 100%;
  overflow-wrap: anywhere;
  background: transparent;
  color: var(--text);
  padding: 0;
}
.learning-tree-item span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}
.learning-tree-item small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
}
.learning-detail {
  min-width: 0;
}
.learning-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 12px;
}
.learning-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.learning-card-main code {
  display: inline-block;
  max-width: 100%;
  overflow-wrap: anywhere;
}
.learning-card-main p {
  margin: 10px 0 0;
  color: var(--muted);
}
.learning-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  color: var(--muted);
  font-size: 12px;
}
.learning-card-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: auto;
}
.learning-editor-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}
.learning-editor-head h1 { margin-bottom: 6px; }
.learning-editor-head code {
  display: inline-block;
  max-width: 100%;
  overflow-wrap: anywhere;
}
.learning-editor-meta {
  min-width: 190px;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}
.learning-editor-meta span { display: block; }
.learning-editor-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 16px;
  align-items: start;
}
.learning-editor-form {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}
.learning-help {
  position: sticky;
  top: 16px;
}
.learning-help ul {
  margin: 0;
  padding-left: 18px;
}
.learning-help li {
  margin: 8px 0;
  color: var(--muted);
}
.instr-form textarea {
  width: 100%; min-height: 280px; padding: 12px; font-family: SFMono-Regular, Menlo, monospace;
  font-size: 13px; line-height: 1.5; border: 1px solid var(--border); border-radius: 6px;
  resize: vertical; background: #fafbfc;
}
.instr-form input[type="text"] {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 14px; font-family: inherit;
}
.instr-form label { display: block; margin-bottom: 16px; }
.instr-form .form-label {
  font-size: 12px; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.5px; margin-bottom: 6px;
}
.instr-form .form-row {
  display: flex; align-items: center; gap: 18px; margin-top: 8px;
}
.btn-primary {
  background: var(--accent); color: white; border: none;
  padding: 9px 22px; border-radius: 6px; cursor: pointer; font-size: 14px;
  font-weight: 500;
}
.btn-primary:hover { background: #234a8c; }
.hint { margin-top: 18px; }
.hint summary { padding: 6px 0; }
.hint ul { margin: 8px 0 0 20px; padding: 0; }
.hint li { margin: 4px 0; font-size: 13px; }
.instr-pre {
  background: #f4f4f0; padding: 12px; border-radius: 6px;
  font-family: SFMono-Regular, Menlo, monospace; font-size: 12px; line-height: 1.5;
  white-space: pre-wrap; word-wrap: break-word; max-height: 400px; overflow-y: auto;
  margin: 8px 0 0 0;
}

/* --- Brand page --- */
.brand-avatar-preview {
  width: 120px; height: 120px; border-radius: 50%;
  overflow: hidden; margin: 12px auto 16px;
  border: 3px solid var(--border); position: relative;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent);
}
.brand-avatar-preview img { width: 100%; height: 100%; object-fit: cover; }
.brand-avatar-placeholder {
  font-size: 48px; font-weight: 600; color: white;
}
.brand-upload {
  display: flex; gap: 8px; align-items: center; margin-bottom: 8px;
}
.brand-upload-label { cursor: pointer; }
.brand-upload-label input[type="file"] {
  position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none;
}
.btn-secondary {
  display: inline-block; background: white; color: var(--text);
  border: 1px solid var(--border); padding: 8px 16px;
  border-radius: 6px; font-size: 14px;
}
.btn-secondary:hover { background: #fafbfc; }
.small { font-size: 12px; }
.brand-mock {
  border-radius: 12px; overflow: hidden;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1); margin-bottom: 12px;
}
.brand-mock-head {
  padding: 14px 16px; display: flex; align-items: center; gap: 12px; color: white;
}
.brand-mock-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  overflow: hidden; object-fit: cover;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.15);
}
.brand-mock-avatar-placeholder { font-size: 20px; font-weight: 600; }
.brand-mock-name { font-weight: 600; font-size: 14px; }
.brand-mock-bullet { opacity: 0.55; margin: 0 4px; }
.brand-form input[type="text"], .brand-form select {
  width: 100%; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: 6px; font-size: 14px; font-family: inherit;
  background: white;
}
.brand-form label { display: block; margin-bottom: 16px; }
.brand-form .form-label {
  font-size: 12px; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.5px; margin-bottom: 6px;
}
.brand-form .form-row {
  display: flex; align-items: center; gap: 16px; margin-top: 8px;
}
.brand-form-check {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 14px; cursor: pointer;
}
.brand-form-check input { margin: 0; }
.brand-textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 6px; font-size: 14px; font-family: inherit;
  line-height: 1.5; resize: vertical;
}
.brand-wallpaper-preview {
  height: 180px;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin: 12px 0 16px;
  background-color: #f4f3ef;
  background-size: 320px auto;
  background-position: top center;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.45);
}
.scheme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}
.scheme-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}
.scheme-card.selected { border-color: var(--accent); background: #f5f8ff; }
.scheme-card strong { display: block; margin: 6px 0 2px; }
.scheme-card small { display: block; color: var(--muted); line-height: 1.35; }
.scheme-swatch {
  display: block;
  height: 24px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--c1) 0 45%, var(--c2) 45% 70%, var(--c3) 70% 100%);
}

/* --- LLM model picker --- */
.llm-form { max-width: 720px; }
.llm-option {
  display: flex; gap: 12px; padding: 14px 16px;
  border: 1.5px solid var(--border); border-radius: 10px;
  margin-bottom: 10px; cursor: pointer; background: white;
  transition: border-color 0.12s, background 0.12s;
}
.llm-option:hover { border-color: #c5cad3; }
.llm-option.selected { border-color: var(--accent); background: #f5f8ff; }
.llm-option input[type="radio"] { margin-top: 4px; flex-shrink: 0; }
.llm-option-body { flex: 1; }
.llm-option-title {
  display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px;
}
.llm-option-title strong { font-size: 15px; }
.llm-option-id {
  background: #f4f4f0; padding: 1px 6px; border-radius: 4px;
  font-size: 11px; font-family: SFMono-Regular, Menlo, monospace; color: var(--muted);
}
.llm-option-desc { font-size: 13px; color: var(--text); margin-bottom: 4px; line-height: 1.4; }
.llm-option-price { font-size: 11px; color: var(--muted); }
.llm-custom-input {
  width: 100%; margin-top: 8px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 13px; font-family: SFMono-Regular, Menlo, monospace;
}
.llm-form .form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 10px;
}
.llm-form .form-grid label,
.llm-form .panel label {
  display: block;
  margin: 0;
}
.llm-form .label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}
.llm-form select {
  width: 100%;
  margin-top: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  font: inherit;
}
.llm-form .form-row { margin-top: 16px; display: flex; align-items: center; gap: 18px; }

/* Code */
code {
  background: var(--code-bg);
  padding: 1px 6px;
  border-radius: 3px;
  font-family: SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  margin: 24px 0;
}

/* Footer */
.footer {
  text-align: center;
  padding: 24px;
  color: var(--muted);
  font-size: 12px;
}

/* Login */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #1e2433;
}
.login-shell {
  width: 100%;
  max-width: 420px;
  padding: 24px;
}
.login-panel {
  background: var(--panel);
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.12);
  box-shadow: 0 18px 50px rgba(0,0,0,0.28);
  padding: 28px;
}
.login-brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  color: var(--muted);
  margin-bottom: 22px;
}
.login-logo {
  display: block;
  width: 240px;
  max-width: 100%;
  height: auto;
}
.login-brand strong { color: var(--text); font-size: 18px; }
.login-panel h1 { margin-bottom: 18px; }
.login-form label { display: block; margin-bottom: 14px; }
.login-form label span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}
.login-form input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font: inherit;
}
.login-form button { width: 100%; margin-top: 6px; }
.login-error {
  background: #fee2e2;
  color: var(--danger);
  border: 1px solid #fecaca;
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 14px;
}

@media (max-width: 768px) {
  .grid-2 { grid-template-columns: 1fr; }
  .dialogs-workspace { grid-template-columns: 1fr; }
  .dialogs-sidebar {
    position: static;
    max-height: 460px;
  }
  .dialog-detail-head { flex-direction: column; }
  .learning-head,
  .learning-editor-head {
    flex-direction: column;
  }
  .learning-summary,
  .learning-editor-meta {
    width: 100%;
    text-align: left;
  }
  .learning-editor-layout { grid-template-columns: 1fr; }
  .learning-workspace { grid-template-columns: 1fr; }
  .learning-tree {
    position: static;
    max-height: 420px;
  }
  .learning-help { position: static; }
  .llm-form .form-grid { grid-template-columns: 1fr; }
  .topbar-inner { flex-direction: column; gap: 8px; }
}
