* { box-sizing: border-box; }

/* ── Variables de tema ── */
:root {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-item: #334155;
  --bg-item-hover: #3d4d63;
  --bg-input: #0f172a;
  --border: #475569;
  --border-light: #334155;
  --border-divider: #283548;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --shadow: rgba(0,0,0,0.5);
  --overlay: rgba(0,0,0,0.6);
}

[data-theme="light"] {
  --bg: #f1f5f9;
  --bg-card: #ffffff;
  --bg-item: #e2e8f0;
  --bg-item-hover: #cbd5e1;
  --bg-input: #ffffff;
  --border: #cbd5e1;
  --border-light: #e2e8f0;
  --border-divider: #cbd5e1;
  --text: #1e293b;
  --text-muted: #475569;
  --text-dim: #64748b;
  --shadow: rgba(0,0,0,0.15);
  --overlay: rgba(0,0,0,0.3);
}

body {
  margin: 0; font-family: system-ui, sans-serif;
  background: var(--bg); color: var(--text);
  transition: background 0.3s, color 0.3s;
}
body.auth { display: grid; place-items: center; min-height: 100vh; }
.card { background: var(--bg-card); padding: 2rem; border-radius: 12px; display: grid; gap: 1rem; width: 320px; }
label { display: grid; gap: .25rem; }
input { padding: .5rem; border-radius: 6px; border: 1px solid var(--border); background: var(--bg-input); color: inherit; }
button { padding: .6rem; border: 0; border-radius: 6px; background: #3b82f6; color: white; cursor: pointer; transition: background 0.2s; }
button:hover { background: #2563eb; }
.error { color: #f87171; }

/* Header */
header { display: flex; justify-content: space-between; align-items: center; padding: 1rem; }
#meta { display: flex; gap: 1rem; align-items: center; }
#streak { font-weight: bold; }

/* Theme toggle */
.theme-toggle {
  background: var(--bg-item); border: 1px solid var(--border); border-radius: 8px;
  padding: .35rem .55rem; cursor: pointer; font-size: 1.1rem; line-height: 1;
  color: var(--text); transition: background 0.2s;
}
.theme-toggle:hover { background: var(--bg-item-hover); }

/* Toast */
#toast {
  position: fixed; top: 1rem; right: 1rem; z-index: 1000;
  background: var(--bg-card); color: var(--text); padding: .75rem 1.25rem;
  border-radius: 8px; border-left: 4px solid #22c55e;
  opacity: 0; transform: translateX(120%); transition: all 0.3s ease;
  max-width: 300px; font-size: .9rem;
}
#toast.show { opacity: 1; transform: translateX(0); }
#toast.warn { border-left-color: #eab308; }
#toast.error { border-left-color: #ef4444; }

/* Quick add */
.quick-add { display: flex; gap: .5rem; padding: 0 1rem 1rem; flex-wrap: wrap; }
.quick-add input { flex: 1; min-width: 150px; }
.quick-add select {
  padding: .5rem; border-radius: 6px; border: 1px solid var(--border);
  background: var(--bg-input); color: inherit; font-size: .85rem;
}

/* Matrix */
.matrix { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; padding: 0 1rem; }
.quadrant { background: var(--bg-card); border-radius: 12px; padding: 1rem; min-height: 200px; }
.quadrant h2 { font-size: 1rem; margin-top: 0; }
.quadrant ul { list-style: none; padding: 0; }
.quadrant li {
  background: var(--bg-item); padding: .5rem .75rem; border-radius: 6px; margin-bottom: .5rem;
  display: flex; justify-content: space-between; gap: .5rem; align-items: center;
  transition: background 0.2s;
}
.quadrant li:hover { background: var(--bg-item-hover); }
.empty-hint { color: var(--text-dim); font-size: .8rem; font-style: italic; margin: .5rem 0; }

/* Quadrant colors */
.quadrant[data-q="1"] { border-top: 4px solid #ef4444; }
.quadrant[data-q="2"] { border-top: 4px solid #22c55e; }
.quadrant[data-q="3"] { border-top: 4px solid #eab308; }
.quadrant[data-q="4"] { border-top: 4px solid #6b7280; }

/* Task actions */
select, .task-actions button { padding: .25rem .5rem; font-size: .8rem; border: 0; border-radius: 4px; }
.task-actions { display: flex; gap: .25rem; }
.task-actions select { background: var(--border); color: white; }
.btn-done { background: #16a34a; color: white; cursor: pointer; }
.btn-done:hover { background: #15803d; }
.btn-del { background: #dc2626; color: white; cursor: pointer; }
.btn-del:hover { background: #b91c1c; }
.btn-details { background: #6366f1; color: white; cursor: pointer; }
.btn-details:hover { background: #4f46e5; }
.task-title { flex: 1; }

/* Alerts */
#alerts { padding: 0 1rem; }
.alert { background: #fef2f2; color: #991b1b; padding: .5rem; border-radius: 6px; margin-bottom: .5rem; font-size: .85rem; }

/* Stats */
#stats { padding: 1rem; font-size: .85rem; color: var(--text-muted); }

@media (max-width: 600px) {
  .matrix { grid-template-columns: 1fr; }
  .quick-add { flex-wrap: wrap; }
}

/* Historial */
#history-section { margin: 0 1rem 2rem; background: var(--bg-card); border-radius: 12px; overflow: hidden; }
.history-header {
  display: flex; align-items: center; gap: .5rem;
  padding: 1rem; cursor: pointer; user-select: none;
  transition: background 0.2s;
}
.history-header:hover { background: var(--bg-item-hover); }
.history-header h2 { font-size: 1rem; margin: 0; flex: 1; }
.badge {
  background: var(--bg-item); color: var(--text); border-radius: 999px;
  padding: .15rem .6rem; font-size: .8rem; font-weight: bold;
}
.arrow { color: var(--text-dim); font-size: .8rem; transition: transform 0.2s; }
.hidden { display: none !important; }

.history-list {
  list-style: none; padding: 0; margin: 0;
  max-height: 400px; overflow-y: auto; border-top: 1px solid var(--border-light);
}
.history-item {
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem 1rem; border-bottom: 1px solid var(--border-divider);
}
.history-item:last-child { border-bottom: none; }
.history-item.done { border-left: 3px solid #22c55e; }
.history-item.deleted { border-left: 3px solid #6b7280; }
.history-icon { font-size: 1.1rem; flex-shrink: 0; }
.history-info { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.history-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-meta { font-size: .75rem; color: var(--text-dim); }
.history-empty { padding: 1rem; text-align: center; color: var(--text-dim); font-style: italic; }

/* Modal */
.modal-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: var(--overlay); z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn 0.2s ease;
}
.modal {
  background: var(--bg-card); border-radius: 12px; width: 90%; max-width: 600px;
  max-height: 85vh; overflow-y: auto; box-shadow: 0 25px 50px var(--shadow);
  animation: slideUp 0.3s ease;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1.25rem; border-bottom: 1px solid var(--border-light); position: sticky; top: 0;
  background: var(--bg-card); z-index: 1;
}
.modal-header h2 { font-size: 1.1rem; margin: 0; }
.modal-close {
  background: var(--bg-item); border: 0; border-radius: 6px; padding: .4rem .6rem;
  color: var(--text); cursor: pointer; font-size: 1rem;
}
.modal-close:hover { background: #dc2626; color: white; }
.modal-body { padding: 1.25rem; }
.modal-label { font-weight: 600; font-size: .9rem; margin-bottom: .5rem; display: block; color: var(--text-muted); }
.modal-body textarea {
  width: 100%; padding: .75rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-input); color: var(--text); font-family: inherit; font-size: .9rem; resize: vertical;
}
.modal-body textarea:focus { outline: none; border-color: #3b82f6; }
.btn-save-notes {
  margin-top: .5rem; padding: .5rem 1rem; background: #3b82f6; color: white;
  border: 0; border-radius: 6px; cursor: pointer; font-size: .85rem;
}
.btn-save-notes:hover { background: #2563eb; }
.modal-divider { height: 1px; background: var(--border-light); margin: 1.5rem 0; }

/* Attachments */
.attachments-list { display: flex; flex-direction: column; gap: .5rem; margin-bottom: .75rem; }
.attachment-item {
  display: flex; align-items: center; gap: .5rem; padding: .5rem .75rem;
  background: var(--bg-item); border-radius: 6px; font-size: .85rem;
}
.attachment-item:hover { background: var(--bg-item-hover); }
.attachment-icon { font-size: 1.1rem; }
.attachment-info { flex: 1; min-width: 0; }
.attachment-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-meta { font-size: .7rem; color: var(--text-dim); }
.attachment-actions { display: flex; gap: .25rem; }
.attachment-actions a {
  padding: .25rem .5rem; background: var(--border); border-radius: 4px; color: white;
  text-decoration: none; font-size: .75rem; cursor: pointer;
}
.attachment-actions a:hover { background: #3b82f6; }
.attachment-actions button {
  padding: .25rem .5rem; background: #dc2626; color: white; border: 0;
  border-radius: 4px; cursor: pointer; font-size: .75rem;
}
.attachment-actions button:hover { background: #b91c1c; }

/* Upload zone */
.upload-zone {
  display: flex; align-items: center; justify-content: center; gap: .5rem;
  padding: 1.25rem; border: 2px dashed var(--border); border-radius: 8px;
  cursor: pointer; transition: border-color 0.2s, background 0.2s; font-size: .85rem; color: var(--text-dim);
}
.upload-zone:hover { border-color: #3b82f6; background: var(--bg-card); color: var(--text); }
.upload-zone.dragover { border-color: #22c55e; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Toolbar */
.toolbar { display: flex; gap: .5rem; padding: 0 1rem .75rem; align-items: center; flex-wrap: wrap; }
.search-bar {
  flex: 1; min-width: 200px; padding: .5rem; border-radius: 6px;
  border: 1px solid var(--border); background: var(--bg-input); color: inherit;
}
.filter-select {
  padding: .5rem; border-radius: 6px; border: 1px solid var(--border);
  background: var(--bg-input); color: inherit; font-size: .85rem;
}
.export-buttons { display: flex; gap: .25rem; }
.btn-export {
  padding: .5rem .75rem; background: var(--bg-item); color: var(--text); border: 0;
  border-radius: 6px; cursor: pointer; font-size: .8rem; transition: background 0.2s;
}
.btn-export:hover { background: var(--bg-item-hover); }

/* Quick add extras */
.quick-add input[type="date"], .quick-add select { font-size: .85rem; }

/* Inline edit */
.edit-inline-input {
  flex: 1; padding: .25rem .5rem; border-radius: 4px;
  border: 1px solid #3b82f6; background: var(--bg-input); color: var(--text); font-family: inherit; font-size: inherit;
}

/* Date badges */
.date-badge { font-size: .7rem; padding: .1rem .35rem; border-radius: 4px; margin-left: .25rem; }
.date-normal { background: var(--bg-item); color: var(--text-muted); }
.date-soon { background: #fef3c7; color: #92400e; }
.date-overdue { background: #fee2e2; color: #991b1b; }
.rec-badge { font-size: .7rem; margin-left: .1rem; }

/* Modal date row */
.modal-date-row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.modal-date-input, .modal-recurrence-input {
  padding: .5rem; border-radius: 6px; border: 1px solid var(--border);
  background: var(--bg-input); color: inherit; font-size: .85rem;
}
.btn-save-date {
  padding: .5rem 1rem; background: #3b82f6; color: white;
  border: 0; border-radius: 6px; cursor: pointer; font-size: .85rem;
}
.btn-save-date:hover { background: #2563eb; }

/* Tags */
.tag-badge {
  font-size: .65rem; padding: .1rem .4rem; border-radius: 4px;
  color: white; margin-left: .25rem; font-weight: 500; white-space: nowrap;
}
.tag-input {
  width: 120px; padding: .5rem; border-radius: 6px;
  border: 1px solid var(--border); background: var(--bg-input); color: inherit; font-size: .85rem;
}
.tag-color-picker {
  width: 40px; height: 36px; border: 1px solid var(--border);
  border-radius: 6px; background: transparent; cursor: pointer; padding: 2px;
}

/* ── Cajón "Por asignar" ── */
.inbox-section { margin: 1.2rem 1rem 0; }
.inbox-header { display: flex; align-items: center; gap: .5rem; }
.inbox-hint { font-size: .75rem; color: var(--text-muted); font-weight: 400; }
.inbox-list { list-style: none; padding: 0; margin: .5rem 0 0; display: flex; flex-direction: column; gap: .4rem; }
.inbox-item {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  background: var(--bg-item); border: 1px dashed var(--border);
  border-radius: 8px; padding: .5rem .6rem; flex-wrap: wrap;
}
.inbox-info { flex: 1; min-width: 160px; display: flex; flex-direction: column; gap: .1rem; }
.inbox-meta { font-size: .72rem; color: var(--text-muted); }
.btn-assign {
  background: #2563eb; color: white; cursor: pointer;
  padding: .3rem .6rem; font-size: .8rem; border: 0; border-radius: 5px; white-space: nowrap;
}
.btn-assign:hover { background: #1d4ed8; }
@media (max-width: 640px) {
  .inbox-item { flex-direction: column; align-items: flex-start; }
  .inbox-item .task-actions { width: 100%; justify-content: flex-start; flex-wrap: wrap; }
}

/* ── Aviso (correo del colegio que solo apunta al intranet) ── */
.aviso-badge {
  align-self: flex-start;
  background: #f59e0b22; color: #d97706;
  border: 1px solid #d9770655;
  font-size: .65rem; font-weight: 600; padding: .08rem .4rem; border-radius: 999px;
  margin-bottom: .15rem; width: fit-content;
}
[data-theme="dark"] .aviso-badge { color: #fbbf24; background: #f59e0b33; border-color: #f59e0b55; }
.inbox-aviso { border-style: solid; border-color: #d9770655; }
.inbox-link {
  font-size: .72rem; color: #2563eb; text-decoration: none; margin-top: .15rem; width: fit-content;
}
.inbox-link:hover { text-decoration: underline; }
[data-theme="dark"] .inbox-link { color: #60a5fa; }
