:root {
  /* Colores de Framework Tax & Control (frameworktaxes.com) */
  --bg: #f3f6f0; --card: #fff; --text: #082a19; --muted: #5f6f64; --line: #d5dfd2; --soft: #e4ecdf;
  --primary: #064326; --primary-2: #0b5a32; --accent: #064326; --brand: #829b72;
  --ok: #1a7f4b; --warn: #b54708; --danger: #c0352b;
  --radius: 12px;
  --serif: Georgia, "Times New Roman", serif;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0c1611; --card: #14211a; --text: #e4ecdf; --muted: #9aab9f; --line: #26382d; --soft: #1d3025;
    --primary: #0b5a32; --primary-2: #2f6b45; --accent: #a9c197; --warn: #f0a35e; --ok: #6fcf97; }
  .logo { filter: brightness(0) invert(.92); }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); }
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
h1, h2, .stat strong, .month { font-family: var(--serif); }
h1 { font-size: 1.5rem; margin: 0 0 12px; }
h2 { font-size: 1.2rem; margin: 24px 0 10px; }
h3 { font-size: 1rem; margin: 0 0 8px; }

#topbar {
  position: sticky; top: 0; z-index: 5; display: flex; gap: 8px; align-items: center;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--primary); color: #fff; border-bottom: 3px solid var(--brand);
}
#topbar .brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; margin-right: auto; }
#topbar .brand img { padding: 3px; background: #fff; border-radius: 6px; }
#topbar .brand span { font-family: var(--serif); font-size: 1.15rem; font-weight: 700; letter-spacing: .04em; line-height: 1; }
#topbar .brand small { display: block; margin-top: 3px; font-family: system-ui, sans-serif; font-size: .62rem;
  font-weight: 600; letter-spacing: .18em; text-transform: uppercase; color: #e4ecdf; opacity: .8; }
