:root {
  --bg: #0b0d12;
  --surface: #11141b;
  --surface-2: #181c26;
  --surface-3: #202633;
  --text: #e8ebf0;
  --text-secondary: #9aa4b8;
  --muted: #6b778c;
  --border: #2a3040;
  --accent: #3b82f6;
  --accent-2: #60a5fa;
  --critical: #ef4444;
  --critical-bg: rgba(239, 68, 68, 0.12);
  --high: #f59e0b;
  --high-bg: rgba(245, 158, 11, 0.12);
  --medium: #10b981;
  --medium-bg: rgba(16, 185, 129, 0.12);
  --open: #8b5cf6;
  --open-bg: rgba(139, 92, 246, 0.12);
  --recurrent: #ec4899;
  --recurrent-bg: rgba(236, 72, 153, 0.12);
  --completed: #22c55e;
  --pending: #f59e0b;
  --inprogress: #3b82f6;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --font: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  font-size: 14px;
  min-height: 100vh;
}

.app { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(17, 20, 27, 0.82);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  padding: 18px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #d71e28 0%, #b01c22 100%);
  display: grid; place-items: center;
  font-weight: 800; font-size: 16px; letter-spacing: -0.5px;
  color: #fff; box-shadow: 0 4px 16px rgba(215, 30, 40, 0.28);
}
.brand h1 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.2px; }
.subtitle { margin: 2px 0 0; color: var(--text-secondary); font-size: 12.5px; }

.topbar-actions { display: flex; align-items: center; gap: 16px; }
.lang-switch {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}
.lang-btn {
  border: none; background: transparent; color: var(--text-secondary);
  padding: 6px 14px; border-radius: 999px; cursor: pointer;
  font-weight: 600; font-size: 12px; transition: all .15s ease;
}
.lang-btn.active { background: var(--accent); color: #fff; }
.report-date {
  font-size: 12px; color: var(--text-secondary);
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 999px;
}

.container { flex: 1; padding: 24px; max-width: 1520px; margin: 0 auto; width: 100%; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 14px;
  margin-bottom: 22px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  transition: transform .12s ease;
}
.kpi:hover { transform: translateY(-2px); }
.kpi-meta { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.kpi-label { font-size: 12px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.4px; }
.kpi-value { font-size: 34px; font-weight: 800; letter-spacing: -1px; line-height: 1; }
.kpi-desc { margin-top: 8px; font-size: 12px; color: var(--text-secondary); }
.kpi.critical { border-left: 4px solid var(--critical); background: linear-gradient(180deg, var(--surface) 0%, var(--critical-bg) 100%); }
.kpi.critical .kpi-value { color: var(--critical); }
.kpi.high { border-left: 4px solid var(--high); background: linear-gradient(180deg, var(--surface) 0%, var(--high-bg) 100%); }
.kpi.high .kpi-value { color: var(--high); }
.kpi.medium { border-left: 4px solid var(--medium); background: linear-gradient(180deg, var(--surface) 0%, var(--medium-bg) 100%); }
.kpi.medium .kpi-value { color: var(--medium); }
.kpi.open { border-left: 4px solid var(--open); background: linear-gradient(180deg, var(--surface) 0%, var(--open-bg) 100%); }
.kpi.open .kpi-value { color: var(--open); }
.kpi.recurrent { border-left: 4px solid var(--recurrent); background: linear-gradient(180deg, var(--surface) 0%, var(--recurrent-bg) 100%); }
.kpi.recurrent .kpi-value { color: var(--recurrent); }
.kpi.total { border-left: 4px solid var(--accent-2); }
.kpi.total .kpi-value { color: var(--accent-2); }

.badge {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 3px 8px; border-radius: 6px;
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px;
}
.badge-critical { background: var(--critical-bg); color: var(--critical); }
.badge-high { background: var(--high-bg); color: var(--high); }
.badge-medium { background: var(--medium-bg); color: var(--medium); }
.badge-open { background: var(--open-bg); color: var(--open); }
.badge-recurrent { background: var(--recurrent-bg); color: var(--recurrent); }
.badge-total { background: rgba(96, 165, 250, 0.12); color: var(--accent-2); }
.badge-status-pending { background: rgba(245, 158, 11, 0.14); color: var(--pending); }
.badge-status-inprogress { background: rgba(59, 130, 246, 0.14); color: var(--inprogress); }
.badge-status-completed { background: rgba(34, 197, 94, 0.14); color: var(--completed); }

.filters {
  display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 22px;
}
.filter-group { display: flex; flex-direction: column; gap: 6px; min-width: 140px; flex: 1; }
.filter-group label { font-size: 11px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.4px; }
.filter-group input, .filter-group select {
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); padding: 9px 12px; border-radius: var(--radius-sm);
  font-size: 13px; outline: none;
}
.filter-group input:focus, .filter-group select:focus { border-color: var(--accent); }
.filter-group input::placeholder { color: var(--muted); }

.btn {
  border: none; border-radius: var(--radius-sm); padding: 10px 16px;
  font-weight: 600; font-size: 13px; cursor: pointer; transition: all .15s ease;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--surface-3); }

