/* ──────────────────────────────────────────────────────────────────────────
   Terrano Components
   Componentes reutilizables del panel logistica.terrano.co.
   Requiere tokens.css cargado antes.
   ────────────────────────────────────────────────────────────────────────── */

/* ── Reset mínimo ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body{
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  min-height: 100vh;
  transition: background .2s, color .2s;
}

/* ── Header (amarillo, sticky) ─────────────────────────────── */
header{
  background: var(--yellow);
  height: var(--header-h);
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky; top: 0; z-index: 100;
  box-shadow: var(--shadow-sm);
}
.logo{
  display: flex;
  align-items: center;
  gap: 12px;
  align-self: stretch;
}
.logo img{
  height: calc(100% - 14px);
  object-fit: contain;
}
.logo-tag{
  font-size: 1.25rem;
  font-weight: 700;
  color: #000;
  letter-spacing: .01em;
  margin-left: 32px;
}
.logo-fallback{
  font-size: 1.9rem;
  font-weight: 700;
  font-style: italic;
  font-family: var(--font-serif);
  letter-spacing: 1px;
}
.header-right{
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Botones cuando viven adentro del header */
header .btn-ghost{
  color: var(--accent);
  border-color: rgba(0,0,0,.3);
  background: rgba(0,0,0,.07);
}
header .btn-ghost:hover:not(:disabled){
  background: rgba(0,0,0,.15);
  color: var(--accent);
}
header .btn-primary{
  background: var(--accent);
  color: var(--yellow);
  border-color: var(--accent);
}
header .btn-primary:hover:not(:disabled){
  background: #2d2d2a;
  box-shadow: 0 3px 8px rgba(0,0,0,.25);
}

/* ── Sidebar de navegación ─────────────────────────────────── */
.app-sidebar{
  position: fixed;
  top: var(--header-h); left: 0;
  width: var(--sidebar-w);
  height: calc(100vh - var(--header-h));
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 50;
  overflow-y: auto;
}
.sb-nav{
  display: flex;
  flex-direction: column;
  padding: 14px 0 8px;
  gap: 1px;
}
.sb-item{
  display: block;
  padding: 10px 18px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: .88rem;
  font-weight: 500;
  color: var(--text2);
  font-family: inherit;
  text-align: left;
  border-left: 3px solid transparent;
  transition: background .12s, color .12s, border-color .12s;
  white-space: nowrap;
  width: 100%;
}
.sb-item:hover{ background: var(--surface2); color: var(--text); }
.sb-item.active{
  background: var(--yellow-light);
  color: var(--accent);
  border-left-color: var(--yellow);
  font-weight: 700;
}
.sb-footer{
  margin-top: auto;
  padding: 14px 14px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.sb-user{
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 2px 4px 6px;
}
.sb-user-name{ font-weight: 700; font-size: .86rem; color: var(--text); line-height: 1.2; }
.sb-user-role{ font-size: .7rem; color: var(--muted); text-transform: capitalize; }
.sb-action{
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text2);
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  width: 100%;
  transition: background .12s, color .12s, border-color .12s;
}
.sb-action:hover{ background: var(--border); color: var(--text); }
.sb-action.dark{
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.sb-action.dark:hover{ background: #000; color: #fff; border-color: #000; }

/* ── App shell (deja espacio para el sidebar fijo) ─────────── */
.app-shell{ padding-left: var(--sidebar-w); }

/* ── Layout main ──────────────────────────────────────────── */
main{
  display: block;
  padding: 20px 28px;
  max-width: 1200px;
  margin: 0 auto;
}

/* ── Stats cards ──────────────────────────────────────────── */
.stats{
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}
.stat{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-num{ font-size: 2rem; font-weight: 800; line-height: 1; }
.stat-label{
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}
.stat-bar{
  height: 3px;
  border-radius: 2px;
  margin-top: 8px;
  background: var(--border);
}
.stat-yellow .stat-num{ color: var(--yellow-dark); }
.stat-yellow .stat-bar{ background: var(--yellow); }
.stat-red    .stat-num{ color: var(--red); }
.stat-red    .stat-bar{ background: var(--red); }
.stat-green  .stat-num{ color: var(--green); }
.stat-green  .stat-bar{ background: var(--green); }
.stat-blue   .stat-num{ color: var(--blue); }
.stat-blue   .stat-bar{ background: var(--blue); }

/* ── Botones ──────────────────────────────────────────────── */
.btn{
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: .82rem;
  font-weight: 600;
  font-family: inherit;
  white-space: nowrap;
  transition: all .15s;
}
.btn:disabled{ opacity: .45; cursor: not-allowed; transform: none !important; }

.btn-primary{
  background: var(--yellow);
  color: var(--accent);
  border: 2px solid var(--yellow-dark);
}
.btn-primary:hover:not(:disabled){
  background: var(--yellow-dark);
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(255,203,0,.4);
}

.btn-secondary{
  background: var(--surface);
  color: var(--text2);
  border: 1px solid var(--border2);
}
.btn-secondary:hover:not(:disabled){ background: var(--surface2); }

.btn-blue{
  background: var(--blue);
  color: #fff;
  border: 2px solid #1d4ed8;
}
.btn-blue:hover:not(:disabled){
  background: #1d4ed8;
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(37,99,235,.3);
}

.btn-danger{
  background: var(--red-light);
  color: var(--red);
  border: 1px solid #fca5a5;
}
.btn-danger:hover:not(:disabled){ background: #fee2e2; }

.btn-warn{
  background: var(--orange-light);
  color: var(--orange);
  border: 1px solid #fed7aa;
}
.btn-warn:hover:not(:disabled){ background: #ffedd5; }

.btn-ghost{
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 4px 7px;
}
.btn-ghost:hover:not(:disabled){ background: var(--surface2); color: var(--text2); }

.btn-sm{ padding: 5px 11px; font-size: .75rem; border-radius: 6px; }

/* ── Inputs ──────────────────────────────────────────────── */
.input,
input[type="text"].input,
input[type="email"].input,
input[type="password"].input,
input[type="tel"].input,
input[type="number"].input,
select.native{
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: .92rem;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
}
.input:focus,
select.native:focus{ border-color: var(--yellow); }
.input::placeholder{ color: var(--muted); }

/* Input con icono (search) */
.search-wrap{ position: relative; flex: 1; min-width: 0; max-width: 420px; }
.search-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.search-input{
  width: 100%;
  padding: 10px 14px 10px 38px;
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: .92rem;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
}
.search-input:focus{ border-color: var(--yellow); }
.search-icon{
  position: absolute;
  left: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
  font-size: .9rem;
}

/* ── Section block (card colapsable) ──────────────────────── */
.section-block{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  margin-bottom: 8px;
}
.section-header{
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid transparent;
  transition: background .12s;
}
.section-header:hover{ background: var(--surface2); }
.section-header.has-open{ border-bottom-color: var(--border); }
.section-name{
  font-weight: 700;
  font-size: .9rem;
  color: var(--text);
}
.chevron{
  color: var(--muted);
  font-size: .75rem;
  transition: transform .2s;
}
.chevron.open{ transform: rotate(90deg); }

/* ── Pills, badges, dots ──────────────────────────────────── */
.status-pill{
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: .78rem;
  color: var(--text2);
}
.dot{
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
}
.dot.busy{ background: var(--orange); animation: pulse 1s infinite; }

.badge{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 20px;
  padding: 0 7px;
  border-radius: 10px;
  font-size: .72rem;
  font-weight: 700;
  background: var(--surface2);
  color: var(--muted);
  border: 1px solid var(--border);
}
.badge-ready{
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--green-light);
  color: var(--green);
  border: 1px solid #86efac;
  min-width: 22px;
  height: 22px;
  padding: 0 10px;
  border-radius: 11px;
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .2px;
}
.badge-ready::before{ content: '\2713'; font-size: .82rem; font-weight: 900; }

.role-badge{
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: .68rem;
  font-weight: 700;
}
.role-badge.super_admin{ background: #fef9c3; color: #713f12; }
.role-badge.admin       { background: var(--blue-light); color: var(--blue); }

/* ── Modales y overlays ───────────────────────────────────── */
.overlay{
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.overlay.open{ display: flex; }
.modal{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  min-width: 340px;
  max-width: 460px;
  box-shadow: 0 20px 60px rgba(0,0,0,.15);
}
.modal h3{ margin-bottom: 10px; font-size: 1rem; font-weight: 700; }
.modal p {
  color: var(--text2);
  font-size: .85rem;
  margin-bottom: 20px;
  line-height: 1.5;
}
.modal-actions{
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* Toggle switch (24x44 con pelota interna 18) */
.cfg-toggle{
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--border2);
  border-radius: 24px;
  transition: .2s;
}
.cfg-toggle::before{
  content: '';
  position: absolute;
  height: 18px; width: 18px;
  left: 3px; bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: .2s;
}
input:checked + .cfg-toggle           { background: var(--green); }
input:checked + .cfg-toggle::before   { transform: translateX(20px); }

/* ── Toasts ───────────────────────────────────────────────── */
#toast{
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast-msg{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 16px;
  font-size: .82rem;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 9px;
  animation: toastIn .2s ease;
}
.toast-msg.ok { border-left: 3px solid var(--green); }
.toast-msg.err{ border-left: 3px solid var(--red); }

/* ── Banners ──────────────────────────────────────────────── */
.error-banner{
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--red-light);
  border: 1px solid #fca5a5;
  border-radius: var(--radius);
  padding: 10px 16px;
  margin-bottom: 12px;
}
.error-banner-msg{
  flex: 1;
  font-size: .83rem;
  color: var(--red);
  font-weight: 600;
}
.info-banner{
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--blue-light);
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  font-size: .83rem;
  color: var(--blue);
  padding: 10px 14px;
  margin: 0 0 10px 0;
  box-shadow: var(--shadow);
}

/* ── Auth (login / invitación) ────────────────────────────── */
.auth-overlay{
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-card{
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}
.auth-logo{ text-align: center; margin-bottom: 24px; }
.auth-logo span{
  font-size: 1.6rem;
  font-weight: 800;
  font-style: italic;
  font-family: var(--font-serif);
  letter-spacing: 1px;
}
.auth-title{
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 6px;
  text-align: center;
}
.auth-sub{
  font-size: .8rem;
  color: var(--muted);
  margin-bottom: 24px;
  text-align: center;
}
.auth-field{ margin-bottom: 14px; }
.auth-field label{
  display: block;
  font-size: .75rem;
  font-weight: 600;
  margin-bottom: 5px;
  color: var(--text2);
}
.auth-field input{
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: .88rem;
  font-family: inherit;
  transition: border-color .15s;
}
.auth-field input:focus{ outline: none; border-color: var(--yellow-dark); }
.auth-btn{
  width: 100%;
  padding: 10px;
  background: var(--yellow);
  color: var(--accent);
  border: none;
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
  margin-top: 4px;
}
.auth-btn:hover{ background: var(--yellow-dark); }
.auth-err{
  color: var(--red);
  font-size: .78rem;
  min-height: 18px;
  margin-top: 8px;
  text-align: center;
}

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 5px; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }

/* ── Animaciones ──────────────────────────────────────────── */
@keyframes pulse    { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }
@keyframes toastIn  { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes drawerIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes popupIn  { from { opacity: 0; transform: scale(.93); } to { opacity: 1; transform: scale(1); } }
@keyframes spin     { to { transform: rotate(360deg); } }
