/*************************************************
 * ATAS Documentos Móvil – estilos v2
 * Sistema de diseño: fondo casi-negro navy, acento
 * en gradiente verde→oro (limón/piña), tipografía
 * IBM Plex, nav flotante tipo cápsula, sheets con
 * handle de arrastre, micro-interacciones sutiles.
 *************************************************/

:root {
  --bg: #0a0e1a;
  --surface: #121a2c;
  --surface-2: #1a2438;
  --surface-3: #232f47;

  --lime: #22a288;
  --lime-strong: #1a8570;
  --gold: #c9a25c;
  --sky: #5b93b3;
  --amber: #c4924a;
  --red: #bf6363;

  --accent: #1d9078;

  --text-0: #f3f5f9;
  --text-1: #aab2c5;
  --text-2: #6b7690;

  --border: rgba(255,255,255,0.08);
  --border-strong: rgba(255,255,255,0.14);

  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 11px;
  --radius-pill: 999px;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);

  --font-display: 'IBM Plex Sans', -apple-system, Segoe UI, Roboto, sans-serif;
  --font-body: 'IBM Plex Sans', -apple-system, Segoe UI, Roboto, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;

  --ease: cubic-bezier(.22,.9,.32,1);
}

[data-theme="light"] {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --surface-3: #e4e8f0;
  --text-0: #0f1626;
  --text-1: #5b6478;
  --text-2: #8892a3;
  --border: rgba(15,22,38,0.09);
  --border-strong: rgba(15,22,38,0.16);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--text-0);
  font-family: var(--font-body);
}

body {
  display: flex;
  flex-direction: column;
  overscroll-behavior-y: contain;
}

button { font-family: inherit; cursor: pointer; }

svg.icon { width: 20px; height: 20px; display: block; flex-shrink: 0; }
svg.icon-inline { width: 12px; height: 12px; }

/* ===== Barra de estado (línea de color arriba de todo) ===== */
.status-bar {
  height: 3px;
  width: 100%;
  background: var(--border);
}
.status-bar.online { background: var(--accent); }
.status-bar.pending { background: var(--amber); animation: pulseBar 1.6s ease-in-out infinite; }
.status-bar.offline { background: var(--red); }
@keyframes pulseBar { 0%,100% { opacity: 1; } 50% { opacity: 0.45; } }

/* ===== Topbar ===== */
.topbar {
  position: sticky; top: 0; z-index: 20;
  padding-top: var(--safe-top);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-row {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px;
}
.topbar-title {
  flex: 1; min-width: 0;
  font-weight: 600; font-size: 17px;
  letter-spacing: -0.01em;
  display: flex; align-items: center; gap: 8px;
}
.topbar-title .crumb {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.icon-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-0);
  border-radius: var(--radius-sm);
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  transition: transform .12s var(--ease), background .12s;
}
.icon-btn:active { transform: scale(0.92); background: var(--surface-3); }

.status-chip {
  font-size: 11.5px;
  font-weight: 600;
  padding: 5px 10px 5px 8px;
  border-radius: var(--radius-pill);
  display: flex; align-items: center; gap: 5px;
  white-space: nowrap;
}
.status-chip .dot { width: 6px; height: 6px; border-radius: 50%; }
.chip-online { background: rgba(29,144,120,0.14); color: var(--lime); }
.chip-online .dot { background: var(--lime); }
.chip-offline { background: rgba(201,106,106,0.14); color: var(--red); }
.chip-offline .dot { background: var(--red); }
.chip-pending { background: rgba(207,154,74,0.16); color: var(--amber); }
.chip-pending .dot { background: var(--amber); animation: pulseBar 1.4s ease-in-out infinite; }

/* ===== Contenido ===== */
.app-main {
  flex: 1; overflow-y: auto;
  padding: 14px 16px calc(112px + var(--safe-bottom));
  animation: fadeSlideIn .22s var(--ease);
}
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .app-main, .sheet, .list-card, .doc-card { animation: none !important; transition: none !important; }
}

