/* ==========================================================================
   IBM Z Control Desk — sistema visual
   Linguagem: enterprise/analítica, inspirada no IBM Carbon. Superfícies planas
   delimitadas por bordas de 1px (sem sombras pesadas), raios discretos,
   tipografia densa com numerais tabulares e uma paleta neutra restrita.
   ========================================================================== */

:root {
  /* Neutros */
  --gray-10: #f4f4f4;
  --gray-20: #e0e0e0;
  --gray-30: #c6c6c6;
  --gray-50: #8d8d8d;
  --gray-60: #6f6f6f;
  --gray-70: #525252;
  --gray-90: #262626;
  --gray-100: #161616;

  /* Superfícies */
  --canvas: #f4f4f4;
  --surface: #ffffff;
  --surface-subtle: #fafafa;
  --surface-hover: #f2f4f8;
  --shell: #161616;
  --shell-line: #393939;

  /* Texto */
  --ink: #161616;
  --ink-secondary: #525252;
  --ink-muted: #6f6f6f;
  --ink-inverse: #ffffff;

  /* Traço */
  --border: #e0e0e0;
  --border-strong: #c6c6c6;

  /* Semânticos */
  --primary: #0f62fe;
  --primary-hover: #0353e9;
  --primary-light: #edf5ff;
  --danger: #da1e28;
  --danger-light: #fff1f1;
  --success: #198038;
  --success-light: #defbe6;
  --warning: #8e6a00;
  --warning-light: #fcf4d6;
  --accent: #6929c4;
  --accent-light: #f6f2ff;

  --radius: 4px;
  --radius-lg: 6px;

  --font: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--font);
  background: var(--canvas);
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.45;
}

.hidden { display: none !important; }
.muted { color: var(--ink-secondary); }
.small { font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

svg { flex-shrink: 0; }

/* ── Shell / topbar ──────────────────────────────────────────────────────── */

.topbar {
  background: var(--shell);
  color: var(--ink-inverse);
  position: sticky;
  top: 0;
  z-index: 40;
  border-bottom: 1px solid var(--shell-line);
}

.topbar-inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 20px;
  min-height: 52px;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: nowrap; /* nada de segunda linha: a nav encolhe/rola no lugar */
}

.brand { display: flex; align-items: stretch; gap: 14px; min-width: 0; flex: 1 1 auto; }
.brand > div { display: flex; align-items: center; }

.brand-mark {
  align-self: center;
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: #fff;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 1.4px;
  border-radius: var(--radius);
  padding: 5px 8px;
}

.brand h1 {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.1px;
  align-self: center;
  white-space: nowrap;
}

.brand p { display: none; } /* o subtítulo vive no cabeçalho da página, não no shell */

/* Navegação entre módulos: abas do shell, sem cápsulas nem ícones decorativos */
/* A nav é a peça elástica: rola na horizontal quando o espaço aperta. */
.module-nav {
  display: flex;
  align-items: stretch;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.module-nav::-webkit-scrollbar { display: none; }

.module-nav a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.72);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  transition: color 0.12s ease, background 0.12s ease, border-color 0.12s ease;
  white-space: nowrap;
}

.module-nav a:hover { color: #fff; background: rgba(255, 255, 255, 0.08); }

.module-nav a.active {
  color: #fff;
  border-bottom-color: var(--primary);
  background: rgba(255, 255, 255, 0.06);
}

.topbar-actions { display: flex; align-items: center; gap: 8px; padding: 8px 0; flex: 0 0 auto; }

.client-select-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: var(--radius);
  padding: 5px 10px;
}

.client-select-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: rgba(255, 255, 255, 0.6);
}

#client-select {
  background: transparent;
  border: none;
  color: #fff;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  outline: none;
  max-width: 200px;
  cursor: pointer;
}

#client-select option { color: var(--ink); }

/* ── Botões ──────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 8px 14px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
  white-space: nowrap;
}

.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }

.btn-ghost {
  background: transparent;
  color: var(--primary);
  border-color: var(--border-strong);
}
.btn-ghost:hover { background: var(--primary-light); border-color: var(--primary); }

.topbar .btn-ghost {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.35);
}
.topbar .btn-ghost:hover { background: rgba(255, 255, 255, 0.12); border-color: rgba(255, 255, 255, 0.6); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #ba1b23; }

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
  border-color: var(--border-strong);
}
.btn-danger-ghost:hover { background: var(--danger-light); border-color: var(--danger); }

/* ── Layout ──────────────────────────────────────────────────────────────── */

.container { max-width: 1600px; margin: 0 auto; padding: 20px; }

.client-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 16px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.client-header h2 { font-size: 21px; font-weight: 600; letter-spacing: -0.2px; }
.client-header .muted { font-size: 13px; margin-top: 3px; }
.client-header-actions { display: flex; gap: 8px; }

/* ── KPIs ────────────────────────────────────────────────────────────────── */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 18px;
}

.kpi-card { background: var(--surface); padding: 16px 18px; }

.kpi-card h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--ink-muted);
  font-weight: 500;
  margin-bottom: 10px;
}

.kpi-card .value {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.4px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.kpi-card .value-accent { color: var(--accent); }
.kpi-card .subtitle { font-size: 12px; color: var(--ink-muted); margin-top: 6px; }

.delta { font-weight: 600; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--danger); }
.delta.down { color: var(--success); }
.delta.flat { color: var(--ink-muted); }

