:root {
  --bg: #f8fafc;
  --panel: #ffffff;
  --muted: #64748b;
  --text: #0f172a;
  --primary: #2563eb;
  --green: #16a34a;
  --yellow: #f59e0b;
  --red: #ef4444;
  --border: #e5e7eb;
}

* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, Segoe UI, Roboto, Arial;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.app-header .left {
  display: flex;
  align-items: center;
  gap: 16px;
}
.header-logo {
  display: flex;
  align-items: center;
  gap: 8px;
}
.header-logo img:first-child {
  height: 50px;
}
.header-logo img:last-child {
  height: 35px;
}
.nav-tabs {
  display: flex;
  gap: 8px;
}
.nav-tabs a {
  text-decoration: none;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 8px;
  font-weight: 600;
}
.nav-tabs a.active {
  border-bottom: 2px solid var(--primary);
  color: var(--primary);
}

#navMiEmpresa {
  display: none;
}

.app-footer {
  border-top: 1px solid var(--border);
  border-bottom: none;
  justify-content: center;
  color: var(--muted);
}

.controls {
  display: none;
}
.btn {
  background: var(--primary);
  color: #ffffff;
  border: none;
  padding: 8px 12px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.back-button {
  margin-bottom: 12px;
}

.container {
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
}

main.container {
  flex-grow: 1;
}

.status {
  color: var(--muted);
  font-size: 20px;
  font-weight: 500;
  text-align: left;
  padding: 8px 0 16px 0;
}

.summary {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.summary-controls {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.search-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}
.summary-head,
.summary-row {
  display: grid;
  grid-template-columns: 2.2fr 2fr 1.2fr 1.2fr 1.2fr 1.2fr 1.2fr;
  gap: 0;
}
.summary-head {
  background: #f1f5f9;
  color: var(--muted);
  padding: 12px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}
.summary-body {
  max-height: 60vh;
  overflow: auto;
}
.summary-row {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  align-items: center;
  cursor: pointer;
}
.summary-row:hover {
  background: #eef2f7;
}
.summary-row:nth-child(odd) {
  background: #fafafa;
}

.col {
  padding-right: 8px;
}
.col-name {
  font-weight: 600;
}
.col-cat .pill {
  display: inline-block;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
}
.total-cell {
  font-weight: 700;
  color: #0f172a;
  text-align: right;
}

.pill.green {
  background: rgba(16, 163, 74, 0.12);
  color: #166534;
}
.pill.yellow {
  background: rgba(245, 158, 11, 0.12);
  color: #92400e;
}
.pill.red {
  background: rgba(239, 68, 68, 0.12);
  color: #991b1b;
}

.bar-wrap {
  background: #e5e7eb;
  border-radius: 6px;
  height: 16px;
  position: relative;
  overflow: hidden;
}
.bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #60a5fa);
}
.bar.green {
  background: linear-gradient(90deg, #16a34a, #22c55e);
}
.bar.yellow {
  background: linear-gradient(90deg, #f59e0b, #fbbf24);
}
.bar.red {
  background: linear-gradient(90deg, #ef4444, #f87171);
}
.bar-label {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  right: 6px;
  font-size: 12px;
  color: #111827;
  font-weight: 700;
}

.charts {
  margin-top: 24px;
}
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 16px;
}
.chart-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  min-height: 450px;
  display: flex;
  flex-direction: column;
}
.chart-card canvas {
  display: block;
  width: 100% !important;
  max-width: 100%;
}

#chart-categories {
  height: 350px !important;
  margin: 0 auto;
}

/* Gauge layout */
.gauge-card {
  display: flex;
  align-items: center;
  justify-content: center;
}
.gauge-wrap {
  position: relative;
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  aspect-ratio: 2 / 1;
}

.donut-wrap {
  flex-grow: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.donut-wrap canvas {
  height: 240px !important;
  margin: 0 auto;
}
.category-note {
  font-size: 12px;
  color: #374151;
  margin-top: 16px;
  text-align: center;
}

.legend-items {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-bottom: 12px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-item .dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.score-ranges {
  text-align: center;
  line-height: 1.5;
  color: #64748b;
  font-size: 11px;
}

/* add breathing room so charts don't touch container edges */
.charts.container {
  padding-left: 24px;
  padding-right: 24px;
}

/* RUC page donuts need a bit more breathing room when the legend is below */
#donutsGrid .chart-card {
  min-height: 360px;
}
#donutsGrid .chart-card canvas {
  height: 300px !important;
}

@media (max-width: 900px) {
  .summary-head,
  .summary-row {
    grid-template-columns: 1.6fr 1.6fr repeat(5, 1fr);
  }
  .charts-grid {
    grid-template-columns: 1fr;
  }
  .donut-wrap {
    grid-template-columns: 1fr;
  }
}

/* Providers Page */
.company-selector-section {
  margin-bottom: 24px;
}

.ms-host .btn {
  font-size: 16px;
}

.dashboard-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr 2fr 1.5fr;
  gap: 16px;
  margin-bottom: 24px;
}

