/* ── Переменные ── */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e0e0e0;
  --accent: #c0392b;
  --accent-dark: #96281b;
  --dark: #2c2c3e;
  --text: #1a1a2e;
  --text-muted: #666;
  --success: #27ae60;
  --info: #2980b9;
  --warn: #e67e22;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Шапка ── */
.app-header {
  background: var(--dark);
  color: white;
  padding: 10px 20px;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
}
.header-inner {
  display: flex;
  align-items: center;
  gap: 16px;
}
.header-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}
.header-email {
  font-size: 12px;
  color: #aaa;
}
.btn-logout {
  font-size: 12px;
  color: #aaa;
  text-decoration: none;
  border: 1px solid #555;
  border-radius: 5px;
  padding: 3px 10px;
  transition: color .15s, border-color .15s;
}
.btn-logout:hover {
  color: #fff;
  border-color: #aaa;
}
.header-logo {
  height: 36px;
  object-fit: contain;
  filter: brightness(0) invert(1);
}
.header-title {
  display: flex;
  flex-direction: column;
}
.title-main {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .3px;
}
.title-sub {
  font-size: 11px;
  color: #aaa;
}

/* ── Лэйаут ── */
.app-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  gap: 0;
}

/* ── Левая панель ── */
.left-panel {
  width: 280px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel-section {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 12px;
  border: 1px solid var(--border);
}

.section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* ── Зоны загрузки ── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  margin-bottom: 8px;
  background: var(--surface);
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--accent);
  background: #fef9f9;
}
.upload-zone.has-file {
  border-color: var(--success);
  background: #f0fdf4;
}
.upload-icon { font-size: 24px; margin-bottom: 6px; color: var(--text-muted); line-height: 1; }
.upload-icon svg { display: block; margin: 0 auto; stroke: var(--text-muted); }
.upload-label { font-size: 12px; font-weight: 600; }
.upload-hint { font-size: 10px; color: var(--text-muted); margin-top: 2px; }
.upload-filename {
  font-size: 10px;
  color: var(--success);
  font-weight: 600;
  margin-top: 4px;
  word-break: break-all;
}

