/* ============================================================
   CIFRAS — Main Stylesheet
   Dark/Light theme · Mobile-first (iPhone)
   ============================================================ */

/* ---------- CSS Variables ---------- */
:root {
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* Dark theme (default) */
  --bg:           #0f0f13;
  --bg-card:      #1a1a24;
  --bg-input:     #22222e;
  --bg-nav:       #15151f;
  --border:       #2e2e3e;
  --text:         #f0f0f5;
  --text-muted:   #8888aa;
  --text-label:   #aaaacc;
  --accent:       #7c6af7;
  --accent-hover: #6a58e8;
  --accent-soft:  rgba(124,106,247,.15);
  --danger:       #f05252;
  --danger-soft:  rgba(240,82,82,.15);
  --success:      #34d399;
  --success-soft: rgba(52,211,153,.15);
  --warning:      #fbbf24;
  --warning-soft: rgba(251,191,36,.15);
  --shadow:       0 8px 32px rgba(0,0,0,.45);
  --shadow-sm:    0 2px 8px rgba(0,0,0,.3);
  --radius:       16px;
  --radius-sm:    10px;
  --radius-xs:    6px;
  --nav-h:        64px;
  --safe-bottom:  env(safe-area-inset-bottom, 0px);
}

[data-theme="light"] {
  --bg:           #f4f4f8;
  --bg-card:      #ffffff;
  --bg-input:     #f0f0f6;
  --bg-nav:       #ffffff;
  --border:       #e0e0ec;
  --text:         #1a1a2e;
  --text-muted:   #666688;
  --text-label:   #555577;
  --accent:       #6c5ce7;
  --accent-hover: #5a4bd4;
  --accent-soft:  rgba(108,92,231,.12);
  --shadow:       0 8px 32px rgba(0,0,0,.10);
  --shadow-sm:    0 2px 8px rgba(0,0,0,.07);
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: -webkit-fill-available;
  line-height: 1.6;
  overscroll-behavior: none;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

img { max-width: 100%; display: block; }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ============================================================
   LOGIN
   ============================================================ */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  padding: 24px 20px;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 60% at 50% 0%, rgba(124,106,247,.18) 0%, transparent 70%);
}

.login-wrapper {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 28px 32px;
  box-shadow: var(--shadow);
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.logo-icon {
  font-size: 2.2rem;
  margin-bottom: 8px;
  color: var(--accent);
  filter: drop-shadow(0 0 12px rgba(124,106,247,.5));
}

.login-logo h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
}

.login-logo p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

.login-footer {
  display: flex;
  justify-content: center;
}

.theme-toggle-login {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s, transform .2s;
}
.theme-toggle-login:hover { background: var(--accent-soft); transform: rotate(20deg); }

/* ============================================================
   FORMS
   ============================================================ */
.form-group {
  margin-bottom: 18px;
}

label {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-label);
  margin-bottom: 7px;
  letter-spacing: .3px;
  text-transform: uppercase;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 14px;
  font-size: 0.95rem;
  pointer-events: none;
  z-index: 1;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="tel"],
input[type="number"],
select,
textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  padding: 13px 14px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  -webkit-appearance: none;
  appearance: none;
}

.input-wrapper input {
  padding-left: 42px;
}