.search-bar-wrap {
  position: relative;
  margin-bottom: 16px;
}
.search-bar-wrap svg.icon {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--text-2);
}
.search-bar {
  width: 100%;
  padding: 13px 14px 13px 42px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-0);
  font-size: 15px;
  transition: border-color .15s, box-shadow .15s;
}
.search-bar:focus {
  outline: none;
  border-color: var(--lime-strong);
  box-shadow: 0 0 0 3px rgba(29,144,120,0.14);
}
.search-bar::placeholder { color: var(--text-2); }

.section-label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-2);
  margin: 20px 2px 10px;
  font-weight: 700;
}

/* ===== Cards de lista (navegación) ===== */
.list-card {
  display: flex; align-items: center; gap: 13px;
  width: 100%; text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 9px;
  color: var(--text-0);
  transition: transform .1s var(--ease), border-color .12s, background .12s;
}
.list-card:active { transform: scale(0.985); background: var(--surface-2); }

.list-card-icon {
  width: 42px; height: 42px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--lime);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.list-card-body { flex: 1; min-width: 0; }
.list-card-title {
  font-weight: 600; font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.list-card-sub { font-size: 12.5px; color: var(--text-2); margin-top: 2px; }
.list-card-chevron { color: var(--text-2); flex-shrink: 0; }

/* ===== Card de documento ===== */
.doc-card {
  width: 100%; text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 15px;
  margin-bottom: 10px;
  color: var(--text-0);
  transition: transform .1s var(--ease), background .12s;
}
.doc-card:active { transform: scale(0.985); background: var(--surface-2); }
.doc-card-code {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-2);
  letter-spacing: 0.01em;
}
.doc-card-title { font-weight: 600; font-size: 15px; margin-top: 3px; line-height: 1.3; }
.doc-card-meta { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 11px; }

/* ===== Pills / badges ===== */
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px; font-weight: 700;
  letter-spacing: 0.01em;
}
.pill-green { background: rgba(29,144,120,0.14); color: var(--lime); }
.pill-amber { background: rgba(207,154,74,0.16); color: var(--amber); }
.pill-red { background: rgba(201,106,106,0.15); color: var(--red); }
.pill-neutral { background: var(--surface-2); color: var(--text-1); border: 1px solid var(--border); }
.pill-notas { background: rgba(110,163,201,0.14); color: var(--sky); }
.pill-gold { background: rgba(209,168,92,0.16); color: var(--gold); }

.empty-state {
  text-align: center; color: var(--text-2);
  padding: 56px 24px; font-size: 14px; line-height: 1.6;
}
.empty-state svg.icon { width: 34px; height: 34px; margin: 0 auto 14px; opacity: 0.5; }

/* ===== Skeleton (carga) ===== */
.skeleton-card {
  height: 66px;
  border-radius: var(--radius-md);
  background: linear-gradient(100deg, var(--surface) 30%, var(--surface-2) 50%, var(--surface) 70%);
  background-size: 200% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
  margin-bottom: 9px;
}
@keyframes shimmer { 0% { background-position: 140% 0; } 100% { background-position: -40% 0; } }

/* ===== Nav flotante (cápsula) ===== */
.bottom-nav {
  position: fixed; left: 14px; right: 14px;
  bottom: calc(12px + var(--safe-bottom));
  z-index: 30;
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 4px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
}
[data-theme="light"] .bottom-nav { box-shadow: 0 4px 16px rgba(15,22,38,0.08); }

