/* ============================================================
   Portal Intelecto & CSTR — Design System v1.0
   Identidade visual: verde institucional (#1f7a3d)
   Tipografia: IBM Plex Sans + IBM Plex Mono
   Tema claro / escuro com transição suave
   ============================================================ */

/* ---------- Google Fonts ---------- */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:wght@400;500;600;700&display=swap');

/* ---------- Tokens de Tema ---------- */
:root {
  /* Superfícies */
  --bg: #f0f3ee;
  --bg2: #e6ebe3;
  --surface: #ffffff;
  --surface2: #f7f9f6;
  --surface-hover: #eef2ec;
  --glass: rgba(255,255,255,0.72);
  --glass-border: rgba(31,122,61,0.12);

  /* Linha e sombra */
  --line: #d3ddd0;
  --line2: #c2cebf;
  --shadow-sm: 0 1px 3px rgba(16,40,20,0.06), 0 1px 2px rgba(16,40,20,0.04);
  --shadow-md: 0 4px 12px rgba(16,40,20,0.08), 0 2px 4px rgba(16,40,20,0.04);
  --shadow-lg: 0 12px 40px rgba(16,40,20,0.12), 0 4px 12px rgba(16,40,20,0.06);
  --shadow-xl: 0 24px 60px rgba(16,40,20,0.16), 0 8px 20px rgba(16,40,20,0.08);

  /* Texto */
  --ink: #0f1f14;
  --ink2: #334d3a;
  --muted: #5b7562;
  --faint: #8ca093;

  /* Marca */
  --brand: #1f7a3d;
  --brand-dark: #155c2c;
  --brand-light: #e3f0e8;
  --brand-text: #ffffff;
  --brand-glow: rgba(31,122,61,0.15);

  /* Status */
  --ok: #1f9048;
  --ok-bg: #e6f5ed;
  --warn: #b4791b;
  --warn-bg: #fef5e7;
  --serious: #c0561f;
  --serious-bg: #fef0e9;
  --crit: #b3261e;
  --crit-bg: #fce8e8;
  --pend: #5b7562;
  --info: #0a6e8a;
  --info-bg: #e6f4f8;

  /* Gráficos (séries) */
  --s1: #1f7a3d;
  --s2: #2e9e5b;
  --s3: #0a6e8a;
  --s4: #b4791b;
  --s5: #c0561f;
  --s6: #7a5b1f;

  /* Sidebar */
  --sidebar-w: 260px;
  --sidebar-w-collapsed: 64px;

  /* Tipografia */
  --sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Transições */
  --t-fast: 0.15s ease;
  --t-normal: 0.25s ease;
  --t-slow: 0.4s ease;

  /* Raio de borda */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 18px;
  --r-full: 999px;
}

/* Tema escuro por preferência do sistema */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a120d;
    --bg2: #0e1a12;
    --surface: #141f18;
    --surface2: #1a2b1f;
    --surface-hover: #1f3325;
    --glass: rgba(20,31,24,0.80);
    --glass-border: rgba(63,161,95,0.18);

    --line: #243a2b;
    --line2: #1e3024;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.35);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.4);
    --shadow-xl: 0 24px 60px rgba(0,0,0,0.5);

    --ink: #e0ede4;
    --ink2: #b8cfbf;
    --muted: #8aaa92;
    --faint: #5e7d66;

    --brand: #3fa15f;
    --brand-dark: #2f8049;
    --brand-light: #162a1d;
    --brand-text: #06130b;
    --brand-glow: rgba(63,161,95,0.20);

    --ok: #4cb570;
    --ok-bg: #132a1c;
    --warn: #d9a441;
    --warn-bg: #2a2213;
    --serious: #e0813f;
    --serious-bg: #2a1a13;
    --crit: #e26a63;
    --crit-bg: #2a1313;
    --pend: #8aaa92;
    --info: #3aa7c4;
    --info-bg: #13262a;

    --s1: #3fa15f;
    --s2: #5bc47a;
    --s3: #3aa7c4;
    --s4: #d9a441;
    --s5: #e0813f;
    --s6: #aa8a3f;
  }
}

/* Tema escuro por escolha do usuário */
:root[data-theme="dark"] {
  --bg: #0a120d;
  --bg2: #0e1a12;
  --surface: #141f18;
  --surface2: #1a2b1f;
  --surface-hover: #1f3325;
  --glass: rgba(20,31,24,0.80);
  --glass-border: rgba(63,161,95,0.18);

  --line: #243a2b;
  --line2: #1e3024;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.35);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.4);
  --shadow-xl: 0 24px 60px rgba(0,0,0,0.5);

  --ink: #e0ede4;
  --ink2: #b8cfbf;
  --muted: #8aaa92;
  --faint: #5e7d66;

  --brand: #3fa15f;
  --brand-dark: #2f8049;
  --brand-light: #162a1d;
  --brand-text: #06130b;
  --brand-glow: rgba(63,161,95,0.20);

  --ok: #4cb570;
  --ok-bg: #132a1c;
  --warn: #d9a441;
  --warn-bg: #2a2213;
  --serious: #e0813f;
  --serious-bg: #2a1a13;
  --crit: #e26a63;
  --crit-bg: #2a1313;
  --pend: #8aaa92;
  --info: #3aa7c4;
  --info-bg: #13262a;

  --s1: #3fa15f;
  --s2: #5bc47a;
  --s3: #3aa7c4;
  --s4: #d9a441;
  --s5: #e0813f;
  --s6: #aa8a3f;
}