@media (max-width: 480px) { #topbar .brand small, #who { display: none; } }
#topbar .ghost { color: #fff; border-color: rgba(255,255,255,.4); }
.menu { position: relative; }
.menu summary { list-style: none; display: flex; align-items: center; gap: 8px; padding: 3px 10px 3px 3px; cursor: pointer;
  border: 1px solid rgba(255,255,255,.35); border-radius: 99px; }
.menu summary::-webkit-details-marker { display: none; }
.menu summary::after { content: "▾"; font-size: .7rem; opacity: .8; }
.menu[open] summary, .menu summary:hover { background: rgba(255,255,255,.1); }
.avatar { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 99px; font-size: .8rem; font-weight: 700;
  color: var(--primary); background: #e4ecdf; }
#who { max-width: 22ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.menu-panel { position: absolute; right: 0; top: calc(100% + 8px); z-index: 10; display: flex; flex-direction: column; gap: 2px;
  min-width: 240px; padding: 8px; color: var(--text); box-shadow: 0 10px 30px rgba(0, 0, 0, .18); }
.menu-who { display: flex; flex-direction: column; gap: 2px; padding: 6px 10px 10px; margin-bottom: 4px;
  border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
#topbar .menu-panel .ghost { justify-content: flex-start; color: var(--text); border-color: transparent; }
#topbar .menu-panel .ghost:hover { background: var(--soft); }

/* Barra de carga: solo aparece si una petición tarda */
body.cargando::before { content: ""; position: fixed; z-index: 30; top: 0; left: 0; width: 35%; height: 3px;
  background: var(--brand); animation: carga 1s ease-in-out infinite; }
@keyframes carga { from { transform: translateX(-100%); } to { transform: translateX(300%); } }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.narrow { width: calc(100% - 32px); max-width: 380px; margin: 8vh auto 0; border-top: 4px solid var(--primary); }
.narrow .logo { display: block; width: 190px; height: auto; margin: 4px auto 18px; }
.narrow h1 { text-align: center; }
.narrow form button { width: 100%; margin-top: 4px; }
.narrow > a { display: block; text-align: center; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { margin-left: auto; }
.muted { color: var(--muted); font-size: .875rem; }
.error { color: var(--danger); min-height: 1.2em; }

label { display: block; font-size: .875rem; color: var(--muted); margin-bottom: 10px; }
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
input, select { display: block; width: 100%; margin-top: 4px; padding: 10px; font: inherit; color: var(--text);
  background: var(--card); border: 1px solid var(--line); border-radius: 8px; }
button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 14px;
  font: inherit; font-weight: 600; color: #fff; background: var(--primary); border: 1px solid transparent;
  border-radius: 8px; cursor: pointer; text-decoration: none;
}
button:disabled { opacity: .6; cursor: wait; }
.ghost { background: transparent; color: var(--accent); border-color: var(--line); }
.danger { background: var(--danger); }
.small { padding: 6px 10px; font-size: .85rem; }

.upload { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 8px; }
.upload label {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  margin: 0; padding: 22px 8px; min-height: 120px; font-size: 1rem; font-weight: 600; color: #fff;
  background: var(--primary); border-radius: var(--radius); cursor: pointer; text-align: center;
}
.upload label:nth-child(2) { background: var(--primary-2); }
.upload .icon { display: flex; }
.dropzone { display: flex; align-items: center; gap: 14px; margin: 0 0 8px; padding: 16px 18px; font-size: .95rem; color: var(--text);
  background: var(--card); border: 2px dashed var(--line); border-radius: var(--radius); cursor: pointer; }
.dropzone svg { flex: none; color: var(--accent); }
.dropzone .muted { display: block; margin-top: 2px; }
.dropzone u { color: var(--accent); }
.dropzone:hover, .dropzone.over { border-color: var(--brand); background: var(--soft); }
.upload input { display: none; }
#progress:empty { display: none; }
#progress { margin: 8px 0; }

.tabs { display: flex; gap: 4px; overflow-x: auto; margin: 12px 0; scrollbar-width: none; }
a.item { color: inherit; text-decoration: none; }
.tabs button { background: var(--card); color: var(--text); border-color: var(--line); flex: 0 0 auto; }
.tabs button.active { background: var(--primary); color: #fff; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat strong { display: block; font-size: 1.3rem; margin-top: 4px; font-variant-numeric: tabular-nums; }
button.stat { display: block; text-align: left; font-weight: 400; color: var(--text); }
button.stat:hover { border-color: var(--brand); }
.warn-text { color: var(--warn); }

.modelo table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.modelo td { padding: 4px 0; border-bottom: 1px solid var(--line); }
.modelo td:last-child, .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.modelo tr:last-child td { font-weight: 700; border-bottom: 0; padding-top: 8px; }

.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; gap: 12px; align-items: center; padding: 12px 14px; cursor: pointer; }
.item > div { min-width: 0; flex: 1; }
.item .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Tres tonos: neutro, verde (venta, recibido, conectado) y naranja (algo que revisar) */
.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; white-space: nowrap;
  background: var(--soft); color: var(--muted); border: 1px solid transparent; }
.badge.emitida { color: var(--accent); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.badge.recibida { background: transparent; border-color: var(--line); }
.badge.revisar { color: var(--warn); background: color-mix(in srgb, var(--warn) 13%, transparent); }

/* Facturas: proveedor e importe arriba; fecha y estados debajo */
.item.factura { display: block; }
.factura-top { display: flex; gap: 12px; align-items: baseline; }
.factura-top .title { flex: 1; min-width: 0; }
.importe { font-family: var(--serif); font-size: 1.05rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.factura-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin-top: 4px; }
.factura-meta .chips { margin: 0 0 0 auto; }
@media (max-width: 640px) { .factura-meta .chips { margin-left: 0; } }
.item.atencion { border-left: 4px solid var(--warn); }
.sin-importe { margin-top: 12px; }
.sin-importe .chips { margin-top: 8px; }

/* Panel de la gestoría: lista de tareas y tabla de empresas */
.tasks { padding: 4px 0; margin-bottom: 8px; }
.task { display: flex; align-items: center; gap: 10px; padding: 10px 16px; color: inherit; text-decoration: none;
  border-bottom: 1px solid var(--line); }
.task:last-of-type { border-bottom: 0; }
.task:hover { background: var(--soft); }
.task-text { flex: 1; min-width: 0; }
.task .arrow { color: var(--muted); }
.tasks .more { margin: 6px 16px 8px; }
.dot { flex: none; width: 9px; height: 9px; border-radius: 99px; background: var(--muted); }
.dot.revisar { background: var(--warn); } .dot.info { background: var(--ok); } .dot.fiscal { background: #2563eb; }
.card.table { padding: 4px 12px; }
table.data th { font-size: .8rem; font-weight: 600; color: var(--muted); }
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--text); }
table.data .num { text-align: right; }
table.data tr[data-action] { cursor: pointer; }
table.data tr[data-action]:hover td { background: var(--soft); }
.cell-title { font-weight: 600; }
.cell-title a { color: inherit; text-decoration: none; }
@media (max-width: 640px) { .hide-sm, .task-gestor { display: none; } }

/* Móvil: las secciones de la ficha pasan a una barra fija abajo, como en una app */
.bottom-nav { display: none; }
@media (max-width: 640px) {
  .company-tabs { display: none; }
  .bottom-nav { position: fixed; z-index: 6; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, 1fr);
    padding: 4px 4px max(4px, env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line);
    box-shadow: 0 -2px 12px rgba(0, 0, 0, .06); }
  .bottom-nav button { position: relative; flex-direction: column; gap: 2px; padding: 6px 0; font-size: .7rem; font-weight: 600;
    color: var(--muted); background: none; border: 0; border-radius: 8px; }
  .bottom-nav button.active { color: var(--accent); background: var(--soft); }
  .bottom-nav .count { position: absolute; top: 2px; left: calc(50% + 6px); }
  main:has(.bottom-nav) { padding-bottom: 92px; }
  body:has(.bottom-nav) #toast { bottom: 88px; }
}

