:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --border: #2d3a4d;
  --text: #e8eef7;
  --muted: #8b9cb3;
  --accent: #3d8bfd;
  --accent-dim: #2563c4;
  --radius: 12px;
  font-family: "DM Sans", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

/* Evita que clases con display: flex/… pisen el ocultado nativo de [hidden] (p. ej. .login-screen). */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(1200px 600px at 10% -10%, #1a2744 0%, var(--bg) 45%);
  color: var(--text);
  line-height: 1.5;
}

header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.header-left {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  min-width: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
  margin-left: auto;
}

.header-username {
  font-size: 0.9rem;
  color: var(--muted);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

header h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

header .badge {
  font-size: 0.75rem;
  color: var(--muted);
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 999px;
}

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  box-sizing: border-box;
}

.login-card {
  width: 100%;
  max-width: 400px;
}

.login-title {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
  font-weight: 600;
}

.login-hint {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

nav.tabs {
  display: flex;
  gap: 0.5rem;
  padding: 0 1.5rem;
  margin-top: 1rem;
}

nav.tabs button {
  font: inherit;
  cursor: pointer;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  transition: background 0.15s, border-color 0.15s;
}

nav.tabs button:hover {
  border-color: var(--accent-dim);
}

nav.tabs button.active {
  background: linear-gradient(180deg, #2a3f66, #1e2d4a);
  border-color: var(--accent);
  color: #fff;
}

main {
  padding: 1.25rem 1.5rem 2.5rem;
  max-width: 1200px;
  margin: 0 auto;
}

.panel {
  display: none;
  animation: fade 0.2s ease;
}

.panel.active {
  display: block;
}

.badge-idle {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(158, 158, 158, 0.15);
  color: var(--muted);
}

.analysis-status-summary {
  margin-bottom: 0.75rem;
}

.analysis-status-badge {
  margin: 0 0 0.35rem;
}

.analysis-pending-total {
  margin: 0;
  font-size: 0.9rem;
}

table.compact-table {
  font-size: 0.82rem;
  margin-top: 0.5rem;
}

.analysis-current-box {
  margin-top: 1rem;
  padding: 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.15);
}

.analysis-current-box h3 {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.status-dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 0.75rem;
  font-size: 0.85rem;
}

.status-dl dt {
  color: var(--muted);
  font-weight: 500;
}

.status-dl dd {
  margin: 0;
  word-break: break-word;
}

@keyframes fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  color: var(--muted);
  margin-bottom: 1rem;
}

.drop-zone input[type="file"] {
  margin-top: 0.75rem;
}

.btn-primary {
  font: inherit;
  cursor: pointer;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius);
  border: none;
  background: linear-gradient(180deg, var(--accent), var(--accent-dim));
  color: #fff;
  font-weight: 600;
}

.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-danger {
  font: inherit;
  cursor: pointer;
  padding: 0.35rem 0.65rem;
  border-radius: 8px;
  border: 1px solid #c62828;
  background: rgba(198, 40, 40, 0.2);
  color: #ffcdd2;
  font-size: 0.8rem;
}

.btn-danger:hover {
  background: rgba(198, 40, 40, 0.35);
}

.btn-secondary {
  font: inherit;
  cursor: pointer;
  padding: 0.45rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 0.85rem;
}

.btn-secondary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-secondary:not(:disabled):hover {
  border-color: var(--accent-dim);
}

.import-filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  margin-bottom: 1rem;
}

.import-filter-row label {
  font-size: 0.9rem;
  color: var(--muted);
}

.analysis-control-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.import-filter-row select {
  font: inherit;
  min-width: min(100%, 320px);
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
}

.badge-process {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(61, 139, 253, 0.25);
  color: #9ecbff;
}

.badge-wait {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  font-size: 0.75rem;
  background: rgba(255, 193, 7, 0.12);
  color: #ffe082;
}