/* ── Сетка данных ── */
.data-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.data-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 11px;
  padding: 3px 0;
  border-bottom: 1px solid var(--border);
}
.data-row:last-child { border-bottom: none; }
.data-label { color: var(--text-muted); }
.data-value { font-weight: 600; text-align: right; }
.data-value.missing { color: #e67e22; }
.data-value.ok { color: var(--success); }

/* ── Прогресс ── */
.progress-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.step { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.step-icon { font-size: 14px; width: 18px; text-align: center; }
.step.done .step-icon { color: var(--success); }
.step.active .step-icon { color: var(--warn); }
.step.done { color: var(--text-muted); }

/* ── Кнопки ── */
.btn {
  border: none;
  border-radius: var(--radius);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s, transform .1s;
  white-space: nowrap;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); }
.btn-secondary { background: var(--info); color: white; }
.btn-secondary:hover:not(:disabled) { background: #1a6fa8; }
.btn-success { background: var(--success); color: white; }
.btn-success:hover:not(:disabled) { background: #1e8449; }
.btn-outline {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-outline:hover:not(:disabled) { background: var(--bg); }
.btn-full { width: 100%; }
.btn-send { padding: 10px 18px; border-radius: 0 var(--radius) var(--radius) 0; }

/* ── Чат ── */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  display: flex;
  max-width: 88%;
}
.message.user { align-self: flex-end; }
.message.assistant { align-self: flex-start; }

.message-content {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.message.user .message-content {
  background: var(--dark);
  color: white;
  border-bottom-right-radius: 3px;
}
.message.assistant .message-content {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 3px;
  box-shadow: var(--shadow);
}

/* ── Question-карточки — единый стиль ── */
.message.question-bubble .message-content {
  background: #f8f9ff;
  border: 1px solid #dde3f0;
  box-shadow: none;
}
.sw-eyebrow { display: none; } /* убран — лишний визуальный шум */

/* ── Select-виджет в чате ── */
.select-widget {
  white-space: normal;
  width: 100%;
  box-sizing: border-box;
}
.sw-question {
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text);
  font-size: 13.5px;
}
.sw-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sw-select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ccd0e0;
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  appearance: auto;
}
.sw-select:focus { outline: none; border-color: var(--accent); }
.sw-facade-areas {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}
.sw-facade-areas label {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.sw-num {
  width: 80px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}
.sw-confirm {
  align-self: flex-start;
  padding: 7px 22px;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius);
  cursor: pointer;
  border: none;
  background: var(--accent);
  color: #fff;
  transition: background .15s;
}
.sw-confirm:hover:not(:disabled) { background: var(--accent-dark); }
.sw-confirm:disabled { opacity: 0.45; cursor: default; }

/* Markdown-like inside message */
.message-content strong, .message-content b { font-weight: 700; }
.message-content em, .message-content i { font-style: italic; }
.message-content a { color: var(--info); text-decoration: underline; }

/* ── Кнопки действий ── */
.action-buttons {
  display: flex;
  gap: 8px;
  padding: 8px 16px 0;
  flex-wrap: wrap;
}

.chat-links {
  padding: 4px 16px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.chat-links a {
  font-size: 12px;
  color: var(--info);
  text-decoration: none;
  font-weight: 600;
}
.chat-links a:hover { text-decoration: underline; }

/* ── Поле ввода ── */
.chat-input-row {
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 8px;
  gap: 0;
}
.chat-input {
  flex: 1;
  border: 1px solid var(--border);
  border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
  padding: 8px 12px;
  font-size: 13.5px;
  font-family: inherit;
  resize: none;
  outline: none;
  color: var(--text);
  background: var(--bg);
  line-height: 1.4;
}
.chat-input:focus { border-color: var(--accent); background: white; }

/* ── Спиннер ── */
.spinner-overlay {
  position: fixed; inset: 0;
  background: rgba(255,255,255,.75);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  gap: 16px;
}
.spinner {
  width: 44px; height: 44px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.spinner-text { font-size: 14px; color: var(--text-muted); font-weight: 600; }

/* ── Уведомление об ошибке ── */
.error-toast {
  position: fixed;
  bottom: 20px; right: 20px;
  background: #c0392b;
  color: white;
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 2000;
  max-width: 360px;
  animation: slideIn .3s ease;
}
@keyframes slideIn { from { transform: translateY(20px); opacity: 0; } }

/* ── Скроллбары ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #bbb; }

/* ── Индикатор «думает» ── */
.thinking-bubble .message-content {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 10px 16px;
  min-width: 56px;
}
.thinking-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #bbb;
  animation: thinking-bounce 1.2s ease-in-out infinite;
}
.thinking-dot:nth-child(2) { animation-delay: .2s; }
.thinking-dot:nth-child(3) { animation-delay: .4s; }
@keyframes thinking-bounce {
  0%, 80%, 100% { transform: translateY(0); background: #ccc; }
  40%            { transform: translateY(-6px); background: #888; }
}
.thinking-status {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
  margin-left: 4px;
  white-space: nowrap;
}


/* ── Список файлов ── */
.file-list {
  list-style: none;
  margin: 0 0 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.file-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 4px 6px 4px 8px;
  font-size: 11px;
}
.file-item-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.file-remove {
  flex-shrink: 0;
  border: none;
  background: none;
  color: #aaa;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
  border-radius: 3px;
  transition: color .15s, background .15s;
}
.file-remove:hover { color: var(--accent); background: #fef0f0; }

/* ── Состояние извлечения ── */
.extracting-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--warn);
  padding: 6px 0;
}
.extracting-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--warn);
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

/* Комментарии */
.project-notes {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 13px;
  resize: vertical;
  font-family: inherit;
  color: #333;
  background: #fafafa;
}
.project-notes:focus {
  outline: none;
  border-color: #c0392b;
  background: #fff;
}

.btn-audit {
  background: #2c3e50;
  color: #fff;
  border: none;
}
.btn-audit:hover:not(:disabled) {
  background: #1a252f;
}

/* ── Превью сметы ───────────────────────────────────────────────── */
.estimate-preview {
  font-size: 12px;
  font-family: Arial, sans-serif;
  color: #1a1a2e;
  max-width: 100%;
}
.ep-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 10px;
  color: #2c2c3e;
}
.ep-section-header {
  background: #2c2c3e;
  color: #fff;
  padding: 6px 8px;
  font-weight: 700;
  font-size: 11px;
  margin-top: 10px;
  border-radius: 3px 3px 0 0;
}
.ep-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 0;
  table-layout: fixed;
}
.ep-table thead tr {
  background: #e8e8e8;
}
.ep-table th {
  padding: 4px 5px;
  font-size: 10px;
  font-weight: 600;
  color: #555;
  border: 1px solid #ccc;
  text-align: center;
}
.ep-table th:nth-child(2) { text-align: left; }
.ep-table tbody tr:nth-child(even) { background: #f8f8f8; }
.ep-table tbody tr:hover { background: #eef4ff; }
.ep-table td {
  padding: 3px 5px;
  border: 1px solid #ddd;
  vertical-align: middle;
  word-break: break-word;
}
.ep-n   { color: #666; font-size: 10px; text-align: center; }
.ep-desc { font-size: 11px; }
.ep-c   { text-align: center; font-size: 11px; }
.ep-r   { text-align: right;  font-size: 11px; white-space: nowrap; }
.ep-total { font-weight: 600; }
.ep-stage {
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  color: #1e40af;
  background: #ebf4ff;
}
.ep-section-total {
  background: #f0f0f0;
  text-align: right;
  padding: 4px 8px;
  font-size: 11px;
  border: 1px solid #ccc;
  border-top: none;
  margin-bottom: 4px;
}
.ep-grand-total {
  background: #2c2c3e;
  color: #fff;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  margin-top: 12px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.ep-per-m2 {
  font-size: 11px;
  font-weight: 400;
  opacity: 0.75;
}
.ep-actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ─── Card Select ─────────────────────────────────────────────── */
.cs-grid {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}
.cs-card {
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 10px 8px 8px;
  cursor: pointer;
  text-align: center;
  transition: border-color .15s, background .15s, transform .1s;
  background: var(--bg-main);
}
.cs-card:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--bg-main));
}
.cs-card.selected {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--bg-main));
}
.cs-card.disabled {
  opacity: .6;
  pointer-events: none;
}
.cs-icon {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 52px;
  margin-bottom: 6px;
}
.cs-icon svg {
  width: 70px;
  height: 52px;
  color: var(--text);
}
.cs-label {
  font-size: .82em;
  font-weight: 600;
  line-height: 1.3;
}
.cs-desc {
  font-size: .72em;
  opacity: .65;
  margin-top: 3px;
  line-height: 1.3;
}
.cs-photo {
  width: 100%;
  height: 80px;
  overflow: hidden;
  border-radius: 6px;
  margin-bottom: 6px;
}
.cs-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.ws-checklist { background: color-mix(in srgb, var(--accent) 5%, var(--bg-main)); }
.ws-item { display:flex; align-items:center; gap:8px; padding:5px 4px; cursor:pointer; font-size:.85em; border-radius:5px; border-bottom: 1px solid color-mix(in srgb, var(--border) 40%, transparent); }
.ws-item:last-child { border-bottom: none; }
.ws-item:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.ws-check { width:15px; height:15px; accent-color:var(--accent); cursor:pointer; flex-shrink:0; }
.ws-code { font-family: monospace; opacity:.5; font-size:.85em; min-width:40px; flex-shrink:0; }
.ws-label { flex:1; }
.ws-price { font-variant-numeric: tabular-nums; opacity:.7; white-space:nowrap; flex-shrink:0; }