/* ── Cards ───────────────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.card-header h2 { font-size: 15px; font-weight: 600; letter-spacing: -0.1px; }
.card-header .muted { font-size: 12.5px; margin-top: 3px; }

.chart-container { position: relative; height: 340px; width: 100%; }

.chart-toggles { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }

.toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--ink-secondary);
  cursor: pointer;
}
.toggle input { accent-color: var(--primary); cursor: pointer; }

.segmented {
  display: inline-flex;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  overflow: hidden;
}

.seg-btn {
  border: none;
  border-right: 1px solid var(--border-strong);
  background: var(--surface);
  padding: 6px 13px;
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-secondary);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.seg-btn:last-child { border-right: none; }
.seg-btn:hover { background: var(--surface-hover); color: var(--ink); }
.seg-btn.active { background: var(--primary); color: #fff; }

.two-col {
  display: grid;
  grid-template-columns: minmax(380px, 5fr) minmax(420px, 7fr);
  gap: 18px;
  align-items: start;
}

@media (max-width: 1080px) {
  /* minmax(0,1fr) e não 1fr: com o piso implícito de min-content a tabela larga
     estica a coluna e a página inteira passa a rolar na horizontal. */
  .two-col { grid-template-columns: minmax(0, 1fr); }
}

/* ── Tabelas ─────────────────────────────────────────────────────────────── */

.table-responsive { overflow-x: auto; max-height: 480px; overflow-y: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }

th, td {
  padding: 9px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }

th {
  background: var(--surface-subtle);
  font-weight: 500;
  color: var(--ink-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  position: sticky;
  top: 0;
  z-index: 1;
  border-bottom: 1px solid var(--border-strong);
}

tbody tr:last-child td { border-bottom: none; }

th[data-sort] {
  cursor: pointer;
  user-select: none;
  transition: background 0.12s ease, color 0.12s ease;
}
th[data-sort]:hover { background: var(--surface-hover); color: var(--ink); }
th[data-sort].sorted { color: var(--primary); background: var(--primary-light); }

#history-tbody tr,
#machines-tbody tr,
#compare-machines-tbody tr { cursor: pointer; transition: background 0.1s ease; }

#history-tbody tr:hover,
#machines-tbody tr:hover,
#compare-machines-tbody tr:hover { background: var(--surface-hover); }

#history-tbody tr.selected,
#machines-tbody tr.selected,
#compare-machines-tbody tr.selected {
  background: var(--primary-light);
  box-shadow: inset 2px 0 0 var(--primary);
}

/* Barras dentro de células */
.pct-bar-wrap { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.pct-bar-track { width: 88px; background: var(--gray-20); border-radius: 2px; overflow: hidden; display: flex; }
.pct-bar { height: 6px; background: var(--primary); min-width: 2px; border-radius: 2px; }

.delta-bar-track {
  position: relative;
  width: 92px;
  height: 6px;
  background: var(--gray-20);
  border-radius: 2px;
  overflow: hidden;
}
.delta-bar-track::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--gray-30);
}
.delta-bar { position: absolute; top: 0; bottom: 0; border-radius: 2px; }
.delta-bar.up { left: 50%; background: var(--danger); }
.delta-bar.down { right: 50%; background: var(--success); }

.delta-cell { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }

