/* RefHub Public CSS v2.0 - Light default + dark mode auto */

/* Light theme variables */
:root {
  --rh-bg:       #f8fafc;
  --rh-surface:  #ffffff;
  --rh-surface2: #f1f5f9;
  --rh-border:   #e2e8f0;
  --rh-text:     #1e293b;
  --rh-muted:    #64748b;
  --rh-subtle:   #94a3b8;
  --rh-accent:   #6366f1;
  --rh-accent2:  #818cf8;
  --rh-glow:     rgba(99,102,241,.12);
  --rh-success:  #059669;
  --rh-danger:   #dc2626;
  --rh-warning:  #d97706;
  --rh-radius:   12px;
  --rh-radius-sm:8px;
  --rh-radius-lg:20px;
  --rh-shadow:   0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.04);
  --rh-shadow-md:0 4px 14px rgba(0,0,0,.09);
}

/* Dark mode - follows OS */
@media (prefers-color-scheme: dark) {
  :root {
    --rh-bg:       #0f172a;
    --rh-surface:  #1e293b;
    --rh-surface2: #0f172a;
    --rh-border:   #334155;
    --rh-text:     #f1f5f9;
    --rh-muted:    #94a3b8;
    --rh-subtle:   #475569;
    --rh-shadow:   0 1px 3px rgba(0,0,0,.3);
    --rh-shadow-md:0 4px 14px rgba(0,0,0,.4);
  }
}

/* Base */
.rh-wrap * { box-sizing: border-box; margin: 0; padding: 0; }
.rh-wrap {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  color: var(--rh-text);
  max-width: 680px;
  margin: 0 auto;
  padding: clamp(20px,4vw,44px) clamp(14px,4vw,24px) 60px;
}
.rh-wrap button, .rh-wrap select, .rh-wrap input, .rh-wrap textarea {
  font-family: inherit;
}

/* Hero */
.rh-hero { margin-bottom: 32px; }
.rh-chip {
  display: inline-block; padding: 4px 12px;
  background: var(--rh-glow); border: 1px solid rgba(99,102,241,.2);
  border-radius: 100px; font-size: 11px; font-weight: 700;
  color: var(--rh-accent); letter-spacing: .4px; margin-bottom: 12px;
}
.rh-hero-title {
  font-size: clamp(26px,5vw,40px) !important;
  font-weight: 800 !important; letter-spacing: -1px !important;
  line-height: 1.1 !important; margin: 0 0 10px !important;
  color: var(--rh-text) !important;
}
.rh-hero-desc { font-size: 15px; color: var(--rh-muted); line-height: 1.65; }

