/* ============================================================
   Portal de Fornecedores MJLESTE — Design System
   Sem dependências externas (CSP estrita); tudo self-hosted.
   ============================================================ */

:root {
  color-scheme: light;

  /* Identidade MJLESTE */
  --brand-blue: #0f4c81;
  --brand-blue-dark: #0a3357;
  --brand-orange: #ff6b00;
  --brand-orange-dark: #cc5600;

  /* Superfícies e tinta (paleta neutra validada para acessibilidade) */
  --surface: #ffffff;
  --page: #f5f6f8;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --border: rgba(11, 11, 11, 0.1);
  --border-strong: rgba(11, 11, 11, 0.16);
  --gridline: #e5e7eb;

  /* Paleta de status — fixa, nunca reaproveitada para outra coisa */
  --status-good: #0ca30c;
  --status-good-text: #006300;
  --status-good-bg: #e7f6e7;
  --status-warning: #fab219;
  --status-warning-text: #8a5a00;
  --status-warning-bg: #fef3dc;
  --status-serious: #ec835a;
  --status-serious-text: #a3401a;
  --status-serious-bg: #fce6dc;
  --status-critical: #d03b3b;
  --status-critical-text: #a11f1f;
  --status-critical-bg: #fbe4e4;
  --status-neutral-bg: #eef0f3;
  --status-neutral-text: #52514e;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(11, 11, 11, 0.06);
  --shadow-md: 0 4px 16px rgba(11, 11, 11, 0.08);
  --shadow-lg: 0 12px 32px rgba(11, 11, 11, 0.14);

  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }
p { margin: 0; }

.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 0.95rem; }

/* ---------- Login ---------- */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--brand-blue-dark), var(--brand-blue) 55%, #123f6b);
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
  padding: 40px 36px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.login-brand .logo-badge {
  display: block;
  height: 56px;
  width: auto;
  object-fit: contain;
  background: white;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm, 0 1px 2px rgba(0,0,0,0.08));
}

.login-brand h1 { font-size: 1.15rem; color: var(--brand-blue-dark); }
.login-subtitle { color: var(--text-secondary); font-size: 0.9rem; margin: 4px 0 28px; }

.field { margin-bottom: 18px; }
.field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--brand-blue);
  box-shadow: 0 0 0 3px rgba(15, 76, 129, 0.15);
}
.field-hint { font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; }
.field-error { font-size: 0.8rem; color: var(--status-critical-text); margin-top: 6px; }

/* Campo de senha com botão de mostrar/ocultar (olho) */
.password-field { position: relative; }
.password-field input { padding-right: 42px; }
.password-toggle-btn {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.password-toggle-btn:hover { color: var(--text-secondary); background: var(--status-neutral-bg); }
.password-toggle-btn .icon { width: 19px; height: 19px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 0.9rem;
  transition: transform 0.06s ease, box-shadow 0.15s, background 0.15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand-orange); color: white; }
.btn-primary:hover { background: var(--brand-orange-dark); }
.btn-secondary { background: var(--surface); color: var(--brand-blue-dark); border-color: var(--border-strong); }
.btn-secondary:hover { background: #f0f3f7; }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--status-neutral-bg); }
.btn-danger { background: var(--status-critical-bg); color: var(--status-critical-text); }
.btn-danger:hover { background: #f6cfcf; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.login-demo-box {
  margin-top: 24px;
  padding: 14px 16px;
  background: var(--page);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  color: var(--text-secondary);
  border: 1px dashed var(--border-strong);
}
.login-demo-box strong { color: var(--text-primary); }

/* ---------- App shell ---------- */

.app-header {
  background: var(--brand-blue-dark);
  color: white;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: var(--shadow-md);
}
.app-header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.app-brand { display: flex; align-items: center; gap: 12px; }
.app-brand .logo-badge {
  display: block;
  height: 38px;
  width: auto;
  object-fit: contain;
  background: white;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}
.app-brand .title { font-size: 0.95rem; font-weight: 700; }
.app-brand .subtitle { font-size: 0.72rem; color: #c8d6e6; }

.app-nav { display: flex; gap: 4px; background: rgba(0,0,0,0.18); padding: 4px; border-radius: var(--radius-md); }
.app-nav button {
  background: transparent;
  border: none;
  color: #dbe6f2;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
}
.app-nav button.active { background: var(--brand-orange); color: white; }
.app-nav button:hover:not(.active) { background: rgba(255,255,255,0.08); }

.user-menu { display: flex; align-items: center; gap: 12px; font-size: 0.82rem; }
.user-menu .who { text-align: right; }
.user-menu .who .name { font-weight: 700; }
.user-menu .who .role { color: #c8d6e6; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; }

.app-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ---------- Cards / Panels ---------- */

.panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: 24px;
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
  justify-content: space-between;
}
.panel-header .heading { display: flex; align-items: center; gap: 12px; }
.panel-header .icon-badge {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  background: #eaf1f8;
  color: var(--brand-blue);
  flex-shrink: 0;
}
.panel-header h2 { font-size: 1.05rem; color: var(--brand-blue-dark); }
.panel-header .desc { font-size: 0.82rem; color: var(--text-muted); margin-top: 2px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ---------- Stat tiles (KPI) ---------- */

.stat-tile {
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
}
.stat-tile .label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: block;
}
.stat-tile .value {
  font-size: 1.65rem;
  font-weight: 800;
  color: var(--text-primary);
  font-variant-numeric: proportional-nums;
}
.stat-tile .sub { font-size: 0.76rem; color: var(--text-muted); margin-top: 4px; }
.stat-tile.accent-blue .value { color: var(--brand-blue); }
.stat-tile.accent-orange .value { color: var(--brand-orange-dark); }
.stat-tile.accent-good .value { color: var(--status-good-text); }
.stat-tile.accent-critical .value { color: var(--status-critical-text); }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
thead th {
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  font-weight: 700;
  padding: 10px 12px;
  border-bottom: 1px solid var(--gridline);
  white-space: nowrap;
}
tbody td {
  padding: 12px;
  border-bottom: 1px solid var(--gridline);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }
.table-empty { text-align: center; color: var(--text-muted); padding: 32px !important; }

/* ---------- Badges (status: sempre ícone + rótulo, nunca só cor) ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
}
.badge svg { width: 12px; height: 12px; }
.badge-good { background: var(--status-good-bg); color: var(--status-good-text); }
.badge-warning { background: var(--status-warning-bg); color: var(--status-warning-text); }
.badge-serious { background: var(--status-serious-bg); color: var(--status-serious-text); }
.badge-critical { background: var(--status-critical-bg); color: var(--status-critical-text); }
.badge-neutral { background: var(--status-neutral-bg); color: var(--status-neutral-text); }

/* ---------- Forms ---------- */

.form-row { display: grid; gap: 14px; grid-template-columns: repeat(4, 1fr); }
.form-row.cols-2 { grid-template-columns: repeat(2, 1fr); }
.form-row.cols-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 900px) { .form-row { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .form-row { grid-template-columns: 1fr; } }

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

.dropzone {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 16px;
  background: var(--page);
}

/* ---------- Tabs (dentro de uma view) ---------- */

.subtabs { display: flex; gap: 6px; margin-bottom: 18px; flex-wrap: wrap; border-bottom: 1px solid var(--gridline); }
.subtabs button {
  background: transparent;
  border: none;
  padding: 10px 4px;
  margin-right: 18px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
}
.subtabs button.active { color: var(--brand-blue-dark); border-bottom-color: var(--brand-orange); }

.subview { display: none; flex-direction: column; gap: 20px; }
.subview.active { display: flex; }

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(11,11,11,0.5);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--gridline);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: 1rem; color: var(--brand-blue-dark); }
.modal-body { padding: 20px 24px; display: flex; flex-direction: column; gap: 14px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--gridline); display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- Toasts ---------- */