/* Tags de estado */
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 2px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.tag-history { background: var(--primary-light); color: #0043ce; }
.tag-alert { background: var(--danger-light); color: #a2191f; }
.tag-ok { background: var(--success-light); color: #0e6027; }
.tag-neutral { background: var(--gray-10); color: var(--ink-muted); }
.tag-group { background: var(--accent-light); color: #491d8b; }
.tag-new { background: var(--primary-light); color: #0043ce; }
.tag-gone { background: var(--gray-10); color: var(--ink-muted); }

.row-action {
  border: none;
  background: transparent;
  color: var(--gray-50);
  cursor: pointer;
  padding: 3px 5px;
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  transition: background 0.12s ease, color 0.12s ease;
}
.row-action:hover { background: var(--danger-light); color: var(--danger); }

.report-meta {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  line-height: 1.7;
  font-size: 12px;
  color: var(--ink-muted);
}

/* ── Avisos ──────────────────────────────────────────────────────────────── */

.banner {
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  margin-bottom: 16px;
  line-height: 1.55;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.banner-warning {
  background: var(--warning-light);
  border-left: 3px solid #f1c21b;
  color: var(--warning);
}

/* ── Estados vazios ──────────────────────────────────────────────────────── */

.empty-state {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 72px 24px;
  text-align: center;
  margin-top: 5vh;
}

.empty-icon { color: var(--gray-30); margin-bottom: 16px; display: flex; justify-content: center; }
.empty-state h2 { font-size: 17px; font-weight: 600; margin-bottom: 8px; }
.empty-state p { color: var(--ink-secondary); margin-bottom: 22px; font-size: 13.5px; }

/* ── Drag & drop ─────────────────────────────────────────────────────────── */

.drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(22, 22, 22, 0.6);
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
}

.drop-box {
  background: var(--surface);
  border: 2px dashed var(--primary);
  border-radius: var(--radius-lg);
  padding: 44px 60px;
  text-align: center;
  pointer-events: none;
}

.drop-icon { color: var(--primary); margin-bottom: 12px; display: flex; justify-content: center; }
.drop-box h2 { font-size: 17px; font-weight: 600; margin-bottom: 6px; }
.drop-box p { color: var(--ink-secondary); font-size: 13px; }

/* ── Modais ──────────────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(22, 22, 22, 0.5);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px 26px;
  width: 100%;
  max-width: 460px;
  border: 1px solid var(--border);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
  animation: modal-in 0.14s ease;
}

.modal-wide { max-width: 660px; }

@keyframes modal-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.modal h2 { font-size: 16px; font-weight: 600; margin-bottom: 12px; }
.modal p { font-size: 13px; margin-bottom: 14px; line-height: 1.55; color: var(--ink-secondary); }

.field { display: block; margin-bottom: 14px; }

/* Só o rótulo direto do campo vira micro-label; spans internos (ex.: nomes de
   LPAR nos checkboxes) mantêm a tipografia normal. */
.field > span {
  display: block;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--ink-muted);
  margin-bottom: 6px;
}

/* Só campos de digitação; checkboxes dentro do campo mantêm o tamanho nativo. */
.field input[type="text"],
.field input[type="number"] {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 13.5px;
  background: var(--surface-subtle);
}
.field input[type="text"]:focus,
.field input[type="number"]:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
  border-color: transparent;
  background: var(--surface);
}

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.upload-summary { font-size: 13px; line-height: 1.7; color: var(--ink-secondary); }
.upload-summary strong { color: var(--ink); }
.upload-summary .big {
  font-size: 26px;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
  margin: 8px 0;
}
.upload-summary ul { margin: 10px 0 0 18px; }

/* ── Notificações ────────────────────────────────────────────────────────── */

.toast-stack {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--gray-100);
  color: #fff;
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  border-left: 3px solid var(--gray-50);
  animation: toast-in 0.18s ease;
  max-width: 380px;
}
.toast.success { border-left-color: #42be65; }
.toast.error { border-left-color: #fa4d56; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: none; }
}

/* ── Grupos de LPARs ─────────────────────────────────────────────────────── */

.lpar-controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.groups-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }

.group-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface-subtle);
  border: 1px solid var(--border-strong);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 5px 11px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.group-chip:hover { background: var(--surface-hover); border-color: var(--primary); }
.group-chip.editing { border-color: var(--primary); background: var(--primary-light); color: #0043ce; }
.group-chip .count { color: var(--ink-muted); font-weight: 400; }

.groups-empty { font-size: 12.5px; color: var(--ink-muted); padding: 2px 0 4px; }

.lpar-checks {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 4px 10px;
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--surface-subtle);
}

.lpar-check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  cursor: pointer;
  min-width: 0;
}
.lpar-check input { accent-color: var(--primary); cursor: pointer; }
.lpar-check > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lpar-check .origin { color: var(--ink-muted); font-size: 10.5px; }

.group-row td:first-child { border-left: 2px solid var(--accent); }
.group-row { cursor: pointer; transition: background 0.1s ease; }
.group-row:hover { background: var(--accent-light); }

.chev {
  display: inline-block;
  width: 12px;
  color: var(--gray-50);
  transition: transform 0.14s ease;
}
.chev.open { transform: rotate(90deg); }

.group-member-row td { background: var(--surface-subtle); }
.group-member-row td:first-child { padding-left: 32px; }

.machine-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-light);
  color: #0043ce;
  border: 1px solid #a6c8ff;
  border-radius: var(--radius);
  padding: 3px 9px;
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  margin-left: 8px;
  vertical-align: middle;
  transition: background 0.12s ease;
}
.machine-chip:hover { background: #d0e2ff; }

/* ── Comparativo mês a mês ───────────────────────────────────────────────── */

.compare-select-wrap { display: flex; align-items: center; gap: 8px; }

#compare-base, #compare-base:focus {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink);
  background: var(--surface);
  cursor: pointer;
}
#compare-base:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.compare-summary {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-left: 3px solid var(--gray-30);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 18px;
  font-size: 13px;
  color: var(--ink-secondary);
}
.compare-summary strong { color: var(--ink); }
.compare-summary .headline {
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.4px;
  font-variant-numeric: tabular-nums;
}

.compare-grid { align-items: start; grid-template-columns: 1fr 1fr; }
.compare-grid th, .compare-grid td { padding: 8px 9px; }
.compare-grid .delta-bar-track { width: 52px; }
.compare-grid .delta-cell { gap: 6px; }

@media (max-width: 1180px) {
  .compare-grid { grid-template-columns: 1fr; }
}

.compare-subtitle {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--ink-muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.compare-subtitle .muted { text-transform: none; letter-spacing: 0; font-size: 12px; }

/* ── Animação de entrada ─────────────────────────────────────────────────── */

.reveal { animation: rise 0.22s ease both; }
@keyframes rise {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .reveal, .modal, .toast { animation: none; }
  .chev { transition: none; }
}

@media (max-width: 720px) {
  .container { padding: 14px; }
  .chart-container { height: 280px; }
  html { font-size: 14px; }
  .kpi-grid { grid-template-columns: 1fr; }
}

/* ── Origens (SCRTs) que compõem o mês ───────────────────────────────────── */

.sources-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 12px;
  background: var(--surface-subtle);
}