.input-wrapper input:has(~ .toggle-password) {
  padding-right: 48px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input::placeholder { color: var(--text-muted); opacity: 1; }

.toggle-password {
  position: absolute;
  right: 12px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  padding: 4px;
  color: var(--text-muted);
  line-height: 1;
}

textarea {
  resize: vertical;
  min-height: 120px;
}

select option {
  background: var(--bg-card);
  color: var(--text);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-check {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.form-check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px 20px;
  cursor: pointer;
  transition: background .2s, transform .1s, box-shadow .2s;
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
  white-space: nowrap;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 16px rgba(124,106,247,.35);
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-input);
  color: var(--text);
  border: 1.5px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { background: #d93f3f; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1.5px solid var(--border);
}
.btn-ghost:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

.btn-full { width: 100%; }

.btn-sm {
  font-size: 0.82rem;
  padding: 8px 14px;
  border-radius: var(--radius-xs);
}

.btn-login {
  padding: 15px;
  font-size: 1rem;
  margin-top: 8px;
  letter-spacing: .3px;
}

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  color: var(--text-muted);
  font-size: 1.1rem;
  border-radius: var(--radius-xs);
  transition: color .2s, background .2s;
}
.btn-icon:hover { color: var(--accent); background: var(--accent-soft); }

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  margin-bottom: 20px;
  line-height: 1.5;
}
.alert-error   { background: var(--danger-soft);  color: var(--danger);  border: 1px solid rgba(240,82,82,.25); }
.alert-success { background: var(--success-soft); color: var(--success); border: 1px solid rgba(52,211,153,.25); }
.alert-warning { background: var(--warning-soft); color: var(--warning); border: 1px solid rgba(251,191,36,.25); }

/* ============================================================
   NAVIGATION (bottom nav for mobile)
   ============================================================ */
.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: -webkit-fill-available;
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-nav);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.top-bar-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.main-content {
  flex: 1;
  padding: 20px 16px;
  padding-bottom: calc(var(--nav-h) + 16px + var(--safe-bottom));
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--bg-nav);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  padding-bottom: var(--safe-bottom);
  height: calc(var(--nav-h) + var(--safe-bottom));
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 500;
  padding: 8px 4px;
  transition: color .2s;
  border-radius: var(--radius-xs);
  -webkit-tap-highlight-color: transparent;
}

.nav-item .nav-icon {
  font-size: 1.4rem;
  line-height: 1;
  transition: transform .2s;
}

.nav-item.active,
.nav-item:hover {
  color: var(--accent);
}
.nav-item.active .nav-icon { transform: scale(1.15); }

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.card + .card { margin-top: 14px; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

/* ============================================================
   KPIs legacy
   ============================================================ */
.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent);
  border-radius: var(--radius) var(--radius) 0 0;
}

.kpi-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
}

.kpi-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.kpi-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ============================================================
   CIFRA LIST ITEMS
   ============================================================ */
.cifra-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cifra-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: block;
  transition: border-color .2s, box-shadow .2s, transform .15s;
  -webkit-tap-highlight-color: transparent;
  box-shadow: var(--shadow-sm);
}

.cifra-item:hover,
.cifra-item:active {
  border-color: var(--accent);
  box-shadow: 0 4px 20px var(--accent-soft);
  transform: translateY(-1px);
}

.cifra-item-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
}

.cifra-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
  flex: 1;
}

.cifra-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.cifra-lugar {
  font-size: 0.8rem;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 8px;
}

.cifra-preview {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.5;
}

.cifra-meta {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.cifra-badge {
  font-size: 0.72rem;
  padding: 3px 8px;
  border-radius: 20px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
}

.cifra-attachments {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.cifra-attach-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
}

/* ============================================================
   CIFRA DETAIL VIEW
   ============================================================ */
.cifra-detail-title {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 12px;
}

.cifra-detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.meta-item strong { color: var(--text); }

.cifra-descripcion {
  font-size: 0.95rem;
  line-height: 1.75;
  color: var(--text);
  margin-bottom: 24px;
  overflow-wrap: break-word;
  word-break: break-word;
  white-space: pre-wrap;
}

/* Listas dentro del contenido generado por Quill */
.cifra-descripcion ol,
.cifra-descripcion ul {
  padding-left: 1.6em;
  margin: 0.5em 0;
}

.cifra-descripcion ol { list-style: decimal; }
.cifra-descripcion ul { list-style: disc; }

.cifra-descripcion li {
  margin-bottom: 0.3em;
  line-height: 1.65;
  white-space: normal;
}

.cifra-descripcion li > ol,
.cifra-descripcion li > ul {
  margin: 0.2em 0;
}

/* Otros elementos rich-text */
.cifra-descripcion p   { margin-bottom: 0.75em; min-height: 1.3em; white-space: normal; }
.cifra-descripcion p:last-child { margin-bottom: 0; }
.cifra-descripcion p:empty::before,
.cifra-descripcion p:has(> br:only-child)::before { content: '\00a0'; }
.cifra-descripcion strong { font-weight: 600; }
.cifra-descripcion em     { font-style: italic; }
.cifra-descripcion u      { text-decoration: underline; }
.cifra-descripcion a      { color: var(--accent); text-decoration: underline; }
.cifra-descripcion blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 14px;
  color: var(--text-muted);
  margin: 12px 0;
}

