:root {
  --primary: #1a365d;
  --primary-light: #2b6cb0;
  --accent: #38a169;
  --accent-light: #c6f6d5;
  --bg: #f7fafc;
  --card-bg: #ffffff;
  --text: #1a202c;
  --text-muted: #718096;
  --border: #e2e8f0;
  --danger: #e53e3e;
  --warning: #d69e2e;
  --success: #38a169;
  --official-bg: #ebf8ff;
  --official-border: #3182ce;
  --gov-bg: #fefcbf;
  --gov-border: #d69e2e;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1rem;
}

.navbar {
  background: var(--primary);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-lg);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo {
  background: var(--accent);
  color: white;
  font-weight: 800;
  font-size: 1.2rem;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
}

.brand-text {
  color: white;
  font-size: 1.15rem;
  font-weight: 600;
}

.nav-links {
  display: flex;
  gap: 0.25rem;
}

.nav-link {
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  transition: all 0.2s;
}

.nav-link:hover, .nav-link.active {
  color: white;
  background: rgba(255,255,255,0.15);
}

.nav-toggle {
  display: none;
  background: none;
  border: none;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
}

.hero {
  text-align: center;
  padding: 3rem 1rem 2rem;
}

.hero h1 {
  font-size: 2.5rem;
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.subtitle {
  font-size: 1.2rem;
  color: var(--primary-light);
  margin-bottom: 0.5rem;
}

.tagline {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1.25rem;
  padding: 1rem 0 2rem;
}

.feature-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all 0.2s;
  border: 2px solid transparent;
}

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

.feature-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
}

.feature-card h2 {
  color: var(--primary);
  margin-bottom: 0.5rem;
  font-size: 1.15rem;
}

.feature-card p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

.trust-badge {
  display: inline-block;
  background: var(--accent-light);
  color: var(--success);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}

.trust-section {
  padding: 2rem 0;
  text-align: center;
}

.trust-section h2 {
  color: var(--primary);
  margin-bottom: 1rem;
}

.trust-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 0.75rem;
}

.trust-item {
  padding: 0.75rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
}

.trust-item.official {
  background: var(--official-bg);
  border: 1px solid var(--official-border);
}

.trust-item.government {
  background: var(--gov-bg);
  border: 1px solid var(--gov-border);
}

.next-exam {
  padding: 1.5rem 0 2rem;
  text-align: center;
}

.next-exam h2 {
  color: var(--primary);
  margin-bottom: 1rem;
}

.exam-box {
  background: var(--card-bg);
  border: 2px solid var(--primary-light);
  border-radius: var(--radius);
  padding: 1.5rem;
  display: inline-block;
}

.exam-box p {
  margin-bottom: 0.5rem;
}

.exam-box .small {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.exam-box a {
  color: var(--primary-light);
}

.page-header {
  padding: 2rem 0 1rem;
  text-align: center;
}

.page-header h1 {
  color: var(--primary);
  margin-bottom: 0.35rem;
}

.page-header p {
  color: var(--text-muted);
}

.news-filters, .materials-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 1rem 0;
  align-items: center;
}

.news-filters select, .materials-filters select,
.news-filters input, .materials-filters input {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  background: white;
}

.news-list, .materials-list {
  padding: 1rem 0;
}

.news-card, .material-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--primary-light);
}

.news-card .news-source, .material-card .mat-source {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.35rem;
}

.news-card .news-source.official { color: var(--official-border); }
.news-card .news-source.government { color: var(--warning); }

