/* ============================================================
   TROPICO TOSTADORES — Estilos globales
   ============================================================ */

:root {
  --c-brand:      #1a1a1a;
  --c-brand-mid:  #2e2e2e;
  --c-accent:     #a31916;
  --c-accent-lt:  #e8dacb;
  --c-accent-dim: #c94340;
  --c-green:      #3B6D11;
  --c-green-lt:   #EAF3DE;
  --c-orange:     #BA7517;
  --c-orange-lt:  #FAEEDA;
  --c-red:        #a31916;
  --c-red-lt:     #f5e5e5;
  --c-bg:         #f5f0ea;
  --c-surface:    #FFFFFF;
  --c-border:     #ddd4c6;
  --c-text:       #1a1a1a;
  --c-text-mid:   #3a3a3a;
  --c-text-muted: #7a6f66;
  --sidebar-w:    230px;
  --radius:       10px;
  --shadow:       0 2px 12px rgba(0,0,0,0.07);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'DM Sans', sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  font-size: 15px;
  line-height: 1.6;
}

/* ============================================================
   LAYOUT
   ============================================================ */
#app { display: flex; height: 100vh; overflow: hidden; }
#sidebar {
  width: var(--sidebar-w);
  background: #1a1a1a;
  display: flex; flex-direction: column;
  flex-shrink: 0;
}
#main-content { flex: 1; overflow-y: auto; padding: 32px 36px; }

/* ============================================================
   SIDEBAR
   ============================================================ */
#sidebar-nav { flex: 1; padding: 12px 10px; overflow-y: auto; }

