/* ============================================================
   PresuCostos — sistema de diseño
   Tema oscuro con naranja (idéntico a Presufast).
   Poppins para títulos, Inter para datos.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@500;600;700;800&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --primary:        #F5A623;
  --primary-dark:   #D4891A;
  --primary-light:  #FFB84D;
  --bg-dark:        #0D0D0D;
  --bg-card:        #1A1A1A;
  --bg-sidebar:     #0F0F0F;
  --surface:        #242424;
  --surface-2:      #2E2E2E;
  --border:         #333333;
  --border-light:   #404040;
  --text-main:      #FFFFFF;
  --text-muted:     #AAAAAA;
  --text-dim:       #666666;
  --success:        #2ECC71;
  --danger:         #E74C3C;
  --warning:        #F39C12;
  --info:           #3498DB;
  --sidebar-w:      260px;
  --header-h:       60px;
  --radius:         8px;
  --radius-sm:      4px;
  --shadow:         0 4px 20px rgba(0,0,0,0.5);
  --shadow-sm:      0 2px 8px rgba(0,0,0,0.3);
  --transition:     all 0.25s ease;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg-dark);
  color: var(--text-main);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1, h2, h3, h4, .font-title { font-family: 'Poppins', sans-serif; font-weight: 600; margin: 0; }

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

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: var(--bg-dark); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ============================================================
   LOGIN
   ============================================================ */
