:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --bg: #f8fafc;
  --bg-card: #ffffff;
  --bg-hover: #f1f5f9;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 25px rgba(0,0,0,.1), 0 4px 10px rgba(0,0,0,.05);
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-hover: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #334155;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
  --shadow-lg: 0 10px 25px rgba(0,0,0,.5);
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

.hidden { display: none !important; }

/* LOGIN */
.login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  padding: 20px;
  z-index: 100;
}
.login-box {
  background: var(--bg-card);
  padding: 40px 30px;
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 380px;
  text-align: center;
}
.login-box .logo { font-size: 56px; margin-bottom: 10px; }
.login-box h1 { font-size: 26px; margin-bottom: 8px; }
.login-box .subtitle { color: var(--text-muted); margin-bottom: 24px; }
.login-box input {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: 10px;
  font-size: 18px;
  background: var(--bg);
  color: var(--text);
  text-align: center;
  letter-spacing: 4px;
  margin-bottom: 12px;
}
.login-box input:focus { outline: none; border-color: var(--primary); }
.login-box .hint { margin-top: 18px; color: var(--text-muted); font-size: 12px; }
.error-msg { color: var(--danger); font-size: 14px; min-height: 20px; margin-top: 8px; }

/* APP */
.app { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }

.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-top) + 14px) 16px 14px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header h1 { font-size: 18px; font-weight: 700; }
.header-actions { display: flex; gap: 4px; }
.sync-status { font-size: 10px; color: var(--text-muted); transition: color .3s; }
.sync-status.online { color: var(--success); }
.sync-status.offline { color: var(--warning); }
.sync-status.syncing { color: var(--primary); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .4; } }

.icon-btn {
  background: none; border: none;
  width: 38px; height: 38px;
  font-size: 18px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text);
  transition: background .15s;
}
.icon-btn:hover { background: var(--bg-hover); }

.toolbar {
  display: flex; gap: 8px; padding: 12px 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.toolbar input[type="search"] {
  flex: 1 1 200px; min-width: 140px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.toolbar select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

.main { flex: 1; padding: 16px; padding-bottom: calc(100px + var(--safe-bottom)); }

/* Quick add */
.quick-add {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin: 0 auto 12px;
  max-width: 800px;
  box-shadow: var(--shadow);
  transition: border-color .15s, box-shadow .15s;
}
.quick-add:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.15);
}
.quick-add-circle {
  width: 22px; height: 22px;
  border: 2px dashed var(--border);
  border-radius: 50%;
  flex-shrink: 0;
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: bold;
  line-height: 1;
}
.quick-add input {
  flex: 1; border: none; background: transparent;
  color: var(--text); font-size: 15px;
  outline: none; padding: 4px 0;
  min-width: 0;
}
.quick-add input::placeholder { color: var(--text-muted); }

.reminders-list {
  display: flex; flex-direction: column; gap: 6px;
  max-width: 800px; margin: 0 auto;
}

.reminder {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  transition: transform .15s, box-shadow .15s;
  display: flex; gap: 12px; align-items: flex-start;
  position: relative;
}
.reminder:hover { box-shadow: var(--shadow-lg); }
.reminder:hover .info-btn { opacity: 1; }
.reminder.priority-high { border-left: 4px solid var(--danger); }
.reminder.priority-medium { border-left: 4px solid var(--warning); }
.reminder.priority-low { border-left: 4px solid var(--success); }
.reminder.done { opacity: .55; }
.reminder.done .reminder-title { text-decoration: line-through; }
.reminder.overdue:not(.done) { background: color-mix(in srgb, var(--danger) 8%, var(--bg-card)); }

.reminder-check {
  width: 22px; height: 22px;
  border: 2px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  transition: all .15s;
  margin-top: 1px;
}
.reminder.done .reminder-check {
  background: var(--success); border-color: var(--success); color: white;
}
.reminder.done .reminder-check::after { content: "✓"; font-size: 14px; font-weight: bold; }