.news-card h3 {
  font-size: 1rem;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.news-card .news-summary {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.news-card .news-why {
  font-size: 0.85rem;
  color: var(--text);
  background: var(--accent-light);
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  margin-bottom: 0.75rem;
}

.news-card .news-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.tag {
  background: var(--primary);
  color: white;
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: 12px;
}

.news-card .news-link {
  display: inline-block;
  color: var(--primary-light);
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

.material-card {
  border-left-color: var(--accent);
}

.material-card.official { border-left-color: var(--official-border); }
.material-card.government { border-left-color: var(--warning); }

.material-card h3 {
  font-size: 1rem;
  margin-bottom: 0.25rem;
}

.material-card h3 a {
  color: var(--primary);
  text-decoration: none;
}

.material-card h3 a:hover {
  text-decoration: underline;
}

.material-card .mat-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.trust-tag {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  margin-left: 0.35rem;
}

.trust-tag.official {
  background: var(--official-bg);
  color: var(--official-border);
}

.trust-tag.government {
  background: var(--gov-bg);
  color: var(--warning);
}

.chat-container {
  max-width: 800px;
  margin: 0 auto;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat-messages {
  height: 500px;
  overflow-y: auto;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.chat-message {
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  max-width: 85%;
}

.chat-message.user {
  background: var(--primary);
  color: white;
  margin-left: auto;
}

.chat-message.assistant {
  background: #edf2f7;
  color: var(--text);
}

.chat-message.system {
  background: #ebf8ff;
  color: var(--primary);
  max-width: 100%;
}

.chat-message .message-content p {
  margin-bottom: 0.5rem;
}

.chat-message .message-content ul {
  padding-left: 1.25rem;
  margin-bottom: 0.5rem;
}

.chat-message .message-content code {
  background: rgba(0,0,0,0.05);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  font-size: 0.85rem;
}

.chat-message .sources {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
}

.chat-input-area {
  padding: 1rem;
}

.quick-questions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.quick-q {
  background: #edf2f7;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}

.quick-q:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

#chat-form {
  display: flex;
  gap: 0.5rem;
}

#chat-input {
  flex: 1;
  padding: 0.65rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
}

#chat-input:focus {
  outline: none;
  border-color: var(--primary-light);
}

.btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s;
}

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

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

.btn-secondary {
  background: #edf2f7;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: #e2e8f0;
}

.btn-large {
  padding: 0.75rem 2rem;
  font-size: 1rem;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.quiz-setup {
  max-width: 500px;
  margin: 0 auto;
  background: var(--card-bg);
  padding: 1.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--primary);
  font-size: 0.9rem;
}

.form-group select, .form-group input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.quiz-progress {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.progress-bar {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  margin: 0 1rem;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.quiz-question {
  background: var(--card-bg);
  padding: 1.25rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.quiz-question h3 {
  color: var(--primary);
  margin-bottom: 0.75rem;
  font-size: 1rem;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.quiz-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
}

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

.quiz-option.selected {
  border-color: var(--primary);
  background: var(--official-bg);
}

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

.quiz-option.incorrect {
  border-color: var(--danger);
  background: #fed7d7;
}

.quiz-option input {
  margin-right: 0.25rem;
}

.quiz-explanation {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: #edf2f7;
  border-radius: 4px;
  font-size: 0.85rem;
  display: none;
}

.quiz-explanation.visible {
  display: block;
}

.quiz-actions {
  text-align: center;
  padding: 1rem 0;
}

.results-summary {
  background: var(--card-bg);
  padding: 1.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
  margin-bottom: 1.5rem;
}

.results-summary .score {
  font-size: 3rem;
  font-weight: 800;
  color: var(--primary);
}

.results-detail {
  padding: 0;
}

.loading {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
}

.empty {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
}

.error {
  text-align: center;
  padding: 2rem;
  color: var(--danger);
}

.footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
  margin-top: 2rem;
}

.btn-delete {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0 0.25rem;
  line-height: 1;
  opacity: 0.5;
  transition: opacity 0.2s;
}
.btn-delete:hover { opacity: 1; }

.timestamp {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.db-warning {
  padding: 0.65rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
  font-weight: 500;
}
.db-warning.warn {
  background: #fffbeb;
  border: 1px solid var(--warning);
  color: #92400e;
}
.db-warning.danger {
  background: #fef2f2;
  border: 1px solid var(--danger);
  color: #991b1b;
}

.material-card.suggestion {
  border-left-color: #6b46c1;
  background: #faf5ff;
}

@media (max-width: 768px) {
  .nav-links {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--primary);
    flex-direction: column;
    padding: 0.5rem;
  }

  .nav-links.active {
    display: flex;
  }

  .nav-toggle {
    display: block;
  }

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

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

  .chat-messages {
    height: 350px;
  }

  .news-filters, .materials-filters {
    flex-direction: column;
  }

  .news-filters select, .materials-filters select,
  .news-filters input, .materials-filters input {
    width: 100%;
  }

  .quiz-setup {
    padding: 1rem;
  }
}