.sources-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  font-weight: 500;
  color: var(--ink-muted);
  margin-bottom: 8px;
}

.source-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
}
.source-row:first-of-type { border-top: none; }
.source-row .source-file {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
}
.source-row .num { font-variant-numeric: tabular-nums; white-space: nowrap; }

.conflict-note {
  background: var(--danger-light);
  border-left: 3px solid var(--danger);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 12.5px;
  line-height: 1.55;
  color: #a2191f;
}

/* ── Capacity planning ───────────────────────────────────────────────────── */

.forecast-controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

#forecast-method, #forecast-years {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink);
  background: var(--surface);
  cursor: pointer;
}
#forecast-method:focus, #forecast-years:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.forecast-model {
  padding: 10px 12px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
  line-height: 1.6;
}

.tag-forecast { background: #fff2e8; color: #8a3800; }

/* ── Modal do capacity planning ──────────────────────────────────────────── */
.modal.modal-forecast {
  max-width: 940px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal-forecast-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.modal-forecast .forecast-controls { margin: 14px 0 4px; }
.modal-forecast-scroll {
  overflow-y: auto;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

/* Comparativo mês a mês: modal largo com as duas tabelas lado a lado. */
.modal.modal-compare {
  max-width: min(1320px, 96vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal-compare-head { display: flex; align-items: center; gap: 14px; }

/* ============================================================ *
 *  MLC (Monthly License Charge)
 * ============================================================ */
.client-header-actions { display: flex; gap: 8px; align-items: center; }

.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  vertical-align: middle;
}
.badge-scrt { background: var(--primary-light); color: var(--primary); }

td.strong, .num.strong { font-weight: 600; color: var(--ink); }

.mlc-year { margin-bottom: 18px; }
.mlc-year-range { font-size: 12.5px; font-weight: 400; }
.mlc-encargos { font-size: 12px; margin-top: 2px; }

.mlc-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.mlc-table th, .mlc-table td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.mlc-table thead th {
  position: sticky; top: 0;
  background: var(--surface-subtle);
  font-weight: 600; color: var(--ink-secondary);
  border-bottom: 1px solid var(--border-strong);
  text-align: left;
}
.mlc-table th.num, .mlc-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.mlc-table tbody tr:hover td { background: var(--surface-hover); }
.mlc-row-pending td { color: var(--ink-muted); font-style: italic; background: var(--surface-subtle); }
.mlc-row-pending:hover td { background: var(--surface-subtle); }
.mlc-row-total td {
  background: var(--surface-subtle);
  font-weight: 600;
  border-top: 2px solid var(--border-strong);
  border-bottom: none;
}
.mlc-row-total:hover td { background: var(--surface-subtle); }

/* Editor do contrato */
.contract-form-top { margin-bottom: 6px; }
.contract-editor-scroll { max-height: 52vh; overflow-y: auto; margin: 4px -4px 10px; padding: 0 4px; }
.year-editor {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  background: var(--surface-subtle);
}
.year-editor-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.year-label {
  flex: 1; font-weight: 600; font-size: 14px;
  padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
}
.year-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 16px; }
.year-grid .field { margin-bottom: 4px; }
.encargos-block { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--border); }
.encargos-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.encargos-head span { font-size: 12.5px; font-weight: 600; color: var(--ink-secondary); }
.encargo-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.encargo-row .enc-nome { flex: 2; }
.encargo-row .enc-valor { flex: 1; }
.encargo-row input {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); font-size: 13px;
}
.btn-icon {
  border: 1px solid var(--border); background: var(--surface);
  color: var(--ink-muted); border-radius: var(--radius);
  width: 30px; height: 30px; cursor: pointer; font-size: 16px; line-height: 1;
  flex: 0 0 auto;
}
.btn-icon:hover { background: var(--danger-light); color: var(--danger); border-color: var(--danger); }

.modal-actions-split { display: flex; align-items: center; justify-content: space-between; }
.modal-actions-right { display: flex; gap: 8px; }
.form-error {
  color: var(--danger); font-size: 12.5px; margin: 8px 0 0;
  padding: 8px 10px; background: var(--danger-light); border-radius: var(--radius);
}

@media (max-width: 720px) {
  .year-grid { grid-template-columns: 1fr; }
}

/* ── Por Ano Contratual ─────────────────────────────────────── */
.contract-years { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.contract-years-head { font-size: 13px; font-weight: 600; color: var(--ink-secondary); margin-bottom: 10px; }
.contract-year-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.contract-year-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: var(--surface-subtle);
}
.cyc-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.cyc-head strong { font-size: 13px; }
.cyc-total { font-size: 19px; font-weight: 600; letter-spacing: -0.2px; font-variant-numeric: tabular-nums; }
.cyc-sub { font-size: 11.5px; color: var(--ink-muted); margin-top: 3px; }
.contract-empty {
  padding: 16px 18px;
  background: var(--surface-subtle);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--ink-secondary);
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}

