/* Tickets Monitor — estilos mínimos para login y configuración de departamentos */

:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --border: #2d3a4d;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --danger: #f85149;
  --danger-hover: #ff7b72;
  --radius: 8px;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

#app {
  min-height: 100vh;
}

.view {
  min-height: 100vh;
  padding: 1.5rem;
}

.view.hidden {
  display: none;
}

/* Login */
.login-card {
  max-width: 400px;
  margin: 4rem auto;
  padding: 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
}

.subtitle {
  margin: 0 0 1.5rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.form label {
  display: block;
  margin-top: 1rem;
  margin-bottom: 0.25rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.form input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.form input:focus {
  outline: none;
  border-color: var(--accent);
}

.form .error {
  margin-top: 0.75rem;
  color: var(--danger);
  font-size: 0.875rem;
}

.form .error.hidden {
  display: none;
}

.form button[type="submit"] {
  width: 100%;
  margin-top: 1.25rem;
  padding: 0.7rem;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
}

.form button[type="submit"]:hover {
  background: var(--accent-hover);
}

.form button[type="submit"]:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Dashboard */
.header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.header h1 {
  margin: 0;
  font-size: 1.35rem;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* Temporizador hasta la próxima actualización automática de tickets */
.next-refresh-timer {
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.next-refresh-timer.updating {
  color: var(--primary);
  font-weight: 500;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.user-email {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.btn {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
}

.btn-secondary {
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-danger {
  color: #fff;
  background: var(--danger);
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-add {
  color: #fff;
  background: var(--accent);
}

.btn-add:hover {
  background: var(--accent-hover);
}

.section {
  margin-bottom: 2.5rem;
}

.section h2 {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
}

.hint {
  margin: 0 0 1rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.department-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.department-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 0.85rem;
  margin-bottom: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.department-list li .name {
  flex: 1;
}

.department-list li .id {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.watch-webhook-select {
  min-width: 7rem;
  max-width: 10rem;
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.webhooks-list {
  list-style: none;
  margin: 0 0 1.5rem;
  padding: 0;
}
.webhooks-list .webhook-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
}
.webhooks-list .webhook-url-input {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.6rem;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.webhooks-list .webhook-orientation-select {
  padding: 0.4rem 0.6rem;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 10rem;
}

.watch-order-btns {
  display: flex;
  gap: 0.2rem;
}
.btn-icon {
  padding: 0.25rem 0.5rem;
  font-size: 0.85rem;
  min-width: 2rem;
}

.loading,
.empty {
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 0.75rem 0;
}

.empty.hidden,
.loading.hidden {
  display: none;
}

/* Navegación entre Dashboard y Configuración */
.nav {
  display: flex;
  gap: 0.25rem;
}
.nav-btn {
  padding: 0.45rem 0.9rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
}
.nav-btn:hover {
  color: var(--text);
}
.nav-btn.active {
  color: var(--accent);
  background: rgba(88, 166, 255, 0.1);
  border-color: var(--border);
}

.panel {
  margin-top: 0.5rem;
}
.panel.hidden {
  display: none;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.25rem;
}
.section-head h2 {
  margin: 0;
}
.section-head .status-text {
  color: var(--text-muted);
  font-size: 0.9rem;
}
.section-head .status-text.hidden {
  display: none;
}

/* Bloque de estado del refresh (última ejecución, próxima, actualizando) */
.refresh-status-block {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.5rem;
  align-items: center;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
}
.refresh-status-updating {
  padding: 0.2rem 0.5rem;
  background: rgba(88, 166, 255, 0.15);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  color: var(--accent);
}
.refresh-status-updating.hidden {
  display: none;
}
.refresh-status-next,
.refresh-status-last {
  color: var(--text-muted);
}
.refresh-status-next strong,
.refresh-status-last strong {
  color: var(--text);
}
.refresh-status-last.refresh-status-error #refresh-status-last-value {
  color: var(--danger);
}

/* Barra de progreso durante actualización */
.progress-bar {
  margin-bottom: 0.75rem;
  padding: 0.5rem 0;
}
.progress-bar.hidden {
  display: none;
}
.progress-bar-track {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.2s ease;
  width: 0%;
}
.progress-bar-text {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Lista por departamentos */
.by-department.hidden {
  display: none;
}
.dept-section {
  margin-bottom: 2rem;
}
.dept-section .dept-title {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
  color: var(--accent);
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
}
.ticket-conclusion-row {
  background: rgba(88, 166, 255, 0.06);
}
.ticket-conclusion-row .conclusion-cell {
  padding: 0.5rem 0.75rem 0.75rem 1rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.ticket-conclusion-row .conclusion-cell strong {
  color: var(--text);
  margin-right: 0.35rem;
}

/* Tabla tickets que necesitan respuesta */
.table-wrap {
  overflow-x: auto;
  margin-top: 1rem;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.data-table th,
.data-table td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.data-table th {
  color: var(--text-muted);
  font-weight: 600;
}
.data-table tbody tr:hover {
  background: var(--surface);
}
.data-table .reason-badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
}
.data-table .reason-cliente_espera_respuesta {
  background: rgba(248, 81, 73, 0.2);
  color: #ff7b72;
}
.data-table .reason-nuevo_sin_respuesta {
  background: rgba(210, 153, 34, 0.2);
  color: #d2a022;
}
.llm-priority { font-weight: 500; }
.llm-priority.priority-alta { color: #f85149; }
.llm-priority.priority-media { color: #d2a022; }
.llm-priority.priority-baja { color: #8b949e; }
.data-table .llm-reason {
  max-width: 220px;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.error.hidden {
  display: none;
}

/* Registro de notificaciones Teams */
.teams-log-section {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.teams-log-section .section-head {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.5rem;
}
.teams-log-section .section-head h3 {
  margin: 0;
  font-size: 1.1rem;
}
.teams-logs-pre {
  margin: 0;
  padding: 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.8rem;
  line-height: 1.5;
  max-height: 280px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