.login-screen {
  position: fixed; inset: 0; z-index: 500;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: radial-gradient(1000px 600px at 20% 0%, #1c1409 0%, var(--bg-dark) 60%);
  overflow-y: auto;
}

.login-card {
  width: 100%; max-width: 430px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 30px 26px 24px;
  text-align: center;
  margin: auto;
}

.login-mark {
  width: 76px; height: 76px; margin: 0 auto 14px;
  border-radius: 17px;
  background: #0F1B2E;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-family: 'Poppins', sans-serif; font-weight: 800; font-size: 27px;
  color: var(--primary); letter-spacing: 0.5px;
  box-shadow: var(--shadow-sm);
}
.login-mark span { display: block; width: 34px; height: 4px; border-radius: 2px; background: var(--primary); margin-top: 3px; }

.login-card h1 { font-size: 25px; font-weight: 700; margin-bottom: 6px; }
.login-card h1 em { font-style: normal; color: var(--primary); }
.login-card > p { color: var(--text-muted); font-size: 13.5px; margin: 0 0 20px; }

.login-note { color: var(--text-dim); font-size: 11.5px; margin-top: 14px; line-height: 1.55; }

.setup-banner {
  background: rgba(243,156,18,.12);
  border: 1px solid rgba(243,156,18,.4);
  color: #F6D08A;
  border-radius: var(--radius);
  padding: 12px 14px; font-size: 12.5px; text-align: left; line-height: 1.6;
  margin-bottom: 14px;
}
.setup-banner code { background: rgba(0,0,0,.35); padding: 1px 5px; border-radius: 3px; font-size: 11.5px; }

.google-btn {
  width: 100%; min-height: 46px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  background: #FFFFFF; color: #202124;
  border: none; border-radius: var(--radius);
  font-family: 'Inter', sans-serif; font-weight: 600; font-size: 14.5px;
  cursor: pointer; transition: var(--transition);
}
.google-btn:hover { background: #F1F3F4; }
.google-btn:disabled { cursor: default; }

.login-progress {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  margin-top: 14px; color: var(--text-muted); font-size: 13px;
}

.spinner {
  width: 18px; height: 18px; flex: none;
  border: 2.4px solid rgba(245,166,35,.25);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   LAYOUT: sidebar + topbar + contenido
   ============================================================ */
#app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex: none;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; inset: 0 auto 0 0; z-index: 60;
  transition: transform .25s ease;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.brand-mark {
  width: 38px; height: 38px; flex: none; border-radius: 9px; background: #0F1B2E;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Poppins', sans-serif; font-weight: 800; font-size: 14px; color: var(--primary);
}
.brand-name { font-family: 'Poppins', sans-serif; font-weight: 700; font-size: 17px; }
.brand-name span { color: var(--primary); }

.nav-group-label {
  padding: 15px 18px 6px; font-size: 10.5px; letter-spacing: 1.1px;
  text-transform: uppercase; color: var(--text-dim); font-weight: 600;
}

.nav-list { list-style: none; margin: 0; padding: 0 10px 10px; overflow-y: auto; flex: 1; }
.nav-list li { margin-bottom: 2px; }

.nav-item {
  width: 100%; display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border: none; background: none;
  color: var(--text-muted); font-family: 'Inter', sans-serif; font-size: 13.5px; font-weight: 500;
  border-radius: var(--radius-sm); cursor: pointer; text-align: left;
  transition: var(--transition);
}
.nav-item:hover { background: var(--surface); color: var(--text-main); }
.nav-item.active { background: rgba(245,166,35,.14); color: var(--primary); font-weight: 600; }
.nav-ico { width: 20px; flex: none; text-align: center; font-size: 14.5px; }

.nav-user {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-top: 1px solid var(--border);
}
.nav-user img { width: 34px; height: 34px; border-radius: 50%; flex: none; background: var(--surface-2); object-fit: cover; }
.nav-user-info { min-width: 0; flex: 1; }
.nav-user-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-user-email { font-size: 11px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-signout {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  padding: 6px; border-radius: var(--radius-sm); flex: none; font-size: 15px;
}
.nav-signout:hover { color: var(--danger); background: var(--surface); }

.sidebar-overlay {
  display: none; position: fixed; inset: 0; z-index: 55;
  background: rgba(0,0,0,.62); backdrop-filter: blur(2px);
}
.sidebar-overlay.open { display: block; }

.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }

.topbar {
  height: var(--header-h); flex: none;
  display: flex; align-items: center; gap: 12px;
  padding: 0 18px;
  background: var(--bg-card); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 40;
}
.topbar-title { font-family: 'Poppins', sans-serif; font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-spacer { flex: 1; }

.hamburger {
  display: none; background: none; border: none; color: var(--text-main);
  cursor: pointer; padding: 6px; border-radius: var(--radius-sm); font-size: 19px;
}
.hamburger:hover { background: var(--surface); }

/* Selector de proyecto activo */
.proy-switch {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border-light);
  border-radius: 20px; padding: 4px 6px 4px 12px; max-width: 340px;
}
.proy-switch-label { font-size: 10.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .7px; white-space: nowrap; }
.proy-select {
  background: none; border: none; color: var(--text-main);
  font-family: 'Inter', sans-serif; font-size: 13px; font-weight: 600;
  cursor: pointer; outline: none; max-width: 220px; padding: 4px;
}
.proy-select option { background: var(--bg-card); color: var(--text-main); }

.sync-pill { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--text-dim); white-space: nowrap; }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); flex: none; }
.sync-dot.syncing { background: var(--warning); animation: pulse 1s infinite; }
.sync-dot.offline { background: var(--danger); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

.content { flex: 1; padding: 22px; max-width: 1500px; width: 100%; }

/* ============================================================
   TARJETAS Y BLOQUES
   ============================================================ */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
}
.card + .card { margin-top: 16px; }
.card-title {
  font-family: 'Poppins', sans-serif; font-weight: 600; font-size: 15px;
  margin: 0 0 14px; display: flex; align-items: center; gap: 8px;
}
.card-sub { color: var(--text-muted); font-size: 12.5px; margin: -8px 0 14px; }

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 16px;
}
.section-head h2 { font-size: 19px; font-weight: 700; }
.section-head .text-muted { font-size: 12.5px; }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-row { display: flex; align-items: center; }
.wrap { flex-wrap: wrap; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.text-muted { color: var(--text-muted); }
.text-dim { color: var(--text-dim); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-primary { color: var(--primary); }
.nowrap { white-space: nowrap; }
.mt-0 { margin-top: 0; } .mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; }
.hidden { display: none !important; }
.mono { font-variant-numeric: tabular-nums; }

/* KPI */
.kpi {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 15px 16px;
  display: flex; flex-direction: column; gap: 3px;
  border-left: 3px solid var(--primary);
}
.kpi.ok { border-left-color: var(--success); }
.kpi.bad { border-left-color: var(--danger); }
.kpi.warn { border-left-color: var(--warning); }
.kpi.info { border-left-color: var(--info); }
.kpi-label { font-size: 11px; text-transform: uppercase; letter-spacing: .7px; color: var(--text-dim); font-weight: 600; }
.kpi-value { font-family: 'Poppins', sans-serif; font-weight: 700; font-size: 21px; line-height: 1.25; }
.kpi-sub { font-size: 11.5px; color: var(--text-muted); }

/* ============================================================
   BOTONES
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 38px; padding: 8px 15px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif; font-size: 13.5px; font-weight: 600;
  cursor: pointer; transition: var(--transition); white-space: nowrap;
  background: var(--surface); color: var(--text-main);
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #1A1206; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-light); }
.btn-outline { background: transparent; border-color: var(--border-light); color: var(--text-main); }
.btn-outline:hover { background: var(--surface); border-color: var(--primary); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #C0392B; }
.btn-success { background: var(--success); color: #06301A; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface); color: var(--text-main); }
/* "Explorar en modo demo": es la 2ª puerta de entrada, se le da algo más
   de peso que a los otros botones secundarios del login. */
#demoModeBtn { font-size: 15.5px; font-weight: 700; color: var(--text-main); min-height: 44px; }
/* Tutorial de YouTube (mismo diseño que CitasPro, adaptado al tema oscuro) */
.btn-tutorial { background: rgba(255,0,0,.10); color: #FF8A80; border-color: rgba(255,0,0,.32); }
.btn-tutorial:hover { background: rgba(255,0,0,.18); color: #FFB3AB; }
.btn-sm { min-height: 30px; padding: 5px 11px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn-icon { min-height: 32px; width: 32px; padding: 0; font-size: 14px; }

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 14px; font-size: 12px; font-weight: 600;
  background: var(--surface); color: var(--text-muted); border: 1px solid var(--border);
  cursor: pointer; transition: var(--transition);
}
.chip:hover { border-color: var(--border-light); color: var(--text-main); }
.chip.active { background: rgba(245,166,35,.16); color: var(--primary); border-color: rgba(245,166,35,.45); }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 11px; font-size: 11.5px; font-weight: 600;
  background: var(--surface); color: var(--text-muted);
}
.badge-ok   { background: rgba(46,204,113,.16); color: var(--success); }
.badge-bad  { background: rgba(231,76,60,.16);  color: var(--danger); }
.badge-warn { background: rgba(243,156,18,.16); color: var(--warning); }
.badge-info { background: rgba(52,152,219,.16); color: var(--info); }
.badge-dim  { background: var(--surface-2); color: var(--text-dim); }

.dot-color { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

/* ============================================================
   FORMULARIOS
   ============================================================ */
.field { margin-bottom: 13px; }
.field label, .lbl {
  display: block; font-size: 12px; font-weight: 600; color: var(--text-muted);
  margin-bottom: 5px;
}
.field label .req { color: var(--danger); }

.input, .select, .textarea {
  width: 100%; min-height: 38px; padding: 8px 11px;
  background: var(--surface); color: var(--text-main);
  border: 1px solid var(--border-light); border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif; font-size: 13.5px;
  transition: var(--transition); outline: none;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(245,166,35,.15); }
.input::placeholder, .textarea::placeholder { color: var(--text-dim); }
.textarea { min-height: 78px; resize: vertical; line-height: 1.55; }
.select option { background: var(--bg-card); }
.input:disabled, .select:disabled { opacity: .55; cursor: not-allowed; }
.input.err, .select.err { border-color: var(--danger); }

.input-num { text-align: right; font-variant-numeric: tabular-nums; }

.field-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

.check { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--primary); cursor: pointer; flex: none; }

.hint { font-size: 11.5px; color: var(--text-dim); margin-top: 4px; line-height: 1.5; }

/* Autocompletado */
.autocomplete-wrap { position: relative; }
.autocomplete-list {
  position: absolute; z-index: 30; left: 0; right: 0; top: 100%;
  background: var(--surface); border: 1px solid var(--border-light);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  max-height: 240px; overflow-y: auto; margin-top: 3px;
}
.autocomplete-list div { padding: 9px 11px; cursor: pointer; font-size: 13px; border-bottom: 1px solid var(--border); }
.autocomplete-list div:last-child { border-bottom: none; }
.autocomplete-list div:hover, .autocomplete-list div.sel { background: rgba(245,166,35,.14); color: var(--primary); }
.autocomplete-list .ac-sub { display: block; font-size: 11px; color: var(--text-dim); }

/* ------------------------------------------------------------
   Lista flotante del selector de insumos.
   Va pegada al <body> con position:fixed, NO dentro de la tabla:
   .table-wrap tiene overflow-x:auto y, por las reglas de CSS, eso
   convierte el overflow-y en auto también — un desplegable absoluto
   dentro de la tabla queda RECORTADO por ese scroll.
   ------------------------------------------------------------ */
.ac-flotante {
  position: fixed; z-index: 950; display: none;
  background: var(--surface); border: 1px solid var(--primary);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  max-height: 300px; overflow-y: auto; min-width: 240px;
}
.ac-flotante .ac-op {
  padding: 9px 11px; cursor: pointer; font-size: 13px;
  border-bottom: 1px solid var(--border); line-height: 1.35;
}
.ac-flotante .ac-op:last-child { border-bottom: none; }
.ac-flotante .ac-op:hover, .ac-flotante .ac-op.sel { background: rgba(245,166,35,.16); color: var(--primary); }
.ac-flotante .ac-sub { display: block; font-size: 11px; color: var(--text-dim); }
.ac-flotante .ac-op:hover .ac-sub, .ac-flotante .ac-op.sel .ac-sub { color: var(--primary-light); }
.ac-flotante .ac-nuevo { background: rgba(46,204,113,.10); border-top: 1px solid var(--border-light); }
.ac-flotante .ac-nuevo:hover { background: rgba(46,204,113,.20); color: var(--success); }
.ac-flotante .ac-vacio { padding: 11px; font-size: 12.5px; color: var(--text-dim); cursor: default; }
.ac-flotante .ac-titulo {
  padding: 7px 11px; font-size: 10.5px; letter-spacing: .6px; text-transform: uppercase;
  color: var(--text-dim); background: var(--bg-card); cursor: default;
  position: sticky; top: 0; border-bottom: 1px solid var(--border);
}

/* Indicador de que el campo es una lista desplegable */
.ac-caret {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text-dim); font-size: 9px; pointer-events: none;
}
.autocomplete-wrap input { padding-right: 22px; }

/* ============================================================
   TABLAS
   ============================================================ */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius); border: 1px solid var(--border); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--bg-card); }