/* Steps */
.rh-steps {
  display: flex; align-items: center; margin-bottom: 20px;
}
.rh-step {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  background: var(--rh-surface2); border: 2px solid var(--rh-border);
  color: var(--rh-subtle); display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; transition: all .2s;
}
.rh-step-active { background: var(--rh-accent); border-color: var(--rh-accent); color: #fff; }
.rh-step-done   { background: var(--rh-success); border-color: var(--rh-success); color: #fff; }
.rh-step-line   { flex: 1; height: 2px; background: var(--rh-border); }

.rh-section-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .8px; color: var(--rh-subtle); margin-bottom: 12px;
}

/* Grid de cards */
.rh-grid {
  display: grid; grid-template-columns: repeat(3,1fr);
  gap: 10px; margin-bottom: 18px;
}
.rh-grid-sm { grid-template-columns: repeat(3,1fr); }
@media(max-width:500px) { .rh-grid, .rh-grid-sm { grid-template-columns: repeat(2,1fr); } }

.rh-loading { grid-column: 1/-1; color: var(--rh-muted); font-size: 13px; padding: 8px 0; }

.rh-card {
  display: flex; flex-direction: column; gap: 4px;
  padding: 13px 11px; background: var(--rh-surface);
  border: 1.5px solid var(--rh-border); border-radius: var(--rh-radius);
  cursor: pointer; text-align: left; color: var(--rh-text);
  transition: border-color .15s, box-shadow .15s, transform .12s;
  box-shadow: var(--rh-shadow); position: relative;
  min-height: 82px;
}
.rh-card:hover:not(.rh-card-empty) {
  border-color: var(--rh-accent); transform: translateY(-2px);
  box-shadow: 0 0 0 3px var(--rh-glow), var(--rh-shadow-md);
}
.rh-card.rh-card-sel {
  border-color: var(--rh-accent);
  background: var(--rh-glow);
  box-shadow: 0 0 0 3px var(--rh-glow);
}
.rh-card.rh-card-empty { opacity: .4; cursor: not-allowed; }
.rh-card.rh-card-any   { border-style: dashed; }
.rh-card-check {
  position: absolute; top: 7px; right: 7px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--rh-accent); display: none;
  align-items: center; justify-content: center;
}
.rh-card.rh-card-sel .rh-card-check { display: flex; }
.rh-card-check::after { content: '✓'; color: #fff; font-size: 9px; font-weight: 800; }
.rh-card-emoji { font-size: 21px; line-height: 1; }
.rh-card-name  { font-size: 12px; font-weight: 600; }
.rh-card-count { font-size: 10px; color: var(--rh-subtle); }
.rh-card:focus-visible { outline: 2px solid var(--rh-accent); outline-offset: 2px; }

/* Boton principal */
.rh-btn-main {
  width: 100%; padding: 14px; display: flex; align-items: center; justify-content: center; gap: 8px;
  background: linear-gradient(135deg, var(--rh-accent), var(--rh-accent2));
  border: none; border-radius: var(--rh-radius); color: #fff;
  font-size: 15px; font-weight: 700; cursor: pointer; margin-bottom: 12px;
  box-shadow: 0 4px 14px var(--rh-glow); transition: opacity .2s, transform .1s;
  min-height: 48px;
}
.rh-btn-main:hover:not(:disabled) { opacity: .92; transform: translateY(-1px); }
.rh-btn-main:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.rh-btn-main:focus-visible { outline: 2px solid var(--rh-accent); outline-offset: 3px; }

.rh-btn-ghost {
  padding: 9px 16px; background: var(--rh-surface);
  border: 1.5px solid var(--rh-border); border-radius: var(--rh-radius-sm);
  color: var(--rh-muted); font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all .15s; min-height: 38px;
}
.rh-btn-ghost:hover { border-color: var(--rh-accent); color: var(--rh-accent); }

.rh-btn-copy {
  padding: 8px 14px; background: var(--rh-accent); border: none;
  border-radius: 7px; color: #fff; font-size: 12px; font-weight: 700;
  cursor: pointer; white-space: nowrap; transition: background .2s; min-height: 36px;
}
.rh-btn-copy.copied { background: var(--rh-success); }

/* Mensajes */
.rh-msg-err {
  font-size: 13px; color: var(--rh-danger); font-weight: 500;
  padding: 8px 12px; background: rgba(220,38,38,.07);
  border: 1px solid rgba(220,38,38,.18); border-radius: var(--rh-radius-sm);
  margin-top: 6px;
}
.rh-cta-link { font-size: 13px; color: var(--rh-muted); text-align: center; margin-top: 4px; }
.rh-cta-link a { color: var(--rh-accent); font-weight: 600; }
.rh-need-login, .rh-already-in { font-family: inherit; color: var(--rh-muted); font-size: 14px; }

/* Resultado */
.rh-result-card {
  background: var(--rh-surface); border: 1.5px solid var(--rh-border);
  border-radius: var(--rh-radius-lg); padding: clamp(18px,4vw,28px);
  margin-bottom: 14px; box-shadow: var(--rh-shadow-md);
  animation: rh-in .25s ease;
}
@keyframes rh-in { from { opacity:0; transform:translateY(12px); } to { opacity:1; transform:none; } }

.rh-result-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.rh-tag {
  padding: 3px 10px; border-radius: 100px; font-size: 11px; font-weight: 700;
}
.rh-tag-cat {
  background: var(--rh-glow); border: 1px solid rgba(99,102,241,.2); color: var(--rh-accent2);
}
.rh-tag-sub {
  background: rgba(5,150,105,.1); border: 1px solid rgba(5,150,105,.2); color: var(--rh-success);
}
.rh-result-plat {
  font-size: clamp(22px,4vw,30px); font-weight: 800; margin-bottom: 4px; letter-spacing: -.5px;
}
.rh-result-owner { font-size: 12px; color: var(--rh-muted); margin-bottom: 14px; }
.rh-result-desc {
  padding: 10px 12px; background: rgba(5,150,105,.07);
  border: 1px solid rgba(5,150,105,.15); border-radius: 8px;
  font-size: 13px; color: var(--rh-success); line-height: 1.55; margin-bottom: 12px;
}
.rh-code-block {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--rh-surface2); border: 1.5px solid var(--rh-border);
  border-radius: var(--rh-radius-sm); padding: 12px 14px; margin-bottom: 12px;
}
.rh-code {
  flex: 1; font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: clamp(15px,3vw,21px); font-weight: 700;
  color: var(--rh-accent); letter-spacing: 1.5px; word-break: break-all;
}
.rh-result-meta { font-size: 11px; color: var(--rh-subtle); }
.rh-result-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Auth */
.rh-auth-wrap { display: flex; justify-content: center; }
.rh-auth-card {
  width: 100%; max-width: 400px;
  background: var(--rh-surface); border: 1.5px solid var(--rh-border);
  border-radius: var(--rh-radius-lg); padding: clamp(22px,5vw,36px);
  box-shadow: var(--rh-shadow-md);
}
.rh-auth-icon  { font-size: 28px; margin-bottom: 12px; display: block; }
.rh-auth-title { font-size: clamp(18px,4vw,24px) !important; font-weight: 800 !important; margin: 0 0 4px !important; }
.rh-auth-sub   { font-size: 13px; color: var(--rh-muted); margin-bottom: 20px; }
.rh-auth-links { font-size: 12px; color: var(--rh-muted); text-align: center; margin-top: 12px; }
.rh-auth-links a { color: var(--rh-accent); font-weight: 600; }

