/* ===== Variables ===== */
:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-secondary: #5a5a5a;
  --border: #e2e4e8;
  --primary: #1e3a8a;
  --primary-light: #dbeafe;
  --accent: #dc2626;
  --accent-light: #fee2e2;
  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #ca8a04;
  --warning-light: #fef9c3;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0,0,0,0.06);
  --shadow-hover: 0 8px 30px rgba(0,0,0,0.10);
  --transition: 0.2s ease;
}

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

html {
  scroll-behavior: smooth;
}

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

.container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ===== Header ===== */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: 1.2rem;
}

.logo-img {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: block;
}

.logo-text {
  letter-spacing: -0.02em;
}

.main-nav {
  display: flex;
  gap: 6px;
}

.main-nav a {
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 0.95rem;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 8px;
  transition: var(--transition);
}

.main-nav a:hover,
.main-nav a.active {
  color: var(--primary);
  background: var(--primary-light);
}

.menu-toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
}

.menu-toggle span {
  display: block;
  width: 24px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: var(--transition);
}

/* ===== Main ===== */
main {
  flex: 1;
  padding: 32px 0 48px;
}

.page-title {
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}

.page-subtitle {
  color: var(--text-secondary);
  margin-bottom: 28px;
  font-size: 1.05rem;
}

.section-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 32px 0 16px;
}

/* ===== Cards ===== */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  transition: var(--transition);
  cursor: pointer;
}

.card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
  border-color: var(--primary-light);
}

.card h3 {
  font-size: 1.15rem;
  margin-bottom: 8px;
  color: var(--primary);
}

.card p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.5;
}

.card .meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--primary-light);
  color: var(--primary);
}

.badge-accent {
  background: var(--accent-light);
  color: var(--accent);
}

.badge-success {
  background: var(--success-light);
  color: var(--success);
}

.badge-warning {
  background: var(--warning-light);
  color: var(--warning);
}

/* ===== Hero ===== */
.hero {
  background: linear-gradient(135deg, var(--primary) 0%, #172554 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 48px 40px;
  margin-bottom: 32px;
  box-shadow: var(--shadow);
}

.hero h1 {
  font-size: 2.2rem;
  font-weight: 800;
  margin-bottom: 14px;
  max-width: 700px;
}

.hero p {
  font-size: 1.15rem;
  opacity: 0.9;
  max-width: 700px;
  margin-bottom: 24px;
}

.hero-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  border: none;
  cursor: pointer;
  transition: var(--transition);
}

.btn-primary {
  background: #fff;
  color: var(--primary);
}

.btn-primary:hover {
  background: var(--primary-light);
}

.btn-secondary {
  background: rgba(255,255,255,0.15);
  color: #fff;
}

.btn-secondary:hover {
  background: rgba(255,255,255,0.25);
}

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}

.btn-outline:hover {
  background: var(--primary-light);
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-success:hover {
  background: #15803d;
}

.btn-danger {
  background: var(--accent);
  color: #fff;
}

.btn-danger:hover {
  background: #b91c1c;
}

/* ===== Search & filters ===== */
.search-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.search-bar input,
.search-bar select {
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  background: var(--surface);
  color: var(--text);
  flex: 1;
  min-width: 200px;
}

.search-bar input:focus,
.search-bar select:focus {
  outline: none;
  border-color: var(--primary);
}

/* ===== Topic page ===== */
.topic-detail {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.topic-detail h2 {
  font-size: 1.8rem;
  margin-bottom: 8px;
  color: var(--primary);
}

.topic-detail h3 {
  font-size: 1.25rem;
  margin: 28px 0 12px;
  color: var(--text);
}

.topic-detail p {
  margin-bottom: 12px;
}

.topic-detail ul,
.topic-detail ol {
  margin: 12px 0 12px 24px;
}

.topic-detail li {
  margin-bottom: 6px;
}

.topic-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  flex-wrap: wrap;
}

/* ===== Test ===== */
.test-container {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.question {
  margin-bottom: 28px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.question:last-child {
  border-bottom: none;
}

.question-text {
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 14px;
}

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

.option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition);
  background: var(--bg);
}

.option:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.option input {
  margin-top: 3px;
}

.option.correct {
  border-color: var(--success);
  background: var(--success-light);
}

.option.wrong {
  border-color: var(--accent);
  background: var(--accent-light);
}

.explanation {
  margin-top: 12px;
  padding: 14px;
  background: var(--primary-light);
  border-radius: 8px;
  font-size: 0.95rem;
  display: none;
}

.explanation.visible {
  display: block;
}

.test-result {
  margin-top: 24px;
  padding: 20px;
  border-radius: 8px;
  font-weight: 700;
  text-align: center;
  font-size: 1.1rem;
}

/* ===== Progress ===== */
.progress-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  text-align: center;
}

