:root {
  --bg: #f4f6fa; --panel: #fff; --text: #1b2230; --muted: #667085; --line: #e3e7ee;
  --brand: #2f6df6; --brand-d: #1f55cc; --ok: #16a34a; --warn: #d97706; --bad: #dc2626; --side: #111827;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0e1320; --panel: #171e2e; --text: #e6eaf2; --muted: #93a0b8; --line: #263049; --side: #0a0f1a; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
h1 { font-size: 22px; margin: 0 0 4px; } h2 { font-size: 16px; margin: 0 0 12px; } h3 { font-size: 14px; margin: 0 0 8px; }
a { color: var(--brand); text-decoration: none; } a:hover { text-decoration: underline; }
.muted { color: var(--muted); } .small { font-size: 12px; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.ok { color: var(--ok); } .warn { color: var(--warn); } .bad { color: var(--bad); }
.hidden { display: none !important; }

/* Layout */
.shell { display: flex; min-height: 100vh; }
.side { width: 220px; background: var(--side); color: #cbd5e1; padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; flex-shrink: 0; }
.brand { color: #fff; font-weight: 700; font-size: 17px; padding: 4px 10px 16px; display: flex; gap: 8px; align-items: center; }
.brand i { width: 22px; height: 22px; border-radius: 6px; background: var(--brand); display: inline-block; }
.nav a { display: flex; justify-content: space-between; align-items: center; color: #cbd5e1; padding: 9px 10px; border-radius: 8px; margin-bottom: 2px; }
.nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; }
.nav a.active { background: var(--brand); color: #fff; }
.badge { background: var(--bad); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 7px; min-width: 18px; text-align: center; }
.side-foot { margin-top: auto; padding: 10px; font-size: 12px; }
.side-foot button { margin-top: 8px; width: 100%; }
.main { flex: 1; min-width: 0; padding: 24px 28px 60px; max-width: 1200px; }
.topbar { display: none; }
@media (max-width: 800px) {
  .shell { flex-direction: column; }
  .side { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 8px; gap: 4px; }
  .brand { padding: 4px 8px; } .nav { display: flex; flex-wrap: wrap; gap: 2px; } .nav a { margin: 0; padding: 6px 9px; }
  .side-foot { margin: 0 0 0 auto; padding: 0; } .side-foot button { margin: 0; width: auto; } .side-foot .who { display: none; }
  .main { padding: 16px 14px 60px; }
}

/* Components */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.grid { display: grid; gap: 14px; } .grid.cols4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); } .grid.cols2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 4px; }
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 8px; padding: 7px 13px; cursor: pointer; display: inline-block; }
button:hover, .btn:hover { border-color: var(--brand); text-decoration: none; }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; } button.primary:hover { background: var(--brand-d); }
button.danger { color: var(--bad); } button.sm { padding: 3px 9px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
input[type=checkbox] { width: auto; }
label.inline { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; color: var(--text); margin: 4px 0 10px; cursor: pointer; }
pre.code { background: var(--bg); border-radius: 8px; padding: 10px; overflow-x: auto; font-family: ui-monospace, Consolas, monospace; }
.quote td, .quote th { padding: 6px 8px; } .quote tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
textarea { min-height: 90px; resize: vertical; } textarea.big { min-height: 260px; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; } .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
tr.click { cursor: pointer; } tr.click:hover td { background: rgba(47,109,246,.05); }
.table-wrap { overflow-x: auto; }
.pill { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; background: var(--line); }
.pill.activo, .pill.hecho, .pill.entregado, .pill.cobrado, .pill.listo { background: rgba(22,163,74,.15); color: var(--ok); }
.pill.prospecto, .pill.propuesta, .pill.pendiente, .pill.borrador { background: rgba(47,109,246,.15); color: var(--brand); }
.pill.en_curso, .pill.pausado, .pill.analizando, .pill.alta { background: rgba(217,119,6,.15); color: var(--warn); }
.pill.baja, .pill.devuelto, .pill.error { background: rgba(220,38,38,.15); color: var(--bad); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 9px 14px; color: var(--muted); }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }
.empty { text-align: center; color: var(--muted); padding: 28px 10px; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; } .kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; }
.pre { white-space: pre-wrap; word-break: break-word; }
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; } .bar > span { display: block; height: 100%; background: var(--brand); } .bar.hot > span { background: var(--bad); }
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; background: rgba(217,119,6,.12); border: 1px solid rgba(217,119,6,.35); }
.alert.bad { background: rgba(220,38,38,.1); border-color: rgba(220,38,38,.35); }
.list-item { padding: 9px 0; border-bottom: 1px solid var(--line); } .list-item:last-child { border: 0; }
ul.clean { margin: 0; padding-left: 18px; } ul.clean li { margin-bottom: 4px; }

/* Calendario / agenda */
.day-group h3 { margin-top: 16px; text-transform: capitalize; }
.task { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; background: var(--panel); }
.task.done .t-title { text-decoration: line-through; color: var(--muted); }
.task .t-main { flex: 1; min-width: 0; }
.task input[type=checkbox] { width: auto; margin-top: 4px; }

/* Chat */
.chat { display: flex; flex-direction: column; height: calc(100vh - 220px); min-height: 360px; }
.chat-log { flex: 1; overflow-y: auto; padding: 8px; background: var(--bg); border-radius: 8px; border: 1px solid var(--line); }
.msg { max-width: 75%; padding: 8px 12px; border-radius: 12px; margin-bottom: 8px; background: var(--panel); border: 1px solid var(--line); }
.msg.me { margin-left: auto; background: var(--brand); color: #fff; border-color: var(--brand); }
.msg .meta { font-size: 11px; opacity: .7; }
.chat-form { display: flex; gap: 8px; margin-top: 10px; } .chat-form textarea { min-height: 44px; height: 44px; }

/* Modal, toast, login */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--panel); color: var(--text); width: min(560px, 94vw); box-shadow: 0 20px 50px rgba(0,0,0,.3); }
dialog.wide { width: min(820px, 96vw); }
dialog::backdrop { background: rgba(10,15,26,.55); }
.dlg-head { padding: 16px 20px 0; display: flex; justify-content: space-between; } .dlg-body { padding: 14px 20px 6px; max-height: 70vh; overflow-y: auto; } .dlg-foot { padding: 12px 20px 18px; display: flex; gap: 8px; justify-content: flex-end; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; margin-bottom: 6px; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 99; }
.toast { background: var(--side); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: 340px; } .toast.bad { background: var(--bad); }
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: min(420px, 100%); padding: 28px; } .login .brand { color: var(--text); padding: 0 0 16px; font-size: 20px; }
.qr { display: block; margin: 8px auto; background: #fff; padding: 6px; border-radius: 8px; }
code.secret { display: block; text-align: center; letter-spacing: .12em; word-break: break-all; padding: 8px; background: var(--bg); border-radius: 8px; }
.pw-cell { font-family: ui-monospace, Consolas, monospace; }
.vault-lock { text-align: center; padding: 30px 10px; }
@media print { .side, .actions, .tabs, #toasts { display: none !important; } .main { padding: 0; } }
.codes { columns: 2; font-size: 15px; letter-spacing: .06em; }
