:root {
    --bg: #f2f4f7;
    --panel: #ffffff;
    --text: #122025;
    --muted: #5a6d75;
    --line: #d8e0e4;
    --accent: #0f766e;
    --danger: #b91c1c;
    --warn: #b45309;
    --ok: #166534;
  }
  * { box-sizing: border-box; }
  body {
    margin: 0;
    background: linear-gradient(135deg, #f4f7f8, #edf3f5);
    color: var(--text);
    font-family: "Segoe UI", Tahoma, sans-serif;
  }
  .layout {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 240px 1fr;
  }
  .sidebar {
    border-right: 1px solid var(--line);
    background: #0b2c36;
    color: #e8f4f6;
    padding: 16px;
  }
  .brand {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 16px;
  }
  .whoami {
    font-size: 12px;
    color: #c5dde2;
    margin-bottom: 16px;
    line-height: 1.4;
  }
  .menu {
    display: grid;
    gap: 8px;
  }
  .menu button {
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.06);
    color: #e8f4f6;
    border-radius: 8px;
    padding: 10px 12px;
    text-align: left;
    cursor: pointer;
  }
  .menu button.active {
    background: rgba(16, 185, 129, 0.22);
    border-color: rgba(16, 185, 129, 0.55);
  }
  .content {
    padding: 18px;
  }
  .topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
  }
  .topbar h1 {
    margin: 0;
    font-size: 22px;
  }
  .message {
    min-height: 20px;
    color: var(--muted);
    font-size: 13px;
  }
  .panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 12px;
  }
  .cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 10px;
  }
  .card {
    background: #f9fcfd;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px;
  }
  .card .label {
    font-size: 12px;
    color: var(--muted);
  }
  .card .value {
    font-size: 24px;
    font-weight: 700;
    margin-top: 4px;
  }
  .filters {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 8px;
    margin-bottom: 10px;
  }
  input, select, textarea, button {
    font: inherit;
  }
  input, select, textarea {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
  }
  button {
    border: 1px solid #9eb0b8;
    background: #fff;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
  }
  button:disabled {
    opacity: 0.65;
    cursor: not-allowed;
  }
  button.is-busy {
    position: relative;
  }
  .btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
  }
  .btn-danger {
    background: #fff2f2;
    color: var(--danger);
    border-color: #fecaca;
  }
  .btn-warn {
    background: #fffbeb;
    color: var(--warn);
    border-color: #fde68a;
  }
  .btn-ok {
    background: #ecfdf3;
    color: var(--ok);
    border-color: #bbf7d0;
  }
  .btn-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
  }
  table {
    width: 100%;
    border-collapse: collapse;
  }
  th, td {
    border-bottom: 1px solid var(--line);
    padding: 7px;
    font-size: 13px;
    vertical-align: top;
  }
  th {
    text-align: left;
    background: #f6fafb;
  }
  .badge {
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 11px;
    border: 1px solid transparent;
    display: inline-block;
  }
  .badge.vigente { background: #ecfdf3; color: #166534; border-color: #bbf7d0; }
  .badge.prox_venc { background: #fffbeb; color: #b45309; border-color: #fde68a; }
  .badge.vencido { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
  .badge.sincronizando { background: #eef2ff; color: #3730a3; border-color: #c7d2fe; }
  .badge.high { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
  .badge.moderate { background: #fffbeb; color: #b45309; border-color: #fde68a; }
  .badge.low { background: #ecfdf3; color: #166534; border-color: #bbf7d0; }
  .editor-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 8px;
  }
  .hfmea-table input, .hfmea-table textarea {
    min-width: 90px;
  }
  .hint {
    font-size: 12px;
    color: var(--muted);
  }
  .sync-hint {
    color: #334155;
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    border-radius: 999px;
    padding: 4px 8px;
    display: inline-block;
  }
  .hidden { display: none !important; }
  .job-toast-container {
    position: fixed;
    right: 12px;
    bottom: 12px;
    display: grid;
    gap: 8px;
    z-index: 9999;
  }
  .job-toast {
    background: #0f172a;
    color: #f8fafc;
    border-radius: 10px;
    padding: 10px 12px;
    min-width: 240px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
    font-size: 12px;
  }
  .job-toast.ok { background: #14532d; }
  .job-toast.fail { background: #7f1d1d; }
  .modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9000;
  }
  .modal {
    width: min(420px, 92vw);
    background: white;
    border-radius: 12px;
    padding: 14px;
    border: 1px solid var(--line);
  }
  @media (max-width: 900px) {
    .layout {
      grid-template-columns: 1fr;
    }
    .sidebar {
      border-right: 0;
      border-bottom: 1px solid #244550;
    }
  }
