:root {
  --brand:      #e30613;
  --brand-dark: #c50011;
  --sidebar-w:  220px;
  --nav-h:      52px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font-family: 'Segoe UI', system-ui, sans-serif; background: #f4f5f7; color: #222; }

/* ── Brand Wordmark ── */
.brand-wordmark {
  font-family: 'EB Garamond', Garamond, Georgia, serif;
  font-weight: 700; font-size: 2.6rem; color: var(--brand);
  letter-spacing: .12em; line-height: 1; margin-bottom: .15rem;
}
.brand-wordmark-sub {
  font-size: .78rem; font-weight: 600; letter-spacing: .18em;
  text-transform: uppercase; color: #555; margin-bottom: .1rem;
}
.brand-wordmark-nav {
  font-family: 'EB Garamond', Garamond, Georgia, serif;
  font-weight: 700; font-size: 1.15rem; color: #fff;
  letter-spacing: .1em; line-height: 1; vertical-align: middle;
}
.nav-brand-divider {
  color: rgba(255,255,255,.35); margin: 0 .55rem;
  font-weight: 300; font-size: 1rem; vertical-align: middle;
}

/* ── Login ── */
.login-overlay {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, #e30613 0%, #8b0000 100%);
  display: flex; align-items: center; justify-content: center; z-index: 9999;
}
.login-card {
  background: #fff; border-radius: 14px;
  padding: 2.5rem 2rem; width: 100%; max-width: 380px;
  box-shadow: 0 24px 64px rgba(0,0,0,.4); text-align: center;
}
.login-brand { margin-bottom: .25rem; }
.login-sub   { font-size: .85rem; color: #888; margin-bottom: 1.5rem; }

/* ── App Shell ── */
#appShell { display: flex; flex-direction: column; height: 100vh; }

/* ── Navbar ── */
.app-nav {
  height: var(--nav-h); background: var(--brand);
  display: flex; align-items: center; padding: 0 1.25rem;
  gap: 1rem; flex-shrink: 0; box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.nav-brand { color: #fff; font-weight: 800; font-size: 1.1rem; letter-spacing: .03em; flex: 1; }
.nav-user  { color: rgba(255,255,255,.85); font-size: .82rem; }

/* ── Body = sidebar + content ── */
.app-body { display: flex; flex: 1; overflow: hidden; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w); background: #fff; border-right: 1px solid #e5e7eb;
  overflow-y: auto; flex-shrink: 0; padding: .75rem 0;
}
.sidebar-section { padding: .25rem .75rem; font-size: .65rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: .08em; color: #aaa; margin-top: .75rem; }
.nav-item {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem 1rem; font-size: .85rem; color: #555; cursor: pointer;
  border-left: 3px solid transparent; transition: all .12s;
}
.nav-item:hover { background: #fef2f2; color: var(--brand); }
.nav-item.active { background: #fef2f2; color: var(--brand); font-weight: 600;
  border-left-color: var(--brand); }
.nav-item i { font-size: 1rem; width: 20px; text-align: center; }

/* ── Page Content ── */
.page-content { flex: 1; overflow-y: auto; padding: 1.5rem; }
.page-title   { font-size: 1.25rem; font-weight: 700; margin-bottom: 1.25rem; color: #1a1a1a; }
.page-subtitle { font-size: .82rem; color: #888; margin: -.75rem 0 1.25rem; }

/* ── KPI Cards ── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .875rem; margin-bottom: 1.5rem; }
.kpi-card {
  background: #fff; border: 1px solid #DEE2E6; border-radius: 12px;
  padding: .9rem 1.1rem .8rem; box-shadow: 0 1px 3px rgba(0,0,0,.06);
  border-top: 3px solid var(--brand-color, #1971C2);
}
.kpi-label {
  font-size: .6rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: #868E96; margin: 0 0 5px;
}
.kpi-value {
  font-size: clamp(.82rem, 1.5vw, 1.2rem); font-weight: 700;
  color: var(--brand-color, #1971C2); line-height: 1.2; margin: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ── Tables ── */
.table-wrap { background: #fff; border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,.07); overflow-x: auto; }
.table-wrap table { width: 100%; border-collapse: collapse; font-size: .83rem; min-width: max-content; }
.table-wrap thead th {
  background: #f8f9fa; padding: .625rem .875rem; text-align: left;
  font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: #6c757d; border-bottom: 2px solid #e9ecef;
  white-space: nowrap; position: sticky; top: 0; z-index: 2;
  box-shadow: 0 1px 0 #e9ecef;
}
.table-wrap tbody tr { border-bottom: 1px solid #f0f0f0; transition: background .1s; }
.table-wrap tbody tr:hover { background: #fafafa; }
.table-wrap tbody td { padding: .45rem .65rem; vertical-align: middle; }
.table-wrap tbody tr:last-child { border-bottom: none; }

/* ── Badges ── */
.badge {
  display: inline-block; padding: .2rem .55rem; border-radius: 20px;
  font-size: .7rem; font-weight: 700; text-transform: capitalize;
}
.badge-aguardando_aprovacao { background: #fff3cd; color: #856404; }
.badge-aprovado             { background: #d1e7dd; color: #0f5132; }
.badge-reprovado            { background: #f8d7da; color: #842029; }
.badge-cadastrado_erp       { background: #cff4fc; color: #055160; }
.badge-rascunho             { background: #e9ecef; color: #6c757d; }

.semaforo-vermelho { color: #C92A2A; font-weight: 700; }
.semaforo-amarelo  { color: #E67700; font-weight: 600; }
.semaforo-verde    { color: #2F9E44; }

/* ── Filters bar ── */
.filters-bar {
  display: flex; align-items: flex-end; gap: .75rem; flex-wrap: wrap;
  background: #fff; padding: .875rem 1rem; border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,.07); margin-bottom: 1rem;
}
.filter-group label { display: block; font-size: .72rem; font-weight: 600; color: #555; margin-bottom: .25rem; }
.filter-group select, .filter-group input[type=text], .filter-group input[type=date] {
  border: 1px solid #ced4da; border-radius: 6px; padding: .3rem .6rem; font-size: .82rem; color: #333; background: #fff;
}

/* ── Cards / Sections ── */
.card { background: #fff; border-radius: 10px; padding: 1.25rem; box-shadow: 0 1px 4px rgba(0,0,0,.07); margin-bottom: 1rem; }
.card-title { font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .07em; color: #888; margin: 0 0 .875rem; }

/* ── Form ── */
.form-section { background: #fff; border-radius: 10px; padding: 1.5rem; box-shadow: 0 1px 4px rgba(0,0,0,.07); max-width: 800px; }
.form-section h6 { font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .07em; color: #888; margin: 1.25rem 0 .875rem; }
.form-section h6:first-child { margin-top: 0; }
.form-row { display: grid; gap: .75rem; margin-bottom: .75rem; }
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-row.cols-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }
.form-group label { display: block; font-size: .75rem; font-weight: 600; color: #555; margin-bottom: .3rem; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; border: 1px solid #ced4da; border-radius: 6px;
  padding: .4rem .65rem; font-size: .85rem; color: #333;
}
.form-group textarea { min-height: 70px; resize: vertical; }

/* ── Markup badges ── */
.markup-row { margin-top: -.4rem; margin-bottom: .5rem; }
.markup-row .form-group { display: flex; flex-direction: column; justify-content: flex-end; }
.markup-label { font-size: .68rem; font-weight: 700; color: #aaa; text-transform: uppercase; letter-spacing: .05em; padding-bottom: .1rem; }
.markup-badge {
  font-size: .92rem; font-weight: 700;
  padding: .28rem .55rem; border-radius: 5px;
  background: #f1f3f5; color: #999;
  display: inline-block; min-width: 3.5rem; text-align: center;
}
.markup-badge.mk-high { background: #d1fae5; color: #065f46; }
.markup-badge.mk-mid  { background: #fef3c7; color: #92400e; }
.markup-badge.mk-low  { background: #fee2e2; color: #991b1b; }
/* ── Cores e Quantidades ── */
.cor-row { display: grid; grid-template-columns: 1fr 110px 32px; gap: .45rem; margin-bottom: .35rem; align-items: center; }
.cor-row select, .cor-row input[type=number] { margin: 0; }
.cor-rm { background: none; border: 1px solid #e0e0e0; border-radius: 5px; color: #bbb; cursor: pointer; padding: .25rem .4rem; line-height: 1; transition: background .12s, color .12s; }
.cor-rm:hover { background: #fee2e2; color: #dc3545; border-color: #dc3545; }
.btn-add-cor { background: none; border: 1px dashed #adb5bd; border-radius: 5px; padding: .28rem .65rem; font-size: .75rem; color: #666; cursor: pointer; margin-top: .2rem; }
.btn-add-cor:hover { background: #f8f9fa; }

.btn-suggest {
  width: 100%; padding: .3rem .5rem; font-size: .73rem; font-weight: 600;
  background: #f8f9fa; border: 1px dashed #adb5bd; border-radius: 5px;
  color: #666; cursor: pointer; transition: background .15s, border-color .15s;
}
.btn-suggest:hover { background: #e9ecef; border-color: #868e96; color: #333; }

/* ── Accordion / Expander ── */
.expander { border: 1px solid #e5e7eb; border-radius: 8px; margin-bottom: .5rem; overflow: hidden; }
.expander-header {
  background: #f8f9fa; padding: .75rem 1rem; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
  font-size: .85rem; font-weight: 600; color: #333;
}
.expander-header:hover { background: #f0f0f0; }
.expander-body { padding: 1rem; background: #fff; border-top: 1px solid #e5e7eb; }
.expander-body.hidden { display: none; }

/* ── Toast ── */
.toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 9000; }

/* ── Spinner ── */
.page-loading { display: flex; align-items: center; justify-content: center; height: 200px; }
.spinner-border { width: 2rem; height: 2rem; border: .25em solid currentColor;
  border-right-color: transparent; border-radius: 50%; animation: spin .75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty state ── */
.empty-state { text-align: center; padding: 3rem; color: #aaa; }
.empty-state i { font-size: 2.5rem; display: block; margin-bottom: .5rem; }

/* ── Tab bar ── */
.tab-bar { display: flex; gap: 0; border-bottom: 2px solid #e9ecef; margin-bottom: 1.25rem; }
.tab-btn {
  background: none; border: none; border-bottom: 3px solid transparent;
  padding: .55rem .9rem; font-size: .85rem; font-weight: 600; color: #6b7280;
  cursor: pointer; margin-bottom: -2px; transition: color .15s, border-color .15s;
}
.tab-btn:hover { color: #374151; }
.tab-btn.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .form-row.cols-4 { grid-template-columns: 1fr 1fr; }
}

/* ── MDO Grade ── */
.mdo-grade-wrap {
  overflow-x: auto; background: #fff; border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,.07);
}
.mdo-grade {
  border-collapse: separate; border-spacing: 0;
  font-size: .82rem; min-width: max-content; width: 100%;
}
.mdo-grade th, .mdo-grade td {
  padding: .55rem .5rem; border-bottom: 1px solid #f0f0f0; white-space: nowrap;
}
.mdo-grade thead th {
  background: #f8f9fa; font-size: .68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: #6c757d; border-bottom: 2px solid #e9ecef;
  position: sticky; top: 0; z-index: 3; box-shadow: 0 1px 0 #e9ecef;
  white-space: normal; vertical-align: bottom; text-align: center;
  line-height: 1.2; min-height: 56px; padding-top: .5rem;
}
.mdo-grade tfoot td {
  font-weight: 700; background: #f8f9fa; border-top: 2px solid #e9ecef;
  position: sticky; bottom: 0; z-index: 2;
}
.mdo-grade tbody tr:hover td { background: #fafafa; }
.mdo-col-sticky {
  position: sticky; background: #fff; z-index: 2;
}
.mdo-grade thead th.mdo-col-sticky { z-index: 4; background: #f8f9fa; }
.mdo-grade tfoot td.mdo-col-sticky { z-index: 3; background: #fff; }
.mdo-grade tbody tr:hover td.mdo-col-sticky { background: #fafafa; }
.mdo-sticky-last { box-shadow: 3px 0 6px -2px rgba(0,0,0,.12); }
.mdo-fab-th {
  text-align: center; border-left: 2px solid #f0e0e0;
  background: #fff8f8 !important;
  min-width: 80px !important;
  max-width: 100px;
  width: 90px;
  white-space: normal;
  vertical-align: bottom;
  line-height: 1.25;
  padding-bottom: .5rem !important;
}
.mdo-fab-td {
  border-left: 1px solid #f5e5e5; text-align: right; vertical-align: middle;
  padding: .3rem .5rem !important;
}
/* Orçamento badges */
.orcamento-badge {
  display: inline-block; padding: .2rem .7rem; border-radius: 20px;
  font-size: .78rem; font-weight: 700;
}
.orcamento-verde    { background: #d1fae5; color: #065f46; }
.orcamento-amarelo  { background: #fef3c7; color: #92400e; }
.orcamento-vermelho { background: #fee2e2; color: #991b1b; }
/* MDO config list (fabricantes / produtos) */
.mdo-list-wrap {
  max-height: 400px; overflow-y: auto;
  border: 1px solid #e9ecef; border-radius: 8px;
  background: #fff; margin-bottom: .75rem;
}
.mdo-list-hdr {
  display: grid; align-items: center;
  padding: .3rem .75rem;
  background: #f1f3f5; border-bottom: 1px solid #e9ecef;
  font-size: .72rem; font-weight: 700; text-transform: uppercase;
  color: #666; letter-spacing: .04em;
  position: sticky; top: 0; z-index: 1;
}
.mdo-list-row {
  display: grid; align-items: center;
  padding: .32rem .75rem;
  border-bottom: 1px solid #f4f4f4;
  cursor: pointer; user-select: none; transition: background .1s;
}
.mdo-list-row:last-child { border-bottom: none; }
.mdo-list-row:hover { background: #fef2f2; }
.mdo-list-hdr, .mdo-list-row { grid-template-columns: 72px 1fr 60px; }
.mdo-prod-hdr, .mdo-prod-row  { grid-template-columns: 130px 1fr 160px 60px; }
.mdo-list-id   { font-size: .78rem; color: #888; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mdo-list-nome { font-size: .84rem; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mdo-list-sub  { font-size: .75rem; color: #aaa; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mdo-list-chk  { display: flex; justify-content: center; }
.mdo-list-chk input { cursor: pointer; accent-color: var(--brand); }
.mdo-list-chk input:checked { background-color: var(--brand); border-color: var(--brand); }

/* MDO histórico btn */
.mdo-hist-btn {
  background: none; border: none; padding: .1rem .25rem; cursor: pointer;
  color: #ced4da; font-size: .75rem; border-radius: 3px;
  transition: color .1s, background .1s;
}
.mdo-hist-btn:hover { color: #1971C2; background: #e7f0ff; }

/* ── Permission matrix ── */
.perm-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.perm-table th { background: #F1F3F5; padding: 10px 14px; text-align: left;
                 border-bottom: 2px solid #DEE2E6; font-weight: 600; color: #495057; }
.perm-table td { padding: 10px 14px; border-bottom: 1px solid #E9ECEF; color: #212529; }
.perm-table tr:hover td { background: #F8F9FA; }

/* ── Programação Não-MDO ── */
.naomdo-wrap { overflow-x: auto; }

.naomdo-table {
  width: 100%; border-collapse: collapse; font-size: .78rem;
  min-width: 900px;
}
.naomdo-table th, .naomdo-table td {
  border: 1px solid #DEE2E6; padding: 4px 7px; white-space: nowrap;
}
.naomdo-table thead tr:first-child th { background: #1971C2; color: #fff; font-weight: 700; text-align: center; }
.naomdo-table thead tr:nth-child(2) th { background: #E7F0FF; color: #1971C2; font-weight: 600; text-align: center; }
.naomdo-table thead tr:nth-child(3) th { background: #F8F9FA; color: #495057; font-weight: 600; text-align: center; font-size: .72rem; }

.naomdo-th-fix  { background: #F1F3F5 !important; color: #212529 !important; }
.naomdo-th-period { z-index: 1 !important; }
.naomdo-th-sub  { z-index: 1 !important; }

.naomdo-th-seg {
  position: sticky; left: 0; z-index: 5 !important;
  background: #F1F3F5 !important;
}
.naomdo-th-faixa {
  position: sticky; left: 0; z-index: 5 !important;
  background: #F1F3F5 !important;
}

.naomdo-seg-cell {
  font-weight: 700; background: #E9ECEF; color: #212529;
  vertical-align: middle; text-align: left;
  position: sticky; left: 0; z-index: 2;
}
.naomdo-faixa-cell {
  color: #495057; text-align: left; padding-left: 14px !important;
  background: #fff;
  position: sticky; left: 0; z-index: 2;
}
.naomdo-td { text-align: right; vertical-align: middle; }

.naomdo-meta-input {
  width: 72px; text-align: right; border: 1px solid #ADB5BD; border-radius: 4px;
  padding: 2px 5px; font-size: .78rem; background: #fff;
}
.naomdo-meta-input:focus { outline: none; border-color: #1971C2; box-shadow: 0 0 0 2px #d0e4ff; }

.naomdo-lanc {
  width: 72px; text-align: right; border: 1px solid #ADB5BD; border-radius: 4px;
  padding: 2px 5px; font-size: .78rem; background: #fff; display: block; margin: 0 auto;
}
.naomdo-lanc:focus { outline: none; border-color: #1971C2; box-shadow: 0 0 0 2px #d0e4ff; }
.naomdo-lanc-ref { display: block; text-align: center; line-height: 1.2; margin-top: 1px; }

.naomdo-pct, .naomdo-pct-input, .naomdo-cob1 {
  width: 52px; text-align: right; border: 1px solid #ADB5BD; border-radius: 4px;
  padding: 2px 5px; font-size: .78rem; background: #fff;
}
.naomdo-pct:focus, .naomdo-pct-input:focus, .naomdo-cob1:focus { outline: none; border-color: #1971C2; box-shadow: 0 0 0 2px #d0e4ff; }

.naomdo-table input[type=number]::-webkit-inner-spin-button,
.naomdo-table input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.naomdo-table input[type=number] { -moz-appearance: textfield; appearance: textfield; }

.naomdo-total-row td { background: #E9ECEF; font-weight: 700; }
.naomdo-total { text-align: right; }
.naomdo-total-label {
  text-align: left; font-weight: 700;
  position: sticky; left: 0; z-index: 2;
  background: #E9ECEF;
}
.naomdo-grand-row td { background: #1E293B; color: #F1F5F9; font-weight: 700; font-size: .8rem; }
.naomdo-grand { text-align: right; }
.naomdo-grand-label {
  text-align: left; font-weight: 700;
  position: sticky; left: 0; z-index: 2;
  background: #1E293B; color: #F1F5F9;
}
.naomdo-perf-hdr { position: sticky; z-index: 4 !important; }
.naomdo-perf-sub { position: sticky; z-index: 4 !important; }
.naomdo-perf-col { position: sticky; z-index: 2; }

/* Naomdo multi-select dropdown */
.naomdo-ms-wrap { position: relative; min-width: 200px; }
.naomdo-ms-btn {
  width: 100%; text-align: left; cursor: pointer; padding: 4px 28px 4px 10px;
  font-size: .82rem; border: 1px solid #ADB5BD; border-radius: 4px; background: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
  background-repeat: no-repeat; background-position: right 8px center; background-size: 12px;
}
.naomdo-ms-btn:focus { outline: none; border-color: #1971C2; box-shadow: 0 0 0 2px #d0e4ff; }
.naomdo-ms-drop {
  display: none; position: absolute; top: calc(100% + 2px); left: 0; z-index: 1050;
  background: #fff; border: 1px solid #ADB5BD; border-radius: 4px;
  min-width: 100%; max-height: 220px; overflow-y: auto;
  padding: 4px 0; box-shadow: 0 4px 12px rgba(0,0,0,.15);
}
.naomdo-ms-drop.open { display: block; }
.naomdo-ms-opt {
  display: flex; align-items: center; gap: 7px;
  padding: 5px 12px; cursor: pointer; font-size: .82rem;
  white-space: nowrap; margin: 0; font-weight: normal;
}
.naomdo-ms-opt:hover { background: #f1f3f5; }
.naomdo-ms-opt input { cursor: pointer; }
/* legacy listbox (config page) */
.naomdo-ms { min-height: 110px; font-size: .78rem; }
.naomdo-ms option:checked { background: #1971C2; color: #fff; }

/* Naomdo tab bar */
.naomdo-tab-bar { display: flex; gap: 2px; margin-bottom: 12px; border-bottom: 2px solid #DEE2E6; }
.naomdo-tab {
  padding: 5px 18px; border: none; border-bottom: 3px solid transparent;
  margin-bottom: -2px; background: none; cursor: pointer; font-size: .83rem;
  color: #495057; font-weight: 500; border-radius: 4px 4px 0 0; transition: background .15s;
}
.naomdo-tab:hover { background: #f1f3f5; color: #212529; }
.naomdo-tab.active { color: #1971C2; border-bottom-color: #1971C2; font-weight: 700; }

/* Cobertura color badges */
.cob-ok   { background: #D3F9D8; color: #2F9E44; border-radius: 4px; padding: 1px 5px; }
.cob-warn { background: #FFF3BF; color: #E67700; border-radius: 4px; padding: 1px 5px; }
.cob-low  { background: #FFE3E3; color: #C92A2A; border-radius: 4px; padding: 1px 5px; }
.cob-high { background: #E0F2FE; color: #0C4A6E; border-radius: 4px; padding: 1px 5px; }
