:root {
  --earth: #8c827a;
  --peak: #341570;
  --flame: #fc7703;
  --sky: #83a7ce;
  --newsguard: #4d85a2;
  --tekhelet: #065399;
  --ink: #152033;
  --muted: #667085;
  --line: #d9e2ec;
  --bg: #f4f7fb;
  --surface: #fff;
  --danger: #b42318;
  --success: #027a48;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink); }
a { color: var(--tekhelet); text-decoration: none; }
button, input, select, textarea { font: inherit; }
input, select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px;
  background: #fff; color: var(--ink);
}
textarea { resize: vertical; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; font-weight: 700; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { border-bottom: 1px solid var(--line); padding: 13px 11px; text-align: left; vertical-align: top; }
th { color: var(--earth); font-size: 12px; text-transform: uppercase; }

.login-page {
  display: grid; place-items: center;
  background: radial-gradient(circle at 20% 20%, rgba(131, 167, 206, .35), transparent 32%),
              linear-gradient(135deg, #fff 0%, #eef5fb 48%, #e7edf5 100%);
}
.login-shell { width: min(94vw, 560px); }
.login-card {
  border: 1px solid rgba(77, 133, 162, .22); border-radius: 28px; padding: 34px;
  background: rgba(255,255,255,.92); box-shadow: 0 24px 70px rgba(6,83,153,.18);
}
.login-logo { width: 235px; max-width: 100%; display: block; margin-bottom: 24px; }
.login-card h1 { margin: 0 0 24px; font-size: 30px; color: var(--peak); white-space: nowrap; }

.topbar {
  position: sticky; top: 0; z-index: 4; height: 74px; display: flex; align-items: center;
  justify-content: space-between; gap: 20px; padding: 10px 24px; background: rgba(255,255,255,.94);
  border-bottom: 1px solid var(--line); backdrop-filter: blur(10px);
}
.brand img { height: 54px; width: auto; display: block; }
.session { display: flex; align-items: center; gap: 14px; color: var(--muted); font-weight: 700; }
.profile-menu { position: relative; }
.profile-trigger {
  list-style: none; display: inline-flex; align-items: center; gap: 9px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 999px; padding: 7px 11px; background: #fff; color: var(--ink);
}
.profile-trigger::-webkit-details-marker { display: none; }
.profile-icon {
  position: relative; width: 28px; height: 28px; display: inline-block; border-radius: 50%;
  background: var(--tekhelet);
}
.profile-icon::before {
  content: ""; position: absolute; left: 9px; top: 6px; width: 10px; height: 10px; border-radius: 50%;
  background: #fff;
}
.profile-icon::after {
  content: ""; position: absolute; left: 6px; bottom: 5px; width: 16px; height: 9px; border-radius: 999px 999px 6px 6px;
  background: #fff;
}
.profile-dropdown {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 150px; z-index: 8;
  display: grid; padding: 7px; border: 1px solid var(--line); border-radius: 14px; background: #fff;
  box-shadow: 0 16px 38px rgba(21,32,51,.14);
}
.profile-dropdown a { color: var(--ink); padding: 10px 12px; border-radius: 10px; }
.profile-dropdown a:hover { background: #eef5fb; color: var(--tekhelet); }
.app-shell { display: grid; grid-template-columns: 250px 1fr; min-height: calc(100vh - 74px); }
.sidebar { background: #152033; padding: 22px 14px; }
.sidebar nav { display: grid; gap: 8px; }
.sidebar a { display: block; padding: 13px 14px; border-radius: 18px; color: #e9f3fb; font-weight: 750; }
.sidebar a:hover { background: rgba(131,167,206,.18); }
.menu-group { display: grid; gap: 6px; }
.menu-group-title {
  display: flex; align-items: center; gap: 8px; list-style: none; cursor: pointer;
  padding: 13px 14px; border-radius: 18px; color: #e9f3fb; font-weight: 850;
}
.menu-group-title::-webkit-details-marker { display: none; }
.menu-group-title::before {
  content: "▾"; display: inline-block; color: var(--sky); transition: transform .18s ease;
}
.menu-group:not([open]) .menu-group-title::before { transform: rotate(-90deg); }
.menu-group-title:hover { background: rgba(131,167,206,.18); }
.submenu { display: grid; gap: 5px; margin: 2px 0 8px 18px; padding-left: 10px; border-left: 1px solid rgba(131,167,206,.35); }
.sidebar .submenu a { padding: 10px 12px; border-radius: 14px; font-size: 14px; }
.content { padding: 28px; display: grid; align-content: start; gap: 20px; }

.hero-panel {
  min-height: 220px; border-radius: 30px; padding: 34px; display: flex; align-items: end; color: #fff;
  background: linear-gradient(135deg, rgba(52,21,112,.96), rgba(6,83,153,.9)), url("../logo-cswlatam.jpg") center right 34px / 260px auto no-repeat;
  box-shadow: 0 22px 60px rgba(52,21,112,.22);
}
.hero-panel p { margin: 0 0 8px; color: #c9d8ea; font-weight: 800; }
.hero-panel h1 { margin: 0; max-width: none; white-space: nowrap; font-size: clamp(28px, 4.2vw, 56px); letter-spacing: 0; }
.module-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; }
.module-tile, .panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: 22px;
  box-shadow: 0 12px 34px rgba(21,32,51,.07);
}
.module-tile { min-height: 128px; padding: 22px; display: grid; align-content: end; color: var(--ink); }
.module-tile span { font-size: 22px; font-weight: 850; }
.module-tile small { color: var(--muted); margin-top: 6px; }
.panel { padding: 20px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.section-head h1 { margin: 0; color: var(--peak); font-size: 30px; }
.stack { display: grid; gap: 16px; }
.two-col { display: grid; grid-template-columns: minmax(320px, 430px) 1fr; gap: 20px; align-items: start; }
.users-layout { display: grid; grid-template-columns: 1fr minmax(320px, 430px); gap: 20px; align-items: start; }
.panel h2 { margin: 0; color: var(--peak); font-size: 22px; }
.form-row, .filters { display: grid; grid-template-columns: repeat(3, minmax(170px, 1fr)) auto; align-items: end; gap: 14px; }
.filters { grid-template-columns: repeat(6, minmax(120px, 1fr)) auto; }
.audit-filters { grid-template-columns: repeat(4, minmax(150px, 1fr)) auto auto; }
.primary, .button {
  border: 0; border-radius: 14px; padding: 12px 18px; background: var(--tekhelet); color: #fff;
  font-weight: 850; cursor: pointer; white-space: nowrap;
}
.primary:hover, .button:hover { background: var(--peak); color: #fff; }
.primary:disabled { cursor: wait; opacity: .82; background: var(--newsguard); }
.generate-button { min-width: 112px; display: inline-flex; align-items: center; justify-content: center; gap: 9px; }
.small { padding: 7px 11px; border-radius: 11px; font-size: 12px; }
.button-spinner {
  width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(255,255,255,.45);
  border-top-color: #fff; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.button { display: inline-flex; align-items: center; justify-content: center; }
.link-danger { border: 0; background: transparent; color: var(--danger); padding: 0; cursor: pointer; }
.danger-button {
  border: 0; border-radius: 14px; padding: 12px 18px; background: var(--danger); color: #fff;
  font-weight: 850; cursor: pointer; white-space: nowrap;
}
.danger-button:hover { filter: brightness(.92); }
.danger-button.small { padding: 7px 11px; border-radius: 11px; font-size: 12px; }
.actions { white-space: nowrap; }
.action-buttons { display: flex; gap: 10px; align-items: center; justify-content: flex-start; }
.action-buttons .small { width: 76px; }
.actions form { margin: 0; }
.check { display: flex; grid-template-columns: auto 1fr; align-items: center; gap: 9px; }
.check input, .permission-table input { width: auto; }
.permission-table {
  display: grid; grid-template-columns: 1fr 90px 150px; gap: 10px 12px; align-items: center;
  padding: 14px; border-radius: 16px; background: #f8fbfe;
}
.alert { border-radius: 16px; padding: 13px 15px; border: 1px solid; font-weight: 750; }
.alert.success { color: var(--success); background: #ecfdf3; border-color: #abefc6; }
.alert.danger { color: var(--danger); background: #fef3f2; border-color: #fecdca; }
.narrow { max-width: 720px; }
.table-scroll { overflow-x: auto; }
.cost-total {
  justify-self: start; border-radius: 16px; padding: 13px 16px; background: #eef5fb;
  color: var(--tekhelet); border: 1px solid var(--line); font-weight: 850;
}
.report-output { display: grid; gap: 18px; }
.history-panel { display: grid; gap: 14px; }
.history-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.history-head h2 { margin: 0; color: var(--peak); font-size: 22px; }
.secondary { background: var(--earth); }
.secondary:hover { background: var(--newsguard); }
.status { display: inline-flex; border-radius: 999px; padding: 5px 9px; font-weight: 850; font-size: 12px; }
.status-spinner {
  width: 12px; height: 12px; margin-right: 6px; border-radius: 50%;
  border: 2px solid rgba(6,83,153,.25); border-top-color: var(--tekhelet); animation: spin .8s linear infinite;
}
.status-generado { color: var(--success); background: #ecfdf3; }
.status-enproceso { color: var(--tekhelet); background: #eef5fb; }
.status-error { color: var(--danger); background: #fef3f2; }
.pager { display: flex; gap: 10px; justify-content: flex-end; }
.report-toolbar { display: flex; justify-content: space-between; gap: 14px; align-items: center; border-bottom: 1px solid var(--line); padding-bottom: 14px; }
.report-toolbar span { display: block; color: var(--muted); margin-top: 4px; font-size: 13px; }
.formatted-report { font-size: 16px; line-height: 1.72; color: #26364d; }
.formatted-report h1, .formatted-report h2, .formatted-report h3 { color: var(--peak); line-height: 1.2; margin: 20px 0 10px; }
.formatted-report p { margin: 0 0 12px; }
.formatted-report ul, .formatted-report ol { margin: 0 0 14px 24px; }
.formatted-report table { margin: 14px 0; background: #fff; border-radius: 12px; overflow: hidden; }
.formatted-report th { background: #eef5fb; color: var(--tekhelet); }
.pdf-render {
  position: fixed; left: 0; top: 0; width: 760px; padding: 28px; background: #fff; color: #26364d;
  transform: translateX(-120vw); opacity: 1; pointer-events: none; z-index: -1;
  font-family: "Segoe UI", Arial, sans-serif; font-size: 14px; line-height: 1.6;
}
.pdf-render .pdf-generated-date {
  margin: 0 0 18px; padding: 10px 12px; border: 1px solid #d9e2ec; background: #eef5fb; color: #065399;
}
.pdf-render h1, .pdf-render h2, .pdf-render h3 { color: #341570; line-height: 1.2; margin: 18px 0 9px; }
.pdf-render table { width: 100%; border-collapse: collapse; margin: 12px 0; }
.pdf-render th, .pdf-render td { border: 1px solid #d9e2ec; padding: 8px; text-align: left; }

@media (max-width: 920px) {
  .app-shell, .two-col, .users-layout { grid-template-columns: 1fr; }
  .sidebar { padding: 10px; }
  .sidebar nav { grid-auto-flow: column; overflow-x: auto; }
  .form-row, .filters, .audit-filters { grid-template-columns: 1fr; }
  .content { padding: 18px; }
}
@media (max-width: 560px) {
  .topbar { height: auto; align-items: flex-start; padding: 10px 14px; }
  .brand img { height: 45px; }
  .login-card h1 { white-space: normal; font-size: 27px; }
  .section-head, .report-toolbar { align-items: flex-start; flex-direction: column; }
  .hero-panel { padding: 24px; background-image: linear-gradient(135deg, rgba(52,21,112,.96), rgba(6,83,153,.9)); }
}