/* ── Адаптивность ─────────────────────────────────────────────────── */

/* Планшет — ≤1024px: сужаем левую панель */
@media (max-width: 1024px) {
  .left-panel { width: 220px; padding: 8px; gap: 8px; }
  .panel-section { padding: 8px; }
  .cs-grid { gap: 6px; }
  .cs-icon { height: 42px; }
  .cs-icon svg { width: 56px; height: 42px; }
  .cs-photo { height: 64px; }
  .title-main { font-size: 15px; }
  .header-email { display: none; }
}

/* Малый планшет — ≤768px: левая панель уходит наверх */
@media (max-width: 768px) {
  body { height: auto; overflow: auto; }

  .app-layout {
    flex-direction: column;
    overflow: visible;
    height: auto;
  }

  .left-panel {
    width: 100%;
    max-height: 280px;
    overflow-y: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px;
  }

  .panel-section {
    flex: 1 1 calc(50% - 8px);
    min-width: 140px;
  }

  /* Секции прогресса и данных — скрываем на маленьком экране */
  #extractedSection { display: none !important; }
  .panel-section:has(#progressSteps) { flex: 0 0 100%; }

  .chat-panel {
    height: calc(100vh - 280px - 56px);
    min-height: 400px;
  }

  .message { max-width: 95%; }

  .chat-messages { padding: 10px; gap: 8px; }

  .cs-grid { gap: 6px !important; }
  .cs-card { padding: 8px 6px 6px; }
  .cs-photo { height: 56px; }
  .cs-icon { height: 36px; }
  .cs-icon svg { width: 46px; height: 36px; }

  .ep-table { font-size: 10px; }
  .ep-desc { font-size: 10px; }

  .action-buttons { padding: 6px 10px 0; gap: 6px; }
  .action-buttons .btn { font-size: 12px; padding: 6px 10px; }

  .chat-input-row { padding: 6px; }
  .chat-input { font-size: 13px; }

  .header-inner { gap: 8px; }
  .title-sub { display: none; }
  .header-logo { height: 28px; }
}

/* Мобильный — ≤480px: одна колонка, всё стекует */
@media (max-width: 480px) {
  .left-panel {
    max-height: 200px;
    padding: 6px;
  }

  .panel-section { flex: 0 0 100%; }

  .chat-panel { height: calc(100vh - 200px - 48px); }

  .cs-grid { grid-template-columns: repeat(2, 1fr) !important; }

  /* Карточки кровли — 2 колонки вместо 3 */
  .cs-grid[style*="repeat(3"] { grid-template-columns: repeat(2, 1fr) !important; }

  .message { max-width: 100%; }

  .ep-r, .ep-c { white-space: normal; }

  .app-header { padding: 6px 12px; }
  .header-logo { height: 24px; }
  .title-main { font-size: 13px; }

  .btn-send { padding: 8px 12px; }

  .ws-price { display: none; }
  .ws-code { display: none; }
}