/* Fields */
.rh-field { margin-bottom: 14px; }
.rh-field-row { display: flex; gap: 10px; }
@media(max-width:420px) { .rh-field-row { flex-direction: column; } }
.rh-field-row > .rh-field { flex: 1; min-width: 0; }
.rh-label {
  display: block; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .7px;
  color: var(--rh-muted); margin-bottom: 5px;
}
.rh-input {
  width: 100%; padding: 10px 12px;
  background: var(--rh-surface2); border: 1.5px solid var(--rh-border);
  border-radius: var(--rh-radius-sm); color: var(--rh-text);
  font-family: inherit; font-size: 14px; transition: border-color .15s;
}
.rh-input:focus { outline: none; border-color: var(--rh-accent); box-shadow: 0 0 0 3px var(--rh-glow); }
.rh-mono { font-family: 'SF Mono', 'Fira Code', monospace; letter-spacing: .5px; }

/* Dashboard */
.rh-dash-header {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 14px; margin-bottom: 22px;
}
.rh-dash-greet { display: flex; align-items: center; gap: 10px; }
.rh-dash-emoji { font-size: 26px; flex-shrink: 0; }
.rh-dash-title { font-size: clamp(17px,3.5vw,22px) !important; font-weight: 800 !important; margin: 0 0 2px !important; }
.rh-dash-name  { color: var(--rh-accent); }
.rh-dash-sub   { font-size: 12px; color: var(--rh-muted); }
.rh-kpis       { display: flex; gap: 8px; flex-wrap: wrap; }
.rh-kpi {
  display: flex; flex-direction: column; align-items: center;
  background: var(--rh-surface); border: 1.5px solid var(--rh-border);
  border-radius: var(--rh-radius-sm); padding: 8px 14px;
  box-shadow: var(--rh-shadow); min-width: 60px;
}
.rh-kpi-val { font-size: 20px; font-weight: 800; }
.rh-kpi-lbl { font-size: 10px; color: var(--rh-subtle); text-transform: uppercase; letter-spacing: .4px; }

