/*
 * MP Engenharia — Design Tokens & Bootstrap Override
 * OS-113 Etapa 15: CSS Consolidado
 *
 * Este arquivo mapeia os tokens visuais do ERP para variaveis CSS
 * e estende Bootstrap com componentes especificos do sistema.
 *
 * Regra: NAO altera regras de negocio, apenas presentaçao.
 */

/* =========================================================================
   TOKENS VISUAIS — MP Engenharia
   ========================================================================= */
:root {
  /* Cores oficiais */
  --mp-yellow: #f4c438;
  --mp-yellow-soft: #fff4bf;
  --mp-bg: #f6f6f3;
  --mp-panel: #ffffff;
  --mp-panel-soft: #fbfbf8;
  --mp-ink: #171812;
  --mp-muted: #6b706f;
  --mp-faint: #9aa0a0;
  --mp-line: #deded8;
  --mp-line-strong: #c9c9c1;
  --mp-black: #11120f;

  /* Status */
  --mp-status-new: #2563eb;
  --mp-status-new-soft: #e8f1fb;
  --mp-status-waiting: #b77900;
  --mp-status-waiting-soft: #fff3d4;
  --mp-status-success: #287a46;
  --mp-status-success-soft: #e7f5eb;
  --mp-status-finance: #6f45a5;
  --mp-status-finance-soft: #f1eafa;
  --mp-status-danger: #b43a32;
  --mp-status-danger-soft: #fde9e7;
  --mp-status-neutral: #525957;
  --mp-status-neutral-soft: #ecefed;

  /* Formatacao */
  --mp-radius: 8px;
  --mp-radius-sm: 4px;
  --mp-radius-lg: 12px;
  --mp-shadow: 0 14px 38px rgba(17, 18, 15, 0.07);
  --mp-shadow-sm: 0 2px 8px rgba(17, 18, 15, 0.06);
  --mp-shadow-lg: 0 20px 50px rgba(17, 18, 15, 0.10);

  /* Espacamento */
  --mp-gap-xs: 4px;
  --mp-gap-sm: 8px;
  --mp-gap-md: 16px;
  --mp-gap-lg: 24px;
  --mp-gap-xl: 32px;

  /* Sidebar */
  --mp-sidebar-width: 244px;
  --mp-sidebar-bg: #151612;
  --mp-sidebar-color: #f4f4ef;
  --mp-sidebar-active-bg: rgba(244, 196, 56, 0.12);
  --mp-sidebar-active-border: var(--mp-yellow);

  /* Tipografia */
  --mp-font-body: "Roboto", Arial, Helvetica, sans-serif;
  --mp-font-brand: "Comfortaa", Arial, Helvetica, sans-serif;

  /* Bootstrap overrides */
  --bs-primary: #171812;
  --bs-primary-rgb: 23, 24, 18;
  --bs-link-color: #2563eb;
  --bs-link-color-rgb: 37, 99, 235;
  --bs-body-bg: var(--mp-bg);
  --bs-body-color: var(--mp-ink);
  --bs-border-color: var(--mp-line);
  --bs-border-radius: var(--mp-radius);
  --bs-border-radius-sm: var(--mp-radius-sm);
  --bs-border-radius-lg: var(--mp-radius-lg);
  --bs-font-sans-serif: var(--mp-font-body);
  --bs-success: var(--mp-status-success);
  --bs-danger: var(--mp-status-danger);
  --bs-warning: var(--mp-status-waiting);
  --bs-info: var(--mp-status-new);
}

/* =========================================================================
   RESET & BASE
   ========================================================================= */
*, *::before, *::after { box-sizing: border-box; }

html {
  min-height: 100%;
  background: var(--mp-bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--mp-ink);
  background: var(--mp-bg);
  font-family: var(--mp-font-body);
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button, input, select, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: none; }

/* =========================================================================
   APP SHELL — Layout principal
   ========================================================================= */
.mp-app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--mp-sidebar-width) minmax(0, 1fr);
}

@media (max-width: 860px) {
  .mp-app-shell {
    grid-template-columns: 1fr;
  }
}

/* =========================================================================
   SIDEBAR
   ========================================================================= */
.mp-app-sidebar {
  min-height: 100vh;
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  background: var(--mp-sidebar-bg);
  color: var(--mp-sidebar-color);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  position: sticky;
  top: 0;
  z-index: 100;
  overflow-y: auto;
}