/* ── Tags de máquina (produção / dev-test / ignoradas) ─────────── */
.banner-muted {
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-left: 3px solid var(--ink-muted);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 12.5px;
  color: var(--ink-secondary);
  margin-bottom: 12px;
}
.tag-cell { white-space: nowrap; }
.tag-select {
  font-family: var(--font);
  font-size: 12px;
  padding: 3px 6px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  max-width: 140px;
}
.tag-select.ignored { color: var(--danger); border-color: var(--danger); background: var(--danger-light); }
/* Linha de máquina ignorada: consumo não conta -> apagada e riscada. */
tr.machine-ignored td { color: var(--ink-muted); }
tr.machine-ignored td:nth-child(6) { text-decoration: line-through; }
.pct-bar.ignored { background: var(--ink-muted) !important; }

/* Modal de catálogo de tags */
.tags-editor { margin: 12px 0 6px; display: flex; flex-direction: column; gap: 8px; }
.tag-row { display: flex; align-items: center; gap: 12px; }
.tag-row .tag-name {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--surface);
  color: var(--ink);
}
.tag-ignored { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink-secondary); white-space: nowrap; }
.upload-tagging { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.upload-tag-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 6px 0; border-bottom: 1px solid var(--border);
}
.upload-tag-row:last-child { border-bottom: none; }
.upload-tag-select { max-width: 160px; }

/* ── Modal "Arquivos SCRT" (zOTC e MLC) ────────────────────────── */
.scrt-file-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.scrt-file-row:last-child { border-bottom: none; }
.scrt-file-actions { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.scrt-preview { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.scrt-preview-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
#scrt-preview-body {
  font-family: var(--mono); font-size: 11.5px; line-height: 1.5;
  background: var(--surface-subtle); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; max-height: 48vh; overflow: auto; white-space: pre;
  color: var(--ink);
}
.mlc-scrt-link { cursor: pointer; user-select: none; }
.mlc-scrt-link:hover { outline: 1px solid var(--primary); outline-offset: 1px; }

/* ============================================================ *
 *  Infraestrutura (Sites · Máquinas · LPARs)
 * ============================================================ */
.infra-tabs { margin: 4px 0 16px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.badge-neutral { background: var(--gray-20); color: var(--ink); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.btn-link { background: none; border: none; color: var(--primary); cursor: pointer; font-size: 12px; font-family: var(--font); padding: 0 2px; }
.btn-link:hover { text-decoration: underline; }
.btn-link.danger { color: var(--danger); }
.empty-inline { padding: 18px; background: var(--surface-subtle); border: 1px dashed var(--border-strong); border-radius: var(--radius); color: var(--ink-secondary); font-size: 13px; }
.empty-inline.small { padding: 10px 12px; font-size: 12px; }

/* Marca de máquina (substitui a foto): bloco com gradiente */
.imc-mark { width: 34px; height: 34px; border-radius: var(--radius); flex: 0 0 auto; display: inline-block; }
.imc-mark.inline { width: 18px; height: 18px; vertical-align: middle; margin-right: 6px; border-radius: 3px; }
.grad-linuxone { background: linear-gradient(135deg, #0f62fe, #4589ff); }
.grad-z { background: linear-gradient(135deg, #262626, #525252); }

/* Formulários em grade */
.machine-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 16px; }
.machine-dormant { margin-top: 8px; }
.role-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 4px; }
.role-opt { padding: 7px 8px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); cursor: pointer; font-size: 12.5px; font-family: var(--font); color: var(--ink-secondary); }
.role-opt.active { background: color-mix(in srgb, var(--rc) 12%, white); border-color: var(--rc); color: var(--rc); font-weight: 600; }

/* Visão geral: colunas por site */
.site-columns { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.site-block { background: var(--surface); border: 1px solid var(--border); border-top: 3px solid var(--primary); border-radius: var(--radius); padding: 12px; }
.site-block-nosite { border-top-color: var(--border-strong); border-top-style: dashed; }
.site-block-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.site-block-foot { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.infra-machine-card { display: block; width: 100%; text-align: left; background: var(--surface-subtle); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; margin-bottom: 8px; cursor: pointer; }
.infra-machine-card:hover { border-color: var(--primary); }
.infra-machine-card.dormant { opacity: 0.6; }
.imc-head { display: flex; align-items: center; gap: 10px; }
.imc-id { display: flex; flex-direction: column; line-height: 1.25; flex: 1; min-width: 0; }
.imc-cap { white-space: nowrap; }
.lpar-strip { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.lpar-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; padding: 2px 7px; border: 1px solid var(--border); border-radius: 20px; background: var(--surface); }
.os-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; flex: 0 0 auto; }

/* Aba Máquinas (tabela) */
.infra-toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.infra-search { flex: 1; min-width: 220px; padding: 7px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius); font-size: 13px; font-family: var(--font); }
.infra-toolbar select { padding: 7px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius); font-size: 13px; background: var(--surface); }
.infra-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.infra-table th, .infra-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.infra-table thead th { position: sticky; top: 0; background: var(--surface-subtle); font-weight: 600; color: var(--ink-secondary); border-bottom: 1px solid var(--border-strong); }
.infra-table th.num, .infra-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.infra-table tbody tr:hover td { background: var(--surface-hover); }
.infra-table tr.machine-dormant td { opacity: 0.6; }
.infra-actions-col { width: 1%; white-space: nowrap; }
.infra-actions { white-space: nowrap; text-align: right; }
.infra-actions .row-action { padding: 4px; }
.row-action.danger:hover { color: var(--danger); }

/* Modal arquivos de config */
.config-slot { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }
.config-slot-head { margin-bottom: 8px; }
.config-slot-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.config-preview { margin-top: 10px; font-family: var(--mono); font-size: 11px; background: var(--surface-subtle); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; max-height: 40vh; overflow: auto; white-space: pre; }

/* Modal LPARs */
.lpar-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }
.lpar-card-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.lpar-card-actions { margin-left: auto; display: flex; gap: 10px; }
.lpar-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 16px; margin-top: 6px; }
.lpar-grid > div > span.muted { display: block; }
.lpar-form { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.nic-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.nic-row .nic-type { flex: 0 0 150px; padding: 6px 8px; border: 1px solid var(--border-strong); border-radius: var(--radius); }
.nic-row .nic-label { flex: 1; padding: 6px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius); }

@media (max-width: 720px) {
  .machine-grid, .lpar-grid, .role-grid { grid-template-columns: 1fr; }
}

/* ── Autenticação: menu do usuário no topbar ────────────────────────────── */
.user-menu { position: relative; display: flex; align-items: center; }
.user-chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: var(--ink-inverse);
  padding: 5px 10px 5px 6px; border-radius: 999px;
  cursor: pointer; font-family: var(--font); font-size: 12.5px; line-height: 1;
}
.user-chip:hover { background: rgba(255, 255, 255, 0.15); border-color: rgba(255, 255, 255, 0.55); }
.user-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--primary); color: #fff; font-weight: 600; font-size: 11px;
  letter-spacing: 0.3px; flex-shrink: 0;
}
.user-avatar.lg { width: 40px; height: 40px; font-size: 15px; }
.user-chip-text { display: flex; flex-direction: column; gap: 2px; text-align: left; max-width: 150px; }
.user-chip-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip-role { font-size: 10.5px; opacity: 0.7; }
.user-chip svg { opacity: 0.7; }
.user-pop {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 60;
  min-width: 232px; background: var(--surface); color: var(--ink);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.16); overflow: hidden;
}
.user-pop-head { display: flex; gap: 10px; align-items: center; padding: 14px; border-bottom: 1px solid var(--border); }
.user-pop-head strong { display: block; font-size: 13.5px; }
.user-pop-head .muted { display: block; font-size: 11.5px; margin-top: 1px; word-break: break-all; }
.user-pop-item {
  display: flex; align-items: center; gap: 9px; width: 100%; text-align: left;
  background: none; border: none; border-top: 1px solid var(--border);
  padding: 11px 14px; font-family: var(--font); font-size: 13px; color: var(--ink);
  cursor: pointer; text-decoration: none;
}
.user-pop-item:first-of-type { border-top: none; }
.user-pop-item:hover { background: var(--surface-hover); }
.user-pop-item svg { opacity: 0.65; }
.user-pop-item.danger { color: var(--danger); }
.user-pop-item.danger:hover { background: var(--danger-light); }