#imports-body tr.import-row-highlight {
  outline: 1px solid rgba(61, 139, 253, 0.45);
  background: rgba(61, 139, 253, 0.08);
}

.import-col-expand {
  width: 2.5rem;
  text-align: center;
  vertical-align: middle;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  min-height: 2rem;
  padding: 0;
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  cursor: pointer;
}

.btn-icon:hover {
  border-color: rgba(100, 181, 246, 0.5);
  background: rgba(100, 181, 246, 0.12);
}

.import-usage-cell {
  padding: 0 !important;
  background: rgba(0, 0, 0, 0.2);
  border-top: none !important;
}

.import-usage-panel {
  padding: 0.85rem 1rem 1rem;
  font-size: 0.85rem;
}

.import-usage-lead {
  margin: 0 0 0.65rem;
  color: var(--muted);
}

.import-usage-dl {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.5rem 1.25rem;
  margin: 0;
}

.import-usage-dl > div {
  margin: 0;
}

.import-usage-dl dt {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 500;
}

.import-usage-dl dd {
  margin: 0.15rem 0 0;
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
}

.import-usage-note {
  margin: 0.65rem 0 0;
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.4;
}

.history-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  align-items: flex-end;
  margin-bottom: 0.75rem;
}

.history-toolbar label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.history-toolbar select {
  font: inherit;
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  min-width: 140px;
}

.history-toolbar .history-id-input {
  font: inherit;
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  min-width: 6.5rem;
  max-width: 10rem;
}

.history-meta {
  font-size: 0.85rem;
  color: var(--muted);
  flex: 1;
  min-width: 120px;
}

.history-nav {
  display: flex;
  gap: 0.5rem;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: min(720px, 100%);
  max-height: min(90vh, 900px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
}

.modal-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.modal-close {
  font: inherit;
  font-size: 1.5rem;
  line-height: 1;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0 0.25rem;
}

.modal-close:hover {
  color: var(--text);
}

.modal-body {
  padding: 1rem;
  overflow: auto;
  font-size: 0.88rem;
  color: var(--text);
}

.modal-section {
  margin-bottom: 1rem;
}

.modal-section h3 {
  margin: 0 0 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

.modal-section pre,
.modal-section .mono {
  margin: 0;
  padding: 0.65rem 0.75rem;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 8px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.8rem;
  max-height: 220px;
  overflow: auto;
}

.token-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.5rem;
}

.token-pill {
  padding: 0.4rem 0.55rem;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.8rem;
}

.token-pill strong {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 500;
}

/* Solo el + visible hasta expandir; texto al abrir */
.modal-tokens-row {
  display: flex;
  justify-content: flex-end;
  width: 100%;
  margin: -0.15rem 0 0.4rem;
}

.modal-tokens-details {
  border: none;
  border-radius: 8px;
  padding: 0;
  overflow: visible;
}

.modal-tokens-details[open] {
  width: 100%;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.12);
  overflow: hidden;
  margin-bottom: 0.35rem;
}

.modal-tokens-details > .modal-tokens-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: min-content;
  margin: 0 0 0 auto;
  padding: 0.2rem;
  font-size: 0;
  color: transparent;
  background: transparent;
  user-select: none;
  border-radius: 8px;
}

.modal-tokens-details[open] > .modal-tokens-summary {
  width: auto;
  justify-content: flex-end;
  padding: 0.4rem 0.6rem;
  background: rgba(0, 0, 0, 0.2);
  border-bottom: 1px solid var(--border);
  border-radius: 0;
}

.modal-tokens-details > .modal-tokens-summary::-webkit-details-marker {
  display: none;
}

.modal-tokens-plus {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.35);
  font-size: 1.05rem;
  line-height: 1;
  flex-shrink: 0;
  opacity: 0.75;
}

.modal-tokens-details[open] .modal-tokens-plus {
  opacity: 1;
}

