:root {
  --bg: #f5f6f8; --panel: #ffffff; --ink: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --brand: #0f3b5f; --brand-2: #14b8a6; --ok: #15803d; --no: #b91c1c; --warn: #d97706;
  --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
       color: var(--ink); background: var(--bg); font-size: 14px; }
a { color: inherit; text-decoration: none; }
h1 { font-size: 22px; margin: 0 0 4px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
code { font-size: 12px; background: #f1f5f9; padding: 1px 4px; border-radius: 4px; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--brand); color: #dbeafe; padding: 18px 14px; display: flex;
           flex-direction: column; gap: 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 18px; color: #fff; }
.brand b { color: var(--brand-2); }
.brand.big { font-size: 24px; justify-content: center; color: var(--brand); }
.logo { width: 32px; height: 32px; border-radius: 8px; background: var(--brand-2); color: #fff;
        display: grid; place-items: center; font-weight: 700; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a, .acc { padding: 8px 10px; border-radius: 8px; display: flex; align-items: center; gap: 8px; }
.sidebar nav a:hover, .acc:hover { background: rgba(255,255,255,.08); }
.sidebar nav a.active, .acc.active { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.side-title { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; opacity: .7; margin: 4px 10px; }
.side-section { display: flex; flex-direction: column; gap: 2px; }
.sidebar-foot { margin-top: auto; display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.pill { background: var(--warn); color: #fff; padding: 2px 8px; border-radius: 99px; font-size: 11px; }
.badge { margin-left: auto; background: rgba(255,255,255,.2); color: #fff; border-radius: 99px;
         padding: 0 8px; font-size: 12px; }
.badge.warn { background: var(--warn); }
.content { padding: 24px 32px; max-width: 1100px; width: 100%; }

/* ---------- elementos ---------- */
.btn { border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 8px 14px;
       border-radius: 8px; cursor: pointer; font: inherit; font-weight: 600; display: inline-block; }
.btn:hover { border-color: #94a3b8; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.full { width: 100%; }
.btn-primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn-primary:hover { filter: brightness(.95); border-color: var(--brand-2); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-no { color: var(--no); }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; background: #ecfdf5; color: #065f46;
         border: 1px solid #a7f3d0; }
.flash.error { background: #fef2f2; color: #991b1b; border-color: #fecaca; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; }
.page-head p { margin: 0; }
.search input { width: 320px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.notice { display: block; background: #fffbeb; border: 1px solid #fde68a; color: #92400e; padding: 10px 14px;
          border-radius: 8px; margin-bottom: 12px; }
.empty { padding: 32px; text-align: center; color: var(--muted); background: #fff; border-radius: var(--radius); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; margin-right: 4px; }
.dot.all { background: linear-gradient(135deg,#0f766e,#1d4ed8,#b45309); }
.dot.big { width: 16px; height: 16px; }
.tag { font-size: 11px; border: 1px solid var(--line); border-radius: 99px; padding: 1px 8px; font-weight: 600; }
.tag.cfdi { background: #ecfeff; color: #0e7490; border-color: #a5f3fc; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: #e0f2fe; color: var(--brand);
          display: grid; place-items: center; font-weight: 700; flex: none; }

/* ---------- lista de correos ---------- */
.list { background: var(--panel); border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; }
.row { display: flex; gap: 12px; padding: 12px 16px 12px 0; border-bottom: 1px solid var(--line); align-items: center; }
.row:last-child { border-bottom: 0; }
.row:hover { background: #f8fafc; }
.row.static { padding-left: 16px; }
.bar { width: 4px; align-self: stretch; border-radius: 0 4px 4px 0; }
.row-main { flex: 1; min-width: 0; }
.row-top { display: flex; align-items: center; gap: 8px; }
.from { font-weight: 600; }
.tags { display: flex; gap: 6px; }
.date { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.subject { margin-top: 2px; }
.preview { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.row.unread .subject, .row.unread .from { font-weight: 700; }
.row.unread .subject::before { content: "● "; color: var(--brand-2); }

/* ---------- tarjetas ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
        display: flex; flex-direction: column; gap: 8px; }
.card .preview { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card-head { display: flex; align-items: center; gap: 10px; }
.card-actions form { display: flex; gap: 8px; }
.acc-form { display: flex; flex-direction: column; gap: 10px; }
.acc-form input[name=company] { width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px;
                                font: inherit; margin-top: 4px; }
.swatches { display: flex; gap: 8px; }
.swatch { width: 24px; height: 24px; border-radius: 50%; cursor: pointer; outline-offset: 2px; }
.swatch input { display: none; }
.swatch:has(input:checked) { outline: 2px solid var(--ink); }

/* ---------- mensaje ---------- */
.back { display: inline-block; margin-bottom: 12px; color: var(--muted); }
.message { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 24px; }
.msg-meta { display: flex; align-items: center; gap: 12px; margin: 12px 0 16px; }
.msg-meta .tag { margin-left: auto; }
.msg-body { width: 100%; min-height: 360px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.msg-actions { margin-top: 14px; }
.invoice-box { border: 1px solid #a5f3fc; background: #f0fdfa; border-radius: var(--radius); padding: 14px;
               margin-bottom: 14px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.invoice-grid { display: grid; grid-template-columns: repeat(4, auto); gap: 6px 28px; }
.invoice-grid div { display: flex; flex-direction: column; }

/* ---------- facturas ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { border: 1px solid var(--line); background: #fff; padding: 5px 12px; border-radius: 99px; display: flex; align-items: center; }
.chip.active { border-color: var(--brand); background: var(--brand); color: #fff; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 14px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
        display: flex; flex-direction: column; gap: 4px; }
.stat b { font-size: 22px; }
.table-wrap { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #f8fafc; }
td a { color: var(--brand); font-weight: 600; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- acceso ---------- */
.login-page { display: grid; place-items: center; min-height: 100vh; background: var(--brand); }
.login-card { background: #fff; padding: 32px; border-radius: 14px; width: 340px; display: flex;
              flex-direction: column; gap: 14px; text-align: center; }
.login-card label { text-align: left; display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.login-card input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.login-card .muted { margin: 0; }

/* ---------- celular ---------- */
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .content { padding: 16px; }
  .page-head { flex-direction: column; }
  .search input { width: 100%; }
  .stats { grid-template-columns: 1fr; }
  .invoice-grid { grid-template-columns: 1fr 1fr; }
}

/* ---------- grupos y reglas ---------- */
.panel { margin-bottom: 26px; }
.panel h2 { font-size: 16px; margin: 0 0 10px; }
.grow { flex: 1; }
.text-in { width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.card.dashed { border-style: dashed; background: #fafafa; }
.decide { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line); padding-top: 10px; }
.decide label, .inline-form label { display: flex; align-items: center; gap: 8px; }
.decide select, .inline-form select { padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.check { cursor: pointer; }
.check input { accent-color: var(--brand-2); width: 16px; height: 16px; }
.inline-form { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.msg-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.small-link { font-size: 12px; opacity: .8; }
.decide label.check { align-items: flex-start; }
.decide label.check input { margin-top: 2px; flex: none; }
.decide label.check b { word-break: break-all; }