.nav-section-label {
  font-size: 10px; font-weight: 600;
  color: rgba(255,255,255,0.3);
  text-transform: uppercase; letter-spacing: 1px;
  padding: 14px 10px 6px;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px; cursor: pointer;
  color: rgba(255,255,255,0.6); font-size: 14px;
  transition: background 0.15s, color 0.15s; user-select: none;
}
.nav-item:hover  { background: rgba(255,255,255,0.07); color: #fff; }
.nav-item.active { background: var(--c-accent); color: #fff; font-weight: 500; }
.nav-icon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }

.sidebar-footer {
  padding: 14px 14px 18px;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex; align-items: center; gap: 8px;
}
.user-chip { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.user-avatar {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--c-accent); color: #fff; font-weight: 600; font-size: 13px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.user-info { display: flex; flex-direction: column; min-width: 0; }
.user-name { font-size: 13px; font-weight: 500; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-rol  { font-size: 11px; color: rgba(255,255,255,0.4); text-transform: capitalize; }
.btn-logout {
  background: none; border: none; cursor: pointer;
  color: rgba(255,255,255,0.4); font-size: 17px;
  padding: 4px; border-radius: 6px;
  transition: color 0.15s, background 0.15s;
}
.btn-logout:hover { color: #fff; background: rgba(255,255,255,0.1); }

/* ============================================================
   VISTAS
   ============================================================ */
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.vista-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.vista-titulo   { font-size: 22px; font-weight: 600; }
.vista-subtitulo{ font-size: 13px; color: var(--c-accent); margin-top: 2px; font-weight: 500; }

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius); padding: 20px 24px; box-shadow: var(--shadow);
}
.card-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.stat-card {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow);
}
.stat-label  { font-size: 11px; color: var(--c-text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
.stat-value  { font-size: 26px; font-weight: 600; color: var(--c-text); font-family: 'DM Mono', monospace; }
.stat-detail { font-size: 12px; color: var(--c-text-muted); margin-top: 4px; }

/* ============================================================
   SEMÁFORO
   ============================================================ */
.semaforo-card {
  background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: var(--radius); padding: 20px 24px;
  display: flex; align-items: center; gap: 20px;
  margin-bottom: 24px; box-shadow: var(--shadow);
}
.semaforo-dot { width: 52px; height: 52px; border-radius: 50%; flex-shrink: 0; transition: background 0.4s; }
.semaforo-dot.verde   { background: var(--c-green);  box-shadow: 0 0 0 6px var(--c-green-lt); }
.semaforo-dot.naranja { background: var(--c-orange); box-shadow: 0 0 0 6px var(--c-orange-lt); }
.semaforo-dot.rojo    { background: var(--c-accent); box-shadow: 0 0 0 6px var(--c-red-lt); }
.semaforo-dot.gris    { background: #ccc; }
.semaforo-info { flex: 1; }
.semaforo-titulo  { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.semaforo-detalle { font-size: 13px; color: var(--c-text-muted); }
.progreso-barra { height: 8px; background: var(--c-border); border-radius: 4px; overflow: hidden; margin-top: 10px; position: relative; }
.progreso-fill  { height: 100%; border-radius: 4px; transition: width 0.5s ease, background 0.4s; }
.progreso-esperado-marker { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--c-text-muted); opacity: 0.5; }

/* ============================================================
   TABLAS
   ============================================================ */
.tabla-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  text-align: left; padding: 10px 14px;
  font-size: 11px; font-weight: 600; color: var(--c-text-muted);
  text-transform: uppercase; letter-spacing: 0.5px;
  border-bottom: 2px solid var(--c-border);
}
tbody td   { padding: 11px 14px; border-bottom: 1px solid var(--c-border); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(163,25,22,0.03); }
.td-num    { font-family: 'DM Mono', monospace; text-align: right; }
.td-dias   { font-family: 'DM Mono', monospace; text-align: left; }
.td-gap-pos{ color: var(--c-accent); font-family: 'DM Mono', monospace; text-align: right; font-weight: 500; }
.td-gap-ok { color: var(--c-green);  font-family: 'DM Mono', monospace; text-align: right; font-weight: 500; }
tfoot td   { padding: 11px 14px; font-weight: 600; font-size: 13px; border-top: 2px solid var(--c-border); background: var(--c-bg); }

/* ============================================================
   FORMULARIOS
   ============================================================ */
.form-group  { margin-bottom: 16px; }
.form-label  { display: block; margin-bottom: 5px; font-size: 13px; font-weight: 500; color: var(--c-text-mid); }
.form-control {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--c-border); border-radius: 8px;
  font-family: 'DM Sans', sans-serif; font-size: 14px; color: var(--c-text);
  background: var(--c-surface); outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus { border-color: var(--c-accent); box-shadow: 0 0 0 3px rgba(163,25,22,0.15); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ============================================================
   BOTONES
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px; border-radius: 8px; border: none; cursor: pointer;
  font-family: 'DM Sans', sans-serif; font-size: 14px; font-weight: 500;
  transition: all 0.15s;
}
.btn-primary   { background: var(--c-accent); color: #fff; }
.btn-primary:hover { background: #8a1413; }
.btn-secondary { background: var(--c-bg); color: var(--c-text); border: 1px solid var(--c-border); }
.btn-secondary:hover { background: var(--c-border); }
.btn-sm   { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px 8px; font-size: 14px; background: none; border: 1px solid var(--c-border); color: var(--c-text-muted); border-radius: 6px; }
.btn-icon:hover { background: var(--c-bg); color: var(--c-text); }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ============================================================
   BADGES
   ============================================================ */
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; text-transform: capitalize; }
.badge-admin        { background: #1a1a1a;          color: #e8dacb; }
.badge-planificador { background: #e8dacb;           color: #1a1a1a; }
.badge-tostador     { background: var(--c-red-lt);   color: var(--c-accent); }
.badge-activo       { background: var(--c-green-lt); color: var(--c-green); }
.badge-inactivo     { background: var(--c-red-lt);   color: var(--c-accent); }
.badge-abierta      { background: var(--c-green-lt); color: var(--c-green); }
.badge-cerrada      { background: #f0ece6;           color: #7a6f66; }
.badge-ingreso      { background: rgba(34,197,94,0.15);  color: #15803d; }
.badge-ajuste       { background: rgba(234,179,8,0.15);  color: #92400e; }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; animation: fadeIn 0.15s;
}
.modal {
  background: var(--c-surface); border-radius: 14px;
  padding: 28px 30px; width: 480px; max-width: calc(100vw - 40px);
  box-shadow: 0 12px 48px rgba(0,0,0,0.2); animation: slideUp 0.2s ease;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-header  { display: flex; justify-content: space-between; align-items: center; margin-bottom: 22px; }
.modal-titulo  { font-size: 17px; font-weight: 600; }
.modal-close   { background: none; border: none; cursor: pointer; color: var(--c-text-muted); font-size: 20px; padding: 2px 6px; border-radius: 6px; }
.modal-close:hover { background: var(--c-bg); color: var(--c-text); }
.modal-footer  { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--c-border); }

/* ============================================================
   TOAST
   ============================================================ */
#toast-container { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 9998; }
.toast { padding: 11px 16px; border-radius: 10px; font-size: 14px; font-weight: 500; box-shadow: 0 4px 16px rgba(0,0,0,0.12); animation: toastIn 0.25s ease; min-width: 240px; }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
.toast-success { background: var(--c-green);  color: #fff; }
.toast-error   { background: var(--c-accent); color: #fff; }
.toast-info    { background: #1a1a1a;         color: #e8dacb; }

/* ============================================================
   LOGIN
   ============================================================ */
.login-wrap {
  min-height: 100vh; background: #1a1a1a;
  display: flex; align-items: center; justify-content: center;
}
.login-box {
  background: var(--c-surface); border-radius: 16px;
  padding: 40px 44px; width: 380px; max-width: calc(100vw - 32px);
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.login-logo { font-size: 20px; font-weight: 600; text-align: center; margin-bottom: 28px; color: var(--c-text); }
.login-error {
  background: var(--c-red-lt); color: var(--c-accent);
  padding: 9px 12px; border-radius: 8px;
  font-size: 13px; margin-bottom: 14px;
}

/* ============================================================
   PLAN TABS
   ============================================================ */
.plan-tab {
  background: none; border: none; cursor: pointer;
  padding: 8px 16px; font-size: 14px; font-weight: 500;
  color: var(--c-text-muted); border-bottom: 2px solid transparent;
  margin-bottom: -2px; transition: all 0.15s;
}
.plan-tab.active { color: var(--c-accent); border-bottom-color: var(--c-accent); }
.plan-tab:hover  { color: var(--c-text); }

/* ============================================================
   DIA SELECTOR (carga diaria)
   ============================================================ */
.btn-dia {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 12px; min-width: 52px;
  border: 1px solid var(--c-border); border-radius: var(--radius);
  background: var(--c-surface); color: var(--c-text);
  cursor: pointer; font-family: inherit; line-height: 1.2;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.btn-dia:hover:not(:disabled) { border-color: var(--c-accent); color: var(--c-accent); }
.btn-dia.active { background: var(--c-accent); color: #fff; border-color: var(--c-accent); }
.btn-dia:disabled { opacity: 0.38; cursor: not-allowed; }

/* ============================================================
   IDIOMA
   ============================================================ */
.idioma-sel {
  background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.6); border-radius: 6px;
  padding: 3px 6px; font-size: 12px; font-weight: 600;
  cursor: pointer; outline: none; width: 44px;
}
.idioma-sel option { background: #1a1a1a; color: #fff; }

/* ============================================================
   UTILIDADES
   ============================================================ */
.text-muted { color: var(--c-text-muted); }
.text-sm    { font-size: 13px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }

  /* Sidebar: oculto por defecto, desliza desde la izquierda */
  #sidebar {
    position: fixed; left: -230px; width: 230px;
    z-index: 100; transition: left 0.25s ease;
    height: 100vh;
  }
  #sidebar.open { left: 0; box-shadow: 4px 0 20px rgba(0,0,0,0.3); }

  /* Topbar visible en mobile */
  #topbar { display: flex !important; }

  /* Main content sin padding lateral excesivo */
  #main-content { padding: 0 0 32px; }
  #vista-contenido { padding: 12px 14px 0; }

  /* Vista header compacto */
  .vista-header { flex-direction: column; align-items: flex-start; gap: 10px; margin-bottom: 16px; }
  .vista-titulo { font-size: 18px; }

  /* Cards */
  .card { padding: 14px 14px; }
  .card-grid { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
  .stat-card { padding: 12px 14px; }
  .stat-value { font-size: 20px; }

  /* Semáforo compacto */
  .semaforo-card { padding: 14px; gap: 12px; }
  .semaforo-dot { width: 38px; height: 38px; }

  /* Formularios */
  .form-row { grid-template-columns: 1fr; }

  /* Modal full-width en mobile */
  .modal {
    width: calc(100vw - 20px);
    max-height: 90vh;
    overflow-y: auto;
    padding: 20px 16px;
  }
  .modal-overlay { align-items: flex-end; padding-bottom: 0; }

  /* Tablas: scroll horizontal */
  .tabla-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 500px; }

  /* Toast abajo centrado */
  #toast-container { left: 12px; right: 12px; bottom: 16px; }
  .toast { min-width: unset; width: 100%; }

  /* Botones en header de vista */
  .btn-sm { padding: 6px 10px; }

  /* Roles: layout de una columna */
  #roles-contenido > div { grid-template-columns: 1fr !important; }

  /* Plan tabs scroll horizontal */
  .plan-tab { padding: 8px 10px; font-size: 13px; }
}

@media (max-width: 400px) {
  .card-grid { grid-template-columns: 1fr; }
  .stat-value { font-size: 18px; }
}