/* ============================================================
   ADRGuard — Design System
   Tom: industrial/utilitário refinado
   Paleta: azul-escuro + RAG (verde/âmbar/vermelho)
   Tipografia: IBM Plex Sans + IBM Plex Mono
   ============================================================ */

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

/* ---- Variáveis ---- */
:root {
  /* Superfícies */
  --bg-base:      #0d1117;
  --bg-surface:   #161b22;
  --bg-elevated:  #1c2330;
  --bg-hover:     #21262d;
  --border:       #30363d;
  --border-light: #21262d;

  /* Texto */
  --text-primary:   #e6edf3;
  --text-secondary: #8b949e;
  --text-muted:     #484f58;
  --text-link:      #58a6ff;

  /* RAG — estados de conformidade */
  --verde:       #2ea043;
  --verde-bg:    #0d2818;
  --verde-glow:  rgba(46, 160, 67, 0.15);
  --ambar:       #d29922;
  --ambar-bg:    #2d1f00;
  --ambar-glow:  rgba(210, 153, 34, 0.15);
  --vermelho:    #da3633;
  --vermelho-bg: #2d0000;
  --vermelho-glow: rgba(218, 54, 51, 0.15);
  --cinza:       #484f58;
  --cinza-bg:    #161b22;

  /* Marca */
  --azul:        #1f6feb;
  --azul-light:  #388bfd;
  --azul-bg:     #051d4d;

  /* Tipografia */
  --font-sans: 'IBM Plex Sans', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', 'Courier New', monospace;

  /* Espaçamento */
  --radius:    6px;
  --radius-lg: 10px;

  /* Transições */
  --transition: 150ms ease;
}

/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ---- Layout principal ---- */
.app-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: 48px 1fr;
  grid-template-areas: "header header" "sidebar main";
  min-height: 100vh;
}

/* ---- Topbar ---- */
.topbar {
  grid-area: header;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text-primary);
}

.topbar-logo svg { color: var(--azul-light); }

.topbar-logo-text {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.3px;
}

.topbar-logo-badge {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  background: var(--azul-bg);
  color: var(--azul-light);
  border: 1px solid var(--azul);
  padding: 1px 6px;
  border-radius: 3px;
}

.topbar-sep { flex: 1; }

.topbar-tenant {
  font-size: 0.85rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.topbar-tenant span {
  color: var(--text-primary);
  font-weight: 500;
}

/* ---- Sidebar ---- */
.sidebar {
  grid-area: sidebar;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  padding: 12px 0;
  overflow-y: auto;
  position: sticky;
  top: 48px;
  height: calc(100vh - 48px);
}

.sidebar-section-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 12px 16px 4px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 16px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 400;
  transition: color var(--transition), background var(--transition);
  border-radius: 0;
  border-left: 2px solid transparent;
}

.sidebar-nav a:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.sidebar-nav a.active {
  color: var(--text-primary);
  background: var(--bg-hover);
  border-left-color: var(--azul-light);
  font-weight: 500;
}

.sidebar-nav a svg { opacity: 0.7; flex-shrink: 0; }
.sidebar-nav a.active svg { opacity: 1; color: var(--azul-light); }

/* Badge de contagem na sidebar */
.nav-badge {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 600;
}

.nav-badge.vermelho { background: var(--vermelho-bg); color: var(--vermelho); }
.nav-badge.ambar    { background: var(--ambar-bg);    color: var(--ambar);    }

/* ---- Área de conteúdo ---- */
.main-content {
  grid-area: main;
  padding: 24px;
  overflow-y: auto;
  max-width: 1200px;
}

/* ---- Page header ---- */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}

.page-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.page-subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ---- Cartões ---- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

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

.card-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ---- Métricas RAG (score cards) ---- */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.metric-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  position: relative;
  overflow: hidden;
  transition: border-color var(--transition);
}

.metric-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}

.metric-card.verde::before    { background: var(--verde); }
.metric-card.ambar::before    { background: var(--ambar); }
.metric-card.vermelho::before { background: var(--vermelho); }
.metric-card.azul::before     { background: var(--azul-light); }

.metric-label {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.metric-value {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 600;
  line-height: 1;
}

.metric-card.verde    .metric-value { color: var(--verde); }
.metric-card.ambar    .metric-value { color: var(--ambar); }
.metric-card.vermelho .metric-value { color: var(--vermelho); }
.metric-card.azul     .metric-value { color: var(--azul-light); }

.metric-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
  font-family: var(--font-mono);
}

/* ---- Score circular ---- */
.score-ring {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.score-ring svg { transform: rotate(-90deg); }

.score-ring-track { fill: none; stroke: var(--border); stroke-width: 6; }
.score-ring-fill  {
  fill: none;
  stroke-width: 6;
  stroke-linecap: round;
  transition: stroke-dasharray 1s ease;
}

.score-ring-text {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 1.1rem;
  fill: var(--text-primary);
  dominant-baseline: middle;
  text-anchor: middle;
}

/* ---- Tabelas ---- */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead th {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border-light);
  transition: background var(--transition);
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }

tbody td {
  padding: 10px 14px;
  color: var(--text-primary);
  vertical-align: middle;
}