.rh-tabs { display: flex; gap: 4px; margin-bottom: 16px; }
.rh-tab {
  padding: 8px 14px; background: var(--rh-surface);
  border: 1.5px solid var(--rh-border); border-radius: 8px;
  color: var(--rh-muted); font-family: inherit; font-size: 13px;
  font-weight: 600; cursor: pointer; transition: all .15s; min-height: 38px;
}
.rh-tab.rh-tab-on {
  background: var(--rh-glow); border-color: rgba(99,102,241,.3); color: var(--rh-accent);
}

/* Referido cards */
.rh-ref-list { display: flex; flex-direction: column; gap: 10px; }
.rh-ref-card {
  background: var(--rh-surface); border: 1.5px solid var(--rh-border);
  border-radius: var(--rh-radius); padding: 15px 16px;
  box-shadow: var(--rh-shadow); transition: border-color .15s;
}
.rh-ref-card:hover { border-color: rgba(99,102,241,.3); }
.rh-ref-card-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 8px; margin-bottom: 8px; flex-wrap: wrap;
}
.rh-ref-badges { display: flex; gap: 5px; flex-wrap: wrap; }
.rh-badge {
  display: inline-block; padding: 2px 8px; border-radius: 100px;
  font-size: 10px; font-weight: 700;
}
.rh-badge-cat { background: var(--rh-glow); border: 1px solid rgba(99,102,241,.2); color: var(--rh-accent2); }
.rh-badge-sub { background: rgba(5,150,105,.1); border: 1px solid rgba(5,150,105,.2); color: var(--rh-success); }
.rh-ref-actions { display: flex; gap: 4px; flex-shrink: 0; }
.rh-ref-btn {
  padding: 5px 10px; border-radius: 6px; font-size: 11px;
  font-weight: 700; cursor: pointer; border: 1.5px solid; transition: all .15s; min-height: 30px;
}
.rh-ref-btn-edit { background: none; border-color: rgba(99,102,241,.25); color: var(--rh-accent2); }
.rh-ref-btn-edit:hover { background: var(--rh-glow); }
.rh-ref-btn-del  { background: none; border-color: rgba(220,38,38,.2); color: rgba(220,38,38,.7); }
.rh-ref-btn-del:hover { background: rgba(220,38,38,.07); color: var(--rh-danger); }
.rh-ref-plat { font-size: 16px; font-weight: 700; margin-bottom: 8px; }
.rh-ref-code-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--rh-surface2); border: 1px solid var(--rh-border);
  border-radius: 7px; padding: 8px 10px; margin-bottom: 8px;
}
.rh-ref-code {
  font-family: 'SF Mono', 'Fira Code', monospace; font-size: 14px;
  font-weight: 700; color: var(--rh-accent); letter-spacing: 1px; flex: 1; word-break: break-all;
}
.rh-ref-code-copy {
  padding: 3px 8px; background: var(--rh-glow); border: none;
  border-radius: 5px; color: var(--rh-accent2); font-size: 10px; font-weight: 700; cursor: pointer;
}
.rh-ref-foot { display: flex; gap: 12px; flex-wrap: wrap; }
.rh-ref-stat { font-size: 11px; color: var(--rh-subtle); }

.rh-empty { text-align: center; color: var(--rh-subtle); padding: 32px 16px; font-size: 14px; line-height: 1.7; }
.rh-form-card {
  background: var(--rh-surface); border: 1.5px solid var(--rh-border);
  border-radius: var(--rh-radius); padding: 18px; box-shadow: var(--rh-shadow);
}
.rh-form-title { font-size: 14px; font-weight: 700; margin-bottom: 16px; }

