/* =================================================================
   MUNDO MACÍAS · PLANNER  —  styles.css
   Sistema de diseño minimalista, profesional y motivador.
   Soporta modo claro y oscuro mediante el atributo [data-theme].
   ================================================================= */

/* ---------- 1. Tokens de diseño / variables CSS ---------- */
:root {
  /* Tipografía */
  --font-display: "Sora", system-ui, -apple-system, sans-serif;
  --font-body: "DM Sans", system-ui, -apple-system, sans-serif;

  /* Acento (configurable desde Ajustes) */
  --accent: #1fb98c;
  --accent-soft: rgba(31, 185, 140, 0.14);

  /* Radios y sombras */
  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.10);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.22);

  /* Estados */
  --ok: #1fb98c;
  --late: #f0a92b;
  --bad: #e2574c;
  --pend: #7b86a3;
  --resched: #5b8def;
  --cancel: #9aa3b2;

  /* Prioridades */
  --p-alta: #e2574c;
  --p-media: #f0a92b;
  --p-baja: #5b8def;
}

/* Tema oscuro (por defecto) */
[data-theme="dark"] {
  --bg: #0e1218;
  --bg-2: #141a23;
  --surface: #171e29;
  --surface-2: #1d2632;
  --border: #28323f;
  --border-soft: #212b37;
  --text: #eef2f7;
  --text-dim: #9aa6b6;
  --text-faint: #677082;
  --hover: #1f2934;
}

/* Tema claro */
[data-theme="light"] {
  --bg: #f3f5f8;
  --bg-2: #eaeef3;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --border: #e2e8f0;
  --border-soft: #edf1f6;
  --text: #131a24;
  --text-dim: #5a6675;
  --text-faint: #97a2b1;
  --hover: #f0f3f7;
}

/* ---------- 2. Reset y base ---------- */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
}

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 700; line-height: 1.2; }

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
input, select, textarea { outline: none; }
ul { list-style: none; }
a { color: var(--accent); }

[hidden] { display: none !important; }

/* ---------- 3. Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: var(--r-md); font-weight: 600; font-size: 14px;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #06231b; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: transparent; color: var(--text-dim); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--hover); color: var(--text); }
.btn-soft { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-soft:hover { background: var(--hover); }
.btn-danger { background: transparent; color: var(--bad); border: 1px solid var(--border); }
.btn-danger:hover { background: rgba(226, 87, 76, .12); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 11px; font-size: 13px; }

.icon-btn {
  width: 38px; height: 38px; border-radius: var(--r-md); color: var(--text-dim);
  display: inline-flex; align-items: center; justify-content: center; font-size: 18px;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }

/* ---------- 4. Logo ---------- */
.logo-mark {
  width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 800; font-size: 18px; letter-spacing: -.5px;
  color: #06231b;
  background: linear-gradient(135deg, var(--accent), #14d4a0);
  box-shadow: var(--shadow-sm);
}
.logo-mark.sm { width: 34px; height: 34px; font-size: 14px; border-radius: 10px; }

/* ---------- 5. Pantalla de autenticación ---------- */
.auth-screen {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(900px 500px at 15% -10%, var(--accent-soft), transparent 60%),
    radial-gradient(700px 500px at 110% 110%, rgba(91,141,239,.10), transparent 55%),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 30px; box-shadow: var(--shadow-lg);
}
.auth-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.auth-title { font-size: 22px; }
.auth-sub { color: var(--text-dim); font-size: 13px; }
.auth-tabs { display: flex; background: var(--surface-2); border-radius: var(--r-md); padding: 4px; margin-bottom: 20px; }
.auth-tab { flex: 1; padding: 9px; border-radius: 10px; font-weight: 600; color: var(--text-dim); font-size: 14px; }
.auth-tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-error { background: rgba(226,87,76,.12); color: var(--bad); padding: 10px 12px; border-radius: var(--r-sm); font-size: 13px; }
.auth-warning {
  margin-top: 18px; font-size: 12px; color: var(--text-dim); line-height: 1.5;
  background: var(--surface-2); padding: 12px 14px; border-radius: var(--r-sm); border: 1px solid var(--border-soft);
}

/* Campos de formulario */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--text-dim); }
.field input, .field select, .field textarea {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 10px 12px; color: var(--text); transition: border-color .15s ease;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { resize: vertical; min-height: 70px; }

/* ---------- 6. Layout principal ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 248px; flex-shrink: 0; background: var(--bg-2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 14px; position: sticky; top: 0; height: 100vh;
}
.sidebar-head { display: flex; align-items: center; gap: 10px; padding: 6px 8px 16px; }
.sidebar-title { font-family: var(--font-display); font-weight: 700; font-size: 16px; }
.sidebar-close { display: none; margin-left: auto; }

.nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: var(--r-md);
  color: var(--text-dim); font-weight: 500; font-size: 14px; text-align: left; width: 100%;
  transition: background .12s ease, color .12s ease;
}
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .ni { width: 20px; text-align: center; font-size: 15px; }

.sidebar-foot { display: flex; flex-direction: column; gap: 3px; border-top: 1px solid var(--border-soft); padding-top: 10px; }
.sidebar-version { font-size: 11px; color: var(--text-faint); padding: 6px 12px 0; }
.sidebar-backdrop { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 14px; padding: 14px 24px;
  border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg);
  z-index: 20; backdrop-filter: blur(6px);
}
.menu-btn { display: none; }
.topbar-titles { flex: 1; min-width: 0; }
.view-title { font-size: 20px; }
.view-sub { font-size: 13px; color: var(--text-dim); }
.topbar-actions { display: flex; gap: 8px; }

.view-root { padding: 24px; max-width: 1280px; width: 100%; margin: 0 auto; }

/* ---------- 7. Tarjetas y rejillas ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 18px; box-shadow: var(--shadow-sm);
}
.card-title { font-size: 15px; margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.grid { display: grid; gap: 16px; }
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.section-gap { margin-top: 20px; }

/* KPI / métricas */
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 16px; box-shadow: var(--shadow-sm); }
.kpi-label { font-size: 12px; color: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-family: var(--font-display); font-size: 30px; font-weight: 700; margin-top: 6px; }
.kpi-foot { font-size: 12px; color: var(--text-faint); margin-top: 4px; }
.kpi-value.accent { color: var(--accent); }