/* Selo "somente leitura" e ocultação de controles de edição */
.readonly-badge {
  display: none; align-items: center; gap: 6px;
  background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.28);
  color: var(--ink-inverse); border-radius: 999px; padding: 5px 11px 5px 9px;
  font-size: 11.5px; font-weight: 500; letter-spacing: 0.2px; white-space: nowrap;
}
body.view-only .readonly-badge { display: inline-flex; }
body.view-only [data-requires-edit] { display: none !important; }
body:not(.is-admin) [data-requires-admin] { display: none !important; }

@media (max-width: 720px) {
  .user-chip-text { display: none; }
}

/* ── Administração de usuários ──────────────────────────────────────────── */
.col-actions { width: 1%; white-space: nowrap; text-align: right; }
#users-table td { vertical-align: middle; }
.user-cell { display: flex; align-items: center; gap: 10px; }
.user-cell .user-avatar { width: 30px; height: 30px; font-size: 12px; }
.user-cell strong { font-size: 13px; font-weight: 600; }
.role-tag {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 500;
  padding: 3px 9px; border-radius: 999px; border: 1px solid transparent;
}
.role-tag.admin { background: var(--accent-light); color: var(--accent); border-color: #d9c9f0; }
.role-tag.user { background: var(--surface-hover); color: var(--ink-secondary); border-color: var(--border); }
.access-summary { display: flex; flex-wrap: wrap; gap: 5px; }
.access-chip {
  font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border);
  color: var(--ink-secondary); background: var(--surface-subtle); white-space: nowrap;
}
.access-chip.edit { border-color: #bfe3cb; background: var(--success-light); color: var(--success); }
.access-chip.all { border-color: #d9c9f0; background: var(--accent-light); color: var(--accent); }
#users-table .row-action { color: var(--ink-secondary); }
#users-table tr:hover td { background: var(--surface-subtle); }

.user-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; margin-bottom: 6px; }
.user-form-grid .field:nth-child(3) { grid-column: 1; }
@media (max-width: 640px) { .user-form-grid { grid-template-columns: 1fr; } }

.access-head { display: flex; align-items: center; justify-content: space-between; margin: 18px 0 8px; }
.access-head > span { font-size: 12.5px; font-weight: 600; color: var(--ink-secondary); }
.access-bulk { display: flex; gap: 12px; }
.access-list { border: 1px solid var(--border); border-radius: var(--radius); max-height: 300px; overflow-y: auto; }
.access-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 9px 12px; border-bottom: 1px solid var(--border);
}
.access-row:last-child { border-bottom: none; }
.access-row .ar-name { font-size: 13px; font-weight: 500; }
.access-seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.access-seg button {
  padding: 5px 12px; font-size: 12px; font-family: var(--font); background: var(--surface);
  color: var(--ink-secondary); border: none; border-right: 1px solid var(--border-strong); cursor: pointer;
}
.access-seg button:last-child { border-right: none; }
.access-seg button:hover { background: var(--surface-hover); }
.access-seg button.on { background: var(--primary); color: #fff; }
.access-seg button.on.edit-on { background: var(--success); }
.access-empty { padding: 14px; text-align: center; color: var(--ink-muted); font-size: 12.5px; }
/* Role picker de duas linhas (admin) */
.role-opt-2 { text-align: left; line-height: 1.3; }
.role-opt-2 strong { display: block; font-size: 13px; }
.role-opt-2 span { display: block; font-size: 11px; font-weight: 400; opacity: 0.72; }

/* ── LSPR: painel de referência de capacidade no modal da máquina ────────── */
.lspr-info {
  margin: 6px 0 14px; padding: 12px 14px; border: 1px solid var(--border);
  border-left: 3px solid var(--accent); border-radius: var(--radius); background: var(--accent-light);
}
.lspr-info-head { font-size: 13px; margin-bottom: 8px; }
.lspr-info-head strong { font-weight: 600; }
.lspr-metrics { display: flex; flex-wrap: wrap; gap: 8px; }
.lspr-metrics span {
  font-size: 12px; color: var(--ink-secondary); background: var(--surface);
  border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px;
}
.lspr-metrics b { color: var(--ink); font-variant-numeric: tabular-nums; }

/* ── Contratos e MO/MES ─────────────────────────────────────────────────── */
/* Delta de capacidade: subir capacidade é BOM, então NÃO reusa .delta.up (vermelha). */
.cap-delta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.cap-delta span { font-size: 11.5px; font-variant-numeric: tabular-nums; }
.cap-up { color: var(--success); font-weight: 600; }
.cap-down { color: var(--danger); font-weight: 600; }

/* Linha do tempo da máquina */
.tl { position: relative; padding-left: 22px; }
.tl::before { content: ""; position: absolute; left: 5px; top: 4px; bottom: 4px; width: 1px; background: var(--border-strong); }
.tl-item { position: relative; padding: 0 0 18px 4px; }
.tl-item:last-child { padding-bottom: 0; }
.tl-dot {
  position: absolute; left: -21px; top: 4px; width: 11px; height: 11px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--border-strong);
}
.tl-dot.done { border-color: var(--success); background: var(--success); }
.tl-dot.plan { border-color: var(--primary); }
.tl-head { font-size: 13px; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.tl-meta { font-size: 11.5px; color: var(--ink-muted); margin-top: 3px; }

/* Arquivos do contrato e prévia do PDF */
.contract-file-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.contract-file-row:last-child { border-bottom: none; }
.contract-file-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.contract-pdf-frame { width: 100%; height: 60vh; margin-top: 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-subtle); }

