:root {
  --bg: #f5f3ef; --panel: #ffffff; --ink: #1f1d1a; --muted: #77716a; --line: #e4e0d8;
  --accent: #e4572e; --accent-ink: #fff; --accent-soft: #fdebe5;
  --ok: #2f8f5b; --ok-soft: #e3f4ea; --warn: #b7791f; --warn-soft: #fbf0dc; --bad: #c0392b; --bad-soft: #fbe5e2;
  --side: #1f1d1a; --side-ink: #d9d4cc;
  --r: 10px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink); background: var(--bg); font-size: 15px;
}
* { box-sizing: border-box; }
body { margin: 0; }
.hidden { display: none !important; }
a { color: var(--accent); }
h1 { font-size: 1.45rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); }
.num, td.num, .money { font-variant-numeric: tabular-nums; }
small { color: var(--muted); }

/* layout */
.app { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 18px 14px; position: sticky; top: 0; height: 100vh; overflow: auto; }
.brand { font-weight: 800; font-size: 1.05rem; color: #fff; display: flex; align-items: center; gap: 8px; margin-bottom: 18px; }
.brand small { color: #9a948b; font-weight: 500; font-size: .75rem; }
.brand.big { color: var(--ink); font-size: 1.5rem; justify-content: center; margin-bottom: 4px; }
.logo { color: var(--accent); font-size: 1.2em; }
nav a { display: block; color: var(--side-ink); text-decoration: none; padding: 9px 10px; border-radius: 8px; margin-bottom: 2px; }
nav a:hover { background: #2c2925; }
nav a.active { background: #34302b; color: #fff; }
nav a.cta { background: var(--accent); color: #fff; font-weight: 600; margin: 6px 0 10px; text-align: center; }
nav a.cta:hover { filter: brightness(1.05); }
.nav-sep { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #8a847b; margin: 16px 10px 6px; }
.nav-toggle { display: none; }
.view { padding: 26px 30px 80px; max-width: 1400px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow); }
.card + .card { margin-top: 14px; }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.g6 { grid-template-columns: repeat(6, minmax(0,1fr)); }
.span2 { grid-column: span 2; } .span3 { grid-column: span 3; } .spanall { grid-column: 1 / -1; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.stat b { display: block; font-size: 1.4rem; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .8rem; }

/* forms */
label { display: flex; flex-direction: column; gap: 4px; font-size: .78rem; color: var(--muted); font-weight: 600; }
label.inline { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-weight: 500; font-size: .9rem; }
input, select, textarea { font: inherit; font-size: .92rem; font-weight: 400; color: var(--ink); background: #fff; border: 1px solid #d6d1c8; border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0; }
input[type=checkbox] { width: auto; }
input[type=color] { padding: 2px; height: 38px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { min-height: 70px; resize: vertical; }
.hint { font-weight: 400; color: var(--muted); font-size: .72rem; }
.suffix { position: relative; }
.suffix input { padding-right: 38px; }
.suffix em { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--muted); font-size: .8rem; pointer-events: none; }

/* buttons */
.btn { font: inherit; font-weight: 600; border: 1px solid #d6d1c8; background: #fff; color: var(--ink); padding: 8px 14px; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { background: #faf8f5; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 5px 9px; font-size: .82rem; }
.btn.block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; cursor: pointer; color: var(--muted); font-size: 1.05rem; padding: 4px 6px; border-radius: 6px; }
.icon-btn:hover { background: #f0ece6; color: var(--bad); }

/* tables */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); font-weight: 700; }
td { padding: 10px; border-bottom: 1px solid #f0ece6; vertical-align: middle; }
tr.click { cursor: pointer; } tr.click:hover td { background: #faf8f5; }
td.num, th.num { text-align: right; }
.table-wrap { overflow-x: auto; }
.empty { text-align: center; color: var(--muted); padding: 30px; }
.swatch { display: inline-block; width: 16px; height: 16px; border-radius: 50%; border: 1px solid rgba(0,0,0,.15); vertical-align: middle; margin-right: 6px; }

/* status */
.pill { display: inline-block; font-size: .72rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: #eee; color: #555; white-space: nowrap; }
.pill.rascunho { background: #eeeae4; color: #6b655d; }
.pill.enviado { background: #e5eefb; color: #2b5ea8; }
.pill.visualizado { background: #ede7fb; color: #5b3fae; }
.pill.aprovado { background: var(--ok-soft); color: var(--ok); }
.pill.em_producao { background: var(--warn-soft); color: var(--warn); }
.pill.pronto { background: #dff3f3; color: #1f7a7a; }
.pill.entregue { background: #dcefdf; color: #24663f; }
.pill.recusado, .pill.expirado { background: var(--bad-soft); color: var(--bad); }

/* editor */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; align-items: start; }
.summary { position: sticky; top: 18px; }
.summary .total { font-size: 2rem; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; font-size: .9rem; }
.kv span:first-child { color: var(--muted); }
.kv b { font-variant-numeric: tabular-nums; }
.kv.big b { font-size: 1.05rem; }
.divider { border-top: 1px dashed var(--line); margin: 10px 0; }
.item { border: 1px solid var(--line); border-radius: var(--r); padding: 16px; background: #fff; margin-bottom: 14px; }
.item-head { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.item-head .idx { background: var(--ink); color: #fff; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: .8rem; font-weight: 700; flex: none; }
.item-head input { font-weight: 600; }
.section-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; margin: 14px 0 8px; display: flex; align-items: center; gap: 8px; }
.section-label::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.fil-row { display: grid; grid-template-columns: 1fr 120px 34px; gap: 8px; margin-bottom: 6px; align-items: center; }
.drop { border: 2px dashed #d6d1c8; border-radius: var(--r); padding: 12px; text-align: center; color: var(--muted); cursor: pointer; font-size: .88rem; transition: .15s; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.drop b { color: var(--accent); }
.item-result { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 14px; background: #faf8f5; border-radius: 8px; padding: 10px 12px; }
.item-result div span { display: block; font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.item-result div b { font-variant-numeric: tabular-nums; }
.neg { color: var(--bad) !important; }
.pos { color: var(--ok); }
details.breakdown { margin-top: 8px; font-size: .85rem; }
details.breakdown summary { cursor: pointer; color: var(--muted); }
details.breakdown table td { padding: 4px 8px; }
.warn-box { background: var(--warn-soft); color: #7a5212; border-radius: 8px; padding: 8px 10px; font-size: .82rem; margin-top: 10px; }
.warn-box div + div { margin-top: 2px; }
.timeline { list-style: none; padding: 0; margin: 0; font-size: .82rem; max-height: 260px; overflow: auto; }
.timeline li { padding: 6px 0; border-bottom: 1px solid #f0ece6; display: flex; justify-content: space-between; gap: 8px; }
.timeline li span:last-child { color: var(--muted); white-space: nowrap; }
.send-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tier-row { display: grid; grid-template-columns: 1fr 1fr 1fr 34px; gap: 8px; margin-bottom: 6px; align-items: end; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters input { max-width: 280px; }
.filters select { max-width: 200px; }

/* modal & toast */
.modal { position: fixed; inset: 0; background: rgba(20,18,16,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-card { background: #fff; border-radius: 14px; padding: 22px; width: min(640px, 100%); max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 60; box-shadow: 0 8px 30px rgba(0,0,0,.25); font-size: .9rem; }
.toast.bad { background: var(--bad); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { background: #fff; padding: 30px; border-radius: 16px; width: min(380px, 100%); box-shadow: var(--shadow); border: 1px solid var(--line); display: grid; gap: 14px; text-align: center; }
.login-card label { text-align: left; }
.error { color: var(--bad); min-height: 1em; margin: 0; font-size: .85rem; }

@media (max-width: 1100px) {
  .editor { grid-template-columns: 1fr; }
  .summary { position: static; }
}
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .side { position: sticky; height: auto; z-index: 20; padding: 12px 14px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; }
  .side .brand { margin: 0; }
  .nav-toggle { display: block; background: transparent; border: 0; color: #fff; font-size: 1.4rem; cursor: pointer; }
  nav { display: none; width: 100%; margin-top: 10px; }
  nav.open { display: block; }
  .view { padding: 18px 14px 80px; }
  .g3, .g4, .g6 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .item-result { grid-template-columns: repeat(2, 1fr); }
  .hide-sm { display: none; }
}
