:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --text: #1d2433;
  --muted: #667085;
  --border: #dde2ea;
  --primary: #0a6ed1;
  --primary-text: #ffffff;
  --danger: #c62828;
  --side: #17233a;
  --side-text: #c9d3e3;
  --ok-bg: #e6f4ea; --ok: #1e7b34;
  --info-bg: #e7f0fb; --info: #0a5aa8;
  --warn-bg: #fdecea; --warn: #b42318;
  --neutral-bg: #eef0f3; --neutral: #4b5565;
  --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151c; --panel: #1a2029; --text: #e6e9ef; --muted: #98a2b3; --border: #2c3542;
    --primary: #3d8fe0; --side: #0b0f15; --side-text: #aab4c4;
    --ok-bg: #173323; --ok: #6fcf8b; --info-bg: #15283f; --info: #7ab4f0;
    --warn-bg: #3a1a1a; --warn: #f19a92; --neutral-bg: #262d38; --neutral: #b4bcc8;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 12px; }

.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-text); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; }
.side .brand { color: #fff; font-weight: 700; font-size: 16px; padding: 0 10px 16px; }
.side a { color: var(--side-text); text-decoration: none; padding: 9px 10px; border-radius: 6px; }
.side a.active, .side a:hover { background: rgba(255,255,255,.08); color: #fff; }
.side .who { margin-top: auto; font-size: 12px; padding: 10px; border-top: 1px solid rgba(255,255,255,.1); }
.side .who button { margin-top: 8px; width: 100%; }
main { padding: 24px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.grid .wide { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
input, select, textarea, button { font: inherit; }
input, select, textarea { padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel); color: var(--text); min-width: 0; }
input:disabled, select:disabled, textarea:disabled { background: var(--neutral-bg); color: var(--muted); }
textarea { min-height: 60px; resize: vertical; }
.check { flex-direction: row; align-items: center; gap: 6px; }

button { padding: 7px 14px; border-radius: 6px; border: 1px solid var(--border); background: var(--panel); color: var(--text); cursor: pointer; }
button:hover { filter: brightness(.97); }
button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
button.danger { color: var(--danger); border-color: var(--danger); }
button.link { border: 0; background: none; color: var(--primary); padding: 4px; }
button:disabled { opacity: .55; cursor: default; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filters label { min-width: 140px; }
.filters .grow { flex: 1; min-width: 200px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--bg); }
td.num, th.num { text-align: right; }
td input, td select { width: 100%; }
.lines td { padding: 6px 4px; }
.empty { text-align: center; color: var(--muted); padding: 24px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.neutral { background: var(--neutral-bg); color: var(--neutral); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: inherit; }
.card .n { font-size: 28px; font-weight: 700; }
.card .l { color: var(--muted); }
.card.warn .n { color: var(--warn); }

.pager { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 12px; color: var(--muted); }
.addr { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; }
.addr-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-weight: 600; }
.hint { color: var(--muted); font-size: 12px; }

.login { max-width: 360px; margin: 10vh auto; }
.login form { display: flex; flex-direction: column; gap: 12px; }
.error { color: var(--danger); }

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 10; }
.toast { background: var(--side); color: #fff; padding: 10px 14px; border-radius: 6px; max-width: 420px; box-shadow: 0 4px 14px rgba(0,0,0,.2); }
.toast.err { background: var(--danger); }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .side { flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; }
  .side .brand { padding: 0 8px 0 0; }
  .side .who { margin: 0 0 0 auto; border: 0; padding: 0; display: flex; gap: 8px; align-items: center; }
  .side .who button { margin: 0; width: auto; }
  main { padding: 16px; }
}

/* Itens da solicitação: linha principal + linha de classificação (dimensões, utilização, conta) */
.lines tr.line-main td { border-bottom: 0; padding-top: 10px; }
.lines tr.line-extra td { padding: 0 4px 12px; }
.line-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; padding: 8px; background: var(--bg); border-radius: 6px; }
.line-grid .wide-2 { grid-column: span 2; }
@media (max-width: 760px) { .line-grid .wide-2 { grid-column: auto; } }
td.row-actions { white-space: nowrap; text-align: right; }

.doc-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 8px; flex-wrap: wrap; }
.doc-total { font-size: 15px; }
.lines td[data-total] { white-space: nowrap; }
/* Em telas estreitas a tabela rola na horizontal em vez de espremer item/descrição. */
.lines [data-f="ItemCode"] { min-width: 110px; }
.lines [data-f="ItemDescription"] { min-width: 200px; }
.lines [data-f="WarehouseCode"] { min-width: 170px; }
.lines [data-f="UnitPrice"] { min-width: 100px; text-align: right; }
.lines [data-f="Quantity"] { text-align: right; }
.grid .wide-2 { grid-column: span 2; }
@media (max-width: 760px) { .grid .wide-2 { grid-column: auto; } }

