:root {
  --primary: #3949a0;
  --primary-light: #5c6bc0;
  --primary-dark: #283593;
  --bg: #f0f2f8;
  --surface: #ffffff;
  --text: #1a1a2e;
  --text-muted: #666;
  --border: #e0e3ee;
  --success: #4caf50;
  --warning: #ff9800;
  --danger: #e53935;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(57,73,160,0.08);
  --shadow-lg: 0 8px 24px rgba(57,73,160,0.14);
}

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

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── HEADER ────────────────────────────────────── */
.kb-header {
  background: var(--primary);
  color: #fff;
  padding: 0 16px;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.kb-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
}

.kb-search-box {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 24px;
  padding: 6px 14px;
  transition: background 0.2s;
}

.kb-search-box:focus-within {
  background: rgba(255,255,255,0.25);
}

.kb-search-box input {
  flex: 1;
  border: none;
  background: transparent;
  color: #fff;
  font-size: 13px;
  outline: none;
}

.kb-search-box input::placeholder { color: rgba(255,255,255,0.65); }

.search-scope-pills {
  display: flex;
  gap: 4px;
}

.pill {
  background: rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.85);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
}

.pill.active, .pill:hover {
  background: rgba(255,255,255,0.9);
  color: var(--primary);
  font-weight: 600;
}

.kb-header-right { display: flex; align-items: center; gap: 10px; }

.kb-user {
  font-size: 12px;
  background: rgba(255,255,255,0.15);
  padding: 4px 12px;
  border-radius: 20px;
  white-space: nowrap;
}

/* ── TOOLBAR ───────────────────────────────────── */
.kb-toolbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 12px;
}

.kb-breadcrumb {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  overflow: hidden;
}

.crumb {
  color: var(--primary);
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 4px;
  white-space: nowrap;
  font-weight: 500;
  font-size: 13px;
}

.crumb:hover { background: var(--bg); }
.crumb.current { color: var(--text-muted); cursor: default; font-weight: 400; }

.crumb-sep {
  color: var(--text-muted);
  font-size: 11px;
  user-select: none;
}

.kb-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tb-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}

.tb-btn:hover { border-color: var(--primary); color: var(--primary); }
.tb-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.view-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.vt-btn {
  padding: 5px 9px;
  border: none;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
}

