:root {
  --bg: #faf9f6;
  --surface: #ffffff;
  --surface-2: #f1efe8;
  --text: #1c1c1a;
  --text-secondary: #6b6a63;
  --text-muted: #9a998f;
  --border: #e7e5dd;
  --accent: #3454d1;
  --accent-bg: #e8ecfb;
  --danger: #c94a3d;
  --success: #3b8a4e;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171613;
    --surface: #211f1b;
    --surface-2: #2a2823;
    --text: #f2f1ec;
    --text-secondary: #b5b3a9;
    --text-muted: #78776d;
    --border: #34322b;
    --accent: #7f97ec;
    --accent-bg: #262c47;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button, input, textarea, select {
  font-family: inherit;
  color: inherit;
}

.screen { min-height: 100dvh; display: flex; flex-direction: column; }

/* ---------- Login ---------- */
#login-view {
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: calc(24px + var(--safe-top));
}
.login-box { width: 100%; max-width: 320px; text-align: center; }
.login-logo {
  width: 64px; height: 64px; border-radius: 18px; background: var(--accent-bg);
  color: var(--accent); display: flex; align-items: center; justify-content: center;
  font-size: 28px; margin: 0 auto 16px;
}
.login-box h1 { font-size: 21px; font-weight: 600; margin: 0 0 6px; }
.muted { color: var(--text-secondary); font-size: 14px; margin: 0 0 24px; }
.login-box input {
  width: 100%; height: 46px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); padding: 0 14px; font-size: 16px; margin-bottom: 12px;
}
.error-text { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 10px; }

.btn-primary {
  width: 100%; height: 46px; border-radius: var(--radius); border: none;
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 500;
}
.btn-primary:active { opacity: 0.85; }

/* ---------- App shell ---------- */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky; top: 0; z-index: 5;
}
.app-header h1 { font-size: 19px; font-weight: 600; margin: 0; }
.header-actions { display: flex; align-items: center; gap: 2px; }
.icon-btn {
  width: 34px; height: 34px; border: none; background: none; color: var(--accent);
  font-size: 20px; display: flex; align-items: center; justify-content: center; border-radius: 50%;
}
.icon-btn:active { background: var(--surface-2); }

.content { flex: 1; overflow-y: auto; padding: 14px 16px calc(20px + var(--safe-bottom)); }

.tabbar {
  display: flex; justify-content: space-around; align-items: center;
  border-top: 1px solid var(--border); background: var(--bg);
  padding-bottom: var(--safe-bottom); position: sticky; bottom: 0;
}
.tab-btn {
  flex: 1; border: none; background: none; padding: 8px 0 10px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--text-muted); font-size: 10px;
}
.tab-btn i { font-size: 21px; }
.tab-btn.active { color: var(--accent); }

/* ---------- Cards / list items ---------- */
.card-row {
  display: flex; align-items: center; gap: 12px; background: var(--surface);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; border: 1px solid var(--border);
}
.card-row:active { background: var(--surface-2); }
.row-icon {
  width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center;
  justify-content: center; font-size: 18px; flex-shrink: 0;
}
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 500; font-size: 14px; margin: 0 0 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 12px; color: var(--text-secondary); margin: 0; }
.row-chevron { color: var(--text-muted); font-size: 16px; flex-shrink: 0; }

.check-circle {
  width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--border);
  flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 13px;
}
.check-circle.done { background: var(--success); border-color: var(--success); color: #fff; }

.section-label { font-size: 12px; color: var(--text-muted); margin: 4px 2px 8px; text-transform: uppercase; letter-spacing: 0.04em; }

.filter-chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 12px; margin-bottom: 2px; }
.filter-chip {
  flex-shrink: 0; border: 1px solid var(--border); background: var(--surface); color: var(--text-secondary);
  font-size: 12px; padding: 7px 14px; border-radius: 20px; white-space: nowrap;
}
.filter-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- Vista Hoy ---------- */
.hoy-section { margin-bottom: 22px; }
.hoy-section-title { font-size: 13px; font-weight: 600; margin: 0 0 10px; display: flex; align-items: center; gap: 6px; }
.hoy-section-title.warn { color: var(--danger); }
.hoy-empty { text-align: center; padding: 40px 20px; color: var(--text-secondary); }
.hoy-empty i { font-size: 26px; color: var(--text-muted); margin-bottom: 8px; display: block; }
.hoy-empty p { font-size: 13px; margin: 0; }

/* ---------- Buscador ---------- */
.search-overlay { position: fixed; inset: 0; background: var(--bg); z-index: 30; display: flex; flex-direction: column; }
.search-header { display: flex; align-items: center; gap: 10px; padding: calc(10px + var(--safe-top)) 14px 10px; border-bottom: 1px solid var(--border); }
.search-input-wrap { flex: 1; display: flex; align-items: center; gap: 8px; background: var(--surface-2); border-radius: 10px; padding: 0 12px; height: 40px; }
.search-input-wrap input { flex: 1; border: none; background: none; font-size: 15px; height: 100%; }
.search-input-wrap input:focus { outline: none; }
.search-results { flex: 1; overflow-y: auto; padding: 12px 16px; }
.search-type-badge { font-size: 10px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }

/* ---------- Papelera ---------- */
.papelera-row { opacity: 0.85; }
.btn-restaurar { font-size: 12px; color: var(--accent); background: none; border: none; padding: 6px 10px; flex-shrink: 0; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-secondary); }
.empty-state i { font-size: 32px; color: var(--text-muted); margin-bottom: 10px; display: block; }
.empty-state p { font-size: 14px; margin: 0; }

.dashed-row {
  border: 1.5px dashed var(--border); background: none; display: flex; align-items: center;
  justify-content: center; gap: 8px; color: var(--text-secondary); font-size: 13px;
}

/* ---------- Note editor ---------- */
.field-title {
  width: 100%; border: none; background: none; font-size: 18px; font-weight: 600;
  padding: 4px 0; margin-bottom: 4px;
}
.field-body {
  width: 100%; min-height: 220px; border: none; background: none; font-size: 14px;
  line-height: 1.6; padding: 4px 0; resize: none;
}
.field-title:focus, .field-body:focus { outline: none; }

.markdown-preview { overflow-y: auto; line-height: 1.6; }
.markdown-preview h1 { font-size: 19px; margin: 0 0 10px; }
.markdown-preview h2 { font-size: 16px; margin: 14px 0 8px; }
.markdown-preview h3 { font-size: 14px; margin: 12px 0 6px; }
.markdown-preview p { margin: 0 0 10px; font-size: 14px; }
.markdown-preview code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.markdown-preview pre { background: var(--surface-2); padding: 10px; border-radius: 8px; overflow-x: auto; }
.markdown-preview ul, .markdown-preview ol { padding-left: 20px; font-size: 14px; margin: 0 0 10px; }

.chip { display: inline-block; font-size: 12px; padding: 4px 11px; border-radius: 20px; background: var(--accent-bg); color: var(--accent); margin-bottom: 12px; }

.image-strip { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0; }
.image-thumb { width: 68px; height: 68px; border-radius: 10px; object-fit: cover; flex-shrink: 0; background: var(--surface-2); }
.image-add {
  width: 68px; height: 68px; border-radius: 10px; border: 1.5px dashed var(--border);
  display: flex; align-items: center; justify-content: center; color: var(--text-secondary); flex-shrink: 0; font-size: 18px;
}
.image-thumb-wrap { position: relative; flex-shrink: 0; }
.image-remove {
  position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--danger); color: #fff; border: 2px solid var(--bg); font-size: 11px;
  display: flex; align-items: center; justify-content: center;
}

.editor-footer {
  display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--border);
  padding-top: 12px; margin-top: 14px; font-size: 12px; color: var(--text-muted);
}
.link-action { color: var(--accent); font-size: 13px; display: flex; align-items: center; gap: 4px; background: none; border: none; padding: 0; }

/* ---------- Modal / bottom sheet ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: flex-end;
  z-index: 20;
}
.sheet {
  width: 100%; background: var(--surface); border-radius: 20px 20px 0 0; padding: 20px 18px calc(20px + var(--safe-bottom));
  max-height: 80vh; overflow-y: auto;
}
.sheet h2 { font-size: 17px; font-weight: 600; margin: 0 0 16px; }
.field-label { font-size: 12px; color: var(--text-secondary); margin: 12px 0 6px; }
.sheet input[type="text"], .sheet input[type="datetime-local"], .sheet select {
  width: 100%; height: 44px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); padding: 0 12px; font-size: 15px;
}
.icon-grid, .color-grid { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.icon-opt, .color-opt {
  width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
  border: 2px solid transparent; font-size: 17px; background: var(--surface-2);
}
.icon-opt.selected, .color-opt.selected { border-color: var(--accent); }
.sheet-actions { display: flex; gap: 10px; margin-top: 20px; }
.btn-secondary {
  flex: 1; height: 44px; border-radius: 10px; border: 1px solid var(--border); background: none; font-size: 14px; font-weight: 500;
}
.sheet-actions .btn-primary { flex: 1.4; height: 44px; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); font-size: 13px; padding: 10px 16px; border-radius: 30px;
  opacity: 0; pointer-events: none; transition: all 0.25s ease; z-index: 40; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Ajustes ---------- */
.settings-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 2px; border-bottom: 1px solid var(--border); }
.toggle { width: 44px; height: 26px; border-radius: 20px; background: var(--border); position: relative; border: none; flex-shrink: 0; }
.toggle.on { background: var(--accent); }
.toggle-knob { width: 22px; height: 22px; border-radius: 50%; background: #fff; position: absolute; top: 2px; left: 2px; transition: left 0.15s ease; }
.toggle.on .toggle-knob { left: 20px; }