.reminder-body { flex: 1; min-width: 0; cursor: text; }
.reminder-title {
  font-size: 15px; margin-bottom: 2px; word-break: break-word;
  color: var(--text);
  outline: none; line-height: 1.4;
  min-height: 1.4em;
  cursor: text;
}
.reminder-title:empty::before {
  content: 'Sin título';
  color: var(--text-muted);
  font-style: italic;
}
.reminder-title:focus { color: var(--primary); }
.reminder-desc { color: var(--text-muted); font-size: 13px; margin-top: 2px; word-break: break-word; }
.reminder-meta { display: flex; flex-wrap: wrap; gap: 8px; font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.reminder-meta span { display: inline-flex; align-items: center; gap: 3px; }
.reminder-meta .cat {
  background: var(--bg-hover); padding: 2px 8px; border-radius: 10px;
}
.reminder-meta .overdue { color: var(--danger); font-weight: 600; }

.info-btn {
  background: none; border: none;
  width: 30px; height: 30px;
  border-radius: 50%;
  cursor: pointer;
  color: var(--primary);
  font-size: 18px;
  opacity: 0;
  transition: opacity .15s, background .15s;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.info-btn:hover { background: var(--bg-hover); }
@media (max-width: 768px) { .info-btn { opacity: .6; } }

.empty-state {
  text-align: center; padding: 40px 20px; color: var(--text-muted);
}
.empty-icon { font-size: 52px; margin-bottom: 12px; }

/* MODAL */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 50;
  animation: fadeIn .15s;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal-content {
  background: var(--bg-card);
  width: 100%; max-width: 520px;
  max-height: 92vh;
  border-radius: 20px 20px 0 0;
  overflow-y: auto;
  animation: slideUp .2s;
  padding-bottom: var(--safe-bottom);
}
@keyframes slideUp { from { transform: translateY(100%); } }
@media (min-width: 640px) {
  .modal { align-items: center; padding: 20px; }
  .modal-content { border-radius: 20px; }
}

.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg-card); z-index: 2;
}
.modal-header h2 { font-size: 18px; }

.form { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.form label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 13px; color: var(--text-muted); font-weight: 500;
}
.form input, .form textarea, .form select {
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
}
.form input:focus, .form textarea:focus, .form select:focus {
  outline: none; border-color: var(--primary);
}
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form textarea { resize: vertical; min-height: 70px; }

.toggle-row { border-top: 1px solid var(--border); padding-top: 12px; }
.toggle-label {
  flex-direction: row !important; align-items: center; gap: 10px !important;
  cursor: pointer; color: var(--text) !important; font-size: 15px !important;
}
.toggle-label input[type="checkbox"] {
  width: 20px; height: 20px; cursor: pointer; margin: 0;
  accent-color: var(--primary);
}
#dateFields { display: flex; flex-direction: column; gap: 14px; }

.modal-actions {
  display: flex; gap: 8px; justify-content: flex-end;
  padding-top: 10px; flex-wrap: wrap;
}
.modal-actions button { flex: 0 1 auto; min-width: 100px; }
.modal-actions #deleteBtn { margin-right: auto; }

.btn-primary, .btn-secondary, .btn-danger {
  padding: 11px 18px; border: none; border-radius: 8px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: all .15s;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--bg-hover); color: var(--text); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { opacity: .9; }

/* Toast */
.toast {
  position: fixed;
  bottom: calc(30px + var(--safe-bottom));
  left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 12px 20px;
  border-radius: 24px;
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  animation: slideUp .2s;
  max-width: 90vw; text-align: center;
}

/* FAB (botón flotante) */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(20px + var(--safe-bottom));
  width: 58px; height: 58px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  font-size: 32px;
  font-weight: 300;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(79,70,229,.4);
  z-index: 30;
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s, background .15s;
  line-height: 1;
  padding: 0;
}
.fab:hover { transform: scale(1.05); background: var(--primary-hover); }
.fab:active { transform: scale(.95); }

@media (max-width: 500px) {
  .form .row { grid-template-columns: 1fr; }
  .header h1 { font-size: 16px; }
  .toolbar { gap: 6px; }
  .toolbar select { font-size: 13px; padding: 10px 8px; }
}