.modal-tokens-details > .modal-tokens-summary:hover .modal-tokens-plus {
  opacity: 1;
  border-color: var(--accent-dim);
}

.modal-tokens-plus::before {
  content: "+";
  font-weight: 600;
  color: var(--muted);
}

.modal-tokens-details[open] .modal-tokens-plus::before {
  content: "−";
  color: var(--accent);
}

.modal-tokens-lead {
  margin: 0 0 0.65rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

.modal-tokens-body {
  padding: 0.75rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}

.stat {
  padding: 0.75rem 1rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.stat strong {
  display: block;
  font-size: 1.4rem;
  color: var(--accent);
}

pre.raw {
  background: rgba(0, 0, 0, 0.35);
  padding: 1rem;
  border-radius: 8px;
  overflow: auto;
  font-size: 0.8rem;
  color: var(--muted);
  max-height: 240px;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

table.data th,
table.data td {
  text-align: left;
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

table.data th {
  color: var(--muted);
  font-weight: 500;
}

.sentiment {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
}

.sentiment.positive {
  background: rgba(46, 125, 50, 0.25);
  color: #81c784;
}

.sentiment.negative {
  background: rgba(198, 40, 40, 0.25);
  color: #ef9a9a;
}

.sentiment.neutral {
  background: rgba(21, 101, 192, 0.25);
  color: #90caf9;
}

.sentiment.none {
  background: rgba(117, 117, 117, 0.35);
  color: #e0e0e0;
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.chart-box {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
}

.chart-box h3 {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
}

.table-wrap {
  overflow-x: auto;
  margin-top: 0.5rem;
}

table.stats-table th:nth-child(n + 2),
table.stats-table td:nth-child(n + 2) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

table.stats-table td:first-child {
  font-weight: 500;
}

.top-rt-box .top-rt-list {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.82rem;
}

.top-rt-box .top-rt-list li {
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.65rem;
}

.top-rt-box .top-rt-list li:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.top-rt-meta {
  margin-right: 0.5rem;
  color: var(--text);
}

.top-rt-id {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.top-rt-id strong {
  color: var(--text);
}

.top-rt-text {
  margin: 0.35rem 0 0.2rem;
  color: var(--text);
  line-height: 1.4;
  word-break: break-word;
}

.top-rt-src {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.status-line {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.75rem;
}

.error {
  color: #ff8a80;
}

.success {
  color: #b9f6ca;
}

.reglas-label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.reglas-label span:first-child {
  font-weight: 600;
  color: var(--text);
}

.reglas-textarea,
.reglas-input,
.reglas-select {
  font: inherit;
  width: 100%;
  max-width: 100%;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  resize: vertical;
}

.reglas-select {
  resize: none;
}

.reglas-client-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  background: rgba(0, 0, 0, 0.12);
}

.reglas-client-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.reglas-client-head .reglas-label {
  flex: 1;
  min-width: 200px;
  margin-bottom: 0;
}

.reglas-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.reglas-warning {
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 193, 7, 0.35);
  background: rgba(255, 193, 7, 0.08);
  color: #ffe082;
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

.reglas-raw-only {
  margin-top: 0.5rem;
}

.playground-grid {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.play-client-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

@media (max-width: 640px) {
  .play-client-row {
    grid-template-columns: 1fr;
  }
}

.play-id-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.play-id-row .reglas-input {
  flex: 1;
  min-width: 8rem;
}

.play-db-hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.play-result {
  margin: 0;
  padding: 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.35);
  font-size: 0.8rem;
  word-break: break-word;
  max-height: min(70vh, 720px);
  overflow: auto;
  color: #c5d0de;
}

.play-prompt-block {
  margin-bottom: 1.25rem;
}

.play-prompt-block:last-child {
  margin-bottom: 0;
}

.play-prompt-title {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.play-prompt-pre {
  margin: 0;
  padding: 0.75rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-x: auto;
  color: #d0dae6;
}