/* Modal */
.rh-modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  z-index: 9999; display: flex; align-items: center; justify-content: center; padding: 16px;
}
.rh-modal {
  background: var(--rh-surface); border: 1.5px solid var(--rh-border);
  border-radius: var(--rh-radius-lg); width: 100%; max-width: 460px;
  box-shadow: 0 20px 50px rgba(0,0,0,.2); animation: rh-in .2s ease;
}
.rh-modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 0;
}
.rh-modal-title { font-size: 15px; font-weight: 700; }
.rh-modal-close {
  background: none; border: none; color: var(--rh-muted);
  font-size: 16px; cursor: pointer; padding: 4px 8px; border-radius: 5px; min-height: 32px;
}
.rh-modal-close:hover { background: var(--rh-surface2); }
.rh-modal-body  { padding: 14px 18px; }
.rh-modal-foot  { padding: 0 18px 16px; display: flex; gap: 8px; flex-wrap: wrap; }
.rh-modal-foot .rh-btn-main { display: inline-flex; width: auto; padding: 10px 20px; }

/* Dashboard footer */
.rh-dash-foot {
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px;
  margin-top: 28px; padding-top: 14px; border-top: 1px solid var(--rh-border);
}
.rh-foot-link { font-size: 12px; color: var(--rh-muted); text-decoration: none; }
.rh-foot-link:hover { color: var(--rh-accent); }
.rh-logout:hover { color: var(--rh-danger); }

/* Toast */
#rh-toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1e293b; color: #fff; padding: 10px 22px;
  border-radius: 100px; font-size: 13px; font-weight: 600;
  box-shadow: 0 8px 28px rgba(0,0,0,.25); z-index: 10000;
  pointer-events: none; opacity: 0; white-space: nowrap;
  transition: transform .3s, opacity .3s;
}
#rh-toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* Responsive */
@media(max-width:480px) {
  .rh-code-block { flex-direction: column; align-items: stretch; }
  .rh-btn-copy   { text-align: center; }
  .rh-result-actions, .rh-modal-foot { flex-direction: column; }
  .rh-dash-header { flex-direction: column; align-items: flex-start; }
  .rh-modal-overlay { align-items: flex-end; padding: 0; }
  .rh-modal { border-radius: var(--rh-radius) var(--rh-radius) 0 0; }
  .rh-ref-card-head { flex-direction: column; }
}

/* ---- Autocomplete empresa ---- */
.rh-autocomplete-wrap { position: relative; }

.rh-ac-drop {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 300;
  background: var(--rh-surface); border: 1.5px solid var(--rh-accent);
  border-radius: var(--rh-radius-sm); box-shadow: var(--rh-shadow-md);
  overflow: hidden; max-height: 260px; overflow-y: auto;
}

.rh-ac-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; cursor: pointer; font-size: 13px;
  color: var(--rh-text); transition: background .1s;
  border-bottom: 1px solid var(--rh-border);
}
.rh-ac-item:last-child { border-bottom: none; }
.rh-ac-item:hover, .rh-ac-item.focused { background: var(--rh-surface2); }

.rh-ac-emoji { font-size: 18px; flex-shrink: 0; width: 24px; text-align: center; }

.rh-ac-text { flex: 1; }
.rh-ac-name { font-weight: 600; display: block; }
.rh-ac-sub  { font-size: 11px; color: var(--rh-subtle); }

.rh-ac-badge-new {
  font-size: 10px; font-weight: 700; padding: 2px 7px;
  background: rgba(5,150,105,.1); border: 1px solid rgba(5,150,105,.2);
  border-radius: 100px; color: var(--rh-success); white-space: nowrap;
}
.rh-ac-badge-exists {
  font-size: 10px; font-weight: 700; padding: 2px 7px;
  background: var(--rh-glow); border: 1px solid rgba(99,102,241,.2);
  border-radius: 100px; color: var(--rh-accent); white-space: nowrap;
}

.rh-empresa-selected {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; margin-top: 6px;
  background: var(--rh-glow); border: 1px solid rgba(99,102,241,.2);
  border-radius: 7px; font-size: 12px; color: var(--rh-accent);
}
.rh-empresa-selected-icon { font-size: 16px; }

.rh-empresa-new-notice {
  padding: 8px 12px; margin-top: 6px;
  background: rgba(5,150,105,.07); border: 1px solid rgba(5,150,105,.2);
  border-radius: 7px; font-size: 12px; color: var(--rh-success); line-height: 1.5;
}
