/* =============================================
   Face&Body Business GPT
   Дизайн-язык: "Clinical Precision" (как в TopDoc.AI)
   ============================================= */

:root {
  /* Тёплый серо-оливковый (акцент) */
  --teal-50: #f4f2ee;
  --teal-100: #e6e2d9;
  --teal-300: #a89c85;
  --teal-400: #7d7460;
  --teal-500: #665d4c;
  --teal-600: #544e40;
  --teal-700: #423d32;
  --teal-950: #211e19;

  /* Янтарь — только для главных действий (CTA) */
  --accent: #D4A24E;
  --accent-hover: #E0A458;
  --accent-ink: #241c10;

  --red-50: #fef5f5;
  --red-600: #c52828;
  --red-950: #2a0f0f;

  /* Светлая тема */
  --surface: #ffffff;
  --surface-secondary: #faf9f6;
  --surface-tertiary: #f1efea;
  --ink-primary: #26231f;
  --ink-secondary: #57524a;
  --ink-tertiary: #8a8477;
  --line: #e2ded5;
  --line-light: #ece9e2;
  --icon-bg: var(--teal-50);
  --icon-fg: var(--teal-600);

  --font-display: 'Unbounded', 'SF Pro Display', system-ui, sans-serif;
  --font-body: 'IBM Plex Sans', 'SF Pro Text', system-ui, sans-serif;

  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;

  --shadow-sm: 0 2px 8px rgba(48,43,34,.06), 0 1px 2px rgba(48,43,34,.04);
  --shadow-lg: 0 20px 48px rgba(48,43,34,.1), 0 4px 8px rgba(48,43,34,.04);
}

.dark {
  /* Лестница яркости: фон → поверхности → бордюры */
  --surface: #2A2622;
  --surface-secondary: #1E1B18;
  --surface-tertiary: #2A2622;
  --ink-primary: #edeae4;
  --ink-secondary: #b8b2a6;
  --ink-tertiary: #857f72;
  --line: #3A352F;
  --line-light: #332F29;
  --accent: #E0A458;
  --accent-hover: #E8B36C;
  --icon-bg: var(--teal-950);
  --icon-fg: var(--teal-300);
  --red-50: #2a0f0f;
  --red-600: #ef6a6a;
  --shadow-sm: 0 2px 8px rgba(0,0,0,.3);
  --shadow-lg: 0 20px 48px rgba(0,0,0,.5);
}

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

html, body { height: 100%; }

body {
  background: var(--surface-secondary);
  color: var(--ink-primary);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background-color .3s ease, color .3s ease;
}

/* Зернистость фона */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.035;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 150px 150px;
}

.hidden { display: none !important; }
.hide-mobile { display: inline; }
@media (max-width: 480px) { .hide-mobile { display: none; } }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }

button { font-family: var(--font-body); }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes scale-in { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }
@keyframes fade-in-up { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes bounce-dot { 0%, 80%, 100% { transform: translateY(0); } 40% { transform: translateY(-4px); } }

/* ---------- Общие элементы ---------- */

.brand-icon {
  width: 56px; height: 56px;
  border-radius: 16px;
  background: var(--icon-bg);
  color: var(--teal-500);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto;
}
.brand-icon svg { width: 28px; height: 28px; }
.brand-icon.muted { color: var(--ink-tertiary); background: var(--surface-tertiary); }

.btn-primary {
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--accent-ink);
  font-size: 14px;
  font-weight: 600;
  padding: 12px 16px;
  cursor: pointer;
  transition: background .2s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }

.btn-danger {
  background: var(--red-600);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 12px 16px;
  cursor: pointer;
  transition: opacity .2s;
}
.btn-danger:hover { opacity: .88; }
.btn-danger:disabled { opacity: .4; cursor: not-allowed; }

.modal-text {
  font-size: 13px;
  color: var(--ink-secondary);
  line-height: 1.55;
}

.btn-ghost {
  background: none;
  border: none;
  color: var(--ink-tertiary);
  font-size: 13px;
  font-weight: 500;
  padding: 6px;
  cursor: pointer;
}
.btn-ghost:hover { color: var(--ink-primary); }

