/* ── Reset & base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f5f6f8;
  color: #333;
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Header ──────────────────────────────────────────────────── */
header {
  background: #1a1a2e;
  color: white;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-left { display: flex; align-items: baseline; gap: 10px; }
h1 { font-size: 1.2em; font-weight: 700; }
.subtitle { font-size: 0.85em; color: #8888aa; }
nav { display: flex; gap: 4px; margin-left: auto; }
.nav-btn {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.2);
  color: #ccc;
  padding: 6px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85em;
  transition: all 0.2s;
}
.nav-btn:hover { background: rgba(255,255,255,0.1); color: white; }
.nav-btn.active { background: rgba(255,255,255,0.15); color: white; border-color: rgba(255,255,255,0.4); }
.header-right { font-size: 0.8em; color: #8888aa; }
#stats-badge { white-space: nowrap; }

/* ── Views ───────────────────────────────────────────────────── */
.view { display: none; padding: 20px 24px; max-width: 1100px; margin: 0 auto; }
.view.active { display: block; }

/* ── Search view ─────────────────────────────────────────────── */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
#search-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 0.95em;
  outline: none;
  transition: border-color 0.2s;
}
#search-input:focus { border-color: #4a5aba; }
#search-btn, #semantic-btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9em;
  font-weight: 600;
  transition: background 0.2s;
}
#search-btn { background: #4a5aba; color: white; }
#search-btn:hover { background: #3a4aaa; }
#semantic-btn { background: #e8e0f0; color: #6b4fa0; }
#semantic-btn:hover { background: #d8d0e0; }

.filters {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filters select {
  padding: 6px 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 0.82em;
  background: white;
  cursor: pointer;
}

#search-info {
  font-size: 0.85em;
  color: #888;
  margin-bottom: 12px;
}