td.mono {
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

td.secondary { color: var(--text-secondary); }

/* ---- Badges de estado RAG ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.badge.conforme    { background: var(--verde-bg);    color: var(--verde);    }
.badge.conforme::before    { background: var(--verde); }
.badge.aviso       { background: var(--ambar-bg);    color: var(--ambar);    }
.badge.aviso::before       { background: var(--ambar); }
.badge.nao-conforme { background: var(--vermelho-bg); color: var(--vermelho); }
.badge.nao-conforme::before { background: var(--vermelho); }
.badge.pendente    { background: var(--cinza-bg);    color: var(--cinza);    border: 1px solid var(--border); }
.badge.pendente::before    { background: var(--cinza); }
.badge.nao-aplicavel { display: none; }

/* ---- Dias restantes ---- */
.dias {
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.dias.critico  { color: var(--vermelho); font-weight: 600; }
.dias.aviso    { color: var(--ambar); }
.dias.ok       { color: var(--text-secondary); }
.dias.expirado { color: var(--vermelho); font-weight: 700; }

/* ---- Botões ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

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

.btn-secondary {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--text-muted); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-hover); }

.btn-sm { padding: 4px 10px; font-size: 0.8rem; }

/* ---- Inputs / Formulários ---- */
.form-group { margin-bottom: 16px; }

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

input, select, textarea {
  width: 100%;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  padding: 8px 12px;
  transition: border-color var(--transition);
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--azul-light);
  box-shadow: 0 0 0 3px rgba(56, 139, 253, 0.1);
}

input[type="date"] { font-family: var(--font-mono); }

.input-mono { font-family: var(--font-mono); font-size: 0.85rem; }

/* ---- Upload area ---- */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}

.upload-area:hover, .upload-area.drag-over {
  border-color: var(--azul-light);
  background: rgba(56, 139, 253, 0.04);
}

.upload-icon {
  width: 40px;
  height: 40px;
  margin: 0 auto 12px;
  color: var(--text-muted);
}

.upload-area:hover .upload-icon { color: var(--azul-light); }

.upload-title {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.upload-sub {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.upload-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

/* ---- Toast / Notificações ---- */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  min-width: 280px;
  max-width: 380px;
  animation: slideIn 200ms ease;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.toast.verde    { border-left: 3px solid var(--verde); }
.toast.vermelho { border-left: 3px solid var(--vermelho); }
.toast.ambar    { border-left: 3px solid var(--ambar); }

.toast-msg { font-size: 0.875rem; color: var(--text-primary); flex: 1; }
.toast-close { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 2px; }
.toast-close:hover { color: var(--text-primary); }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ---- Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 560px;
  max-width: calc(100vw - 48px);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  transform: scale(0.95);
  transition: transform 200ms ease;
}

.modal-overlay.open .modal { transform: scale(1); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 0.95rem;
  font-weight: 600;
}

.modal-body { padding: 20px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

/* ---- Tabela de erros de importação ---- */
.import-errors {
  background: var(--vermelho-bg);
  border: 1px solid var(--vermelho);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-top: 12px;
}

.import-error-item {
  display: flex;
  gap: 8px;
  font-size: 0.8rem;
  padding: 4px 0;
  border-bottom: 1px solid rgba(218,54,51,0.2);
}

.import-error-item:last-child { border-bottom: none; }
.import-error-linha { font-family: var(--font-mono); color: var(--vermelho); font-weight: 600; min-width: 60px; }
.import-error-msg   { color: var(--text-secondary); }

/* ---- Progress bar ---- */
.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 600ms ease;
}

.progress-fill.verde    { background: var(--verde); }
.progress-fill.ambar    { background: var(--ambar); }
.progress-fill.vermelho { background: var(--vermelho); }

/* ---- Paginação ---- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.pagination-btns { display: flex; gap: 4px; }

.page-btn {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.page-btn:hover, .page-btn.active {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.page-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ---- Estados vazios ---- */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state svg { margin: 0 auto 12px; opacity: 0.3; }
.empty-state-title { font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 4px; }
.empty-state-sub   { font-size: 0.8rem; }

/* ---- Loading ---- */
.skeleton {
  background: linear-gradient(90deg, var(--bg-elevated) 25%, var(--bg-hover) 50%, var(--bg-elevated) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius);
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.loading-row td { padding: 10px 14px; }

/* ---- Alertas inline ---- */
.alert {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 16px;
}

.alert.vermelho { background: var(--vermelho-bg); border: 1px solid var(--vermelho); color: var(--text-primary); }
.alert.ambar    { background: var(--ambar-bg);    border: 1px solid var(--ambar);    color: var(--text-primary); }
.alert.verde    { background: var(--verde-bg);    border: 1px solid var(--verde);    color: var(--text-primary); }

/* ---- Responsividade ---- */
@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas: "header" "main";
  }
  .sidebar { display: none; }
  .main-content { padding: 16px; }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ---- Utilitários ---- */
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.flex   { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.grid { display: grid; }
.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.text-sm     { font-size: 0.8rem; }
.text-muted  { color: var(--text-secondary); }
.text-mono   { font-family: var(--font-mono); }
.font-medium { font-weight: 500; }
.hidden { display: none !important; }