.form-error { color: var(--red-600); font-size: 13px; }

input[type="text"], input[type="password"] {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink-primary);
  padding: 11px 14px;
  font-size: 16px;
  font-family: var(--font-body);
  outline: none;
  transition: border-color .2s;
  width: 100%;
}
input[type="text"]:focus, input[type="password"]:focus { border-color: var(--accent); }
input::placeholder { color: var(--ink-tertiary); }

/* ---------- Вход ---------- */

.login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: #161412;
  z-index: 100;
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 420px;
  display: flex; flex-direction: column; align-items: center; gap: 22px;
  text-align: center;
  animation: scale-in .3s cubic-bezier(.22,1,.36,1) both;
}
.login-brand { display: flex; align-items: center; gap: 16px; }
.login-logo {
  width: 62px; height: 62px;
  border-radius: 16px;
  display: block;
}
.login-title {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #ffffff;
}
.login-screen input[type="password"] {
  width: auto; min-width: 250px;
  background: #3d3a37;
  border: 1px solid transparent;
  color: #ffffff;
  text-align: center;
  font-size: 15px;
  font-weight: 500;
  padding: 12px 22px;
  border-radius: 10px;
}
.login-screen input[type="password"]:focus { border-color: var(--accent); }
.login-screen input[type="password"]::placeholder { color: #d9d5cf; }
.login-btn {
  background: var(--accent);
  border: none;
  border-radius: 10px;
  color: var(--accent-ink);
  font-size: 14px;
  font-weight: 600;
  padding: 11px 34px;
  cursor: pointer;
  transition: background .2s, opacity .2s;
}
.login-btn:hover { background: var(--accent-hover); }
.login-btn:disabled { opacity: .4; cursor: not-allowed; }
.login-screen .form-error { color: #e88b8b; }
.login-watermark {
  position: absolute;
  bottom: 42px; left: 50%;
  transform: translateX(-50%);
  opacity: .92;
  transition: opacity .2s;
}
.login-watermark:hover { opacity: 1; }
.login-watermark img { height: 34px; display: block; }

/* ---------- Каркас ---------- */

.app {
  height: 100dvh;
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
}

.header {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line-light);
  background: color-mix(in srgb, var(--surface-secondary) 95%, transparent);
  backdrop-filter: blur(8px);
}
.header-brand { display: flex; align-items: center; gap: 9px; }
.header-logo {
  width: 28px; height: 28px;
  border-radius: 8px;
  display: block;
  object-fit: cover;
}
.header-title {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.header-actions { display: flex; align-items: center; gap: 4px; }
.header-btn {
  display: flex; align-items: center; gap: 6px;
  background: none;
  border: none;
  border-radius: var(--radius-xs);
  color: var(--ink-tertiary);
  font-size: 12px;
  font-weight: 500;
  padding: 8px 10px;
  cursor: pointer;
  transition: background .2s, color .2s;
}
.header-btn:hover { background: var(--surface-tertiary); color: var(--ink-primary); }
.header-btn.danger:hover { background: var(--red-50); color: var(--red-600); }

/* ---------- Меню настроек ---------- */

.settings-overlay { position: fixed; inset: 0; z-index: 25; }
.settings-popup {
  position: fixed;
  top: 52px; right: 12px;
  z-index: 30;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  min-width: 180px;
  animation: scale-in .25s cubic-bezier(.22,1,.36,1) both;
}
.settings-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  background: none;
  border: none;
  border-radius: var(--radius-xs);
  color: var(--ink-secondary);
  font-size: 13px;
  font-weight: 500;
  padding: 10px 14px;
  cursor: pointer;
  transition: background .2s, color .2s;
}
.settings-item:hover { background: var(--surface-tertiary); }
.settings-item.danger:hover { background: var(--red-50); color: var(--red-600); }

/* ---------- Вкладки-каркас ---------- */

.view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- Чат ---------- */

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

.welcome {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
}
.welcome-inner {
  text-align: center;
  max-width: 420px;
  padding: 24px 12px;
  animation: fade-in-up .4s cubic-bezier(.22,1,.36,1) both;
}
.welcome-title {
  font-size: 15px;
  font-weight: 600;
  margin: 16px 0 8px;
  font-family: var(--font-display);
  letter-spacing: -0.02em;
}
.welcome-text {
  font-size: 13px;
  color: var(--ink-secondary);
  line-height: 1.65;
}

.msg {
  max-width: 78%;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  line-height: 1.55;
  word-break: break-word;
  animation: fade-in-up .3s cubic-bezier(.22,1,.36,1) both;
}
.msg.user {
  margin-left: auto;
  background: var(--teal-600);
  color: #fff;
  border-bottom-right-radius: var(--radius-xs);
  white-space: pre-wrap;
}
.dark .msg.user {
  background: #e9e5dd;
  color: #26231f;
}
.msg.ai {
  margin-right: auto;
  background: var(--surface-tertiary);
  color: var(--ink-primary);
  border-bottom-left-radius: var(--radius-xs);
}
.msg.ai.error {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
  color: var(--accent);
  font-weight: 500;
}
.msg.ai.error::before {
  content: '⚠';
  flex: none;
  font-size: 15px;
  line-height: 1.45;
}
:root:not(.dark) .msg.ai.error { color: #8a6420; }

/* Форматирование ответов AI */
.msg.ai p { margin: 0.4em 0; }
.msg.ai p:first-child { margin-top: 0; }
.msg.ai p:last-child { margin-bottom: 0; }
.msg.ai ul, .msg.ai ol { padding-left: 1.4em; margin: 0.5em 0; }
.msg.ai li { margin-bottom: 0.15em; }
.msg.ai h1, .msg.ai h2, .msg.ai h3 { font-size: 1.05em; margin: 0.6em 0 0.25em; font-weight: 600; }

.msg.typing { display: flex; align-items: center; padding: 14px 16px; }
.msg.typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--ink-tertiary);
  margin-right: 4px;
  animation: bounce-dot 1.2s infinite;
}
.msg.typing span:nth-child(2) { animation-delay: .15s; }
.msg.typing span:nth-child(3) { animation-delay: .3s; margin-right: 0; }

