:root {
  --bg: #f4f5f7; --card: #ffffff; --border: #e1e4e8; --text: #1f2933; --muted: #6b7280;
  --primary: #2b4c7e; --primary-dark: #1f3a63; --ok: #1f7a4d; --ok-bg: #e6f4ec; --warn: #b45309; --warn-bg: #fdf3e2;
  --pend: #2563a8; --pend-bg: #e8f0fb; --na: #6b7280; --na-bg: #eceef1; --danger: #b42318; --danger-bg: #fbe9e7;
  --radius: 8px; --shadow: 0 1px 2px rgba(16,24,40,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; font-size: 15px; color: var(--text); background: var(--bg); line-height: 1.45; }
a { color: var(--primary); }
button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
.hidden { display: none !important; }

.topbar { background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar .inner { max-width: 1100px; margin: 0 auto; padding: 12px 20px; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 17px; color: var(--primary-dark); letter-spacing: .2px; }
.brand small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
.who { font-size: 13px; color: var(--muted); text-align: right; }
.who b { color: var(--text); }

.container { max-width: 1100px; margin: 0 auto; padding: 20px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 16px; }
.card h2 { margin: 0 0 8px; font-size: 17px; }
.card h3 { margin: 0 0 6px; font-size: 15px; }
.muted { color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.grow { flex: 1 1 auto; }
.right { margin-left: auto; }

/* Progreso */
.progress-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.pbox { padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: #fafbfc; }
.pbox .label { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; }
.pbox .pct { font-size: 28px; font-weight: 700; margin: 2px 0 6px; }
.bar { height: 10px; background: #e5e7eb; border-radius: 5px; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 5px; transition: width .4s; }
.bar.up > span { background: var(--pend); }
.bar.ok > span { background: var(--ok); }
.bar.thin { height: 6px; }
.stats { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-top: 10px; }
.stats b { color: var(--text); }

/* Listados y secciones */
.listing-title { font-size: 14px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 24px 0 8px; font-weight: 600; }
.section { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; box-shadow: var(--shadow); }
.section-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; cursor: pointer; user-select: none; }
.section-head .chev { width: 18px; text-align: center; color: var(--muted); transition: transform .2s; }
.section.open .section-head .chev { transform: rotate(90deg); }
.section-head h3 { margin: 0; font-size: 15px; flex: 1; }
.section-head .mini { min-width: 150px; font-size: 12px; color: var(--muted); }
.section-head .mini .bar { margin-top: 3px; }
.section-body { display: none; border-top: 1px solid var(--border); }
.section.open .section-body { display: block; }
.section-tools { padding: 8px 16px; display: flex; gap: 8px; flex-wrap: wrap; border-bottom: 1px solid var(--border); background: #fafbfc; }

.item { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.item:last-child { border-bottom: 0; }
.item.na { opacity: .62; background: #fafafa; }
.item-head { display: flex; gap: 10px; align-items: flex-start; }
.item-head .title { font-weight: 600; flex: 1; }
.item-head .title small { display: block; font-weight: 400; color: var(--muted); font-size: 13px; margin-top: 2px; }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 12px; white-space: nowrap; }
.badge.empty { background: #f1f3f5; color: var(--muted); }
.badge.pending { background: var(--pend-bg); color: var(--pend); }
.badge.approved { background: var(--ok-bg); color: var(--ok); }
.badge.observed { background: var(--warn-bg); color: var(--warn); }
.badge.na { background: var(--na-bg); color: var(--na); }
.badge.extra { background: #ede9fe; color: #5b21b6; }
.badge.count { background: var(--primary); color: #fff; }

.ftable { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 14px; }
.ftable td { padding: 3px 6px; border-bottom: 1px solid #eef0f3; vertical-align: middle; }
.ftable tr:last-child td { border-bottom: 0; }
.fstate { width: 22px; }
.dot-st { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--pend); }
.dot-st.approved { background: var(--ok); }
.dot-st.observed { background: var(--warn); }
.fname a { text-decoration: none; font-weight: 500; word-break: break-word; }
.fcomment { font-size: 12px; color: var(--warn); }
.facts { width: 1%; white-space: nowrap; text-align: right; }
.ico { border: 0; background: transparent; color: var(--muted); padding: 3px; margin-left: 2px; border-radius: 4px; line-height: 0; vertical-align: middle; }
.ico:hover { background: #eef0f3; color: var(--text); }
.ico.ok { color: var(--ok); } .ico.ok:hover { background: var(--ok-bg); }
.ico.warn { color: var(--warn); } .ico.warn:hover { background: var(--warn-bg); }
.ico.danger:hover { background: var(--danger-bg); color: var(--danger); }

.drop { margin-top: 10px; border: 2px dashed #c9d1dc; border-radius: var(--radius); padding: 16px; text-align: center; color: var(--muted); font-size: 14px; transition: all .15s; background: #fafbfd; }
.drop.over { border-color: var(--primary); background: #eaf1fb; color: var(--primary-dark); }
.drop.busy { opacity: .6; pointer-events: none; }
.drop b { color: var(--primary); cursor: pointer; }
.drop input { display: none; }

.item-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; align-items: center; }
.btn { border: 1px solid var(--border); background: #fff; color: var(--text); padding: 6px 12px; border-radius: 6px; font-size: 13px; font-weight: 500; }
.btn:hover { background: #f4f5f7; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.warn { background: #fff; border-color: #e0b070; color: var(--warn); }
.btn.danger { background: #fff; border-color: #e8b4ae; color: var(--danger); }
.btn.sm { padding: 3px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn .dot { display: inline-block; min-width: 18px; padding: 0 5px; height: 18px; line-height: 18px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; text-align: center; margin-left: 6px; }

.na-note { font-size: 13px; color: var(--muted); margin-top: 8px; font-style: italic; }

/* Gastos */
.pbox.money .pct { color: var(--primary-dark); font-size: 24px; }
.mini.money { color: var(--primary-dark); font-weight: 600; min-width: auto; }
.expenses { margin-top: 10px; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; font-size: 13px; }
.exp-head, .exp-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: 8px; align-items: center; padding: 6px 10px; }
.exp-head { background: #f4f5f7; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .3px; }
.exp-row { border-top: 1px solid var(--border); }
.exp-row.total { background: #fafbfc; font-weight: 600; }
.exp-monthly { font-weight: 600; color: var(--primary-dark); }
.exp-actions { display: flex; gap: 4px; }
@media (max-width: 640px) { .exp-head { display: none; } .exp-row { grid-template-columns: 1fr 1fr; } .exp-name { grid-column: 1 / -1; } }

/* Panel lateral (preguntas) */
.overlay { position: fixed; inset: 0; background: rgba(16,24,40,.35); z-index: 30; display: none; }
.overlay.show { display: block; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100%); background: var(--card); z-index: 31; transform: translateX(100%); transition: transform .2s; display: flex; flex-direction: column; box-shadow: -4px 0 20px rgba(0,0,0,.12); }
.drawer.show { transform: translateX(0); }
.drawer-head { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.drawer-head h3 { margin: 0; font-size: 15px; flex: 1; }
.drawer-head small { display: block; color: var(--muted); font-weight: 400; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px; background: #f8f9fb; }
.msg { max-width: 88%; margin-bottom: 10px; padding: 9px 12px; border-radius: 10px; background: #fff; border: 1px solid var(--border); white-space: pre-wrap; word-break: break-word; }
.msg .meta { font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.msg.mine { margin-left: auto; background: #e8f0fb; border-color: #cfdcf0; }
.drawer-foot { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.drawer-foot textarea { flex: 1; resize: none; height: 64px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; }
.empty-msg { color: var(--muted); font-size: 13px; text-align: center; margin-top: 30px; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(16,24,40,.4); z-index: 40; display: none; align-items: center; justify-content: center; padding: 16px; }
.modal.show { display: flex; }
.modal .box { background: var(--card); border-radius: var(--radius); width: min(520px, 100%); padding: 20px; box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.modal h3 { margin: 0 0 10px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input, .field textarea, .field select { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.field textarea { min-height: 80px; resize: vertical; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

/* Toast */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1f2933; color: #fff; padding: 10px 16px; border-radius: 6px; font-size: 14px; z-index: 50; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90%; }
.toast.show { opacity: 1; }
.toast.err { background: var(--danger); }

/* Tabs y filtros */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tab { border: 1px solid var(--border); background: #fff; padding: 6px 12px; border-radius: 20px; font-size: 13px; }
.tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Tablas admin */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
tr.click { cursor: pointer; }
tr.click:hover { background: #f8f9fb; }
.table-wrap { overflow-x: auto; }
.linkbox { display: flex; gap: 8px; align-items: center; background: #f8f9fb; border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; margin-top: 6px; font-size: 13px; }
.linkbox code { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.login { max-width: 380px; margin: 60px auto; }
.login h1 { font-size: 20px; margin: 0 0 4px; }
.err { color: var(--danger); font-size: 13px; margin-top: 6px; }
.activity li { padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.activity li:last-child { border-bottom: 0; }
.activity .t { color: var(--muted); font-size: 12px; }
.check, .field label.check { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 14px; color: var(--text); }
.check input { margin: 0; flex: none; }

@media (max-width: 640px) {
  .container { padding: 12px; }
  .card { padding: 14px; }
  .section-head .mini { display: none; }
  .who { display: none; }
  .item-head { flex-wrap: wrap; }
}