.rm-cards { margin-bottom: 24px; }
.rm-cards h2 { margin: 0 0 14px; font-size: 16px; font-weight: 700; }
.rm-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px;
}
.rm-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.rm-name { font-weight: 700; font-size: 14px; margin-bottom: 10px; }
.rm-stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
}
.rm-stat { text-align: center; background: var(--surface-2); border-radius: 8px; padding: 8px; }
.rm-stat-value { font-size: 18px; font-weight: 800; display: block; }
.rm-stat-label { font-size: 10px; color: var(--text-secondary); text-transform: uppercase; }
.rm-sites { margin-top: 10px; font-size: 12px; color: var(--text-secondary); line-height: 1.4; }

.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.section-header h2 { margin: 0; font-size: 16px; font-weight: 700; }
.section-actions { display: flex; align-items: center; gap: 12px; }
.count { color: var(--text-secondary); font-size: 13px; }

.table-section { margin-bottom: 30px; }
.table-wrap {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  background: var(--surface-2); color: var(--text-secondary);
  font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: 0.4px;
  padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td { padding: 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table tbody tr { transition: background .1s ease; }
.data-table tbody tr:hover { background: rgba(255,255,255,0.03); }
.data-table tbody tr:last-child td { border-bottom: none; }

.cell-agency { min-width: 160px; }
.cell-agency .name { font-weight: 700; font-size: 14px; }
.cell-agency .meta { color: var(--text-secondary); font-size: 11px; margin-top: 3px; }
.cell-risk { white-space: nowrap; }
.cell-issues { max-width: 260px; }
.cell-issues .tags { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 6px; }
.cell-issues .tag {
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text-secondary); font-size: 10px; font-weight: 600;
  padding: 3px 7px; border-radius: 5px;
}
.cell-issues .summary { color: var(--text-secondary); font-size: 12px; line-height: 1.45; }
.cell-action { color: var(--text); font-size: 12.5px; line-height: 1.45; }
.cell-action, .cell-issues { min-width: 220px; }
.cell-deadline { white-space: nowrap; font-weight: 600; color: var(--text-secondary); }
.cell-wo { text-align: center; white-space: nowrap; }
.wo-count { font-weight: 800; font-size: 16px; }
.wo-state { display: block; font-size: 10px; color: var(--text-secondary); margin-top: 2px; }
.cell-evidence { text-align: center; }
.evidence-btn {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-secondary);
  padding: 6px 10px; border-radius: 6px; font-size: 11px; font-weight: 600; cursor: pointer;
}
.evidence-btn:hover { background: var(--surface-3); color: var(--text); }
.evidence-btn.has-evidence { color: var(--completed); border-color: rgba(34,197,94,.3); }

.footer {
  border-top: 1px solid var(--border); padding: 18px 24px;
  color: var(--muted); font-size: 12px; text-align: center;
}

/* Modal */
.modal { display: none; position: fixed; inset: 0; z-index: 100; align-items: center; justify-content: center; }
.modal.open { display: flex; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.72); backdrop-filter: blur(4px); }
.modal-card {
  position: relative; z-index: 2;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  width: min(900px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  display: flex; flex-direction: column;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 22px 24px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 4px 0 0; font-size: 20px; font-weight: 700; }
.modal-subtitle { color: var(--text-secondary); font-size: 12px; }
.modal-close {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  width: 34px; height: 34px; border-radius: 8px; font-size: 22px; line-height: 1; cursor: pointer;
}
.modal-body { padding: 22px 24px; overflow-y: auto; }

.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 18px; }
.modal-block { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 14px; }
.modal-block h3 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-secondary); }
.modal-block p { margin: 0; font-size: 13px; line-height: 1.55; }
.modal-block .big { font-size: 22px; font-weight: 800; }
.modal-list { list-style: none; margin: 0; padding: 0; }
.modal-list li { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.modal-list li:last-child { border-bottom: none; }
.wo-card {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px; margin-bottom: 10px;
}
.wo-card h4 { margin: 0 0 6px; font-size: 14px; font-weight: 700; }
.wo-card .wo-meta { color: var(--text-secondary); font-size: 12px; margin-bottom: 8px; }
.wo-card p { margin: 0 0 6px; font-size: 13px; line-height: 1.5; }
.wo-card .wo-note { background: rgba(59,130,246,0.08); border-left: 3px solid var(--accent); padding: 8px 10px; border-radius: 0 6px 6px 0; font-size: 12px; color: var(--text-secondary); }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.photo-placeholder {
  aspect-ratio: 4/3; background: var(--surface-2); border: 2px dashed var(--border);
  border-radius: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--muted); font-size: 12px; text-align: center; padding: 12px;
}
.photo-placeholder svg { margin-bottom: 8px; }

@media (max-width: 1200px) {
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
  .rm-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .rm-grid { grid-template-columns: 1fr; }
  .filters { flex-direction: column; align-items: stretch; }
  .filter-group { min-width: auto; }
  .section-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .data-table th, .data-table td { white-space: normal; }
  .modal-grid { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .container { padding: 16px; }
}