/* Barra de progreso */
.progress { height: 9px; border-radius: var(--r-pill); background: var(--surface-2); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--accent); border-radius: inherit; transition: width .4s ease; }

/* ---------- 8. Etiquetas (categoría, prioridad, estado) ---------- */
.tag { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: var(--r-pill); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

.status { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: var(--r-pill); }
.status.a_tiempo { background: rgba(31,185,140,.16); color: var(--ok); }
.status.tarde { background: rgba(240,169,43,.16); color: var(--late); }
.status.no_completada { background: rgba(226,87,76,.16); color: var(--bad); }
.status.pendiente { background: rgba(123,134,163,.18); color: var(--pend); }
.status.reprogramada { background: rgba(91,141,239,.16); color: var(--resched); }
.status.cancelada { background: rgba(154,163,178,.16); color: var(--cancel); text-decoration: line-through; }

/* ---------- 9. Vista semanal (calendario) ---------- */
.week-toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.week-toolbar .spacer { flex: 1; }
.week-grid { display: grid; grid-template-columns: repeat(7, minmax(150px, 1fr)); gap: 10px; overflow-x: auto; padding-bottom: 8px; }
.day-col {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  min-height: 220px; display: flex; flex-direction: column;
}
.day-col.is-today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.day-col.drag-over { border-color: var(--accent); background: var(--accent-soft); }
.day-head { padding: 10px 12px; border-bottom: 1px solid var(--border-soft); display: flex; align-items: center; justify-content: space-between; }
.day-name { font-weight: 700; font-size: 13px; font-family: var(--font-display); }
.day-date { font-size: 11px; color: var(--text-faint); }
.day-overload { font-size: 10px; color: var(--late); font-weight: 700; }
.day-tasks { padding: 8px; display: flex; flex-direction: column; gap: 7px; flex: 1; }
.day-add { margin: 0 8px 8px; color: var(--text-faint); font-size: 12px; padding: 6px; border: 1px dashed var(--border); border-radius: var(--r-sm); }
.day-add:hover { color: var(--accent); border-color: var(--accent); }

/* Tarjeta de tarea */
.task {
  background: var(--surface-2); border: 1px solid var(--border-soft); border-left: 3px solid var(--accent);
  border-radius: var(--r-sm); padding: 8px 10px; cursor: grab; position: relative;
  transition: transform .08s ease, box-shadow .12s ease;
}
.task:hover { box-shadow: var(--shadow-sm); }
.task.dragging { opacity: .5; }
.task.done { opacity: .62; }
.task.done .task-title { text-decoration: line-through; }
.task-time { font-size: 10.5px; color: var(--text-faint); font-weight: 600; }
.task-title { font-size: 13px; font-weight: 600; margin: 1px 0 4px; }
.task-meta { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.task-check { position: absolute; top: 8px; right: 8px; width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border); display: grid; place-items: center; font-size: 12px; color: transparent; }
.task-check:hover { border-color: var(--accent); }
.task.done .task-check { background: var(--accent); border-color: var(--accent); color: #06231b; }

/* ---------- 10. Vista diaria (timeline) ---------- */
.day-view-head { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.timeline { display: flex; flex-direction: column; gap: 8px; }
.tl-row { display: grid; grid-template-columns: 64px 1fr; gap: 12px; }
.tl-time { font-size: 12px; color: var(--text-faint); text-align: right; padding-top: 12px; font-weight: 600; }
.tl-task { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: var(--r-md); padding: 12px 14px; display: flex; gap: 10px; align-items: flex-start; }
.tl-task .tl-body { flex: 1; }
.tl-task h4 { font-size: 14px; margin-bottom: 3px; }
.tl-task p { font-size: 12.5px; color: var(--text-dim); }

/* ---------- 11. Vista mensual / heatmap ---------- */
.month-toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.month-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.month-dow { text-align: center; font-size: 11px; font-weight: 700; color: var(--text-faint); padding: 4px; text-transform: uppercase; }
.month-cell { aspect-ratio: 1 / 1; border-radius: var(--r-sm); border: 1px solid var(--border-soft); padding: 6px; display: flex; flex-direction: column; justify-content: space-between; cursor: pointer; transition: transform .08s ease; min-height: 56px; }
.month-cell:hover { transform: translateY(-2px); border-color: var(--accent); }
.month-cell.empty { background: transparent; border: none; cursor: default; }
.month-cell .mc-day { font-size: 12px; font-weight: 700; }
.month-cell .mc-info { font-size: 10px; color: var(--text-faint); }
.heat-0 { background: var(--surface); }
.heat-1 { background: rgba(31,185,140,.18); }
.heat-2 { background: rgba(31,185,140,.38); }
.heat-3 { background: rgba(31,185,140,.62); }
.heat-4 { background: rgba(31,185,140,.92); color: #06231b; }
.heat-4 .mc-info { color: #06231b; }
.heat-legend { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-dim); margin-top: 12px; }
.heat-legend i { width: 16px; height: 16px; border-radius: 4px; display: inline-block; }

/* ---------- 12. Charts (canvas) ---------- */
.chart-wrap { position: relative; width: 100%; }
canvas.chart { width: 100%; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; font-size: 12px; color: var(--text-dim); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- 13. Listas (pendientes, objetivos, plantillas) ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.list-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: 14px 16px; display: flex; gap: 12px; align-items: center; }
.list-item .li-body { flex: 1; min-width: 0; }
.list-item h4 { font-size: 14px; margin-bottom: 3px; }
.list-item p { font-size: 12.5px; color: var(--text-dim); }
.li-actions { display: flex; gap: 6px; }

.empty-state { text-align: center; padding: 50px 20px; color: var(--text-dim); }
.empty-state .es-icon { font-size: 40px; opacity: .4; margin-bottom: 10px; }

/* Checklist dentro de tarea */
.checklist { display: flex; flex-direction: column; gap: 6px; }
.check-row { display: flex; align-items: center; gap: 8px; }
.check-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
.check-row span.done { text-decoration: line-through; color: var(--text-faint); }

/* ---------- 14. Modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(4,8,12,.55); display: grid; place-items: center; padding: 18px; z-index: 100; animation: fade .15s ease; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); width: 100%; max-width: 560px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: var(--shadow-lg); animation: pop .18s ease; }
.modal-head { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { font-size: 17px; }
.modal-body { padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }

/* ---------- 15. Toasts ---------- */
.toast-root { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent); padding: 12px 16px; border-radius: var(--r-md); box-shadow: var(--shadow-md); font-size: 13.5px; font-weight: 500; animation: slidein .2s ease; max-width: 320px; }
.toast.warn { border-left-color: var(--late); }
.toast.error { border-left-color: var(--bad); }
@keyframes slidein { from { opacity: 0; transform: translateX(30px); } }

/* Aviso de sobrecarga */
.overload-banner { background: rgba(240,169,43,.12); border: 1px solid rgba(240,169,43,.35); color: var(--late); padding: 12px 16px; border-radius: var(--r-md); font-size: 13.5px; font-weight: 600; margin-bottom: 16px; display: flex; gap: 8px; align-items: center; }

/* Chips de selección (días de la semana, colores) */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 6px 12px; border-radius: var(--r-pill); border: 1px solid var(--border); font-size: 12.5px; font-weight: 600; color: var(--text-dim); }
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.swatch.active { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg); }

.muted { color: var(--text-dim); }
.small { font-size: 12.5px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.flex-gap { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- 16. Responsive ---------- */
@media (max-width: 900px) {
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 60; transform: translateX(-100%);
    transition: transform .25s ease; height: 100vh; box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: inline-flex; }
  .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 55; opacity: 0; pointer-events: none; transition: opacity .25s ease; }
  .sidebar-backdrop.show { opacity: 1; pointer-events: auto; }
  .menu-btn { display: inline-flex; }
  .view-root { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .topbar-actions .btn-ghost { display: none; }
}

@media (max-width: 560px) {
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .grid-stats { grid-template-columns: 1fr 1fr; }
  .kpi-value { font-size: 24px; }
  .view-title { font-size: 17px; }
  .week-grid { grid-template-columns: repeat(7, 78vw); }
}

/* ---------- 17. Estilos de impresión (Exportar a PDF) ---------- */
@media print {
  .sidebar, .topbar, .sidebar-backdrop, .toast-root, .day-add, .task-check, .li-actions { display: none !important; }
  body, .app, .main { background: #fff; color: #000; display: block; }
  .view-root { max-width: 100%; padding: 0; }
  .card, .kpi { break-inside: avoid; border-color: #ccc; box-shadow: none; }
}