/* ============================================================
   WORD-DIFF HIGHLIGHT (.aw)
   Marca segmentos insertados/modificados por otro usuario.
   Se aplica a runs completos (palabras + espacios entre ellas)
   para que el fondo sea continuo sin huecos.
   ============================================================ */
.cifra-descripcion .aw {
  background: rgba(251, 191, 36, 0.22);
  border-radius: 3px;
  padding: 0 1px;
  margin: 0 -1px;
  position: relative;
  cursor: help;
  transition: background .15s;
}

.cifra-descripcion .aw:hover {
  background: rgba(251, 191, 36, 0.40);
}

[data-theme="light"] .cifra-descripcion .aw {
  background: rgba(234, 165, 0, 0.18);
}
[data-theme="light"] .cifra-descripcion .aw:hover {
  background: rgba(234, 165, 0, 0.35);
}

/* ============================================================
   DASHBOARD SECTION SPACING
   ============================================================ */
.dash-section {
  margin-bottom: 20px;
}

.dash-section:last-of-type {
  margin-bottom: 16px;
}

.dash-section .section-header {
  margin-bottom: 10px;
}

/* ============================================================
   RESPONSIVE KPI LAYOUT (Lugares fijo arriba / Por año scrollable)
   ============================================================ */
.kpi-section--places {
  display: block;
  width: 100%;
}

.kpi-section--years {
  display: block;
  width: 100%;
  min-width: 0;
}

.kpi-section--years .month-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  padding-bottom: 4px;
}

.kpi-section--years .month-chip {
  flex: 0 0 auto;
  min-width: 58px;
  display: flex;
  align-items: baseline;
  gap: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 20px;
  padding: 10px 10px;
  font-weight: 500;
}

.kpi-section--years .month-chip .month-num {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}

.kpi-section--years .month-chip .month-lbl {
  font-size: 0.7rem;
  color: var(--accent);
  opacity: .85;
  margin-top: 0;
  white-space: nowrap;
}

.kpi-section--years .month-chip--total {
  background: var(--accent);
}
.kpi-section--years .month-chip--total .month-num,
.kpi-section--years .month-chip--total .month-lbl {
  color: #fff;
  opacity: 1;
}

@media (min-width: 768px) {
  .kpi-section--years .month-row {
    overflow-x: visible;
    flex-wrap: wrap;
  }
}

/* ============================================================
   TAGS ROW (Lugares) — compacto, en filas envueltas
   ============================================================ */
.tags-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.tags-row .cifra-badge {
  font-size: 0.7rem;
  padding: 4px 10px;
  line-height: 1.2;
  white-space: nowrap;
}

/* ============================================================
   SEARCH BAR — unidad visual integrada
   ============================================================ */
.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 8px 8px 14px;
  box-shadow: var(--shadow-sm);
}

.search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  color: var(--text-muted);
}

.search-wrapper svg {
  flex-shrink: 0;
}

.search-input {
  flex: 1;
  min-width: 0;
  width: 100%;
  background: none;
  border: none;
  padding: 8px 26px 8px 0;
  font-size: 0.9rem;
  color: var(--text);
  outline: none;
}

.search-input::placeholder { color: var(--text-muted); opacity: .8; }

.search-clear {
  position: absolute;
  right: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  display: none;
  padding: 4px;
  line-height: 1;
}
.search-clear.visible { display: flex; align-items: center; }

#search-empty {
  display: none;
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: .9rem;
}
