:root {
  --color-primary: #0052CC;
  --color-primary-hover: #0747A6;
  --color-success: #36B37E;
  --color-warning: #FF8B00;
  --color-danger: #DE350B;
  --color-neutral-50: #FAFBFC;
  --color-neutral-100: #F4F5F7;
  --color-neutral-200: #EBECF0;
  --color-neutral-300: #DFE1E6;
  --color-neutral-500: #6B778C;
  --color-neutral-700: #42526E;
  --color-neutral-800: #253858;
  --color-neutral-900: #172B4D;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(135deg, #f0f4f8 0%, #e2e8f0 100%);
  color: var(--color-neutral-900);
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}

/* Header */
.header {
  background: var(--color-neutral-900);
  color: white;
  padding: 16px 0;
}

.header .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: white;
  text-decoration: none;
  font-weight: 600;
  font-size: 1.125rem;
}

.logo-icon {
  color: var(--color-primary);
  font-size: 1.25rem;
}

.logo-img {
  height: 36px;
  width: auto;
  object-fit: contain;
  display: block;
  background: transparent;
}

/* Fondos oscuros: el negro del logo (JPEG sin alpha) se funde con el fondo */
.header .logo-img,
.welcome-header .logo-img,
.login-logo-wrap .logo-img {
  mix-blend-mode: screen;
}

.login-logo-wrap {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  margin: -32px -32px 24px -32px;
  padding: 28px;
  border-radius: var(--radius) var(--radius) 0 0;
  text-align: center;
}

.logo-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Página de invitación / bienvenida */
.welcome-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(160deg, #0a0a0a 0%, #1a1a2e 50%, #16213e 100%);
}

.welcome-header {
  padding: 24px;
  text-align: center;
}

.welcome-header .logo-img {
  height: 56px;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.3));
}

.welcome-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.welcome-card {
  background: white;
  border-radius: 16px;
  box-shadow: 0 24px 48px rgba(0,0,0,0.25);
  padding: 40px;
  max-width: 440px;
  width: 100%;
}

.welcome-card .card-title {
  font-size: 1.5rem;
  margin: 0 0 8px;
  color: var(--color-neutral-900);
}

.welcome-card .subtitle {
  margin: 0 0 28px;
}

.admin-link {
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  font-size: 0.875rem;
}

.admin-link:hover {
  color: white;
}

/* Main */
.main {
  max-width: 640px;
  margin: 0 auto;
  padding: 48px 24px;
}

.section {
  margin-bottom: 32px;
}

.card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
}

.card h1, .card h2 {
  margin: 0 0 8px;
  font-size: 1.5rem;
}

.subtitle {
  color: var(--color-neutral-500);
  margin: 0 0 24px;
  font-size: 0.9375rem;
}

/* Forms */
.form, .lookup-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 600px) {
  .form-row {
    grid-template-columns: 1fr;
  }
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-neutral-700);
}

input, select, textarea {
  font-family: inherit;
  font-size: 1rem;
  padding: 12px 14px;
  border: 1px solid var(--color-neutral-300);
  border-radius: 6px;
  transition: border-color 0.2s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary);
}

textarea {
  resize: vertical;
  min-height: 100px;
}

/* Buttons */
.btn {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  padding: 12px 24px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--color-primary);
  color: white;
}

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

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--color-neutral-200);
  color: var(--color-neutral-800);
}

.btn-secondary:hover {
  background: var(--color-neutral-300);
}

.btn-loading {
  display: none;
}

.btn.loading .btn-loading {
  display: inline;
}

.btn.loading span:not(.btn-loading) {
  display: none;
}

/* Lookup */
.lookup-form {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.lookup-form input {
  flex: 1;
  min-width: 140px;
}

/* Ticket view */
.ticket-header {
  border-bottom: 1px solid var(--color-neutral-200);
  padding-bottom: 20px;
  margin-bottom: 24px;
}

.ticket-id {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-primary);
  background: var(--color-neutral-100);
  padding: 4px 10px;
  border-radius: 4px;
  margin-bottom: 8px;
}

