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

:root {
  --bg: #f8f7f6;
  --surface: #ffffff;
  --border: #e8e6e3;
  --border-light: #f0eeec;
  --text: #1a1a1a;
  --text-secondary: #8a8580;
  --text-tertiary: #b5b0ab;
  --accent: #3a8a7c;
  --accent-hover: #2e7267;
  --accent-light: #f0f7f6;
  --success: #3a7d44;
  --success-light: #eef6ef;
  --error: #c25353;
  --warning: #c2883a;
  --radius: 6px;
  --max-width: 600px;
  --font-display: Iowan Old Style, Georgia, serif;
  --font-body: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  padding-top: env(safe-area-inset-top);
}

body.chat-page {
  background: #2c2a28;
}

/* --- Layout --- */

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 4rem 1.5rem 3rem;
}

/* --- Typography --- */

h1 {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 400;
  letter-spacing: -0.02em;
  margin-bottom: 0.75rem;
  color: var(--text);
}

h2 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  margin-bottom: 0.5rem;
  color: var(--text);
}

p {
  margin-bottom: 1rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* --- Form elements --- */

input,
textarea {
  width: 100%;
  padding: 0.7rem 0;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  font-family: var(--font-body);
  font-size: 0.9rem;
  background: transparent;
  color: var(--text);
  outline: none;
  transition: border-color 0.25s;
}
input::placeholder,
textarea::placeholder {
  color: var(--text-tertiary);
}
input:focus,
textarea:focus {
  border-bottom-color: var(--text);
}

/* --- Buttons --- */

button {
  padding: 0.65rem 1.6rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition:
    background 0.2s,
    opacity 0.2s;
}
button:hover {
  background: var(--accent-hover);
}
button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background: var(--border-light);
  border-color: var(--text-tertiary);
}

.btn-danger {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border);
}
.btn-danger:hover {
  background: var(--accent-light);
  border-color: var(--accent);
}

.btn-small {
  padding: 0.4rem 0.9rem;
  font-size: 0.8rem;
}

/* --- Feedback states --- */

.error {
  color: var(--error);
  font-size: 0.8rem;
  margin-top: 0.5rem;
}
.warning {
  color: var(--warning);
  font-size: 0.8rem;
}
.success {
  color: var(--success);
  font-size: 0.8rem;
}

/* --- Card --- */

.card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 2rem;
  margin-bottom: 1.5rem;
}

/* --- Form group --- */

.form-group {
  margin-bottom: 1.25rem;
}
.form-group label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.35rem;
  color: var(--text-secondary);
}

.checkbox-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.checkbox-group input {
  width: auto;
  accent-color: var(--accent);
}
.checkbox-group label {
  text-transform: none;
  letter-spacing: normal;
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--text);
}

/* --- Recovery box --- */

.recovery-box {
  background: var(--bg);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 1rem 1.25rem;
  margin: 1.25rem 0;
}
.recovery-box strong {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  font-weight: 500;
}
.recovery-box code {
  display: block;
  font-size: 1rem;
  font-weight: 500;
  font-family: "SF Mono", "Fira Code", monospace;
  padding: 0.5rem 0;
  color: var(--text);
  word-break: break-all;
  letter-spacing: 0.02em;
}
.recovery-box p {
  font-size: 0.78rem;
  margin: 0;
  color: var(--text-secondary);
}

/* --- Chat layout --- */

.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 3rem);
  max-width: 720px;
  margin: 1.5rem auto;
  background: var(--bg);
  border-radius: 16px;
  overflow: hidden;
  box-shadow:
    0 8px 40px rgba(0, 0, 0, 0.18),
    0 2px 8px rgba(0, 0, 0, 0.1);
}

.chat-header {
  padding: 0.85rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, #5eaaa0 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 500;
  flex-shrink: 0;
}

.chat-header-info strong {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  display: block;
  line-height: 1.2;
}