/* ---------- Reset e Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background var(--t-normal), color var(--t-normal);
}
h1, h2, h3, h4 { margin: 0 0 0.4em; font-weight: 650; line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: clamp(22px, 3.4vw, 30px); }
h2 { font-size: clamp(18px, 2.8vw, 24px); }
h3 { font-size: 17px; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Utilitários ---------- */
.hidden { display: none !important; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.ink2 { color: var(--ink2); }
.err { color: var(--crit); }
.center { text-align: center; }
.mono { font-family: var(--mono); font-size: 0.88em; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ---------- Formulários ---------- */
input, select, textarea {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  padding: 10px 13px;
  width: 100%;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-glow);
}
input::placeholder { color: var(--faint); }
label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  margin: 0 0 5px;
  letter-spacing: 0.01em;
}
.field { margin: 0 0 16px; }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: var(--brand);
  color: var(--brand-text);
  border: none;
  border-radius: var(--r-md);
  padding: 10px 18px;
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  transition: background var(--t-fast), transform 0.08s, box-shadow var(--t-fast);
}
.btn:hover { background: var(--brand-dark); box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(1px); }
.btn.sec {
  background: var(--surface);
  color: var(--ink);
  border: 1.5px solid var(--line);
}
.btn.sec:hover { border-color: var(--brand); color: var(--brand); background: var(--brand-light); }
.btn.sm { padding: 6px 12px; font-size: 0.82rem; border-radius: var(--r-sm); }
.btn.danger { background: transparent; color: var(--crit); border: 1.5px solid var(--line); }
.btn.danger:hover { border-color: var(--crit); background: var(--crit-bg); }
.btn.ghost { background: transparent; color: var(--muted); border: none; padding: 6px 10px; }
.btn.ghost:hover { color: var(--ink); background: var(--surface-hover); }
.linkbtn { background: none; border: none; color: var(--brand); padding: 0; font: inherit; font-weight: 600; font-size: 0.85rem; cursor: pointer; }
.linkbtn:hover { text-decoration: underline; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--t-normal), border-color var(--t-normal);
}
.card:hover { box-shadow: var(--shadow-md); }
.card-glass {
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--shadow-md);
}

/* ---------- KPIs ---------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin: 0 0 20px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  transition: transform var(--t-fast), box-shadow var(--t-fast);
}
.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.kpi .v {
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.kpi .l { color: var(--muted); font-size: 0.78rem; margin-top: 6px; font-weight: 500; }

/* ---------- Badges / Tags ---------- */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--r-full);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.tag-ok { color: var(--ok); background: var(--ok-bg); }
.tag-warn { color: var(--warn); background: var(--warn-bg); }
.tag-serious { color: var(--serious); background: var(--serious-bg); }
.tag-crit { color: var(--crit); background: var(--crit-bg); }
.tag-pend { color: var(--pend); background: var(--surface2); }
.tag-info { color: var(--info); background: var(--info-bg); }
.tag-brand { color: var(--brand); background: var(--brand-light); }

/* ---------- Tabelas ---------- */
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
}
tr { transition: background var(--t-fast); }
tbody tr:hover { background: var(--surface-hover); }
tbody tr[data-cc] { cursor: pointer; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: var(--bg);
  padding: 12px 20px;
  border-radius: var(--r-lg);
  font-size: 0.88rem;
  font-weight: 500;
  max-width: 90vw;
  z-index: 100;
  box-shadow: var(--shadow-xl);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-normal), transform var(--t-normal);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

/* ============================================================
   LAYOUT — Sidebar + Conteúdo principal
   ============================================================ */

/* ---------- Sidebar ---------- */
.layout {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  z-index: 30;
  transition: width var(--t-normal), transform var(--t-normal);
  overflow: hidden;
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.sidebar-logo img {
  height: 30px;
  width: auto;
  display: block;
}
.sidebar-logo .logo-bg {
  background: var(--brand-dark);
  border-radius: var(--r-md);
  padding: 6px 12px;
  display: inline-flex;
  align-items: center;
}
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px;
}
.sidebar-group {
  margin: 0 0 6px;
}
.sidebar-group-label {
  font-family: var(--mono);
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--faint);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 12px 12px 5px;
}
.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: none;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--ink2);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background var(--t-fast), color var(--t-fast);
  position: relative;
}
.sidebar-item:hover {
  background: var(--surface-hover);
  color: var(--ink);
}
.sidebar-item.active {
  background: var(--brand-light);
  color: var(--brand);
  font-weight: 600;
}
.sidebar-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: var(--brand);
  border-radius: 0 3px 3px 0;
}
.sidebar-item .icon {
  width: 20px;
  text-align: center;
  font-size: 1rem;
  flex-shrink: 0;
}
.sidebar-item .badge-count {
  margin-left: auto;
  background: var(--crit);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: var(--r-full);
  min-width: 20px;
  text-align: center;
}
.sidebar-bottom {
  border-top: 1px solid var(--line);
  padding: 14px;
  flex-shrink: 0;
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-md);
  transition: background var(--t-fast);
  cursor: default;
}
.sidebar-user:hover { background: var(--surface-hover); }
.sidebar-user .avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--r-full);
  background: var(--brand);
  color: var(--brand-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.82rem;
  flex-shrink: 0;
}
.sidebar-user .user-info {
  flex: 1;
  min-width: 0;
}
.sidebar-user .user-name {
  font-weight: 600;
  font-size: 0.88rem;
  line-height: 1.2;
}
.sidebar-user .user-role {
  font-size: 0.72rem;
  color: var(--muted);
}