.sections { margin-top: 16px; }
.lector { margin-bottom: 16px; font-size: .9rem; }
.sections button { font-size: 1rem; padding: 10px 18px; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
label.check input { width: auto; margin: 0; }

.t-nota { --c: #64748b; } .t-gasto { --c: #7c3aed; } .t-cobro { --c: #1a7f4b; }
.t-pago { --c: #ea580c; } .t-fiscal { --c: #2563eb; }
@media (max-width: 480px) { .badge.tipo { display: none; } }
.month { margin: 0; }
.month::first-letter { text-transform: uppercase; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin: 12px 0 8px; }
.dow { text-align: center; font-size: .75rem; font-weight: 600; color: var(--muted); }
.day { flex-direction: column; justify-content: space-between; min-height: 56px; padding: 6px 2px; color: var(--text);
  background: var(--card); border: 1px solid var(--line); font-weight: 500; }
.day.out { opacity: .45; }
.day.today span:first-child { color: #fff; background: var(--primary); border-radius: 99px; padding: 0 7px; }
.day.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.dots { display: flex; gap: 3px; justify-content: center; flex-wrap: wrap; min-height: 7px; }
.dots i, .legend i { width: 7px; height: 7px; border-radius: 99px; background: var(--c); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: .8rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.item[class*="t-"] { border-left: 4px solid var(--c); }
.badge.tipo { color: var(--c); background: transparent; border: 1px solid var(--c); }

table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.card.wide { overflow-x: auto; }
.nowrap { white-space: nowrap; }
tr.alerta td { background: color-mix(in srgb, var(--warn) 9%, transparent); }
.perms { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-bottom: 10px; }
.perms label.check { margin: 0; white-space: nowrap; }
.filters { display: grid; gap: 0 12px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); margin-bottom: 8px; }
.steps { padding-left: 20px; font-size: .9rem; color: var(--muted); }
.steps li { margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.aviso { margin-bottom: 10px; border-left: 4px solid var(--brand); background: var(--soft); display: flex; flex-direction: column; gap: 4px; }
.aviso.row { flex-direction: row; }
.count { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 99px; font-size: .75rem;
  background: var(--warn); color: #fff; }
.tray { margin: 8px 0; }
.thumbs { display: flex; gap: 8px; overflow-x: auto; margin: 10px 0; }
.thumbs figure { position: relative; margin: 0; flex: 0 0 auto; text-align: center; font-size: .75rem; color: var(--muted); }
.thumbs img { display: block; width: 84px; height: 112px; object-fit: cover; border: 1px solid var(--line); border-radius: 6px; }
.thumbs button { position: absolute; top: 2px; right: 2px; padding: 0 6px; background: var(--card); }
.chat { display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow-y: auto; margin-bottom: 10px; }
.msg { max-width: 85%; padding: 8px 12px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); }
.msg.mine { align-self: flex-end; background: var(--soft); }
.msg .texto { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .ref { display: block; font-size: .8rem; color: var(--accent); margin: 2px 0; }
#chat-form textarea { flex: 1; min-width: 200px; font: inherit; padding: 10px; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 8px; resize: vertical; }
textarea { display: block; width: 100%; margin-top: 4px; padding: 10px; font: inherit; color: var(--text);
  background: var(--card); border: 1px solid var(--line); border-radius: 8px; }
label.check.card { margin-bottom: 10px; }
dialog.wide { width: min(1150px, calc(100vw - 24px)); }
.split { display: grid; gap: 16px; }
@media (min-width: 860px) { .split { grid-template-columns: 1.1fr 1fr; align-items: start; } }
.preview { max-height: 45vh; overflow: auto; padding: 8px; border-radius: 8px; background: var(--soft); }
@media (min-width: 860px) { .split .preview { max-height: 72vh; position: sticky; top: 0; } }
.preview.tall { max-height: 70vh; margin-bottom: 12px; }
.preview canvas, .preview img { display: block; width: 100%; height: auto; margin-bottom: 8px; background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .15); }

dialog { width: min(560px, calc(100vw - 24px)); max-height: 90vh; border: 0; border-radius: var(--radius);
  padding: 20px; background: var(--card); color: var(--text); }
dialog::backdrop { background: rgba(10, 15, 25, .55); }
.lineas { display: grid; grid-template-columns: 1fr 80px 1fr 36px; gap: 6px; align-items: end; margin-bottom: 8px; }
.lineas label { margin: 0; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.secret { font-family: ui-monospace, monospace; font-size: 1.2rem; overflow-wrap: anywhere; padding: 10px; background: var(--bg); border-radius: 8px; user-select: all; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20; max-width: calc(100vw - 32px);
  padding: 10px 16px; border-radius: 8px; background: #1b2330; color: #fff; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.list + .row, .list + p + .row, .tasks + .row, h1 + p.muted + .row { margin-top: 24px; }
@media (max-width: 640px) {
  .stats { gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat strong { font-size: 1.15rem; }
}
.preview.tall canvas, .preview.tall img { max-width: 760px; margin-left: auto; margin-right: auto; }

/* App instalable y sin conexión */
#offline { position: sticky; top: 0; z-index: 7; padding: 6px 16px; font-size: .85rem; text-align: center; color: #fff;
  background: var(--warn); }
#install-banner { max-width: 1068px; margin: 12px auto 0; width: calc(100% - 32px); }
#install-banner img { border-radius: 10px; flex: none; }
.aviso.alerta { border-left-color: var(--danger); }
.aviso.alerta strong { color: var(--danger); }
code { font-family: ui-monospace, monospace; font-size: .85em; padding: 1px 5px; border-radius: 4px; background: var(--soft);
  overflow-wrap: anywhere; }
@media (display-mode: standalone) { #topbar { padding-top: max(10px, env(safe-area-inset-top)); } }

/* Textos legales */
.legal { max-width: 780px; margin: 0 auto; line-height: 1.6; }
.legal h1 { margin-top: 14px; }
.legal h2 { font-size: 1.05rem; margin: 22px 0 6px; }
.legal p, .legal li { font-size: .95rem; }
.legal ul { padding-left: 20px; }
.legal a { color: var(--accent); }
.datos { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 8px 0; font-size: .95rem; }
.datos dt { color: var(--muted); }
.datos dd { margin: 0; }
.falta { color: var(--warn); font-weight: 600; }
.legal-tabla { margin: 8px 0; }
.legal-tabla td { vertical-align: top; }
.legal-links { margin: 18px 0 0; font-size: .8rem; text-align: center; color: var(--muted); }
.legal-links a { color: var(--muted); }
.legal .legal-links { margin-top: 28px; padding-top: 14px; border-top: 1px solid var(--line); }
label.check.acepto { align-items: flex-start; font-size: .85rem; line-height: 1.4; }
label.check.acepto input { margin-top: 2px; flex: none; }
label.check.acepto a { color: var(--accent); }
@media (max-width: 640px) { .datos { grid-template-columns: 1fr; gap: 0; } .datos dd { margin-bottom: 8px; } }
@media (max-width: 640px) {
  .legal-tabla tr:first-child { display: none; }
  .legal-tabla tr { display: block; padding: 8px 0; border-bottom: 1px solid var(--line); }
  .legal-tabla td { display: block; padding: 2px 0; border: 0; }
  .legal-tabla td:first-child { font-weight: 600; }
  .legal-tabla td[data-l]:not(:first-child)::before { content: attr(data-l) ": "; color: var(--muted); }
}
