:root {
  --bg: #f5f6f8; --surface: #fff; --text: #1a1d23; --muted: #626b7a; --line: #e2e5ea;
  --accent: #1d4ed8; --accent-text: #fff; --danger: #b42318; --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12141a; --surface: #1b1e26; --text: #eceef2; --muted: #9aa3b2; --line: #2b303b;
    --accent: #5b8cff; --accent-text: #0b1020; --danger: #ff7b6e;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 1.35rem; margin: 0; }
.muted { color: var(--muted); }

.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar-in { max-width: 1100px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand { font-weight: 700; letter-spacing: .01em; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; }
.nav a.on { background: var(--bg); color: var(--text); font-weight: 600; }
.who { display: flex; align-items: center; gap: 10px; font-size: .9rem; }

main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.tools { display: flex; gap: 8px; flex-wrap: wrap; }

.btn { border: 1px solid var(--line); background: var(--surface); padding: 8px 14px; border-radius: 8px; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: .85rem; }

input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { min-height: 80px; resize: vertical; }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 3px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line); }
td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr.row { cursor: pointer; }
tbody tr.row:hover { background: var(--bg); }
.badge { font-size: .75rem; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 0; width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 24px); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dlg-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.dlg-body { padding: 18px 20px; overflow: auto; }
.dlg-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: space-between; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.grid .full { grid-column: 1 / -1; }
.err { color: var(--danger); min-height: 1.3em; font-size: .9rem; }

.auth { max-width: 380px; margin: 12vh auto; padding: 28px; }
.auth h1 { margin-bottom: 4px; }
.auth form > div { margin-top: 12px; }
.auth .btn { width: 100%; margin-top: 16px; }

@media (max-width: 680px) {
  .grid { grid-template-columns: 1fr; }
  thead { display: none; }
  table, tbody, tr, td { display: block; }
  td { border: 0; padding: 2px 14px; }
  tr { padding: 10px 0; border-bottom: 1px solid var(--line); }
  td[data-l]::before { content: attr(data-l) ": "; color: var(--muted); }
  .nav { order: 3; flex-basis: 100%; }
}

/* Cotizaciones y facturas */
.pad { padding: 18px 20px; }
.r { text-align: right; }
h2 { font-size: 1.05rem; margin: 22px 0 8px; }
.row-inline { display: flex; gap: 8px; align-items: center; }
.pre { white-space: pre-wrap; }
.big { font-size: 1.05rem; }
.warn { border-color: var(--danger); color: var(--danger); margin-bottom: 14px; }
.card + .card { margin-top: 14px; }
.items { margin: 14px 0; }
.items th, .items td { padding: 8px 10px; }
.items.edit td { padding: 4px 6px; border: 0; }
.items.edit input { padding: 6px 8px; }
.items.edit .qty { width: 80px; text-align: right; }
.items.edit .pr { width: 120px; text-align: right; }
.totals { margin-left: auto; width: min(320px, 100%); }
.totals > div { display: flex; justify-content: space-between; padding: 4px 10px; }
.totals .grand { border-top: 1px solid var(--line); font-weight: 700; font-size: 1.1rem; margin-top: 4px; padding-top: 8px; }
.radios label { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 1rem; padding: 4px 0; }
.radios input { width: auto; }
tr.voided td { text-decoration: line-through; color: var(--muted); }
.badge.st-accepted, .badge.st-paid { color: #067647; border-color: #067647; }
.badge.st-sent, .badge.st-partial { color: var(--accent); border-color: var(--accent); }
.badge.st-rejected, .badge.st-void { color: var(--danger); border-color: var(--danger); }
a.btn { text-decoration: none; display: inline-block; color: inherit; }
a.btn.primary { color: var(--accent-text); }

.printbar { max-width: 820px; margin: 16px auto; padding: 0 16px; display: flex; justify-content: space-between; }
.doc { max-width: 820px; margin: 0 auto 40px; background: #fff; color: #111; padding: 40px; border: 1px solid var(--line); }
.doc header { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.doc h2 { margin: 0 0 4px; font-size: 1.3rem; }
.doc h3 { margin: 22px 0 6px; font-size: 1rem; }
.doc .muted, .doc th { color: #555; }
.doc th, .doc td { border-bottom: 1px solid #ddd; }
.doc .totals .grand { border-color: #bbb; }
@media print {
  .noprint { display: none !important; }
  body { background: #fff; }
  .doc { border: 0; padding: 0; margin: 0; max-width: none; }
}

/* Kanban y tareas */
.board { display: grid; grid-template-columns: repeat(5, minmax(220px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: start; }
.col { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; min-height: 160px; }
.col.over { outline: 2px dashed var(--accent); outline-offset: -4px; }
.col h3 { margin: 2px 4px 10px; font-size: .95rem; }
.cards { display: flex; flex-direction: column; gap: 8px; }
.kcard { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; cursor: grab; }
.kcard:hover, .kcard:focus-visible { border-color: var(--accent); outline: none; }
.kcard.drag { opacity: .45; }
.kcard .meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 6px; font-size: .82rem; color: var(--muted); }
.av { margin-left: auto; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: var(--accent-text); display: inline-grid; place-items: center; font-size: .7rem; font-weight: 700; }
.late { color: var(--danger); font-weight: 600; }
.small { font-size: .85rem; }
label.task { display: flex; gap: 10px; align-items: center; color: var(--text); font-size: 1rem; margin: 0; padding: 6px 0; }
label.task input { width: auto; }
label.task span:nth-of-type(1) { flex: 1; }
label.task.pad { border-bottom: 1px solid var(--line); }
label.task.done span { text-decoration: line-through; color: var(--muted); }
@media (max-width: 680px) { .board { grid-template-columns: repeat(5, 78vw); scroll-snap-type: x mandatory; } .col { scroll-snap-align: start; } }

/* Avisos y pagina publica */
.bellwrap { position: relative; }
.count { background: var(--danger); color: #fff; border-radius: 99px; padding: 0 6px; font-size: .75rem; margin-left: 2px; }
.bellpanel { position: absolute; right: 0; top: calc(100% + 6px); width: min(360px, 90vw); max-height: 70vh; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.18); z-index: 20; }
.nitem { display: block; padding: 10px 14px; border-bottom: 1px solid var(--line); color: var(--text); text-decoration: none; }
.nitem:last-child { border-bottom: 0; }
.nitem.new { background: var(--bg); border-left: 3px solid var(--accent); }
.nitem:hover { background: var(--bg); }
.pub { margin-top: 24px; }
.pubmsg { border: 1px solid #999; border-radius: 8px; padding: 12px 14px; margin: 0 0 18px; background: #f4f4f4; }
.pubmsg.ok { border-color: #067647; background: #ecfdf3; color: #054f31; }
.respond { margin-top: 28px; padding-top: 18px; border-top: 2px solid #ddd; max-width: 420px; }
.respond label { color: #555; }
.respond input[type=text], .respond input:not([type=checkbox]) { background: #fff; color: #111; border-color: #bbb; }
.respond .chk { display: flex; gap: 8px; align-items: center; margin: 12px 0; color: #111; font-size: 1rem; }
.respond .chk input { width: auto; }
.respond .btn.primary { width: 100%; padding: 12px; }
.pub .err { color: #b42318; }
@media print { .bellwrap { display: none; } }

body.pubpage { background: #eef0f3; }
.totals .net { border-top: 1px solid var(--line); margin-top: 2px; padding-top: 6px; font-weight: 600; }