.mp-app-brand {
  min-height: 50px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: #ffffff;
  text-decoration: none;
  font-size: 14px;
  font-weight: 800;
}

.mp-app-brand span {
  font-family: var(--mp-font-brand);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.1;
}

.mp-app-brand img {
  width: 34px;
  height: 34px;
  border-radius: 8px;
}

/* Navegacao sidebar */
.mp-app-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.mp-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: var(--mp-radius);
  color: var(--mp-faint);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
  position: relative;
}

.mp-nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #ffffff;
}

.mp-nav-item.is-active {
  background: var(--mp-sidebar-active-bg);
  color: #ffffff;
  font-weight: 700;
}

.mp-nav-item.is-active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--mp-sidebar-active-border);
}

.mp-nav-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

/* Rodape sidebar */
.mp-sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.mp-sidebar-user {
  padding: 10px 14px;
  font-size: 13px;
  color: var(--mp-faint);
}

.mp-sidebar-user strong {
  color: #ffffff;
  display: block;
  font-size: 14px;
}

.mp-sidebar-logout {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  color: var(--mp-status-danger);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  border-radius: var(--mp-radius);
  transition: background 0.15s ease;
}

.mp-sidebar-logout:hover {
  background: rgba(180, 58, 50, 0.15);
  color: #ffffff;
}

/* =========================================================================
   TOPBAR
   ========================================================================= */
.mp-app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 32px 16px;
  gap: 16px;
  flex-wrap: wrap;
}

.mp-app-topbar .mp-topbar-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.mp-app-topbar .mp-topbar-kicker {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--mp-muted);
}

.mp-app-topbar h1 {
  margin: 0;
  font-family: var(--mp-font-brand);
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--mp-ink);
}

.mp-app-topbar .mp-topbar-subtitle {
  font-size: 14px;
  color: var(--mp-muted);
  margin-top: 2px;
}

.mp-app-topbar .mp-topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* =========================================================================
   MAIN CONTENT
   ========================================================================= */
.mp-app-main {
  min-height: 100vh;
  background: var(--mp-bg);
  overflow-x: hidden;
}

/* =========================================================================
   PANELS — Containers de conteudo
   ========================================================================= */
.mp-module-panel {
  background: var(--mp-panel);
  border: 1px solid var(--mp-line);
  border-radius: var(--mp-radius-lg);
  box-shadow: var(--mp-shadow-sm);
  padding: 24px;
  margin: 0 32px 24px;
}

.mp-module-panel--compact {
  padding: 16px 20px;
}

.mp-module-panel + .mp-module-panel {
  margin-top: 0;
}

@media (max-width: 860px) {
  .mp-module-panel {
    margin: 0 16px 16px;
    padding: 16px;
    border-radius: var(--mp-radius);
  }
}

/* =========================================================================
   FORMULÁRIOS
   ========================================================================= */
.mp-form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mp-form-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--mp-ink);
}

.mp-form-label .mp-required {
  color: var(--mp-status-danger);
  margin-left: 2px;
}

.mp-form-input,
.mp-form-select,
.mp-form-textarea {
  padding: 10px 14px;
  border: 1px solid var(--mp-line);
  border-radius: var(--mp-radius);
  font: inherit;
  font-size: 14px;
  background: var(--mp-panel);
  color: var(--mp-ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.mp-form-input:focus,
.mp-form-select:focus,
.mp-form-textarea:focus {
  outline: none;
  border-color: var(--mp-status-new);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.mp-form-input:disabled,
.mp-form-select:disabled,
.mp-form-textarea:disabled {
  background: var(--mp-panel-soft);
  color: var(--mp-muted);
  cursor: not-allowed;
}

.mp-form-textarea {
  resize: vertical;
  min-height: 80px;
}

.mp-form-hint {
  font-size: 12px;
  color: var(--mp-muted);
}

.mp-form-error {
  font-size: 12px;
  color: var(--mp-status-danger);
  font-weight: 600;
}

/* Grid de formulario */
.mp-form-grid {
  display: grid;
  gap: 16px;
}

.mp-form-grid--2col {
  grid-template-columns: 1fr 1fr;
}

.mp-form-grid--3col {
  grid-template-columns: 1fr 1fr 1fr;
}

@media (max-width: 860px) {
  .mp-form-grid--2col,
  .mp-form-grid--3col {
    grid-template-columns: 1fr;
  }
}

/* =========================================================================
   TABELAS
   ========================================================================= */
.mp-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--mp-line);
  border-radius: var(--mp-radius);
}

.mp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.mp-table thead {
  background: var(--mp-panel-soft);
  border-bottom: 2px solid var(--mp-line);
}

.mp-table th {
  padding: 12px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--mp-muted);
  white-space: nowrap;
}

