:root{
  --paper:#EFF1EA;
  --surface:#FFFFFF;
  --ink:#16241D;
  --muted:#6E7568;
  --rule:#C7CDBF;
  --green:#2F5233;
  --green-soft:#E4EBE2;
  --amber:#B3541E;
  --amber-soft:#F5E6DA;
  --red:#9C3B2E;
}
*{box-sizing:border-box;}
html,body{margin:0;padding:0;}
body{
  background:var(--paper);
  color:var(--ink);
  font-family:'IBM Plex Sans', sans-serif;
  font-size:14px;
  line-height:1.5;
}
[hidden]{display:none!important;}
.login-screen{position:fixed;inset:0;z-index:200;background:var(--paper);display:flex;align-items:center;justify-content:center;}
.login-card{width:360px;background:#fff;border:1px solid var(--rule);padding:30px;box-shadow:0 18px 55px rgba(22,36,29,.12);}
.login-brand{margin-bottom:22px}.login-card h1{font-size:21px;margin:0 0 20px}.login-card label,.settings-card label{display:block;font-size:12px;color:var(--muted);margin:12px 0}.login-card input,.settings-card input,.settings-card textarea,.filter-panel input,.filter-panel select,.modal select{display:block;width:100%;margin-top:5px;padding:9px;border:1px solid var(--rule);background:#fff}.login-card .btn{width:100%;margin-top:12px}.login-error{color:var(--red);font-size:12px;margin-top:12px;min-height:18px}.link-button{border:0;background:none;color:inherit;text-decoration:underline;cursor:pointer;padding:8px 0;}
.filter-panel{display:flex;gap:10px;align-items:flex-end;flex-wrap:wrap;background:var(--surface);border:1px solid var(--rule);padding:12px;margin-bottom:14px}.filter-panel label{font-size:11px;color:var(--muted)}.filter-panel input,.filter-panel select{min-width:160px;padding:7px;margin-top:4px}.filter-panel .btn{margin-bottom:1px}
.settings-card{max-width:650px;background:var(--surface);border:1px solid var(--rule);padding:20px}.settings-card textarea{min-height:100px}.stats-grid{display:grid;grid-template-columns:repeat(3,minmax(140px,1fr));gap:10px;margin-bottom:18px}.stats-grid>div{background:var(--surface);border:1px solid var(--rule);padding:16px}.stats-grid strong{display:block;font-size:22px;color:var(--green)}.stats-grid span{font-size:11px;color:var(--muted)}.stats-lists{display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-bottom:24px}.stats-lists>div{background:var(--surface);border:1px solid var(--rule);padding:14px}.stats-lists h3{margin-top:0}.stats-lists p{display:flex;justify-content:space-between;border-bottom:1px solid var(--rule);padding-bottom:5px}
h1,h2,h3,.serif{font-family:'Source Serif 4', serif;}
.mono, td.num, .amount{font-family:'IBM Plex Mono', monospace; font-variant-numeric: tabular-nums;}

.app{display:flex; min-height:100vh;}

.sidebar{
  width:220px; flex-shrink:0;
  background:var(--ink); color:#EFF1EA;
  display:flex; flex-direction:column;
  padding:28px 0 16px 0;
}
.brand{
  font-family:'Source Serif 4', serif;
  font-size:19px; font-weight:600;
  padding:0 24px 24px 24px;
  border-bottom:1px solid rgba(239,241,234,0.15);
  margin-bottom:8px;
}
.brand .dot{color:#8CA089;}
nav{display:flex; flex-direction:column; margin-top:8px;}
nav button{
  all:unset; cursor:pointer;
  padding:11px 24px;
  font-size:13.5px; color:#C9CEC4;
  display:flex; align-items:center; justify-content:space-between;
  border-left:3px solid transparent;
}
nav button:hover{ color:#fff; background:rgba(255,255,255,0.04); }
nav button.active{
  color:#fff; border-left-color:#8CA089;
  background:rgba(255,255,255,0.06);
}
nav button .count{
  font-family:'IBM Plex Mono', monospace; font-size:11px;
  color:#16241D; background:#8CA089;
  padding:1px 6px; border-radius:9px;
}
.sidebar-foot{
  margin-top:auto; padding:16px 24px 0 24px;
  font-size:11.5px; color:#8B9186;
  border-top:1px solid rgba(239,241,234,0.12);
}
.status-pill{
  margin:0 24px 14px 24px; padding:7px 10px; border-radius:2px;
  font-size:11.5px; line-height:1.4;
}
.status-pill.off{ background:rgba(179,84,30,0.18); color:#E7B694; }
.status-pill.on{ background:rgba(140,160,137,0.18); color:#B7E0B0; }

main{flex:1; padding:36px 44px; max-width:1220px;display:flex;flex-direction:column;}
.view{display:none;}
.view.active{display:block;}
.service-banner{background:#FFF3CD;color:#6B5000;border:1px solid #E6C95C;padding:12px 15px;margin-bottom:18px;font-weight:600;}
.app-footer{margin-top:auto;padding-top:34px;color:var(--muted);font-size:11.5px;display:flex;gap:10px;justify-content:space-between;border-top:1px solid var(--rule);}
.muted{font-size:11px;color:var(--muted);}
.company-state{display:inline-block;padding:3px 8px;border-radius:10px;font-size:11px;text-transform:capitalize;}
.company-state.activa{background:#E7F6ED;color:#176B3A}.company-state.suspendida{background:#FFF3CD;color:#7A5900}.company-state.bloqueada{background:#F5DEDA;color:var(--red)}
.company-actions{text-align:right;white-space:nowrap}.company-actions select{padding:5px;border:1px solid var(--rule);background:#fff;font-size:11px;margin-left:5px}
header.page{margin-bottom:26px;}
header.page h1{font-size:26px; font-weight:600; margin:0 0 4px 0;}
header.page p{color:var(--muted); margin:0; font-size:13.5px; max-width:60ch;}

.gmail-panel{
  display:flex; align-items:center; justify-content:space-between; gap:16px;
  padding:14px 16px; margin-bottom:14px; background:var(--surface); border:1px solid var(--rule);
}
.gmail-panel strong{font-size:13px;}
#correo-status{font-size:12px; color:var(--muted); margin-top:2px;}
.btn:disabled{opacity:.5; cursor:not-allowed;}

.dropzone{
  border:1.5px dashed var(--rule);
  background:var(--surface);
  border-radius:2px;
  padding:38px 30px;
  text-align:center;
  transition:border-color .15s, background .15s;
  cursor:pointer;
}
.dropzone.drag{ border-color:var(--green); background:var(--green-soft); }
.dropzone h3{margin:0 0 6px 0; font-size:16px; font-weight:600;}
.dropzone p{margin:0; color:var(--muted); font-size:13px;}
.dropzone input{display:none;}
.browse-link{color:var(--green); text-decoration:underline; cursor:pointer;}

section.block{margin-top:30px;}
section.block > h2{
  font-size:12px; letter-spacing:0.02em;
  color:var(--muted); font-weight:600; margin:0 0 10px 0;
}

.queue-item{
  background:var(--surface); border:1px solid var(--rule);
  border-radius:2px; padding:14px 16px; margin-bottom:10px;
  display:flex; align-items:center; justify-content:space-between; gap:12px;
}
.queue-item .fname{font-weight:500; font-size:13.5px;}
.queue-item .status{font-size:12px; color:var(--muted); margin-top:2px;}
.status.processing::before{content:"● "; color:var(--amber);}
.status.error::before{content:"● "; color:var(--red);}
.spinner{
  width:13px; height:13px; border-radius:50%;
  border:2px solid var(--rule); border-top-color:var(--amber);
  display:inline-block; animation:spin .7s linear infinite; margin-right:6px; vertical-align:-2px;
}
@keyframes spin{to{transform:rotate(360deg);}}
.btn{
  all:unset; cursor:pointer; font-size:12.5px; font-weight:500;
  padding:7px 13px; border-radius:2px; border:1px solid var(--rule);
  color:var(--ink); background:#fff;
}
.btn:hover{border-color:var(--ink);}
.btn.primary{background:var(--green); color:#fff; border-color:var(--green);}
.btn.primary:hover{background:#25401f;}
.btn.danger{color:var(--red); border-color:var(--red);}
.btn.small{padding:4px 9px; font-size:11.5px;}
.btn.retry{color:var(--amber); border-color:var(--amber);}

.review-card{
  background:var(--surface); border:1px solid var(--rule);
  border-radius:2px; padding:20px 22px; margin-bottom:16px;
}
.review-head{display:flex; justify-content:space-between; align-items:flex-start; margin-bottom:14px;}
.review-head .fname{font-size:12px; color:var(--muted);}
.email-origin{margin-top:3px; color:var(--green); font-size:11px;}
.badge{font-size:11px; padding:2px 8px; border-radius:9px; font-weight:500;}
.badge.match{background:var(--green-soft); color:var(--green);}
.badge.new{background:var(--amber-soft); color:var(--amber);}
.manual-banner{
  background:var(--amber-soft); color:var(--amber);
  padding:9px 12px; border-radius:2px; font-size:12.5px; margin-bottom:14px;
}
.ai-summary{
  display:flex; gap:18px; padding:8px 12px; margin-bottom:10px;
  background:var(--green-soft); color:var(--green); font-size:12px;
}
.warning-banner{
  background:var(--amber-soft); color:var(--amber);
  padding:9px 12px; border-radius:2px; font-size:12.5px; margin-bottom:14px;
}
.warning-banner ul{margin:5px 0 0 18px; padding:0;}

.field-grid{display:grid; grid-template-columns:1fr 1fr 1fr; gap:12px; margin-bottom:14px;}
.field label{display:block; font-size:11px; color:var(--muted); margin-bottom:4px;}
.field input{
  width:100%; padding:7px 9px; border:1px solid var(--rule); border-radius:2px;
  font-size:13px; font-family:'IBM Plex Mono', monospace; background:#FCFCFA; color:var(--ink);
}
.field input:focus{outline:none; border-color:var(--green);}

table.items{width:100%; border-collapse:collapse; margin-bottom:12px;}
table.items th{
  text-align:left; font-size:11px; color:var(--muted); font-weight:500;
  padding:6px 8px; border-bottom:1px solid var(--rule);
}
table.items th.num, table.items td.num{text-align:right;}
table.items td{padding:4px 6px; border-bottom:1px solid #EDEBE1;}
table.items td input{
  width:100%; border:none; background:transparent; font-size:12.5px;
  font-family:'IBM Plex Mono', monospace; padding:4px 2px; color:var(--ink);
}
table.items td input:focus{outline:1px solid var(--green); background:#fff;}
table.items td.del{width:24px; text-align:center; cursor:pointer; color:var(--muted);}
table.items td.del:hover{color:var(--red);}

.totals-row{display:flex; justify-content:flex-end; flex-wrap:wrap; gap:18px; margin-bottom:16px; font-size:13px;}
.totals-row .t{text-align:right;}
.totals-row .t .l{color:var(--muted); font-size:11px;}
.totals-row .t .v input{width:100px;text-align:right;border:none;background:transparent;font-size:15px;font-weight:500}

.review-actions{display:flex; justify-content:space-between; align-items:center; gap:10px;}
.review-actions .left{display:flex; gap:8px;}
.add-row-link{font-size:12px; color:var(--green); cursor:pointer; display:inline-block; margin-bottom:14px;}

table.ledger{width:100%; border-collapse:collapse; background:var(--surface); border:1px solid var(--rule);}
table.ledger th{
  text-align:left; font-size:11px; color:var(--muted); font-weight:500;
  padding:9px 12px; border-bottom:1px solid var(--rule); background:#F8F7F2;
}
table.ledger th.num, table.ledger td.num{text-align:right;}
table.ledger td{padding:10px 12px; border-bottom:1px solid #EDEBE1; font-size:13px;}
table.ledger tr:last-child td{border-bottom:none;}
table.ledger tr.has-missing-codes td{background:#C6EFCE; color:#006100;}
.page-progress{font-family:'IBM Plex Mono', monospace; white-space:nowrap;}
.multipage-status{display:inline-block; padding:4px 8px; border-radius:999px; font-size:11.5px; white-space:nowrap;}
.multipage-status.complete{background:#E7F6ED; color:#176B3A;}
.multipage-status.pending{background:#FFF3CD; color:#7A5900;}
.invoice-actions{display:flex; justify-content:flex-end; gap:7px; white-space:nowrap;}
.empty-state{
  padding:36px 20px; text-align:center; color:var(--muted); font-size:13px;
  background:var(--surface); border:1px dashed var(--rule);
}
.toolbar{display:flex; justify-content:space-between; align-items:center; margin-bottom:14px;}

.provider-card{background:var(--surface); border:1px solid var(--rule); padding:16px 18px; margin-bottom:10px;}
.provider-card .p-head{display:flex; justify-content:space-between; align-items:center; margin-bottom:6px;}
.provider-card .p-name{font-weight:600; font-size:14.5px;}
.provider-card .p-cuit{color:var(--muted); font-family:'IBM Plex Mono', monospace; font-size:12px;}
.provider-card .p-notes{font-size:12.5px; color:var(--muted); margin-top:6px; white-space:pre-wrap;}
.provider-help{font-size:11.5px; color:var(--muted); margin-top:10px;}
.provider-origin-box{
  display:flex; align-items:center; justify-content:space-between; gap:16px;
  margin-top:12px; padding:12px; background:var(--green-soft); border:1px solid #C8D7C4;
}
.provider-origin-box strong{font-size:12.5px;}
.provider-origin-box .provider-help{margin-top:2px;}
.origin-file-name{font-size:11.5px; color:var(--green); margin-top:4px;}
.origin-file-name.pending{color:var(--muted);}
.template-link{color:var(--green); text-decoration:underline;}
.upload-panel{
  display:flex; align-items:center; justify-content:space-between; gap:24px;
  padding:18px; margin-bottom:14px; background:var(--surface); border:1px solid var(--rule);
}
.upload-panel strong{display:block; margin-bottom:4px;}
.upload-panel p{margin:0 0 6px; max-width:70ch; font-size:12px; color:var(--muted);}
.master-stats{padding:10px 12px; margin-bottom:10px; background:var(--green-soft); color:var(--green); font-size:12.5px;}
.table-note{font-size:11.5px; color:var(--muted); margin-top:7px;}

.modal-bg{
  display:none; position:fixed; inset:0; background:rgba(22,36,29,0.35);
  align-items:center; justify-content:center; z-index:50;
}
.modal-bg.active{display:flex;}
.modal{background:#fff; width:460px; max-width:90vw; padding:24px; border-radius:2px; max-height:85vh; overflow-y:auto;}
.modal h3{margin:0 0 14px 0; font-size:16px;}
.modal .field{margin-bottom:12px;}
.modal .field label{font-size:11px; color:var(--muted); display:block; margin-bottom:4px;}
.modal .field input, .modal .field textarea{
  width:100%; padding:8px 9px; border:1px solid var(--rule); font-size:13px; border-radius:2px;
}
.modal .field textarea{font-family:'IBM Plex Mono', monospace; font-size:12px; min-height:80px; resize:vertical;}
.modal-actions{display:flex; justify-content:flex-end; gap:8px; margin-top:16px;}

.toast{
  position:fixed; bottom:24px; right:24px; background:var(--ink); color:#fff;
  padding:11px 18px; border-radius:2px; font-size:13px; opacity:0; transform:translateY(8px);
  transition:opacity .2s, transform .2s; z-index:100; max-width:340px;
}
.toast.show{opacity:1; transform:translateY(0);}
.toast.err{background:var(--red);}

@media (max-width: 760px){
  .app{display:block;}
  .sidebar{width:100%; padding:16px 0;}
  .sidebar-foot{display:none;}
  main{padding:24px 16px;}
  .field-grid{grid-template-columns:1fr;}
  .gmail-panel{align-items:flex-start; flex-direction:column;}
  .upload-panel{align-items:flex-start; flex-direction:column;}
  .review-card{overflow-x:auto;}
  table.items{min-width:760px;}
  .stats-grid,.stats-lists{grid-template-columns:1fr;}
  .app-footer{flex-direction:column;}
}