.ticket-meta {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.badge {
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 4px;
  text-transform: capitalize;
}

.badge.open { background: #DEEBFF; color: #0747A6; }
.badge.in_progress { background: #E3FCEF; color: #006644; }
.badge.waiting { background: #FFF4E5; color: #974F0C; }
.badge.resolved { background: #E3FCEF; color: #006644; }

.badge-priority.low { background: #F4F5F7; color: #6B778C; }
.badge-priority.medium { background: #DEEBFF; color: #0747A6; }
.badge-priority.high { background: #FFE6E6; color: #BF2600; }
.badge-priority.urgent { background: #FFABAB; color: #BF2600; }

.ticket-description {
  color: var(--color-neutral-700);
  line-height: 1.6;
  margin-bottom: 32px;
}

.comment-form {
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.comment {
  background: var(--color-neutral-50);
  border-radius: 6px;
  padding: 16px;
  margin-bottom: 12px;
  border-left: 3px solid var(--color-neutral-200);
}

.comment.staff {
  border-left-color: var(--color-primary);
  background: #F0F7FF;
}

.comment-meta {
  font-size: 0.8125rem;
  color: var(--color-neutral-500);
  margin-bottom: 8px;
}

.back-link {
  display: inline-block;
  margin-top: 24px;
  color: var(--color-primary);
  text-decoration: none;
  font-size: 0.9375rem;
}

.back-link:hover {
  text-decoration: underline;
}

/* Success */
.success-icon {
  width: 64px;
  height: 64px;
  background: var(--color-success);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: bold;
  margin: 0 auto 24px;
}

.ticket-id-display {
  font-size: 1.25rem;
}

.hint {
  color: var(--color-neutral-500);
  font-size: 0.875rem;
}

.hidden {
  display: none !important;
}

/* Footer */
.footer {
  text-align: center;
  padding: 24px;
  color: var(--color-neutral-500);
  font-size: 0.875rem;
}

.footer a {
  color: var(--color-primary);
}

/* Admin */
.admin-body .main {
  max-width: none;
}

.admin-main {
  display: flex;
  min-height: calc(100vh - 60px);
}

.sidebar {
  width: 240px;
  background: white;
  padding: 24px;
  border-right: 1px solid var(--color-neutral-200);
}

.sidebar h3 {
  margin: 0 0 20px;
  font-size: 1rem;
}

.filter-group {
  margin-bottom: 20px;
}

.filter-group label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--color-neutral-700);
}

.content-area {
  flex: 1;
  padding: 24px;
  overflow-x: auto;
}

.tickets-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ticket-card {
  background: white;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: box-shadow 0.2s;
}

.ticket-card:hover {
  box-shadow: var(--shadow-hover);
}

.ticket-card .ticket-id {
  margin-bottom: 4px;
}

.ticket-card h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.ticket-detail {
  position: fixed;
  top: 0;
  right: 0;
  width: 480px;
  max-width: 100%;
  height: 100vh;
  background: white;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.15);
  overflow-y: auto;
  padding: 24px;
}

.detail-header {
  position: relative;
  margin-bottom: 24px;
}

.close-btn {
  position: absolute;
  top: -8px;
  right: 0;
  background: none;
  border: none;
  font-size: 2rem;
  cursor: pointer;
  color: var(--color-neutral-500);
  line-height: 1;
}

.close-btn:hover {
  color: var(--color-neutral-900);
}

.detail-info p {
  margin: 0 0 8px;
  font-size: 0.9375rem;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
  margin: 24px 0;
  padding: 20px;
  background: var(--color-neutral-50);
  border-radius: var(--radius);
}

.action-group {
  flex: 1;
  min-width: 120px;
}

.action-group label {
  display: block;
  font-size: 0.75rem;
  margin-bottom: 4px;
  color: var(--color-neutral-500);
}

.staff-comment-fields {
  display: flex;
  gap: 12px;
}

.staff-comment-fields input {
  flex: 1;
}

.empty-state {
  text-align: center;
  color: var(--color-neutral-500);
  padding: 48px 24px;
}

/* Login */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  max-width: 400px;
  width: 100%;
}

.btn-sm { padding: 8px 16px; font-size: 0.875rem; }

/* Back office nav */
.header-flex { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.nav { display: flex; gap: 16px; }
.nav-link { color: rgba(255,255,255,0.9); text-decoration: none; font-size: 0.9375rem; }
.nav-link:hover { color: white; }
.user-info { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 0.875rem; }

/* Views */
.admin-main { flex-direction: column; padding: 24px; }
.view { width: 100%; max-width: 900px; }
.view h1 { margin: 0 0 24px; }

/* Dashboard */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 16px; margin-bottom: 32px; }
.stat-card { background: white; padding: 24px; border-radius: var(--radius); box-shadow: var(--shadow); text-align: center; }
.stat-card span { display: block; font-size: 2rem; font-weight: 700; color: var(--color-primary); }
.stat-card label { font-size: 0.8125rem; color: var(--color-neutral-500); }

.chart-bars { display: flex; flex-direction: column; gap: 12px; }
.chart-bar { display: flex; align-items: center; gap: 12px; }
.chart-bar .bar { height: 24px; background: var(--color-primary); border-radius: 4px; min-width: 20px; }
.chart-bar span:first-child { min-width: 80px; font-size: 0.875rem; }
.chart-bar span:last-child { font-weight: 600; color: var(--color-neutral-700); }

.filters-row { display: flex; gap: 12px; margin-bottom: 20px; }
.filters-row select { min-width: 160px; }

#cliente-detail { position: relative; }
#cliente-detail .detail-actions { flex-direction: column; align-items: stretch; }
#cliente-detail textarea { min-height: 80px; }

/* Auth tabs (portal) */
.auth-tabs { display: flex; gap: 0; margin-bottom: 0; }
.auth-tab { padding: 12px 24px; border: 1px solid var(--color-neutral-200); background: var(--color-neutral-50); cursor: pointer; font-family: inherit; font-size: 0.9375rem; border-radius: var(--radius) var(--radius) 0 0; }
.auth-tab.active { background: white; border-bottom-color: white; font-weight: 600; }
.auth-tab:first-child { border-right: none; }
.user-info-text { margin-right: 12px; font-size: 0.875rem; color: rgba(255,255,255,0.9); }
.header-flex { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.header-right { display: flex; align-items: center; gap: 12px; }
.qr-container { padding: 16px; text-align: center; }
.qr-container img { border-radius: 8px; }
#agent-2fa-form input, #client-2fa-form input, #client-2fa-setup-form input, #2fa-setup-form input { width: 120px; text-align: center; font-size: 1.25rem; letter-spacing: 4px; }

.user-sections { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 24px; margin-top: 24px; }
.user-section h3 { margin: 0 0 8px; }
.user-section h4 { margin: 20px 0 8px; font-size: 1rem; }
.user-form { margin-top: 16px; }
.agents-list { min-height: 40px; margin-bottom: 16px; }
.user-card { margin-bottom: 8px; }
.empty-hint { color: var(--color-neutral-500); font-size: 0.875rem; margin: 0; }

.password-wrapper { position: relative; display: flex; align-items: center; }
.password-wrapper input { flex: 1; padding-right: 44px; }
.password-toggle { position: absolute; right: 8px; background: none; border: none; cursor: pointer; font-size: 1.1rem; padding: 4px; opacity: 0.7; }
.password-toggle:hover { opacity: 1; }

/* Modal overlay */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 9999; }
.modal-overlay.hidden { display: none; }
