/* Componentes reutilizáveis. Novas telas devem compor estes blocos em vez de criar estilos próprios. */

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 36px; padding: 8px 12px;
  background: var(--surface); color: #405268;
  border: 1px solid #dce2e7; border-radius: var(--radius-sm);
  font-size: var(--fs-md); font-weight: 700;
}
.btn:hover { background: #f3f5f7; }
.btn.strong { background: #eef2f6; color: #294767; border-color: #d6dfe8; }
.btn.strong:hover { background: #e4ebf2; }
.btn.primary { background: var(--accent); color: var(--navy-deep); border-color: var(--accent); font-weight: 750; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--red-ink); border-color: #f0c9ce; }
.btn.small { min-height: 33px; padding: 7px 10px; font-size: var(--fs-sm); }
.btn.wide { width: 100%; }

/* ---------- Formulários ---------- */
.control { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.control label, .form-field label {
  color: #6c7786; font-size: 9px; font-weight: 800; letter-spacing: .6px; text-transform: uppercase;
}
.control input, .control select, .form-field input, .form-field select {
  width: 100%; min-height: 39px; padding: 9px 11px;
  background: var(--surface); color: #34475b;
  border: 1px solid var(--stroke-input); border-radius: 10px; outline: 0;
}
.control input:focus, .control select:focus, .form-field input:focus, .form-field select:focus {
  border-color: #8da1b6; box-shadow: 0 0 0 2px #eaf0f6;
}
.form-field { margin-bottom: 18px; }
.form-field label { display: block; margin-bottom: 8px; font-size: var(--fs-sm); text-transform: none; letter-spacing: 0; font-weight: 650; color: var(--ink); }
.form-field input { height: 48px; padding: 13px 14px; font-size: 14px; border-radius: 9px; }
.form-field small { display: block; margin-top: 7px; color: #677487; font-size: 11px; line-height: 1.6; }

.message { margin: 16px 0 0; padding: 11px 12px; border-radius: var(--radius-sm); background: #eef3f9; color: var(--ink); font-size: var(--fs-sm); line-height: 1.6; }
.message.error { background: #fff1f1; color: #a22c3b; }
.message.success { background: #eaf9f1; color: #174a3a; }
.message.info { background: #edf3f9; color: #3b5876; }

/* ---------- Cards e KPIs ---------- */
.card {
  min-width: 0; margin-bottom: 18px; padding: 20px; overflow: hidden;
  background: var(--surface); border: 1px solid #e3e7ea; border-radius: var(--radius-lg); box-shadow: none;
}
.cardhead { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 17px; }
.cardtitle { display: flex; align-items: center; gap: 10px; color: var(--ink-strong); font-size: var(--fs-lg); font-weight: 800; letter-spacing: -.24px; }
.titlebar { display: inline-block; width: 4px; height: 19px; background: var(--accent); border-radius: 6px; }
.cardsub { margin: 5px 0 0; color: #8190a2; font-size: var(--fs-sm); line-height: 1.5; }

.kpi {
  position: relative; min-width: 0; padding: 21px 20px 20px; overflow: hidden;
  background: var(--surface); border: 1px solid #e3e7ea; border-radius: var(--radius-lg);
}
.kpi::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--kcolor, var(--accent)); opacity: .65; }
.kpi.red { --kcolor: var(--red); }
.kpi.amber { --kcolor: var(--amber); }
.kpi.blue { --kcolor: var(--blue); }
.kpi.gray { --kcolor: #8993a4; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; color: #73808d; font-size: 11px; font-weight: 800; letter-spacing: 0; text-transform: uppercase; }
.miniicon { display: grid; place-items: center; width: 28px; height: 28px; background: #f4f5f6; color: #6b7b8e; border-radius: var(--radius-sm); font-size: 15px; }
.kpi h3 { margin: 15px 0 5px; overflow: hidden; color: #102e51; font-size: var(--fs-kpi); font-weight: 780; letter-spacing: -1px; line-height: 1.2; font-variant-numeric: tabular-nums; white-space: nowrap; text-overflow: ellipsis; }
.kpi p { min-height: 15px; margin: 0; color: var(--muted); font-size: 11px; line-height: 1.5; }

.buy-card { padding: 16px 18px; background: var(--surface); border: 1px solid var(--stroke); border-radius: 14px; }
.buy-card small { display: block; margin-bottom: 8px; color: #7b8a9c; font-size: var(--fs-xs); font-weight: 800; letter-spacing: .45px; text-transform: uppercase; }
.buy-card strong { color: #263e57; font-size: 18px; }
.buy-card p { margin: 6px 0 0; color: #8794a2; font-size: 11px; line-height: 1.55; }

/* ---------- Avisos e estados ---------- */
.note { display: block; margin-bottom: 18px; padding: 14px; background: var(--surface-alt); border: 1px solid var(--stroke); border-radius: 10px; color: #4f657c; font-size: var(--fs-md); line-height: 1.6; }
.note strong { color: #304867; }
.note.warning { background: #fffcf4; border-color: #eee5cf; color: #7f7155; }
.loading, .empty { padding: 25px; color: #8090a3; font-size: var(--fs-md); text-align: center; }
.emptybox { display: flex; align-items: center; gap: 18px; padding: 24px 18px; background: #fafcff; border: 1px dashed #d5dfec; border-radius: var(--radius); }
.emptybox strong { color: #31465d; font-size: 14px; }
.emptybox p { max-width: 700px; margin: 7px 0 0; color: #798ca1; font-size: var(--fs-sm); line-height: 1.7; }

.statuspill { display: inline-flex; align-items: center; gap: 7px; padding: 8px 10px; background: #fffdf3; color: #7a6c41; border: 1px solid #eee6c8; border-radius: 50px; font-size: var(--fs-xs); font-weight: 800; white-space: nowrap; }
.dot { width: 6px; height: 6px; background: #e6b71a; border-radius: 50%; }
.badge { padding: 5px 9px; background: #edf3fa; color: #355579; border-radius: 30px; font-size: 11px; }

/* ---------- Tags e decisões ---------- */
.tag { display: inline-flex; align-items: center; padding: 5px 8px; border-radius: var(--radius-pill); font-size: var(--fs-xs); font-weight: 800; white-space: nowrap; }
.tag.crit { background: var(--red-soft); color: var(--red-ink); }
.tag.att { background: var(--amber-soft); color: var(--amber-ink); }
.tag.ok { background: #f0f4f7; color: #657285; }
.tag.good { background: var(--green-soft); color: var(--green-ink); }
.tag.info { background: var(--blue-soft); color: var(--info-ink); }

.decision-pill {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 82px; min-height: 30px; padding: 6px 10px;
  border-radius: var(--radius-pill); font-size: 11px; font-weight: 800; letter-spacing: .2px; white-space: nowrap;
}
button.decision-pill { cursor: pointer; font-family: inherit; }
.decision-pill.yes { background: #fff0f0; color: #a32332; border: 1px solid #efb9bf; box-shadow: 0 0 0 2px #fff inset; }
button.decision-pill.yes:hover { background: #ffe5e7; border-color: #df929b; }
.decision-pill.no { background: #f1f6f3; color: #456955; border: 1px solid #d7e6dc; }
.decision-pill.pending { background: #fff8e8; color: #8a6b26; border: 1px solid #eadcae; }

.alert-pill { display: inline-block; padding: 5px 7px; border-radius: 5px; font-size: var(--fs-xs); font-weight: 700; line-height: 1.45; }
.alert-pill.urgent { background: #fcf1f2; color: #a56c6f; }
.alert-pill.next { background: #faf6e7; color: #a28539; }
.alert-pill.good { background: var(--green-soft); color: var(--green-ink); }
.alert-pill.neutral { background: var(--neutral-soft); color: var(--neutral-ink); }

/* ---------- Tabelas ---------- */
.tablewrap { width: 100%; max-height: 600px; overflow: auto; border: 1px solid var(--stroke); border-radius: var(--radius); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; white-space: nowrap; }
.table th {
  position: sticky; top: 0; z-index: 1;
  padding: 13px 12px; background: var(--surface-head); color: #52657a;
  border-bottom: 1px solid #e6ecf3; font-size: 11px; font-weight: 800; letter-spacing: .65px; text-align: left; text-transform: uppercase;
}
.table td { max-width: 350px; padding: 12px; overflow: hidden; color: var(--ink-table); border-bottom: 1px solid var(--stroke-soft); font-size: var(--fs-md); text-overflow: ellipsis; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #f6fafc; }
.table .clickable { cursor: pointer; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .emph { color: #18324f; font-weight: 760; }
.table .sub { color: #94a1af; font-size: 11px; }
.table .sku { color: #345674; font-size: var(--fs-sm); font-weight: 800; }
.statline { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: 10px 3px 0; color: #8995a4; font-size: 11px; }

/* Folha de acompanhamento S&OP (colunas fixas e OBS editável). */
.sop-summary { display: grid; grid-template-columns: 1fr 1fr 1fr 2fr; margin-bottom: 18px; padding: 16px 20px; background: var(--surface); border: 1px solid #e2e6ea; border-radius: var(--radius); }
.sop-summary > div { display: flex; align-items: center; gap: 11px; padding: 0 18px; border-right: 1px solid var(--stroke-soft); }
.sop-summary > div:first-child { padding-left: 0; }
.sop-summary > div:last-child { border: 0; padding-right: 0; }
.sop-summary b { color: #344e69; font-size: 26px; letter-spacing: -.5px; }
.sop-summary span { color: #74808d; font-size: 11px; line-height: 1.6; }
.sop-summary small { display: block; color: #9aa2ac; font-size: 9px; }
.sop-controls { display: grid; grid-template-columns: 1.8fr 1.25fr auto; gap: 10px; align-items: end; margin-bottom: 16px; }
.sop-sheet { overflow: hidden; background: var(--surface); border: 1px solid #dee4e9; border-radius: var(--radius); }
.sop-toolbar { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: 14px 16px; border-bottom: 1px solid #e5e9ed; }
.sop-toolbar strong { color: #3e5369; font-size: var(--fs-sm); }
.sop-table-wrap { position: relative; min-height: 250px; max-height: 62vh; overflow: auto; }
.sop-table { width: 100%; min-width: 1500px; border-collapse: separate; border-spacing: 0; color: #2e435a; font-size: var(--fs-sm); }
.sop-table th { position: sticky; top: 0; z-index: 3; padding: 13px 9px 12px; background: #f1f3f5; color: #44596f; border-bottom: 1px solid #dce2e7; font-size: 11px; font-weight: 700; line-height: 1.5; text-align: left; }
.sop-table td { padding: 10px 9px; background: var(--surface); border-bottom: 1px solid var(--stroke-soft); font-variant-numeric: tabular-nums; line-height: 1.5; vertical-align: middle; }
.sop-table tr:nth-child(even) td { background: #fafbfc; }
.sop-table tbody tr:hover td { background: #f5f7fa; }
.sop-table .num { text-align: right; }
.sop-table .sticky-0 { position: sticky; left: 0; z-index: 2; color: #345674; }
.sop-table th.sticky-0 { z-index: 5; }
@media (min-width: 1000px) {
  .sop-table .sticky-end { position: sticky; right: 0; z-index: 2; min-width: 260px; box-shadow: -2px 0 0 #e8e4d7; background: #fffefa; }
  .sop-table th.sticky-end { z-index: 5; background: #faf7eb; }
}
.sop-table .missing { color: #a5afba; }
.sop-obs { display: block; width: 100%; height: 40px; min-height: 40px; padding: 8px 9px; resize: vertical; background: var(--surface); color: #243d57; border: 1px solid #e1dfd2; border-radius: 6px; font: 12px/1.5 var(--font); outline: none; }
.sop-obs:focus { border-color: #8a9eb6; box-shadow: 0 0 0 2px #edf2f7; }
.sop-obs:disabled { opacity: .6; cursor: wait; }
.save-state { display: block; margin: 4px 1px 0; color: #a1a6ad; font-size: 9px; }
.save-state:empty { display: none; }
.save-state.ok { color: var(--green-ink); }
.save-state.error { color: var(--red-ink); }

/* ---------- Barras e listas ---------- */
.metricrow { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; padding: 12px 0 6px; }
.metricrow > div { display: flex; flex-direction: column; padding-left: 10px; border-right: 1px solid var(--stroke); }
.metricrow > div:last-child { border: 0; }
.metricrow strong { font-size: 26px; font-weight: 750; letter-spacing: -.8px; }
.metricrow small { padding-top: 6px; color: var(--muted); font-size: 11px; }
.minor { margin: 10px 0 0; color: #8292a4; font-size: 11px; line-height: 1.7; }
.compactlist { display: flex; flex-direction: column; }
.compactrow { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 9px 0; border-bottom: 1px solid #eef2f5; cursor: pointer; }
.compactrow:last-child { border: 0; }
.compactname { min-width: 0; overflow: hidden; color: #425169; font-size: 11px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.compactname small { display: block; margin-top: 3px; color: #92a0b3; font-weight: 400; }
.compactrow strong { color: #2a5b87; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Painel lateral (detalhes) ---------- */
.overlay { position: fixed; inset: 0; z-index: 30; background: #091c34ac; opacity: 0; pointer-events: none; transition: opacity .2s; }
.overlay.show { opacity: 1; pointer-events: auto; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; z-index: 31; width: min(570px, 100vw); padding: 30px; overflow: auto; background: var(--surface); box-shadow: -14px 0 45px #03112330; transform: translateX(103%); transition: transform .22s; }
.drawer.open { transform: translateX(0); }
.drawer .close { float: right; width: 35px; height: 35px; background: var(--surface); color: #55677c; border: 1px solid var(--stroke); border-radius: 10px; font-size: 21px; }
.drawer h2 { max-width: 430px; font-size: 22px; letter-spacing: -.6px; line-height: 1.35; }
.drawer h3 { margin-top: 24px; color: #193452; font-size: var(--fs-md); }
.fieldgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 20px 0; }
.tile { padding: 12px; background: var(--surface-alt); border: 1px solid #e5e9ed; border-radius: 11px; }
.tile small { display: block; margin-bottom: 9px; color: #8795a7; font-size: var(--fs-xs); font-weight: 700; letter-spacing: .5px; text-transform: uppercase; }
.tile b { color: #203851; font-size: var(--fs-lg); }

/* ---------- Diálogos e upload ---------- */
.modal { width: calc(100% - 32px); max-width: 580px; max-height: 90vh; padding: 28px; overflow: auto; color: #18314f; border: 1px solid #dce2e9; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.modal::backdrop { background: #172b4d66; }
.modal-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.modal h2 { font-size: 22px; }
.dropzone { display: flex; flex-direction: column; gap: 8px; padding: 16px; background: #fafcff; border: 1px dashed #9fb4ca; border-radius: var(--radius); font-weight: 800; }
.dropzone span { color: #7b8c9e; font-size: 11px; font-weight: 500; }
.upload-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 13px; align-items: end; }

@media (max-width: 1250px) {
  .sop-summary { grid-template-columns: 1fr 1fr 1fr; }
  .sop-summary > div:nth-child(3) { border: 0; }
  .sop-summary > div:nth-child(4) { display: none; }
}
@media (max-width: 800px) {
  .kpi { padding: 16px 13px; }
  .kpi h3 { font-size: 21px; }
  .card { padding: 15px; }
  .drawer { padding: 20px; }
  .sop-summary { padding: 13px 10px; }
  .sop-summary > div { display: block; padding: 0 8px; }
  .sop-summary b { display: block; font-size: 21px; }
  .sop-controls { grid-template-columns: 1fr 1fr; }
  .sop-controls .btn { grid-column: 1 / -1; }
  .metricrow strong { font-size: 19px; }
  .upload-grid { grid-template-columns: 1fr; }
}
@media (max-width: 425px) {
  .kpi h3 { font-size: 18px; }
  .kpi-top { font-size: 9px; }
}
@media print {
  .sop-table-wrap { overflow: visible; max-height: none; }
  .sop-table th, .sop-table .sticky-0 { position: static; }
}