/* ── Ticket cards ────────────────────────────────────────────── */
.ticket-card {
  background: white;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  margin-bottom: 12px;
  padding: 16px 20px;
  cursor: pointer;
  transition: box-shadow 0.2s;
  border-left: 3px solid transparent;
}
.ticket-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.12); }
.ticket-card.resolved { border-left-color: #22c55e; }
.ticket-card.open { border-left-color: #f59e0b; }
.ticket-card.waiting { border-left-color: #8b5cf6; }

.ticket-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.ticket-id { font-size: 0.82em; color: #888; font-weight: 600; }
.ticket-summary { font-weight: 600; flex: 1; font-size: 0.95em; }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.72em;
  font-weight: 600;
  white-space: nowrap;
}
.badge-resolved { background: #dcfce7; color: #166534; }
.badge-open { background: #fef9c3; color: #854d0e; }
.badge-waiting { background: #ede9fe; color: #5b21b6; }
.badge-default { background: #f3f4f6; color: #6b7280; }

.ticket-card-meta {
  display: flex;
  gap: 16px;
  font-size: 0.78em;
  color: #888;
  flex-wrap: wrap;
}
.ticket-card-meta span { display: flex; gap: 4px; }
.meta-label { font-weight: 600; }

.score-bar {
  display: inline-block;
  height: 4px;
  border-radius: 2px;
  background: #4a5aba;
  margin-left: 6px;
  vertical-align: middle;
}

/* ── Pagination ──────────────────────────────────────────────── */
#pagination {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-top: 20px;
}
.page-btn {
  padding: 6px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: white;
  cursor: pointer;
  font-size: 0.85em;
}
.page-btn:hover { background: #f0f0f0; }
.page-btn.active { background: #4a5aba; color: white; border-color: #4a5aba; }
.page-btn:disabled { opacity: 0.5; cursor: default; }

/* ── Ticket detail overlay ───────────────────────────────────── */
.detail-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 20px;
  overflow-y: auto;
}
.detail-overlay.hidden { display: none; }
.detail-content {
  background: white;
  border-radius: 12px;
  max-width: 900px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 30px rgba(0,0,0,0.2);
  position: relative;
}
.detail-close {
  position: sticky;
  top: 12px;
  float: right;
  margin: 12px;
  background: #f3f4f6;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 16px;
  font-size: 1.2em;
  cursor: pointer;
  z-index: 10;
}
.detail-close:hover { background: #e5e7eb; }

.detail-header { padding: 20px 24px 12px; border-bottom: 1px solid #eee; }
.detail-header h2 { font-size: 1.1em; margin-bottom: 8px; }
.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  font-size: 0.82em;
  color: #666;
}
.detail-meta .meta-item { display: flex; gap: 4px; }
.detail-meta .meta-label { font-weight: 600; color: #999; }

.detail-section { padding: 16px 24px; border-bottom: 1px solid #f0f0f0; }
.detail-section h3 { font-size: 0.9em; color: #888; margin-bottom: 8px; }
.detail-section .text { font-size: 0.9em; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }

.note-item { padding: 12px 0; border-bottom: 1px solid #f5f5f5; }
.note-item:last-child { border-bottom: none; }
.note-header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; font-size: 0.85em; }
.note-author { font-weight: 600; }
.note-date { color: #999; }
.role-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.7em;
  font-weight: 700;
}
.role-ga { background: #dbeafe; color: #1e40af; }
.role-dev { background: #fef3c7; color: #92400e; }
.note-text { font-size: 0.88em; line-height: 1.55; white-space: pre-wrap; word-break: break-word; }

.att-item { margin-bottom: 6px; }
.att-item a { color: #4a5aba; text-decoration: none; font-size: 0.88em; }
.att-item a:hover { text-decoration: underline; }

/* ── Chat view ───────────────────────────────────────────────── */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 100px);
}
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0;
}
.chat-welcome {
  text-align: center;
  padding: 60px 20px;
  color: #888;
}
.chat-welcome h2 { font-size: 1.3em; color: #333; margin-bottom: 8px; }
.chat-welcome p { margin-bottom: 20px; }
.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
.suggestion {
  padding: 8px 16px;
  border: 1px solid #ddd;
  border-radius: 20px;
  background: white;
  cursor: pointer;
  font-size: 0.85em;
  transition: all 0.2s;
}
.suggestion:hover { border-color: #4a5aba; color: #4a5aba; }

.chat-msg {
  margin-bottom: 16px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.chat-msg.user { justify-content: flex-end; }
.chat-msg.user .chat-bubble { background: #4a5aba; color: white; }
.chat-bubble {
  background: white;
  border-radius: 12px;
  padding: 12px 16px;
  max-width: 80%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  font-size: 0.9em;
  line-height: 1.6;
}
.chat-bubble a { color: #93c5fd; }
.chat-msg.assistant .chat-bubble a { color: #4a5aba; }
.chat-bubble .ticket-ref {
  display: inline-block;
  background: rgba(74,90,186,0.1);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.85em;
  cursor: pointer;
  color: #4a5aba;
}
.chat-bubble .ticket-ref:hover { background: rgba(74,90,186,0.2); }
.chat-sources {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(0,0,0,0.08);
  font-size: 0.8em;
  color: #888;
}
.chat-sources span { cursor: pointer; color: #4a5aba; }
.chat-sources span:hover { text-decoration: underline; }
.chat-loading {
  display: flex;
  gap: 4px;
  padding: 8px;
}
.chat-loading span {
  width: 8px; height: 8px; border-radius: 50%; background: #ccc;
  animation: bounce 1.4s infinite ease-in-out both;
}
.chat-loading span:nth-child(1) { animation-delay: -0.32s; }
.chat-loading span:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

.chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px 0;
  border-top: 1px solid #eee;
}
#chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 0.95em;
  outline: none;
}
#chat-input:focus { border-color: #4a5aba; }
#chat-send {
  padding: 10px 20px;
  background: #4a5aba;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}
#chat-send:hover { background: #3a4aaa; }
#chat-send:disabled { opacity: 0.5; cursor: default; }

/* ── Knowledge view ──────────────────────────────────────────── */
.knowledge-loading { text-align: center; padding: 40px; color: #888; }

.knowledge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}
.knowledge-card {
  background: white;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  cursor: pointer;
  transition: box-shadow 0.2s;
}
.knowledge-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.12); }
.knowledge-card h3 { font-size: 0.95em; margin-bottom: 8px; color: #1a1a2e; }
.knowledge-card p { font-size: 0.82em; color: #888; margin-bottom: 12px; line-height: 1.5; }
.knowledge-card .counts {
  display: flex;
  gap: 12px;
  font-size: 0.75em;
  color: #aaa;
}
.knowledge-card .counts span { display: flex; align-items: center; gap: 3px; }

.knowledge-detail { background: white; border-radius: 8px; padding: 24px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.knowledge-detail h2 { font-size: 1.1em; margin-bottom: 4px; }
.knowledge-detail .summary { font-size: 0.9em; color: #666; margin-bottom: 20px; line-height: 1.6; }
.knowledge-detail .back-btn {
  display: inline-block;
  margin-bottom: 16px;
  color: #4a5aba;
  cursor: pointer;
  font-size: 0.85em;
}
.knowledge-detail .back-btn:hover { text-decoration: underline; }

.knowledge-section { margin-bottom: 24px; }
.knowledge-section h3 { font-size: 0.9em; color: #4a5aba; margin-bottom: 10px; padding-bottom: 4px; border-bottom: 1px solid #eee; }

.rule-item, .procedure-item, .error-item, .evolution-item {
  padding: 10px 12px;
  margin-bottom: 8px;
  background: #f9fafb;
  border-radius: 6px;
  font-size: 0.88em;
  line-height: 1.5;
}
.rule-item .importance {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.72em;
  font-weight: 700;
  margin-left: 6px;
}
.importance-high { background: #fef2f2; color: #991b1b; }
.importance-medium { background: #fef9c3; color: #854d0e; }
.importance-low { background: #f0fdf4; color: #166534; }
.rule-item .details, .error-item .solution { color: #666; margin-top: 4px; }
.procedure-item .steps { padding-left: 20px; margin-top: 6px; }
.procedure-item .steps li { margin-bottom: 4px; }
.error-item strong { color: #991b1b; }
.evolution-item .period { font-weight: 600; color: #4a5aba; }
.source-tickets { font-size: 0.75em; color: #aaa; margin-top: 4px; }
.source-tickets span { cursor: pointer; color: #4a5aba; }

/* ── Utilities ───────────────────────────────────────────────── */
.empty { text-align: center; color: #999; padding: 40px; }
.hidden { display: none !important; }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 700px) {
  header { flex-wrap: wrap; padding: 10px 16px; }
  nav { order: 3; width: 100%; }
  .view { padding: 12px 16px; }
  .search-bar { flex-wrap: wrap; }
  #search-input { min-width: 100%; }
  .filters { flex-direction: column; }
  .ticket-card-header { flex-wrap: wrap; }
  .detail-content { max-height: 95vh; }
  .knowledge-grid { grid-template-columns: 1fr; }
}