.chat-subtitle {
  font-size: 0.72rem;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

.chat-menu-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background 0.2s;
  padding: 0;
}
.chat-menu-btn:hover {
  background: var(--border-light);
}
.chat-menu-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* --- Messages --- */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: linear-gradient(180deg, #f3f1ef 0%, #f8f7f6 40%, #f8f7f6 100%);
}

.message {
  max-width: 80%;
  padding: 0.75rem 1rem;
  border-radius: 20px;
  line-height: 1.55;
  word-wrap: break-word;
  font-size: 0.9rem;
  animation: msgFadeIn 0.25s ease-out;
}

@keyframes msgFadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message-user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-radius: 20px 20px 6px 20px;
  box-shadow: 0 1px 4px rgba(58, 138, 124, 0.18);
}

.message-assistant {
  align-self: flex-start;
  background: var(--surface);
  border: none;
  border-radius: 20px 20px 20px 6px;
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.message-system {
  align-self: center;
  background: rgba(0, 0, 0, 0.04);
  color: var(--text-secondary);
  font-size: 0.78rem;
  text-align: center;
  padding: 0.35rem 1rem;
  border-radius: 12px;
  max-width: 90%;
}

/* --- Thinking indicator --- */

.thinking {
  align-self: flex-start;
  padding: 0;
}

.thinking-bubble {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0.85rem 1.2rem;
  background: var(--surface);
  border-radius: 20px 20px 20px 6px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.thinking-dot {
  width: 8px;
  height: 8px;
  background: var(--text-tertiary);
  border-radius: 50%;
  animation: dotBounce 1.4s ease-in-out infinite;
}
.thinking-dot:nth-child(2) {
  animation-delay: 0.2s;
}
.thinking-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes dotBounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* --- Chat input --- */

.chat-input {
  padding: 0.75rem 1rem max(0.75rem, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: none;
  box-shadow: 0 -1px 8px rgba(0, 0, 0, 0.04);
}

.chat-input-inner {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 0.35rem 0.4rem 0.35rem 1rem;
  transition: border-color 0.2s;
}
.chat-input-inner:focus-within {
  border-color: var(--text-tertiary);
}

.chat-input textarea {
  flex: 1;
  resize: none;
  min-height: 24px;
  max-height: 120px;
  padding: 0.35rem 0;
  line-height: 1.5;
  border: none;
  border-bottom: none;
  background: transparent;
  font-size: 0.9rem;
}
.chat-input textarea:focus {
  border-bottom: none;
}

.send-btn {
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  border: none;
  cursor: pointer;
  transition:
    background 0.2s,
    transform 0.15s;
}
.send-btn:hover {
  background: var(--accent-hover);
  transform: scale(1.05);
}
.send-btn:disabled {
  opacity: 0.35;
  transform: none;
}
.send-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --- Banner --- */

.banner {
  padding: 0.6rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border-light);
  font-size: 0.78rem;
  color: var(--text-secondary);
  text-align: center;
}
.banner a {
  color: var(--accent);
  font-weight: 500;
  text-decoration: none;
}
.banner a:hover {
  text-decoration: underline;
}

/* --- Settings panel --- */

.settings-panel {
  position: fixed;
  top: 0;
  right: -340px;
  width: 340px;
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border-light);
  padding: 2rem 1.5rem;
  transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 100;
  overflow-y: auto;
}
.settings-panel.open {
  right: 0;
}
.settings-panel h2 {
  margin-bottom: 1.5rem;
}

.settings-close {
  position: absolute;
  top: 1.25rem;
  right: 1.25rem;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--text-secondary);
  min-height: 44px;
  padding: 0;
}
.settings-close:hover {
  background: var(--border-light);
  color: var(--text);
}

.settings-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(26, 26, 26, 0.15);
  z-index: 99;
  display: none;
}
.settings-overlay.open {
  display: block;
}

/* --- Message count --- */

.message-count {
  font-size: 0.72rem;
  color: var(--text-tertiary);
  text-align: center;
  padding: 0.25rem;
  letter-spacing: 0.02em;
}
.message-count.warning {
  color: var(--warning);
}