.nav-btn {
  flex: 1; position: relative;
  background: none; border: none;
  color: var(--text-2);
  padding: 9px 4px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 12px; font-weight: 600;
  border-radius: var(--radius-pill);
  transition: color .15s;
  z-index: 1;
  min-width: 0;
}
.nav-btn .nav-label {
  display: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-btn.active .nav-label { display: inline; }
.nav-btn.active { color: #f4f8f5; }
.nav-btn .nav-indicator {
  position: absolute; inset: 0;
  background: var(--accent);
  border-radius: var(--radius-pill);
  z-index: -1;
  opacity: 0;
  transform: scale(0.9);
  transition: opacity .18s var(--ease), transform .18s var(--ease);
}
.nav-btn.active .nav-indicator { opacity: 1; transform: scale(1); }
.nav-badge {
  position: absolute; top: -2px; right: 14%;
  background: var(--amber); color: #241900;
  border-radius: 999px; font-size: 10px; font-weight: 800;
  padding: 1px 5px; min-width: 16px; text-align: center;
  z-index: 2;
}

/* ===== Sheet (modal inferior con handle) ===== */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(4,6,12,0.6);
  z-index: 50;
  display: flex; align-items: flex-end;
  animation: fadeIn .16s var(--ease);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  width: 100%; max-height: 92vh;
  background: var(--surface);
  border-radius: 26px 26px 0 0;
  border: 1px solid var(--border-strong);
  border-bottom: none;
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: sheetUp .22s var(--ease);
}
@keyframes sheetUp { from { transform: translateY(28px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.sheet-handle {
  width: 40px; height: 4px;
  background: var(--border-strong);
  border-radius: 999px;
  margin: 10px auto 0;
}
.sheet-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px 14px;
}
.sheet-title { flex: 1; font-weight: 700; font-size: 16px; letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-body { overflow-y: auto; padding: 4px 18px calc(24px + var(--safe-bottom)); }

/* ===== Visor de documento (pantalla completa) ===== */
.full-modal { position: fixed; inset: 0; z-index: 60; background: #000; display: flex; flex-direction: column; }
.full-modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + var(--safe-top)) 12px 10px;
  background: var(--surface); color: var(--text-0);
  border-bottom: 1px solid var(--border);
}
.full-modal-title { flex: 1; font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.full-modal iframe { flex: 1; border: none; width: 100%; }

/* ===== Formularios ===== */
.field { margin-bottom: 16px; }
.field label {
  display: flex; align-items: center; gap: 6px;
  font-size: 12.5px; color: var(--text-1); margin-bottom: 7px; font-weight: 700;
}
.field textarea, .field select, .field input[type="text"] {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-0);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  font-size: 14.5px;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.field textarea:focus, .field select:focus, .field input:focus {
  outline: none; border-color: var(--lime-strong);
  box-shadow: 0 0 0 3px rgba(29,144,120,0.14);
}
.field textarea { min-height: 96px; resize: vertical; }
.field select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7690' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px; }

.photo-picker { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.photo-picker-btn { flex: 1; min-width: 120px; justify-content: center; }
.photo-picker-btn {
  display: flex; align-items: center; gap: 8px;
  border: 1.5px dashed var(--border-strong);
  background: var(--surface-2); color: var(--text-1);
  border-radius: var(--radius-sm);
  padding: 11px 14px; font-size: 13.5px; font-weight: 600;
  transition: border-color .15s, color .15s;
}
.photo-picker-btn:active { border-color: var(--lime-strong); color: var(--lime); }
.photo-preview { width: 56px; height: 56px; border-radius: var(--radius-sm); object-fit: cover; border: 1px solid var(--border); }

.btn {
  border: none; border-radius: var(--radius-sm);
  padding: 13px 16px; font-size: 14.5px; font-weight: 700;
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .1s var(--ease), opacity .12s;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: #f4f8f5; }
.btn-secondary { background: var(--surface-2); border: 1px solid var(--border); color: var(--text-0); }
.btn:disabled { opacity: 0.5; }

/* ===== Notas ===== */
.note-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 13px;
  margin-bottom: 10px;
  background: var(--surface-2);
}
.note-item-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.note-author { font-size: 12.5px; font-weight: 700; }
.note-date { font-size: 11px; color: var(--text-2); margin-top: 1px; }
.note-text { font-size: 14px; margin: 9px 0; white-space: pre-wrap; line-height: 1.45; }
.note-photo { width: 100%; max-height: 210px; object-fit: cover; border-radius: var(--radius-sm); margin-bottom: 9px; border: 1px solid var(--border); }
.note-meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.note-pending { font-size: 11px; color: var(--amber); font-weight: 700; display: flex; align-items: center; gap: 4px; }
.note-actions { margin-top: 11px; display: flex; gap: 8px; }
.note-actions .btn { width: auto; padding: 9px 13px; font-size: 12.5px; }

/* ===== FAB ===== */
.fab {
  position: fixed; right: 18px;
  bottom: calc(96px + var(--safe-bottom));
  z-index: 40;
  background: var(--accent);
  color: #f4f8f5;
  border: none; border-radius: var(--radius-pill);
  width: 58px; height: 58px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(0,0,0,0.22);
  transition: transform .12s var(--ease);
}
.fab:active { transform: scale(0.92); }

/* ===== Toast ===== */
.toast {
  position: fixed; left: 50%; bottom: calc(112px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  color: var(--text-0);
  padding: 11px 18px; border-radius: var(--radius-pill);
  font-size: 13px; font-weight: 600;
  z-index: 80;
  box-shadow: 0 4px 16px rgba(0,0,0,0.22);
  display: flex; align-items: center; gap: 8px;
  animation: toastIn .18s var(--ease);
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

.muted { color: var(--text-1); }
.section-title-lg { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; margin-bottom: 4px; }

/* ===== Visor de Excel/Word offline ===== */
.xlsx-tabs {
  display: flex; gap: 4px; overflow-x: auto;
  padding: 8px 10px; background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.xlsx-tab {
  flex-shrink: 0;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-1); font-size: 12.5px; font-weight: 600;
  padding: 6px 12px; border-radius: var(--radius-pill);
}
.xlsx-tab.active { background: var(--accent); color: #f4f8f5; border-color: var(--accent); }

.office-preview-wrap { flex: 1; overflow: auto; background: var(--bg); }
.xlsx-scroll { overflow: auto; padding: 8px; }
.xlsx-scroll table {
  border-collapse: collapse; font-size: 12.5px; background: var(--surface);
  color: var(--text-0);
}
.xlsx-scroll td, .xlsx-scroll th {
  border: 1px solid var(--border); padding: 5px 9px; white-space: nowrap;
}
.xlsx-scroll tr:first-child td { font-weight: 700; background: var(--surface-2); position: sticky; top: 0; }

.docx-preview {
  max-width: 720px; margin: 0 auto; padding: 24px 20px 60px;
  color: var(--text-0); font-size: 15px; line-height: 1.6;
}
.docx-preview h1, .docx-preview h2, .docx-preview h3 { color: var(--text-0); line-height: 1.3; }
.docx-preview img { max-width: 100%; height: auto; }
.docx-preview table { border-collapse: collapse; width: 100%; margin: 12px 0; }
.docx-preview td, .docx-preview th { border: 1px solid var(--border); padding: 6px 10px; }

/* Vista girada 90° (útil para tablas de Excel anchas en pantalla angosta) */
.full-modal.rotated-active .xlsx-tabs { display: none; }
.office-preview-wrap.rotated {
  position: fixed;
  top: 50%; left: 50%;
  width: 100vh; height: 100vw;
  transform: translate(-50%, -50%) rotate(90deg);
  z-index: 65;
  background: var(--bg);
}
.rotate-floating-controls {
  position: fixed;
  top: calc(12px + var(--safe-top));
  right: 12px;
  z-index: 70;
  display: flex;
  gap: 8px;
}
.rotate-floating-controls .icon-btn {
  background: var(--surface);
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
}