/* Máquina substituída num MO: continua na lista, mas apagada */
.machine-replaced td, tr.machine-replaced td { opacity: 0.55; }

/* Aviso antes de uma ação que altera o parque */
.banner-warning {
  padding: 11px 14px; border-radius: var(--radius); font-size: 12.5px; line-height: 1.5;
  background: var(--warning-light); border-left: 3px solid #f1c21b; color: var(--ink);
}

/* Seletor de contrato (máquina) e botão Home no topbar */
.tl-ctlist { max-height: 46vh; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); margin-top: 10px; }
.ct-opt {
  display: block; width: 100%; text-align: left; background: var(--surface); border: none;
  border-bottom: 1px solid var(--border); padding: 10px 12px; cursor: pointer;
  font-family: var(--font); font-size: 13px; color: var(--ink);
}
.ct-opt:last-child { border-bottom: none; }
.ct-opt:hover { background: var(--surface-hover); }
.ct-opt.atual { border-left: 3px solid var(--success); }
.topbar .home-btn { color: #fff; border-color: rgba(255, 255, 255, 0.35); text-decoration: none; }
.topbar .home-btn:hover { background: rgba(255, 255, 255, 0.12); border-color: rgba(255, 255, 255, 0.6); }
.tfp-topbar-actions .home-btn { color: #fff; border-color: rgba(255, 255, 255, 0.35); text-decoration: none; }
/* O topbar cede em etapas, na ordem do que menos faz falta.
   Medido: com tudo visível são ~1470px; sem o título, ~1325px; sem os rótulos
   do Home e do usuário, ~1175px. Abaixo disso a nav rola. */
@media (max-width: 1500px) {
  .brand > div:not(.brand-mark) { display: none; } /* título do produto (a marca "Z" fica) */
}
@media (max-width: 1400px) {
  .home-btn-text { display: none; }
  .user-chip-text { display: none; }
}

/* Termos aditivos: selo que expande a lista dentro da própria linha */
.badge-toggle {
  cursor: pointer; border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--ink-secondary); font-family: var(--font); font-weight: 500;
}
.badge-toggle:hover { background: var(--surface-hover); color: var(--ink); border-color: var(--primary); }
.amendment-row > td { background: var(--surface-subtle); padding: 0 !important; }
.amendment-box { padding: 12px 14px 14px; border-left: 3px solid var(--accent); }
.amendment-box .infra-table { background: var(--surface); }
.amendment-box .infra-table thead th { background: var(--surface-subtle); }

/* Escolha de arquivo no cadastro do contrato */
.ct-file-pick { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ══════════════════════════════════════════════════════════════════════════
   CELULAR E TABLET
   No desktop a barra é uma linha só e quem cede é a navegação. No celular isso
   se inverte: as ações passam a ocupar a própria linha e podem quebrar, senão
   elas travariam a largura e a PÁGINA INTEIRA rolaria na horizontal.
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  /* A barra empilha e fica alta; grudada no topo ela comeria meia tela ao rolar.
     No celular ela rola junto com a página. */
  .topbar, .tfp-topbar { position: static; }

  .topbar-inner,
  .tfp-topbar-inner { flex-wrap: wrap; padding: 0 14px; gap: 0 12px; }

  .brand,
  .tfp-brand { flex: 1 1 100%; gap: 12px; min-width: 0; }

  /* Ações ganham a própria linha e podem quebrar entre si. */
  .topbar-actions,
  .tfp-topbar-actions { flex: 1 1 100%; flex-wrap: wrap; gap: 8px; padding: 0 0 10px; }

  .client-select-wrap { flex: 1 1 auto; min-width: 0; }
  #client-select,
  .tfp-client-select { max-width: 100%; width: 100%; }

  /* Botões da barra crescem para virar alvo de toque decente. */
  .topbar-actions .btn,
  .tfp-topbar-actions .btn { flex: 0 1 auto; padding: 9px 12px; }

  .container { padding: 14px 12px; }
  .client-header { padding-bottom: 12px; margin-bottom: 14px; }
  .client-header h2 { font-size: 18px; }
}

@media (max-width: 720px) {
  html { font-size: 14.5px; }

  /* KPIs em duas colunas: uma só deixa a página comprida demais. */
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .kpi-card { padding: 12px 13px; }
  .kpi-card .value { font-size: 19px; }
  .kpi-card h3 { font-size: 10px; letter-spacing: 0.6px; }
  .kpi-card .subtitle { font-size: 11px; }

  /* Abas roláveis em vez de espremidas. */
  .segmented { overflow-x: auto; scrollbar-width: none; }
  .segmented::-webkit-scrollbar { display: none; }
  .seg-btn { white-space: nowrap; }

  /* Modais ocupam quase a tela toda e o rodapé de ações não aperta. */
  .modal-backdrop { padding: 10px; align-items: flex-start; }
  .modal { padding: 16px 16px 18px; max-height: 92vh; overflow-y: auto; }
  .modal-actions { flex-wrap: wrap; gap: 8px; }
  .modal-actions .btn { flex: 1 1 auto; justify-content: center; }
  .modal-actions .btn[style*="margin-right"] { flex-basis: 100%; }

  /* Formulários em coluna única. */
  .machine-grid, .lpar-grid, .role-grid, .user-form-grid { grid-template-columns: 1fr; }

  /* Barras de filtro empilham. */
  .infra-toolbar { flex-direction: column; align-items: stretch; }
  .infra-toolbar .infra-search,
  .infra-toolbar select,
  .infra-toolbar .btn { width: 100%; }

  /* Tabela larga rola dentro do próprio card (nunca a página). Para o overflow
     funcionar, os contêineres precisam poder encolher abaixo do min-content. */
  .table-responsive { max-height: none; -webkit-overflow-scrolling: touch; }
  .card, .two-col > *, .table-responsive { min-width: 0; }
  .chart-toggles { min-width: 0; row-gap: 8px; }
  .chart-toggles > .segmented { min-width: 0; flex: 1 1 100%; }
  .chart-container { height: 260px; }

  /* Alvo de toque nas ações de linha. */
  .row-action { padding: 7px; }
  .infra-actions { white-space: nowrap; }

  .site-columns { grid-template-columns: 1fr; }
  .contract-pdf-frame { height: 48vh; }

  /* Cabeçalho dos modais grandes: título em cima, ações embaixo. Com os dois na
     mesma linha os botões (Vincular/LPARs/Migrar/Histórico) saíam do modal. */
  .modal-forecast-top { flex-direction: column; align-items: stretch; gap: 10px; }
  .modal-compare-head { flex-wrap: wrap; gap: 8px; }
  .modal-compare-head .btn { flex: 1 1 auto; justify-content: center; }
  /* O "fechar" some da fila: dá para fechar no fundo ou no Esc, e assim os
     botões de ação ficam com largura util. */
  .modal-compare-head > .row-action { position: absolute; top: 12px; right: 12px; }
  .modal-compare, .modal-wide { position: relative; }
  .modal-forecast-top > div:first-child { padding-right: 34px; }
  .modal-forecast-scroll { max-height: 66vh; }
  .client-header { flex-direction: column; align-items: stretch; }
  .client-header-actions { flex-wrap: wrap; }
  .client-header-actions .btn { flex: 1 1 auto; justify-content: center; }
}

@media (max-width: 420px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .brand h1 { font-size: 13px; }
  .topbar-actions .btn,
  .tfp-topbar-actions .btn { flex: 1 1 calc(50% - 4px); justify-content: center; }
  .home-btn { flex: 0 0 auto !important; }
}