.vt-btn + .vt-btn { border-left: 1px solid var(--border); }
.vt-btn:hover { background: var(--bg); color: var(--primary); }
.vt-btn.active { background: var(--primary); color: #fff; }

/* ── MAIN ──────────────────────────────────────── */
.kb-main {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

/* ── FILE GRID ─────────────────────────────────── */
.file-grid { display: grid; gap: 12px; }

.file-grid.grid-lg { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.file-grid.grid-md { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
.file-grid.grid-sm { grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); }

.file-grid.list {
  grid-template-columns: 1fr;
  gap: 2px;
}

/* ── FILE CARD ─────────────────────────────────── */
.file-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 8px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
  text-align: center;
  user-select: none;
}

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

.file-card.no-access {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(0.5);
}

.file-icon {
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  font-size: 26px;
  flex-shrink: 0;
}

.icon-folder  { background: #fff3e0; color: #f57c00; }
.icon-gdrive  { background: #e3f2fd; color: #1565c0; }
.icon-local   { background: #f3e5f5; color: #6a1b9a; }
.icon-pdf     { background: #ffebee; color: #c62828; }
.icon-doc     { background: #e3f2fd; color: #1565c0; }
.icon-xls     { background: #e8f5e9; color: #2e7d32; }
.icon-ppt     { background: #fff3e0; color: #e65100; }
.icon-img     { background: #fce4ec; color: #880e4f; }
.icon-txt     { background: #f5f5f5; color: #555; }
.icon-default { background: #f5f5f5; color: #555; }

.file-name {
  font-size: 11px;
  line-height: 1.3;
  word-break: break-word;
  max-width: 100%;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.file-card .lock-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 10px;
  background: var(--warning);
  color: #fff;
  border-radius: 4px;
  padding: 1px 4px;
}

.file-card .perm-btn {
  display: none;
  position: absolute;
  top: 6px;
  left: 6px;
  font-size: 10px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 2px 5px;
  cursor: pointer;
}

.file-card:hover .perm-btn { display: block; }

/* ── LIST VIEW ─────────────────────────────────── */
.file-grid.list .file-card {
  flex-direction: row;
  padding: 8px 12px;
  text-align: left;
  align-items: center;
  gap: 12px;
  border-radius: 4px;
}

.file-grid.list .file-icon {
  width: 32px;
  height: 32px;
  font-size: 16px;
  border-radius: 6px;
  flex-shrink: 0;
}

.file-grid.list .file-name {
  flex: 1;
  font-size: 13px;
  -webkit-line-clamp: 1;
}

.file-meta {
  display: none;
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.file-grid.list .file-meta { display: block; }

/* grid-sm: icon + name em linha */
.file-grid.grid-sm .file-card {
  flex-direction: row;
  padding: 6px 8px;
  text-align: left;
  gap: 8px;
  justify-content: flex-start;
}

.file-grid.grid-sm .file-icon {
  width: 28px;
  height: 28px;
  font-size: 14px;
  border-radius: 5px;
  flex-shrink: 0;
}

.file-grid.grid-sm .file-name {
  font-size: 12px;
  -webkit-line-clamp: 1;
}

/* ── SOURCE CARD (tela inicial) ────────────────── */
.source-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 28px 16px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}

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

.source-icon {
  font-size: 40px;
  width: 70px;
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
}

.source-name { font-weight: 700; font-size: 14px; }
.source-desc { font-size: 12px; color: var(--text-muted); }

/* ── SEARCH RESULTS ────────────────────────────── */
.kb-synthesis {
  background: linear-gradient(135deg, #e8eaf6, #f3f4fb);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 16px;
  line-height: 1.6;
}

.kb-synthesis h4 {
  color: var(--primary);
  margin-bottom: 6px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

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

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all 0.15s;
}

.result-card:hover {
  box-shadow: var(--shadow-lg);
  border-color: var(--primary-light);
}

.result-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.result-title { font-weight: 700; font-size: 14px; color: var(--primary); }
.result-score { font-size: 11px; background: var(--primary); color: #fff; padding: 2px 8px; border-radius: 12px; }
.result-excerpt { color: var(--text-muted); line-height: 1.5; font-size: 12px; }
.result-meta { display: flex; align-items: center; gap: 8px; margin-top: 8px; }

.badge { font-size: 11px; padding: 2px 8px; border-radius: 12px; font-weight: 600; }
.badge-gdrive  { background: #e3f2fd; color: #1565c0; }
.badge-local   { background: #fff3e0; color: #e65100; }
.badge-web     { background: #fce4ec; color: #880e4f; }
.badge-upload  { background: #f3e5f5; color: #6a1b9a; }
.badge-internal{ background: #e8f5e9; color: #2e7d32; }

.result-path { font-size: 11px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── STATUS / MISC ─────────────────────────────── */
.kb-status { text-align: center; color: var(--text-muted); padding: 12px; font-size: 13px; }
.kb-status.error { color: var(--danger); }
.kb-status.success { color: var(--success); }

/* ── MODAL ─────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}

.modal {
  background: var(--surface);
  border-radius: 12px;
  width: 420px;
  max-width: 95vw;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

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

.modal-header h3 { font-size: 15px; }

.modal-close {
  background: none; border: none; color: #fff;
  font-size: 18px; cursor: pointer; line-height: 1;
}

.modal-body { padding: 20px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex; gap: 10px; justify-content: flex-end;
}

.form-label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.form-hint { font-size: 11px; color: var(--text-muted); }
.form-select, .form-input {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px; font-size: 13px;
  outline: none; transition: border-color 0.2s;
}
.form-select:focus, .form-input:focus { border-color: var(--primary); }

.kb-btn-primary {
  background: var(--primary); color: #fff;
  border: none; border-radius: 6px; padding: 8px 18px;
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.kb-btn-primary:hover { background: var(--primary-dark); }
.kb-btn-secondary {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 18px; font-size: 13px; cursor: pointer;
}
.kb-btn-secondary:hover { border-color: var(--primary); }

.section-header {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 0 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
  grid-column: 1 / -1;
}

/* ── ADMIN PANEL ───────────────────────────────── */
.admin-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}

.admin-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 4px;
}

.admin-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

.perm-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  font-size: 13px;
}

.perm-table thead tr {
  background: var(--primary);
  color: #fff;
}

.perm-table th {
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.perm-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.perm-table tbody tr:last-child td { border-bottom: none; }

.perm-table tbody tr:hover { background: var(--bg); }

.perm-folder-name {
  font-weight: 600;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.src-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
  white-space: nowrap;
}
.src-gdrive { background: #e3f2fd; color: #1565c0; }
.src-local  { background: #fff3e0; color: #e65100; }

.level-badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 10px;
  border-radius: 10px;
  font-weight: 600;
  white-space: nowrap;
}
.level-1 { background: #e8f5e9; color: #2e7d32; }
.level-2 { background: #e3f2fd; color: #1565c0; }
.level-3 { background: #fff3e0; color: #e65100; }
.level-4 { background: #fce4ec; color: #c62828; }

.row-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 5px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  margin-right: 4px;
}
.row-btn:hover { border-color: var(--primary); color: var(--primary); }
.btn-delete:hover { border-color: var(--danger); color: var(--danger); }

.text-muted { color: var(--text-muted); font-size: 12px; }

/* ── ADMIN TABS ────────────────────────────────── */
.admin-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 0;
}

.admin-tab {
  padding: 8px 18px;
  border: none;
  background: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s;
}

.admin-tab:hover { color: var(--primary); }
.admin-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── DEPT CHECKBOXES ───────────────────────────── */
.dept-checkbox-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  margin-top: 4px;
}

.dept-check-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
  padding: 2px 0;
}

.dept-check-item input { cursor: pointer; accent-color: var(--primary); }

/* ── USER SEARCH RESULTS ───────────────────────── */
.user-result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 4px;
  font-size: 13px;
  background: var(--surface);
}

/* ── SETTINGS CARD ─────────────────────────────── */
.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-top: 12px;
  box-shadow: var(--shadow);
}

.radio-group { display: flex; gap: 20px; flex-wrap: wrap; margin-top: 8px; }
.radio-item {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; cursor: pointer;
}
.radio-item input { cursor: pointer; accent-color: var(--primary); }

/* ── HIGHLIGHTS SECTION ─────────────────────────── */
.highlights-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.highlights-title {
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}

.highlights-feed {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

/* ── HIGHLIGHT CARD (novo design — Central de Conhecimento) ── */
.highlight-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  transition: box-shadow 0.2s, transform 0.2s;
  cursor: default;
}

.highlight-card:hover {
  box-shadow: 0 6px 20px rgba(57,73,160,0.13);
  transform: translateY(-2px);
}

/* ícone colorido no topo */
.hl-icon-box {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

/* bloco de texto */
.hl-content {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.hl-title {
  font-weight: 700;
  font-size: 14px;
  line-height: 1.35;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.hl-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* rodapé: link + data */
.hl-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
  gap: 8px;
}

.hl-link {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  cursor: pointer;
}

.hl-link:hover { text-decoration: underline; }

.hl-date {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* botão remover — aparece no hover */
.hl-remove-btn {
  position: absolute;
  top: 8px;
  right: 10px;
  background: rgba(0,0,0,0.07);
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 10px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all 0.15s;
  padding: 0;
}

.highlight-card:hover .hl-remove-btn {
  display: flex;
}

.hl-remove-btn:hover {
  background: var(--danger);
  color: #fff;
}

/* estado vazio */
.hl-empty {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 32px 16px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

/* ── ADMIN SOURCES GRID ──────────────────────────── */
.admin-section-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin: 20px 0 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.admin-section-title:first-child { margin-top: 0; }

.sources-grid-admin {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}

.source-card-admin {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: all 0.15s;
}

.source-card-admin:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.source-card-admin .source-icon {
  font-size: 22px;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.source-card-admin .source-name {
  font-weight: 600;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.source-card-admin .source-type {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: capitalize;
}

/* ── PERM USER LIST ─────────────────────────────── */
.perm-user-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 28px;
}

.perm-user-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: var(--bg);
  border-radius: 6px;
  font-size: 13px;
}

.perm-user-item .remove-user-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  padding: 0 2px;
  line-height: 1;
  transition: color 0.15s;
}

.perm-user-item .remove-user-btn:hover { color: var(--danger); }

/* ── USER PILL (tabela de permissões) ───────────── */
.user-pill {
  display: inline-block;
  background: #e8eaf6;
  color: var(--primary-dark);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  margin: 1px;
  white-space: nowrap;
}

/* ── HIGHLIGHT BUTTON (card de arquivo) ─────────── */
.file-card .highlight-btn {
  position: absolute;
  bottom: 5px;
  right: 5px;
  background: none;
  border: none;
  font-size: 13px;
  cursor: pointer;
  padding: 2px;
  display: none;
  opacity: 0.55;
  transition: opacity 0.15s, transform 0.15s;
  line-height: 1;
}

.file-card:hover .highlight-btn {
  display: block;
}

.file-card .highlight-btn:hover {
  opacity: 1;
  transform: scale(1.2);
}

/* list view: reposiciona botões sobrepostos */
.file-grid.list .file-card .highlight-btn,
.file-grid.grid-sm .file-card .highlight-btn {
  position: static;
  display: none;
  margin-left: auto;
}

.file-grid.list .file-card:hover .highlight-btn,
.file-grid.grid-sm .file-card:hover .highlight-btn {
  display: block;
}