/* ---------- Conteúdo principal ---------- */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  transition: margin-left var(--t-normal);
}
.main-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.main-header h1 {
  margin: 0;
  font-size: 1.15rem;
}
.main-header .breadcrumb {
  font-size: 0.82rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.main-header .breadcrumb .sep { opacity: 0.4; }
.main-header .actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
}
.main-body {
  padding: 24px 28px 60px;
  max-width: 1200px;
}

/* ============================================================
   LOGIN
   ============================================================ */
#login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(ellipse at 30% 20%, var(--brand-glow), transparent 60%),
    radial-gradient(ellipse at 70% 80%, var(--brand-glow), transparent 60%),
    var(--bg);
}
#login .login-box {
  width: 100%;
  max-width: 420px;
  animation: fadeUp 0.5s ease both;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
#login .logo-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--brand-dark);
  border-radius: var(--r-xl);
  padding: 24px 30px;
  margin: 0 0 16px;
  box-shadow: var(--shadow-lg);
}
#login .logo-wrap img {
  width: 100%;
  max-width: 220px;
  display: block;
}
.login-subtitle {
  color: var(--muted);
  font-size: 0.88rem;
  margin: 4px 0 22px;
  text-align: center;
  letter-spacing: 0.01em;
}
#login .card {
  box-shadow: var(--shadow-lg);
}
#login .footer-note {
  text-align: center;
  color: var(--faint);
  font-size: 0.72rem;
  margin-top: 16px;
}

/* ============================================================
   RESPONSIVIDADE
   ============================================================ */
/* Mobile menu button */
#ap-menu { display: none; }

@media (max-width: 768px) {
  #ap-menu { display: inline-flex; }
  .sidebar {
    transform: translateX(-100%);
    width: 280px;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0;
  }
  .main-body {
    padding: 18px 16px 60px;
  }
  .main-header {
    padding: 12px 16px;
  }
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 29;
    display: none;
    cursor: pointer;
  }
  .sidebar-overlay.show {
    display: block;
  }
  .kpis {
    grid-template-columns: repeat(2, 1fr);
  }
}

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

/* ---------- Animações auxiliares ---------- */
@keyframes countUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.animate-in { animation: countUp 0.3s ease both; }

/* ---------- Scrollbar customizada ---------- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ---------- Barra de progresso ---------- */
.progress-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}
.progress-bar .track {
  flex: 1;
  background: var(--line);
  border-radius: var(--r-full);
  height: 8px;
  overflow: hidden;
  min-width: 60px;
}
.progress-bar .track .fill {
  height: 100%;
  background: var(--brand);
  border-radius: var(--r-full);
  transition: width var(--t-slow);
}
.progress-bar .pct {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* ---------- Pills de status ---------- */
.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--r-full);
  font-size: 0.72rem;
  font-weight: 600;
  color: #fff;
}
.pill-andamento { background: var(--brand); }
.pill-iniciar { background: var(--warn); }
.pill-espera { background: var(--info); }
.pill-concluido { background: var(--ok); }
.pill-cancelado { background: var(--crit); }

/* ---------- Grids auxiliares ---------- */
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 720px) { .grid3 { grid-template-columns: 1fr; } }

/* ---------- Calendário semanal ---------- */
.week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}
@media (max-width: 560px) { .week { grid-template-columns: 1fr; } }
.day {
  background: var(--surface2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px;
  min-height: 80px;
  transition: border-color var(--t-fast);
}
.day:hover { border-color: var(--brand); }
.day .dh { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; font-weight: 500; }
.day .dt { font-weight: 700; font-size: 1.1rem; }

/* ---------- Filtro inline ---------- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  padding: 14px 16px;
}
.filter-bar .field {
  margin: 0;
  min-width: 0;
  flex: 1 1 160px;
}
.filter-bar .field input,
.filter-bar .field select {
  padding: 8px 11px;
  font-size: 0.88rem;
}

/* ---------- Seção de permissões ---------- */
.pm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px 14px;
}
.pm-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  cursor: pointer;
}
.pm-check input { margin: 0; width: 16px; height: 16px; accent-color: var(--brand); }

/* ---------- Reduz movimento ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