/* Barra de consumo dos contratos */
.bar { height: 8px; background: var(--neutral-bg); border-radius: 4px; overflow: hidden; margin-bottom: 2px; }
.bar > span { display: block; height: 100%; background: var(--primary); }
.bar.mid > span { background: #d98e04; }
.bar.high > span { background: var(--warn); }

/* Estoque de itens */
td.strong { font-weight: 600; }
td.neg { color: var(--warn); font-weight: 600; }
tr.stock-detail > td { background: var(--bg); padding: 8px 12px 14px; }
.stock-wh table { background: var(--panel); border-radius: 6px; }
.lines [data-f="ItemNo"] { min-width: 110px; }
.lines [data-f="PlannedQuantity"], .lines [data-f="PlannedAmountLC"] { min-width: 100px; text-align: right; }
.inline-pair { display: flex; gap: 6px; }
.inline-pair input { width: 90px; }
.inline-pair select { flex: 1; }
.warn-text { color: var(--warn); }
div.strong { font-weight: 600; }
.with-btn { display: flex; gap: 6px; }
.with-btn input { flex: 1; }
.with-btn button { white-space: nowrap; }

/* Aprovações: seleção em lote e detalhe do documento */
.bulk-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.bulk-bar strong { color: var(--text); margin-left: 6px; }
th.sel, td.sel { width: 32px; text-align: center; }
th.sel input, td.sel input { width: 16px; height: 16px; cursor: pointer; }
tr.approval-detail > td { background: var(--bg); padding: 12px 14px 16px; }
tr.approval-detail h3 { font-size: 13px; margin: 14px 0 6px; }
tr.approval-detail table { background: var(--panel); border-radius: 6px; }
tr.approval-detail td, tr.approval-detail th { padding: 6px 8px; }
tr.strong td { font-weight: 600; }
/* O detalhe fica preso à área visível em vez de acompanhar a largura da tabela de pedidos. */
.detail-box { position: sticky; left: 14px; max-width: calc(100vw - 340px); }
@media (max-width: 760px) { .detail-box { max-width: calc(100vw - 92px); } }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px 16px; }
.detail-grid .wide { grid-column: 1 / -1; }
.base-request { border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); padding: 10px 12px; margin-top: 14px; }
.base-request h3 { margin: 0; }
.base-request .detail-grid { margin-bottom: 8px; }
.detail-box td.desc { min-width: 180px; }
.detail-box td.cls { min-width: 170px; }

/* Pedidos de compra: janela de envio */
dialog.dialog { border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; width: min(640px, calc(100vw - 32px)); background: var(--panel); color: var(--text); }
dialog.dialog::backdrop { background: rgba(10, 15, 25, .45); }
dialog.dialog h2 { margin-bottom: 4px; }
dialog.dialog .grid { grid-template-columns: 1fr; margin-top: 10px; }
ul.sends { margin: 6px 0 0; padding-left: 18px; font-size: 12px; color: var(--muted); }
/* Gestão de contratos */
.badge.amber { background: #fdf3d8; color: #8a5a00; }
@media (prefers-color-scheme: dark) { .badge.amber { background: #3a2f12; color: #f2c46d; } }
.pre { white-space: pre-wrap; }
.small { font-size: 12px; }
.m-form { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; background: var(--bg); }
.m-form table { background: var(--panel); }
.alloc-box { padding: 6px 0 6px 24px; border-left: 3px solid var(--border); }
.alloc-box table.alloc { width: auto; } .alloc-box table.alloc td, .alloc-box table.alloc th { padding: 3px 8px; }
details.panel > summary { cursor: pointer; }[hidden] { display: none !important; }