table.tbl th {
  text-align: left; padding: 10px 11px; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .6px; color: var(--text-dim);
  background: var(--surface); border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.tbl td { padding: 9px 11px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.tbl tbody tr:last-child td { border-bottom: none; }
table.tbl tbody tr:hover { background: rgba(255,255,255,.025); }
table.tbl tfoot td { padding: 10px 11px; font-weight: 700; background: var(--surface); border-top: 2px solid var(--border-light); }
table.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.tbl .acciones { text-align: right; white-space: nowrap; }
table.tbl tr.grupo td { background: var(--surface); font-weight: 700; }
table.tbl tr.sub td { background: rgba(255,255,255,.02); }
table.tbl tr.alerta td { background: rgba(243,156,18,.10); }
/* Renglón de factura que NO paga IVA (exento o excluido) */
table.tbl tr.fila-exenta td { background: rgba(52,152,219,.08); }
table.tbl tr.fila-exenta.alerta td { background: rgba(243,156,18,.12); }

/* Cuadro comparativo de cotizaciones: la celda del proveedor más barato
   es lo primero que hay que ver al abrir la tabla. */
table.tbl.comparativo td.celda-mejor {
  background: rgba(46,204,113,.14);
  box-shadow: inset 2px 0 0 var(--success);
  font-weight: 700; color: var(--success);
}
table.tbl.comparativo td.celda-mejor .hint { color: var(--success); opacity: .85; }
table.tbl.comparativo th { vertical-align: bottom; }

/* Tabla editable de ítems de compra */
.items-tbl input, .items-tbl select { min-height: 32px; padding: 5px 7px; font-size: 12.5px; }
.items-tbl td { padding: 5px 6px; }
.items-tbl th { padding: 8px 6px; font-size: 10px; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-dim); }
.empty-state .ico { font-size: 40px; opacity: .5; display: block; margin-bottom: 10px; }
.empty-state h3 { font-size: 15px; color: var(--text-muted); margin-bottom: 5px; }
.empty-state p { font-size: 13px; margin: 0 0 14px; }

/* Barras de progreso */
.bar { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 4px; transition: width .4s ease; }
.bar-fill.ok { background: var(--success); }
.bar-fill.bad { background: var(--danger); }
.bar-fill.warn { background: var(--warning); }

.bar-mini { height: 6px; }

/* Barras horizontales simples de informe */
.hbar-row { display: grid; grid-template-columns: minmax(110px, 1.3fr) 3fr minmax(90px, auto); gap: 10px; align-items: center; margin-bottom: 8px; font-size: 12.5px; }
.hbar { height: 16px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.hbar > div { height: 100%; background: var(--primary); }

/* ============================================================
   MODALES
   ============================================================ */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 900;
  background: rgba(0,0,0,.72); backdrop-filter: blur(3px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 24px 16px; overflow-y: auto;
}
.modal {
  background: var(--bg-card); border: 1px solid var(--border-light);
  border-radius: 12px; box-shadow: var(--shadow);
  width: 100%; max-width: 540px; margin: auto;
}
.modal-wide { max-width: 900px; }
.modal-xl { max-width: 1200px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 16px; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text-dim); font-size: 22px; cursor: pointer; line-height: 1; padding: 2px 6px; border-radius: var(--radius-sm); }
.modal-close:hover { color: var(--danger); background: var(--surface); }
.modal-body { padding: 18px; }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; gap: 9px; justify-content: flex-end; flex-wrap: wrap; }