.chat-input-row {
  flex: none;
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line-light);
  background: var(--surface);
}
.chat-input-row input { flex: 1; }
#send-btn {
  flex: none;
  width: 42px; height: 42px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .2s, opacity .2s;
}
#send-btn:hover { background: var(--accent-hover); }
#send-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- База ---------- */

.base-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px 12px;
  display: flex;
  flex-direction: column;
}

.base-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}
.base-subtitle {
  font-size: 12px;
  color: var(--ink-tertiary);
  margin-bottom: 16px;
}

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

.report-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--line-light);
  border-radius: var(--radius-sm);
  box-shadow: 0 1px 2px rgba(48,43,34,.04);
  padding: 14px 16px;
  cursor: pointer;
  transition: all .2s cubic-bezier(.22,1,.36,1);
  animation: fade-in-up .3s cubic-bezier(.22,1,.36,1) both;
}
.report-card:hover {
  border-color: var(--teal-300);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}
.dark .report-card:hover { border-color: var(--teal-700); }

.report-icon {
  flex: none;
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  background: var(--icon-bg);
  color: var(--icon-fg);
  display: flex; align-items: center; justify-content: center;
}

.report-info { flex: 1; min-width: 0; }
.report-name {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.report-meta {
  font-size: 11px;
  color: var(--ink-tertiary);
  margin-top: 2px;
}

.report-delete {
  flex: none;
  background: none;
  border: none;
  color: var(--ink-tertiary);
  padding: 8px;
  cursor: pointer;
  border-radius: var(--radius-xs);
  transition: background .2s, color .2s;
}
.report-delete:hover { background: var(--red-50); color: var(--red-600); }

.reports-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--ink-tertiary);
  font-size: 13px;
  line-height: 1.6;
  padding: 32px 0;
}