/* --- Status badge --- */

.status-badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  margin-left: 0.5rem;
}
.status-active {
  background: var(--success-light);
  color: var(--success);
}
.status-closed {
  background: var(--accent-light);
  color: var(--accent);
}

/* --- Consent page --- */

.consent-list {
  margin: 1.25rem 0;
  padding: 0;
  list-style: none;
}
.consent-list li {
  position: relative;
  padding: 0.6rem 0 0.6rem 1.25rem;
  font-size: 0.88rem;
  color: var(--text);
  line-height: 1.55;
  border-bottom: 1px solid var(--border-light);
}
.consent-list li:last-child {
  border-bottom: none;
}
.consent-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 1rem;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-tertiary);
}

details summary {
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.5rem 0;
  transition: color 0.2s;
}
details summary:hover {
  color: var(--text);
}
details[open] summary {
  color: var(--text);
}

/* --- Divider --- */

.divider {
  margin: 2rem 0;
  border: none;
  border-top: 1px solid var(--border-light);
}

/* --- Scrollbar --- */

.chat-messages::-webkit-scrollbar {
  width: 4px;
}
.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

/* --- Copy button --- */

.copy-group {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}
.copy-group input {
  flex: 1;
  min-width: 0;
}
.copy-btn {
  flex-shrink: 0;
  padding: 0.5rem 0.85rem;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.78rem;
  font-weight: 500;
  min-height: 44px;
  white-space: nowrap;
  transition:
    background 0.2s,
    color 0.2s;
}
.copy-btn:hover {
  background: var(--border-light);
  color: var(--text);
}
.copy-btn.copied {
  background: var(--success-light);
  color: var(--success);
  border-color: var(--success);
}

/* --- Responsive --- */

/* Laptop / wide screens */
@media (min-width: 768px) {
  .container {
    padding: 5rem 2rem 3rem;
  }
}

/* Tablet */
@media (max-width: 767px) {
  .container {
    padding: 3rem 1.25rem 2rem;
  }
  body.chat-page {
    background: var(--bg);
  }
  .chat-container {
    max-width: 100%;
    height: 100vh;
    margin: 0;
    border-radius: 0;
    box-shadow: none;
  }
  .settings-panel {
    width: 280px;
    right: -280px;
  }
}

/* Mobile */
@media (max-width: 480px) {
  .container {
    padding: 2rem 1rem 1.5rem;
  }
  h1 {
    font-size: 1.65rem;
  }
  .card {
    padding: 1.25rem 1rem;
    border-radius: 8px;
  }
  .chat-header {
    padding: 0.75rem 0.85rem;
  }
  .chat-avatar {
    width: 34px;
    height: 34px;
    font-size: 0.9rem;
  }
  .chat-input {
    padding: 0.6rem 0.75rem max(0.6rem, env(safe-area-inset-bottom));
  }
  .chat-input-inner {
    padding: 0.25rem 0.35rem 0.25rem 0.85rem;
  }
  .send-btn {
    width: 34px;
    height: 34px;
    min-width: 34px;
    min-height: 34px;
  }
  .chat-messages {
    padding: 0.85rem;
    gap: 0.4rem;
  }
  .message {
    max-width: 88%;
    font-size: 0.88rem;
    padding: 0.65rem 0.9rem;
  }
  .settings-panel {
    width: 100%;
    right: -100%;
    padding-bottom: max(2rem, env(safe-area-inset-bottom));
  }
  button {
    padding: 0.7rem 1.25rem;
    min-height: 44px;
  }
  .btn-small {
    min-height: 44px;
    padding: 0.55rem 0.9rem;
  }
}

/* --- Language toggle --- */
.lang-toggle-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 0.35rem 0.7rem;
  border-radius: var(--radius);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font-body);
}
.lang-toggle-btn:hover {
  background: var(--border-light);
  color: var(--text);
}