.mp-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--mp-line);
  vertical-align: middle;
}

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

.mp-table tbody tr:hover {
  background: var(--mp-panel-soft);
}

.mp-table .mp-col-actions {
  white-space: nowrap;
  text-align: right;
}

/* =========================================================================
   CARDS
   ========================================================================= */
.mp-card {
  background: var(--mp-panel);
  border: 1px solid var(--mp-line);
  border-radius: var(--mp-radius-lg);
  box-shadow: var(--mp-shadow-sm);
  padding: 20px;
  transition: box-shadow 0.15s ease;
}

.mp-card:hover {
  box-shadow: var(--mp-shadow);
}

.mp-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}

.mp-card-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--mp-ink);
}

.mp-card-value {
  font-size: 32px;
  font-weight: 800;
  color: var(--mp-ink);
  line-height: 1.1;
}

.mp-card-label {
  font-size: 13px;
  color: var(--mp-muted);
  margin-top: 4px;
}

/* Stat cards (dashboard) */
.mp-stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

@media (max-width: 1180px) {
  .mp-stat-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 560px) {
  .mp-stat-grid { grid-template-columns: 1fr; }
}

.mp-stat-card {
  background: var(--mp-panel);
  border: 1px solid var(--mp-line);
  border-radius: var(--mp-radius-lg);
  box-shadow: var(--mp-shadow-sm);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mp-stat-card .mp-stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--mp-radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.mp-stat-card .mp-stat-value {
  font-size: 42px;
  font-weight: 900;
  line-height: 1;
}

.mp-stat-card .mp-stat-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--mp-ink);
}

/* =========================================================================
   ALERTAS
   ========================================================================= */
.mp-alert {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 18px;
  border-radius: var(--mp-radius);
  font-size: 14px;
  line-height: 1.5;
  border: 1px solid transparent;
}

.mp-alert-icon {
  font-size: 18px;
  flex-shrink: 0;
  margin-top: 1px;
}

.mp-alert-close {
  margin-left: auto;
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  opacity: 0.6;
  padding: 0;
  line-height: 1;
}

.mp-alert-close:hover { opacity: 1; }

.mp-alert--success {
  background: var(--mp-status-success-soft);
  color: var(--mp-status-success);
  border-color: var(--mp-status-success);
}

.mp-alert--danger {
  background: var(--mp-status-danger-soft);
  color: var(--mp-status-danger);
  border-color: var(--mp-status-danger);
}

.mp-alert--warning {
  background: var(--mp-status-waiting-soft);
  color: var(--mp-status-waiting);
  border-color: var(--mp-status-waiting);
}

.mp-alert--info {
  background: var(--mp-status-new-soft);
  color: var(--mp-status-new);
  border-color: var(--mp-status-new);
}

/* =========================================================================
   EMPTY STATES
   ========================================================================= */
.mp-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
}

.mp-empty-state-icon {
  font-size: 48px;
  color: var(--mp-faint);
  margin-bottom: 16px;
}

.mp-empty-state-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--mp-ink);
  margin: 0 0 8px;
}

.mp-empty-state-text {
  font-size: 14px;
  color: var(--mp-muted);
  margin: 0 0 20px;
  max-width: 400px;
}

/* =========================================================================
   RECORD CARDS (listas de registros)
   ========================================================================= */
.mp-record-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mp-record-card {
  background: var(--mp-panel);
  border: 1px solid var(--mp-line);
  border-radius: var(--mp-radius);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.mp-record-card:hover {
  border-color: var(--mp-line-strong);
  box-shadow: var(--mp-shadow-sm);
}

.mp-record-card .mp-record-main {
  flex: 1;
  min-width: 0;
}

.mp-record-card .mp-record-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--mp-ink);
  margin: 0;
}

.mp-record-card .mp-record-subtitle {
  font-size: 13px;
  color: var(--mp-muted);
  margin-top: 2px;
}

.mp-record-card .mp-record-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* =========================================================================
   DETAIL GRID
   ========================================================================= */
.mp-detail-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

.mp-detail-grid--2col {
  grid-template-columns: repeat(2, 1fr);
}