/* Anuncios */
.anuncio-overlay {
  position: fixed; inset: 0; z-index: 100000;
  background: rgba(0,0,0,.85);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.anuncio-modal { position: relative; max-width: 520px; width: 100%; background: var(--bg-card); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.anuncio-modal img { width: 100%; max-height: 66vh; object-fit: contain; display: block; background: #000; }
.anuncio-body { padding: 16px; }
.anuncio-body h3 { font-size: 16px; margin-bottom: 12px; }
.anuncio-close {
  position: absolute; top: 8px; right: 10px; z-index: 2;
  background: rgba(0,0,0,.6); border: none; color: #fff;
  width: 32px; height: 32px; border-radius: 50%; font-size: 20px; cursor: pointer; line-height: 1;
}

/* Toasts */
#toast-host { position: fixed; bottom: 20px; right: 20px; z-index: 100010; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast {
  background: var(--surface); color: var(--text-main);
  border: 1px solid var(--border-light); border-left: 3px solid var(--primary);
  border-radius: var(--radius-sm); padding: 11px 15px; font-size: 13px;
  box-shadow: var(--shadow); max-width: 340px; animation: toastIn .22s ease;
}
.toast.ok  { border-left-color: var(--success); }
.toast.err { border-left-color: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }

/* Badge "Guardando…" del outbox */
.outbox-badge {
  position: fixed; bottom: 20px; left: 20px; z-index: 100005;
  display: none; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border-light);
  border-radius: 18px; padding: 7px 14px; font-size: 12.5px; color: var(--text-muted);
  box-shadow: var(--shadow);
}
.outbox-badge.on { display: flex; }
.outbox-badge .spinner { width: 13px; height: 13px; border-width: 2px; }

/* Fotos */
.foto-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.foto-thumb {
  position: relative; aspect-ratio: 1; border-radius: var(--radius-sm); overflow: hidden;
  background: var(--surface); border: 1px solid var(--border);
}
.foto-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
/* Un PDF no tiene miniatura: se muestra la ficha del archivo. */
.foto-pdf {
  width: 100%; height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 5px; padding: 8px; text-align: center;
  background: rgba(245,166,35,.08); color: var(--text-muted);
}
.foto-pdf .ico { font-size: 26px; line-height: 1; }
.foto-pdf .nom {
  font-size: 10.5px; line-height: 1.25; word-break: break-word;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.foto-thumb .quitar {
  position: absolute; top: 3px; right: 3px;
  background: rgba(0,0,0,.7); border: none; color: #fff;
  width: 22px; height: 22px; border-radius: 50%; cursor: pointer; font-size: 13px; line-height: 1;
}
.foto-drop {
  border: 1.5px dashed var(--border-light); border-radius: var(--radius);
  padding: 18px; text-align: center; color: var(--text-dim); font-size: 12.5px; cursor: pointer;
  transition: var(--transition);
}
.foto-drop:hover { border-color: var(--primary); color: var(--primary); }

/* Semáforo de cuentas por pagar */
.semaforo { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.semaforo.rojo { background: var(--danger); }
.semaforo.naranja { background: var(--warning); }
.semaforo.verde { background: var(--success); }

/* Gráficos */
.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 320px; }

/* Panel lateral de la IA */
.ia-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(245,166,35,.14); border: 1px solid rgba(245,166,35,.4);
  color: var(--primary); border-radius: 14px; padding: 4px 11px; font-size: 12px; font-weight: 600;
}
.ia-chat { display: flex; flex-direction: column; gap: 11px; max-height: 420px; overflow-y: auto; padding-right: 4px; }
.ia-msg { padding: 11px 13px; border-radius: 10px; font-size: 13.3px; line-height: 1.6; white-space: pre-wrap; }
.ia-msg.user { background: var(--surface-2); align-self: flex-end; max-width: 85%; }
.ia-msg.bot  { background: rgba(245,166,35,.09); border: 1px solid rgba(245,166,35,.25); }

.conf-alta  { color: var(--success); }
.conf-media { color: var(--warning); }
.conf-baja  { color: var(--danger); }

/* Tabbar móvil */
.mobile-tabbar { display: none; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 980px) {
  .proy-switch { max-width: 200px; }
  .proy-switch-label { display: none; }
  .sync-pill span:not(.sync-dot) { display: none; }
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .hamburger { display: inline-flex; }
  .content { padding: 15px 13px 80px; }

  /* En móvil la barra superior solo tiene sitio para el menú y el selector
     de proyecto. El título sobra: cada pantalla ya lo repite en su <h2>,
     y dejarlo empujaba el selector fuera de la pantalla. */
  .topbar { padding: 0 10px; gap: 8px; overflow: hidden; }
  .topbar-title { display: none; }
  .proy-switch { flex: 1; min-width: 0; max-width: none; }
  .proy-select { flex: 1; min-width: 0; max-width: none; }

  /* Botones cómodos para el dedo en obra */
  .btn { min-height: 44px; padding: 10px 16px; }
  .btn-sm { min-height: 38px; }
  .btn-icon { min-height: 38px; width: 38px; }
  .input, .select, .textarea { min-height: 44px; font-size: 15px; } /* 15px evita el zoom de iOS */
  .field-row { grid-template-columns: 1fr; }

  .modal-backdrop { padding: 10px; }
  .modal-body { padding: 14px; }
  .grid-4, .grid-3 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .kpi-value { font-size: 18px; }

  .mobile-tabbar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
    background: var(--bg-sidebar); border-top: 1px solid var(--border);
    padding: 4px 2px calc(4px + env(safe-area-inset-bottom));
  }
  .mobile-tabbar button {
    flex: 1; background: none; border: none; color: var(--text-dim);
    font-family: 'Inter', sans-serif; font-size: 10px; font-weight: 600;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 7px 2px; cursor: pointer; min-height: 50px;
  }
  .mobile-tabbar button .ico { font-size: 17px; }
  .mobile-tabbar button.active { color: var(--primary); }
  #toast-host { bottom: 74px; right: 10px; left: 10px; align-items: stretch; }
  .toast { max-width: none; }
  .outbox-badge { bottom: 74px; left: 10px; }
}