.metric-card {
  background-color: var(--panel);
  border-radius: 12px;
  padding: 16px;
  border: 1px solid var(--border);
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.metric-card h4,
.metric-card h5 {
  margin: 0 0 8px 0;
  color: var(--muted);
  font-size: 14px;
}

.metric-card span {
  font-size: 32px;
  font-weight: 700;
  color: var(--text);
}

.metric-card.total-score span {
  color: #1e3a8a;
}
.metric-card.total-score {
  background-color: #dbeafe;
  border-color: #bfdbfe;
}

.metric-card-group {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  padding: 0;
}
.metric-card-group .metric-card {
  padding: 8px;
  border-radius: 8px;
}
.metric-card-group .metric-card span {
  font-size: 24px;
}

.score-governance {
  background-color: #dbeafe;
}
.score-social {
  background-color: #fef9c3;
}
.score-environment {
  background-color: #dcfce7;
}
.score-generales {
  background-color: #fee2e2;
}

.categories-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

#charts-grid.categories-grid {
  grid-template-columns: 1fr 1fr 1fr 1fr;
}

.category-col {
  background-color: var(--panel);
  border-radius: 12px;
  padding: 16px;
  border: 1px solid var(--border);
}

.category-col h3 {
  margin-top: 0;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

#gobernanzaCol {
  background-color: #eff6ff;
}
#socialCol {
  background-color: #fefce8;
}
#medioAmbienteCol {
  background-color: #f0fdf4;
}
#generalesCol {
  background-color: #fff1f2;
}

#gobernanzaDetailCol {
  background-color: #eff6ff;
}
#socialDetailCol {
  background-color: #fefce8;
}
#medioAmbienteDetailCol {
  background-color: #f0fdf4;
}
#generalesDetailCol {
  background-color: #fff1f2;
}

.question-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid #e5e7eb;
}
.question-item:last-child {
  border-bottom: none;
}
.question-text {
  flex: 1;
  padding-right: 16px;
  color: #374151;
  font-size: 14px;
}
.question-answer {
  flex-shrink: 0;
  font-weight: 500;
  background-color: #f3f4f6;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 14px;
  min-width: 40px;
  text-align: center;
  color: #1f2937;
}

.long-answer-item {
  flex-direction: column;
  align-items: flex-start;
}
.question-text-full {
  width: 100%;
  padding-bottom: 8px;
  color: #374151;
  font-size: 14px;
}
.question-answer-long {
  width: 100%;
  padding: 8px 12px;
  background-color: #f3f4f6;
  border-radius: 6px;
  color: #1f2937;
  font-size: 14px;
  word-wrap: break-word;
}

.generales-section {
  margin-top: 24px;
}
.generales-section h3 {
  font-size: 18px;
  color: #1f2937;
  margin-bottom: 16px;
  text-align: center;
}
.generales-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
}
.generales-answer {
  min-height: 48px;
  padding: 8px;
  background: var(--muted-bg, #f3f4f6);
  border-radius: 8px;
  margin-top: 8px;
  color: #374151;
  font-size: 14px;
  word-wrap: break-word;
  line-height: 1.5;
  text-align: center;
}

#results {
  padding: 40px 16px 16px;
}