@media (max-width: 860px) {
  .mp-detail-grid,
  .mp-detail-grid--2col {
    grid-template-columns: 1fr;
  }
}

.mp-detail-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mp-detail-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--mp-muted);
}

.mp-detail-value {
  font-size: 15px;
  color: var(--mp-ink);
}

/* =========================================================================
   FLOW STEPS (triagem)
   ========================================================================= */
.mp-flow-steps {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.mp-flow-step {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  background: var(--mp-panel-soft);
  color: var(--mp-muted);
  border: 1px solid var(--mp-line);
  cursor: pointer;
  transition: all 0.15s ease;
}

.mp-flow-step:hover {
  background: var(--mp-panel);
  border-color: var(--mp-line-strong);
}

.mp-flow-step.is-active {
  background: var(--mp-status-new);
  color: #ffffff;
  border-color: var(--mp-status-new);
}

/* =========================================================================
   DETAILS/SUMMARY (formularios recolhaveis)
   ========================================================================= */
.mp-collapsible {
  border: 1px solid var(--mp-line);
  border-radius: var(--mp-radius);
  overflow: hidden;
}

.mp-collapsible summary {
  padding: 14px 20px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--mp-ink);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--mp-panel-soft);
  border-bottom: 1px solid var(--mp-line);
  transition: background 0.15s ease;
  user-select: none;
}

.mp-collapsible summary:hover {
  background: var(--mp-panel);
}

.mp-collapsible summary::-webkit-details-marker { display: none; }
.mp-collapsible summary::marker { display: none; content: ''; }

.mp-collapsible summary .mp-collapsible-chevron {
  margin-left: auto;
  transition: transform 0.2s ease;
  font-size: 14px;
  color: var(--mp-muted);
}

.mp-collapsible[open] summary .mp-collapsible-chevron {
  transform: rotate(180deg);
}

.mp-collapsible-body {
  padding: 20px;
}

/* =========================================================================
   RESPONSIVIDADE
   ========================================================================= */
@media (max-width: 1380px) {
  .mp-dashboard-grid { grid-template-columns: 1fr 1fr; }
}

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

@media (max-width: 860px) {
  .mp-app-topbar {
    padding: 16px;
  }

  .mp-app-topbar h1 {
    font-size: 20px;
  }

  .mp-app-topbar .mp-topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }
}

@media (max-width: 560px) {
  .mp-app-topbar {
    padding: 12px;
  }

  .mp-app-topbar h1 {
    font-size: 18px;
  }

  .mp-record-card {
    flex-direction: column;
    align-items: flex-start;
  }

  .mp-record-card .mp-record-actions {
    width: 100%;
    justify-content: flex-end;
  }
}

/* =========================================================================
   UTILITIES
   ========================================================================= */
.mp-text-muted { color: var(--mp-muted); }
.mp-text-success { color: var(--mp-status-success); }
.mp-text-danger { color: var(--mp-status-danger); }
.mp-text-warning { color: var(--mp-status-waiting); }
.mp-text-center { text-align: center; }
.mp-text-right { text-align: right; }
.mp-font-brand { font-family: var(--mp-font-brand); }
.mp-font-bold { font-weight: 700; }
.mp-font-black { font-weight: 800; }
.mp-mt-0 { margin-top: 0; }
.mp-mb-0 { margin-bottom: 0; }
.mp-mb-sm { margin-bottom: 8px; }
.mp-mb-md { margin-bottom: 16px; }
.mp-mb-lg { margin-bottom: 24px; }
.mp-mt-lg { margin-top: 24px; }
.mp-gap-sm { gap: 8px; }
.mp-gap-md { gap: 16px; }
.mp-d-flex { display: flex; }
.mp-flex-col { flex-direction: column; }
.mp-flex-wrap { flex-wrap: wrap; }
.mp-align-center { align-items: center; }
.mp-justify-between { justify-content: space-between; }
.mp-w-full { width: 100%; }
.mp-hidden { display: none; }

/* =========================================================================
   PRINT
   ========================================================================= */
@media print {
  .mp-app-sidebar,
  .mp-app-topbar,
  .mp-alert,
  .mp-btn,
  .mp-nav-item {
    display: none !important;
  }

  .mp-app-shell {
    display: block;
  }

  .mp-module-panel {
    box-shadow: none;
    border: none;
    margin: 0;
    padding: 0;
  }
}