.base-footer {
  flex: none;
  padding: 10px 16px 14px;
  border-top: 1px solid var(--line-light);
  background: var(--surface);
}
.add-report-btn {
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 14px;
  padding: 13px;
}
.add-report-btn .plus { font-size: 19px; font-weight: 700; line-height: 1; }

/* ---------- Таббар ---------- */

.tabbar {
  flex: none;
  display: flex;
  gap: 4px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line-light);
  background: color-mix(in srgb, var(--surface) 95%, transparent);
  backdrop-filter: blur(8px);
}
.tab {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: none;
  border: none;
  border-radius: var(--radius-md);
  color: var(--ink-secondary);
  font-size: 13px;
  font-weight: 600;
  padding: 11px;
  cursor: pointer;
  transition: all .2s;
}
.tab:hover { background: var(--surface-tertiary); }
.tab.active {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: var(--shadow-sm);
  transform: scale(1.02);
}
.tab.active:hover { background: var(--accent); }

/* ---------- Модалка ---------- */

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 300;
  padding: 20px;
  animation: fade-in .3s ease both;
}
.modal {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 24px;
  display: flex; flex-direction: column; gap: 14px;
  max-height: 90dvh;
  overflow-y: auto;
  animation: scale-in .25s cubic-bezier(.22,1,.36,1) both;
}
.modal-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.35;
}

.type-block {
  background: var(--surface-tertiary);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 6px;
}
.type-label { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.type-option {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px;
  cursor: pointer;
  color: var(--ink-secondary);
  padding: 4px 0;
}
.type-option input { accent-color: var(--accent); width: 15px; height: 15px; flex: none; }
.type-option b { color: var(--teal-500); margin-right: 4px; }
.type-option:has(input:checked) { color: var(--ink-primary); font-weight: 500; }

.file-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: var(--surface-secondary);
  border: 1.5px dashed var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink-secondary);
  padding: 18px 14px;
  text-align: center;
  font-size: 13.5px;
  cursor: pointer;
  line-height: 1.5;
  transition: border-color .2s;
}
.file-drop:hover { border-color: var(--teal-400); }
.file-drop small { color: var(--ink-tertiary); font-size: 11.5px; }
.file-drop.has-file {
  border-color: var(--teal-500);
  border-style: solid;
  color: var(--ink-primary);
  font-weight: 500;
}

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

/* Мобильные */
@media (max-width: 480px) {
  .messages { padding: 12px; gap: 10px; }
  .msg { max-width: 86%; }
  .header { padding: 8px 12px; }
  .chat-input-row { padding: 10px 12px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .base-scroll { padding: 16px 12px 10px; }
}

/* Десктоп */
@media (min-width: 900px) {
  .app {
    max-width: 900px;
    border-left: 1px solid var(--line-light);
    border-right: 1px solid var(--line-light);
    background: var(--surface);
  }
  .header { padding: 14px 28px; }
  .header-logo { width: 32px; height: 32px; font-size: 12px; }
  .header-title { font-size: 14px; }
  .messages { padding: 28px 40px; gap: 14px; }
  .msg { max-width: 68%; font-size: 14px; }
  .welcome-inner { max-width: 520px; }
  .chat-input-row { padding: 16px 40px 20px; }
  .base-scroll { padding: 28px 40px 16px; }
  .base-footer { padding: 14px 40px 20px; }
  .base-title { font-size: 17px; }
  .tabbar { padding: 10px 28px 12px; }
  .tab { flex: none; min-width: 160px; margin: 0 auto; }
  .tabbar { justify-content: center; }
  .settings-popup { right: calc((100vw - 900px) / 2 + 12px); }
}

/* Широкий десктоп */
@media (min-width: 1440px) {
  .app { max-width: 1040px; }
  .messages { padding: 32px 56px; }
  .chat-input-row { padding: 16px 56px 20px; }
  .base-scroll { padding: 32px 56px 16px; }
  .base-footer { padding: 14px 56px 20px; }
  .settings-popup { right: calc((100vw - 1040px) / 2 + 12px); }
}
