* { box-sizing: border-box; }
html, body {
  height: 100%;
  font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  margin: 0;
  background: #f5f6f8;
  color: #1a1a1a;
}
header {
  background: #1f2937;
  color: white;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
}
header h1 { margin: 0; font-size: 18px; }
.header-left { display: flex; align-items: center; gap: 24px; }
.logout-link { color: #cbd5e1; font-size: 13px; text-decoration: none; }

.main-nav { display: flex; gap: 4px; }
.nav-btn {
  background: none; border: none; color: #cbd5e1;
  padding: 7px 14px; border-radius: 6px; font-size: 13px; cursor: pointer;
}
.nav-btn:hover { background: rgba(255,255,255,0.08); }
.nav-btn.active { background: rgba(255,255,255,0.15); color: white; font-weight: 600; }

.view { display: none; }
.view.active { display: flex; }

#view-instituciones, #view-agenda {
  flex-direction: column;
  height: calc(100vh - 52px);
  padding: 24px 28px;
  overflow-y: auto;
}
.instituciones-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }

.agenda-view-toggle { display: flex; border: 1px solid #d0d5dd; border-radius: 6px; overflow: hidden; }
.agenda-toggle-btn { border: none; border-radius: 0; padding: 6px 12px; }
.agenda-toggle-btn.active { background: #2563eb; color: white; }
.agenda-filters { display: flex; gap: 16px; align-items: center; margin-bottom: 16px; font-size: 13px; color: #555; }
.agenda-filters select { padding: 5px 8px; border: 1px solid #d0d5dd; border-radius: 6px; font-size: 13px; }
.agenda-group-title { font-size: 12px; font-weight: 600; color: #888; margin: 20px 0 8px; text-transform: uppercase; letter-spacing: 0.04em; }
.agenda-group-title:first-child { margin-top: 0; }
.agenda-item {
  display: flex; align-items: flex-start; gap: 10px; background: white;
  border-radius: 8px; padding: 10px 14px; margin-bottom: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.agenda-item.done { opacity: 0.55; }
.agenda-item.done .agenda-item-title { text-decoration: line-through; }
.agenda-item input[type=checkbox] { margin-top: 3px; }
.agenda-item-badge { font-size: 11px; padding: 2px 7px; border-radius: 4px; white-space: nowrap; }
.agenda-item-title { font-weight: 600; font-size: 14px; margin-top: 4px; }
.agenda-item-meta { font-size: 12px; color: #888; margin-top: 2px; }
.agenda-item-actions { margin-left: auto; flex-shrink: 0; }

.agenda-type-examen { background: #fee2e2; color: #991b1b; }
.agenda-type-entrega { background: #fef3c7; color: #92400e; }
.agenda-type-estudio { background: #dbeafe; color: #1e40af; }
.agenda-type-otro { background: #f3f4f6; color: #4b5563; }

.agenda-cal-header { display: flex; align-items: center; justify-content: center; gap: 16px; margin-bottom: 14px; font-size: 15px; }
.agenda-cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.agenda-cal-dow { font-size: 11px; color: #999; text-align: center; text-transform: uppercase; padding-bottom: 4px; }
.agenda-cal-day {
  min-height: 84px; background: white; border-radius: 6px; padding: 4px 6px;
  font-size: 12px; box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.agenda-cal-day.today { box-shadow: inset 0 0 0 2px #2563eb; }
.agenda-cal-day.empty { background: transparent; box-shadow: none; }
.agenda-cal-day-num { font-weight: 600; color: #555; margin-bottom: 4px; }
.agenda-cal-event {
  font-size: 10px; padding: 1px 4px; border-radius: 3px; margin-bottom: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer;
}
.schedule-table { border-collapse: collapse; width: 100%; min-width: 640px; font-size: 12px; }
.schedule-table th { padding: 6px 4px; color: #888; font-weight: 600; text-align: center; }
.schedule-hour-label { color: #999; padding: 4px 8px; white-space: nowrap; text-align: right; }
.schedule-cell {
  border: 1px solid #eee; height: 30px; width: 90px; text-align: center;
  cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 4px;
}
.schedule-cell:hover { background: #f8fafc; }
.schedule-cell.busy { background: #dbeafe; color: #1e40af; font-weight: 600; }
.schedule-cell.busy:hover { background: #bfdbfe; }
.institution-card {
  background: white; border-radius: 8px; padding: 14px 18px;
  margin-bottom: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
}
.institution-card .inst-info { font-size: 13px; color: #555; line-height: 1.6; }
.institution-card .inst-info strong { font-size: 15px; color: #111; display: block; margin-bottom: 4px; }
.institution-card .inst-actions { display: flex; gap: 6px; flex-shrink: 0; }

.institution-card-wrap { margin-bottom: 12px; }
.institution-card-wrap .institution-card { margin-bottom: 0; border-radius: 8px 8px 0 0; }
.materias-panel {
  background: #fafafa; border: 1px solid #eee; border-top: none;
  border-radius: 0 0 8px 8px; padding: 10px 18px 14px 30px;
}
.org-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 0; font-size: 13px; border-bottom: 1px solid #f0f0f0;
}
.org-row:last-child { border-bottom: none; }
.org-row-nested { margin-left: 18px; }
.org-row .org-name { color: #333; }
.org-row-actions { display: flex; gap: 4px; }
.org-row-actions button, .org-add-btn { padding: 3px 8px; font-size: 12px; }
.unidades-panel { background: #f3f3f3; border-radius: 6px; margin: 2px 0 6px; padding: 4px 8px; }

.layout {
  /* el display lo controla .view/.view.active — acá solo el alto,
     para no pisar el display:none cuando esta vista no está activa */
  height: calc(100vh - 52px);
}

aside {
  width: 300px;
  min-width: 300px;
  background: white;
  border-right: 1px solid #e5e7eb;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}
.side-block {
  border-bottom: 1px solid #eee;
  padding-bottom: 16px;
}
.side-block:last-child { border-bottom: none; }
aside input[type=text], aside select {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid #d0d5dd;
  border-radius: 6px;
  font-size: 13px;
}

main {
  flex: 1;
  padding: 20px 28px;
  overflow-y: auto;
}
.empty-state {
  color: #999;
  text-align: center;
  margin-top: 80px;
  font-size: 14px;
}
#results { max-width: 1100px; }
.tab-content { flex: 1; overflow-y: auto; }

.card {
  background: white;
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
#status-line { color: #555; margin-top: 8px; min-height: 1.2em; font-size: 13px; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-box {
  background: white; border-radius: 10px; padding: 20px;
  width: 480px; max-width: 90vw;
  max-height: 85vh; overflow-y: auto;
}
.drive-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 4px; cursor: pointer; border-bottom: 1px solid #f0f0f0;
  font-size: 14px;
}
.drive-item:hover { background: #f8fafc; }
.drive-crumb { cursor: pointer; color: #2563eb; }
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid #ddd;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.tab-btn {
  background: none;
  border: none;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 14px;
  border-bottom: 2px solid transparent;
}
.tab-btn.active { border-bottom-color: #2563eb; font-weight: 600; color: #2563eb; }
.tab-panel { display: none; white-space: pre-wrap; line-height: 1.5; }
.tab-panel.active { display: block; }
button {
  cursor: pointer;
  border: 1px solid #d0d5dd;
  background: white;
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 13px;
}
button.primary { background: #2563eb; color: white; border-color: #2563eb; }
button:hover { filter: brightness(0.97); }
.icon-btn { padding: 5px 8px; font-size: 15px; line-height: 1; }
.material-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid #eee; }
.material-row .material-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.material-row .material-actions { display: flex; gap: 4px; flex-shrink: 0; white-space: nowrap; }
.plan-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.plan-row input[type=text] { flex: 1; padding: 6px 8px; border: 1px solid #d0d5dd; border-radius: 6px; }
.plan-toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
#chat-log { min-height: 240px; max-height: 420px; overflow-y: auto; border: 1px solid #eee; border-radius: 6px; padding: 10px; margin-bottom: 8px; }
.msg-user { color: #111; margin: 6px 0; }
.msg-ai { color: #1d4ed8; margin: 6px 0; }
.tool-proposal { background: #fffbeb; border: 1px solid #f5d90a55; border-radius: 6px; padding: 8px 10px; margin: 6px 0; }
.chat-input-row { display: flex; gap: 8px; }
.chat-input-row input { flex: 1; padding: 8px; border: 1px solid #d0d5dd; border-radius: 6px; }

.flashcard {
  position: relative;
  min-height: 120px;
  border: 1px solid #e0e0e0;
  border-radius: 10px;
  padding: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: white;
  transition: background 0.15s;
}
.flashcard:hover { background: #f8fafc; }
.flashcard.flipped { background: #eff6ff; border-color: #93c5fd; }
.flashcard .label { font-size: 11px; text-transform: uppercase; color: #999; position: absolute; margin-top: -70px; }
.flashcard .content { font-size: 14px; line-height: 1.4; }
.flashcard-actions { position: absolute; top: 6px; right: 6px; display: flex; gap: 2px; }
.flashcard-edit-form { display: flex; flex-direction: column; gap: 6px; width: 100%; cursor: default; }
.flashcard-edit-form textarea { width: 100%; box-sizing: border-box; font-size: 13px; padding: 6px; border: 1px solid #d0d5dd; border-radius: 6px; resize: vertical; min-height: 50px; font-family: inherit; }

.session-tag {
  display: inline-block;
  font-size: 11px;
  background: #eef2ff;
  color: #3730a3;
  border-radius: 4px;
  padding: 1px 6px;
  margin-right: 4px;
  margin-bottom: 2px;
}