/* ============================================================
   IMPRESIÓN (informes en PDF vía window.print)
   ============================================================ */
.print-doc { display: none; }

@media print {
  @page { size: A4; margin: 12mm 10mm 14mm; }

  body { background: #fff !important; color: #000 !important; font-size: 10.5pt; }
  #app, .login-screen, .modal-backdrop, .anuncio-overlay, #toast-host,
  .sidebar, .topbar, .mobile-tabbar, .outbox-badge, .no-print { display: none !important; }

  .print-doc { display: block !important; }

  .print-doc * { color: #000 !important; }
  .print-doc .pd-head {
    display: flex; justify-content: space-between; align-items: flex-start;
    border-bottom: 2px solid #F5A623; padding-bottom: 8px; margin-bottom: 14px;
  }
  .print-doc .pd-logo { max-height: 60px; max-width: 190px; }
  .print-doc h1 { font-size: 16pt; margin: 0 0 2px; }
  .print-doc h2 { font-size: 12.5pt; margin: 16px 0 7px; border-bottom: 1px solid #ccc; padding-bottom: 3px; }
  .print-doc .pd-meta { font-size: 9pt; color: #444 !important; }
  .print-doc table { width: 100%; border-collapse: collapse; font-size: 9pt; margin-bottom: 12px; }
  .print-doc th {
    background: #F7E4C3 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact;
    border: 1px solid #999; padding: 5px 6px; text-align: left; font-size: 8.5pt;
  }
  .print-doc td { border: 1px solid #bbb; padding: 4px 6px; }
  .print-doc td.num, .print-doc th.num { text-align: right; }
  .print-doc tfoot td { font-weight: 700; background: #F2F2F2 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .print-doc tr.grupo td { background: #EFEFEF !important; font-weight: 700; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .print-doc .pd-foot { margin-top: 18px; border-top: 1px solid #ccc; padding-top: 6px; font-size: 8pt; color: #555 !important; }
  .print-doc .pd-break { page-break-before: always; }
  .print-doc .pd-avoid { page-break-inside: avoid; }
  .print-doc .pd-firma { margin-top: 40px; display: flex; gap: 60px; }
  .print-doc .pd-firma div { flex: 1; border-top: 1px solid #000; padding-top: 5px; font-size: 9pt; text-align: center; }
  /* Gráficos del informe: PNG generados con tema claro y fondo blanco */
  .print-doc .pd-graficos { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px 14px; margin-bottom: 6px; }
  .print-doc .pd-graficos figure { margin: 0; page-break-inside: avoid; border: 1px solid #ddd; padding: 6px; }
  .print-doc .pd-graficos img { width: 100%; height: auto; display: block; }
  .print-doc .pd-graficos figcaption {
    font-size: 9pt; font-weight: 700; padding: 0 0 4px; border-bottom: 1px solid #eee; margin-bottom: 5px;
  }
  .print-doc .pd-graf-nota { font-size: 7.5pt; color: #555 !important; padding-top: 4px; }
  /* Un solo gráfico no debe quedar como una estampilla en media hoja */
  .print-doc .pd-graficos figure:only-child { grid-column: 1 / -1; }

  .print-doc .pd-fotos { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .print-doc .pd-fotos figure { margin: 0; page-break-inside: avoid; }
  .print-doc .pd-fotos img { width: 100%; height: 55mm; object-fit: cover; border: 1px solid #999; }
  .print-doc .pd-fotos figcaption { font-size: 8pt; padding-top: 3px; }
  thead { display: table-header-group; }
  tr { page-break-inside: avoid; }
}