/* Login Page Styles */
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: var(--bg);
}

.login-box {
  background: var(--panel);
  padding: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  width: 100%;
  max-width: 400px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
}

.login-box h2 {
  text-align: center;
  margin-top: 0;
  margin-bottom: 24px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: var(--muted);
}

.error-message {
  color: var(--red);
  margin-top: 16px;
  text-align: center;
  min-height: 20px;
}

.company-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.company-info {
  display: flex;
  align-items: center;
  gap: 20px;
}

#companyLogo {
  height: 75px;
  max-width: 225px;
  object-fit: contain;
  display: none;
}

#companyName {
  font-size: 28px;
  font-weight: 700;
  margin: 0;
}

#empresaSelect {
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background-color: #fff;
  font-size: 16px;
  min-width: 250px;
}

/* Dropdown for questions */
.dropdown {
  position: relative;
  display: block;
  width: 100%;
  margin-bottom: 16px;
}

.dropdown .btn {
  width: 100%;
  text-align: left;
  background-color: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dropdown .btn::after {
  content: "▼";
  font-size: 12px;
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #fff;
  min-width: 100%;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.1);
  z-index: 100;
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 4px;
}

.dropdown-content.show {
  display: block;
}

.dropdown-item {
  padding: 10px 12px;
  text-decoration: none;
  display: flex;
  align-items: center;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.dropdown-item:last-child {
  border-bottom: none;
}

.dropdown-item:hover {
  background-color: #f1f5f9;
}

.dropdown-item input[type="checkbox"] {
  margin-right: 10px;
  height: 16px;
  width: 16px;
}

/* Chart containers */
.chart-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.pie-chart-wrapper {
  background-color: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.pie-chart-wrapper h5 {
  text-align: center;
  margin-bottom: 12px;
  font-size: 1rem;
  font-weight: 500;
  color: #333;
}

.custom-chart-legend ul {
  list-style: none;
  padding: 0;
  margin: 0 0 12px 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.custom-chart-legend li {
  display: flex;
  align-items: flex-start;
  margin-bottom: 5px;
  text-align: left;
}

.custom-chart-legend .legend-color-box {
  width: 12px;
  height: 12px;
  margin-right: 8px;
  display: inline-block;
  flex-shrink: 0;
  margin-top: 4px;
}

.custom-chart-legend .legend-text {
  font-size: 14px;
  color: #333;
}

/* RUC Page Question Format */
.question-item-ruc {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.question-item-ruc:last-child {
  border-bottom: none;
}

.question-item-ruc .question-text {
  margin: 0 0 8px 0;
  color: var(--text);
}

.question-item-ruc .answer-text {
  margin: 0;
  font-weight: 600;
  color: var(--primary);
  background-color: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  display: inline-block;
}

.success-message {
  margin-top: 20px;
  padding: 15px;
  background-color: var(--green);
  color: white;
  border-radius: 8px;
  text-align: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.3s ease-in-out;
}

.success-message.show {
  opacity: 1;
}

.page-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
}

.column {
  background: var(--panel);
  padding: 24px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}

.button-group {
  display: flex;
  gap: 10px;
}

.col-num {
  flex-basis: 12%;
  text-align: right;
  padding: 0 10px;
}

.app-footer {
  padding: 24px;
  background-color: var(--bg);
  border-top: 1px solid var(--border);
  color: var(--muted);
}

.footer-content {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 10px;
}

.footer-content p,
.footer-content a {
  margin: 0;
  color: var(--muted);
  text-decoration: none;
}

.footer-content a:hover {
  text-decoration: underline;
}

.linkedin-icon {
  width: 24px;
  height: 24px;
  fill: #0077b5;
}

.detail-company-name {
  margin-top: 16px;
  margin-bottom: 24px;
  font-size: 24px;
  color: #1e293b;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