.stat-card .number {
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary);
}

.stat-card .label {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-top: 4px;
}

.progress-list {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
}

.progress-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
}

.progress-item:last-child {
  border-bottom: none;
}

.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  width: 140px;
}

.progress-bar > div {
  height: 100%;
  background: var(--success);
  border-radius: 4px;
  transition: width 0.4s ease;
}

/* ===== Footer ===== */
.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 24px 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.footer-links {
  margin-top: 8px;
}

.footer-links a {
  color: var(--primary);
  text-decoration: none;
  margin-right: 16px;
}

.footer-links a:hover {
  text-decoration: underline;
}

/* ===== Empty state ===== */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-secondary);
}

.empty-state h3 {
  color: var(--text);
  margin-bottom: 8px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .menu-toggle {
    display: flex;
  }

  .main-nav {
    position: absolute;
    top: 64px;
    left: 0;
    right: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    padding: 12px 20px;
    gap: 4px;
    display: none;
  }

  .main-nav.open {
    display: flex;
  }

  .hero {
    padding: 32px 24px;
  }

  .hero h1 {
    font-size: 1.6rem;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }

  .topic-detail,
  .test-container {
    padding: 22px;
  }

  .ai-chat-window {
    width: calc(100vw - 24px);
    right: 12px;
    bottom: 84px;
    max-height: calc(100vh - 110px);
  }
}

/* ===== AI-юрист: плавающий чат ===== */
.ai-chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.ai-chat-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 50px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-hover);
  transition: transform var(--transition), box-shadow var(--transition);
}

.ai-chat-toggle:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 32px rgba(30, 58, 138, 0.25);
}

.ai-chat-window {
  position: absolute;
  bottom: 72px;
  right: 0;
  width: 380px;
  max-height: 560px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-hover);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.96);
  transition: opacity var(--transition), transform var(--transition), visibility var(--transition);
}

.ai-chat-window.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--primary);
  color: #fff;
}

.ai-chat-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 1rem;
}

.ai-chat-close {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}

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

.ai-message {
  display: flex;
  max-width: 92%;
}

.ai-message-user {
  align-self: flex-end;
}

.ai-message-system,
.ai-message-assistant {
  align-self: flex-start;
}

.ai-message-content {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.92rem;
  line-height: 1.5;
  word-wrap: break-word;
}

.ai-message-user .ai-message-content {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ai-message-system .ai-message-content,
.ai-message-assistant .ai-message-content {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.ai-message-content p {
  margin: 0;
}

.ai-message-content p + p {
  margin-top: 0.6em;
}

.ai-message-content ul,
.ai-message-content ol {
  margin: 0.5em 0 0.5em 1.2em;
}

.ai-message-content li {
  margin-bottom: 0.25em;
}

.ai-chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.ai-chat-input-wrap {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.ai-chat-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.95rem;
  line-height: 1.4;
  max-height: 120px;
  min-height: 42px;
  background: #fff;
  color: var(--text);
  font-family: inherit;
}

.ai-chat-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.ai-chat-send {
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background var(--transition);
  flex-shrink: 0;
}

.ai-chat-send:hover {
  background: #152c6e;
}

.ai-chat-send:disabled {
  background: #94a3b8;
  cursor: not-allowed;
}

.ai-chat-hint {
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--text-secondary);
  line-height: 1.3;
}

.ai-chat-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
}

.ai-chat-typing span {
  width: 7px;
  height: 7px;
  background: var(--text-secondary);
  border-radius: 50%;
  animation: aiTyping 1.2s infinite ease-in-out;
}

.ai-chat-typing span:nth-child(2) {
  animation-delay: 0.2s;
}

.ai-chat-typing span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes aiTyping {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

.ai-chat-error {
  color: var(--accent);
  font-size: 0.85rem;
  margin-top: 6px;
}

.ai-chat-setup {
  padding: 12px;
  background: var(--warning-light);
  border: 1px solid var(--warning);
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--text);
}

.ai-chat-setup a {
  color: var(--primary);
  text-decoration: underline;
}

.ai-chat-empty {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.85rem;
  padding: 20px;
}
}