.toast-stack {
  position: fixed;
  bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 200;
}
.toast {
  background: var(--text-primary);
  color: white;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 0.86rem;
  max-width: 340px;
  display: flex; gap: 10px; align-items: flex-start;
  animation: toast-in 0.2s ease;
}
.toast.success { background: #0f3d0f; }
.toast.error { background: #4a1414; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Misc ---------- */

.muted { color: var(--text-muted); }
.small { font-size: 0.8rem; }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, "SF Mono", Menlo, monospace; }
.divider { height: 1px; background: var(--gridline); margin: 4px 0; }
.text-right { text-align: right; }
.flex { display: flex; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.spacer { flex: 1; }
.icon { width: 18px; height: 18px; flex-shrink: 0; }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty-state .icon { width: 32px; height: 32px; margin: 0 auto 10px; color: var(--border-strong); }

.password-reveal-box {
  background: var(--status-warning-bg);
  border: 1px solid #f0d090;
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 0.85rem;
  color: var(--status-warning-text);
}

.input-with-btn { display: flex; gap: 8px; align-items: center; }
.input-with-btn input { flex: 1; }
.btn-danger-text { color: var(--status-critical-text); }

/* ---------- Utilitários (evitam atributos style="" inline — CSP estrita) ---------- */

.header-action-link { color: #dbe6f2; }
.banner-warning { border-left: 4px solid var(--status-warning); background: var(--status-warning-bg); }
.form-actions-full { grid-column: 1 / -1; margin-top: 0; }
.subtabs-plain { border: none; margin: 0; }
.field-flush { margin: 0; }
.mt-16 { margin-top: 16px; }
.grid-2-equal { grid-template-columns: 1fr 1fr; }
.ml-6 { margin-left: 6px; }
.mt-14 { margin-top: 14px; }
.select-inline {
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  padding: 5px 8px;
  background: var(--surface);
  color: var(--text-primary);
}
.temp-password { font-size: 1rem; }
.mb-10 { margin-bottom: 10px; }
.field-full { grid-column: 1 / -1; }
.actions-cell { display: flex; flex-wrap: wrap; gap: 6px; }

/* Ajudantes dinâmicos (agendamento) */
.helpers-list { display: flex; flex-direction: column; gap: 8px; }
.helper-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: center; }
.helper-row input { margin: 0; }
.helper-remove-btn { padding: 8px 10px; }

/* Checkboxes de permissão por módulo (Gerente/Coordenador) */
.permissions-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (max-width: 700px) { .permissions-grid { grid-template-columns: 1fr; } }
.permission-check {
  display: flex; align-items: flex-start; gap: 8px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-md);
  padding: 10px 12px; background: var(--page);
}
.permission-check input { margin: 3px 0 0; width: auto; }
.permission-check .label { font-weight: 600; font-size: 0.86rem; }
.permission-check .desc { font-size: 0.76rem; color: var(--text-muted); margin-top: 2px; }

/* Dias da semana sem recebimento (Slots & Bloqueios) */
.weekdays-grid { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 700px) { .weekdays-grid { grid-template-columns: repeat(2, 1fr); } }
.weekday-check { justify-content: center; text-align: center; }
.weekday-check input { margin: 0; }

/* Textos de e-mail editáveis (Administração → Notificações) */
.mono-textarea {
  width: 100%;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.85rem;
  line-height: 1.5;
  padding: 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-primary);
  resize: vertical;
}
.smtp-status-ok { color: var(--status-good-text, #1b7a3d); font-weight: 600; }
.smtp-status-missing { color: var(--status-critical-text); font-weight: 600; }
